Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/unikraft/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func instancesTests(t *testing.T, r *testRunner) {
})
})

t.Run("instances/volume", func(t *testing.T) {
t.Run("volume", func(t *testing.T) {
r.
online().
withCleaners(instanceCleaners).
Expand Down Expand Up @@ -230,7 +230,7 @@ func instancesTests(t *testing.T, r *testRunner) {
})
})

t.Run("instances/volume-inline", func(t *testing.T) {
t.Run("volume-inline", func(t *testing.T) {
r.
online().
withCleaners(instanceCleaners).
Expand All @@ -253,7 +253,7 @@ func instancesTests(t *testing.T, r *testRunner) {
})
})

t.Run("instances/autostart", func(t *testing.T) {
t.Run("autostart", func(t *testing.T) {
r.
online().
withCleaners(instanceCleaners).
Expand Down Expand Up @@ -306,7 +306,7 @@ func instancesTests(t *testing.T, r *testRunner) {
})
})

t.Run("instances/add-domain", func(t *testing.T) {
t.Run("add-domain", func(t *testing.T) {
r.
online().
withCleaners(instanceCleaners).
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/unikraft/testdata/TestGolden/instances/connect

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions cmd/unikraft/testdata/TestGolden/instances/help

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/unikraft/testdata/TestGolden/volumes/import/serve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 6 additions & 22 deletions internal/cmd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (c *CertificateCreateCmd) Run(ctx context.Context, stdio config.Stdio, sand
}

type Certificate struct {
MetroName string `mirror:"metro.name" field:"metro,short" create:"set,required"`
Name string `mirror:"certificate.name" field:",short" create:"set"`
UUID string `mirror:"certificate.uuid" field:",long"`
MetroName LinkName[Metro] `mirror:"metro.name" field:"metro,short" create:"set,required"`
Name string `mirror:"certificate.name" field:",short" create:"set"`
UUID string `mirror:"certificate.uuid" field:",long"`

CommonName string `mirror:"certificate.common_name" field:",short"`
Subject string `mirror:"certificate.subject" field:",long"`
Expand Down Expand Up @@ -103,24 +103,8 @@ func (c Certificate) Raw() any {
}

func (c Certificate) Fields(ctx context.Context) ([]resource.Field, error) {
c.MetroName = defaultMetro(ctx, c.MetroName)
result, err := resource.FieldsFromStruct(c)
if err != nil {
return nil, err
}

for key, field := range resource.IterFields(result) {
if key.String() == "metro" {
if c.MetroName != "" {
field.Links = append(field.Links, resource.Link{
Type: "metro",
Key: c.MetroName,
})
}
}
}

return result, nil
c.MetroName = LinkName[Metro](defaultMetro(ctx, string(c.MetroName)))
return resource.FieldsFromStruct(c)
}

func (Certificate) List(ctx context.Context) ([]resource.Resource, error) {
Expand Down Expand Up @@ -245,7 +229,7 @@ func (Certificate) Create(ctx context.Context, fields []resource.Field) ([]resou
name := field.Create.Set.(string)
req.Name = &name
case "metro":
metro = field.Create.Set.(string)
metro = string(field.Create.Set.(LinkName[Metro]))
case "cn":
req.Cn = new(field.Create.Set.(string)) //nolint:staticcheck // CommonName not on stable yet
case "chain":
Expand Down
50 changes: 4 additions & 46 deletions internal/cmd/instance_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func (c *InstanceTemplateEditCmd) Run(ctx context.Context, stdio config.Stdio, s
}

type InstanceTemplate struct {
MetroName string `mirror:"metro.name" field:"metro,short"`
Name string `mirror:"instance.name" field:",short"`
UUID string `mirror:"instance.uuid" field:",long"`
MetroName LinkName[Metro] `mirror:"metro.name" field:"metro,short"`
Name string `mirror:"instance.name" field:",short"`
UUID string `mirror:"instance.uuid" field:",long"`

Tags []string `mirror:"instance.tags" edit:"set,add,del"`
DeleteLock bool `mirror:"instance.delete_lock" field:"delete-lock,hidden" edit:"set"`
Expand Down Expand Up @@ -131,49 +131,7 @@ func (i InstanceTemplate) Raw() any {
}

func (i InstanceTemplate) Fields(ctx context.Context) ([]resource.Field, error) {
result, err := resource.FieldsFromStruct(i)
if err != nil {
return nil, err
}

for key, field := range resource.IterFields(result) {
switch {
case key.String() == "metro":
if i.MetroName != "" {
field.Links = append(field.Links, resource.Link{
Type: "metro",
Key: i.MetroName,
})
}
case key.MatchesString("volumes.*"):
if i.Metro == nil {
break
}
nameField, _ := field.Get("name")
uuidField, _ := field.Get("uuid")
name, _ := nameField.Value.(string)
uuid, _ := uuidField.Value.(string)
if name != "" || uuid != "" {
field.Links = append(field.Links, resource.Link{
Type: "volume",
Key: multimetro.Key{
Metro: i.Metro.Name,
Name: name,
UUID: uuid,
}.String(),
})
}
case key.String() == "image":
if i.Image.Reference != nil {
field.Links = append(field.Links, resource.Link{
Type: "image",
Key: i.Image.Reference.String(),
})
}
}
}

return result, nil
return resource.FieldsFromStruct(i)
}

func (InstanceTemplate) List(ctx context.Context) ([]resource.Resource, error) {
Expand Down
65 changes: 8 additions & 57 deletions internal/cmd/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func (c *InstanceEditCmd) Run(ctx context.Context, stdio config.Stdio, sandbox *
}

type Instance struct {
MetroName string `mirror:"metro.name" field:"metro,short" create:"set,required"`
Name string `mirror:"instance.name" field:",short" create:"set"`
UUID string `mirror:"instance.uuid" field:",long"`
MetroName LinkName[Metro] `mirror:"metro.name" field:"metro,short" create:"set,required"`
Name string `mirror:"instance.name" field:",short" create:"set"`
UUID string `mirror:"instance.uuid" field:",long"`

Tags []string `mirror:"instance.tags"`

Expand Down Expand Up @@ -197,9 +197,7 @@ type Instance struct {
}

type InstanceService struct {
Metro string `field:"-"`
UUID string `mirror:"uuid" field:",long"`
Name string `mirror:"name" field:",long"`
Link[ServiceGroup]
Services []*Service `mirror:"services" field:",invisible,valueless" create:"set"`
Domains []Domain `mirror:"domains" field:",short,embed" create:"set"`
SoftLimit uint32 `field:"soft-limit,invisible,valueless" create:"set"`
Expand Down Expand Up @@ -240,8 +238,7 @@ func (i *InstanceService) UnmarshalJSON(data []byte) error {
}

type InstanceVolume struct {
UUID string `name:"uuid" mirror:"uuid" json:"uuid,omitempty" field:",long"`
Name string `name:"name" mirror:"name" json:"name,omitempty" field:",long"`
Link[Volume]
At string `name:"at" mirror:"at" json:"at" field:",long"`
Readonly bool `name:"readonly" mirror:"readonly" json:"readonly,omitempty" field:",long"`

Expand Down Expand Up @@ -453,61 +450,15 @@ func (i Instance) Raw() any {
}

func (i Instance) Fields(ctx context.Context) ([]resource.Field, error) {
i.MetroName = defaultMetro(ctx, i.MetroName)
i.MetroName = LinkName[Metro](defaultMetro(ctx, string(i.MetroName)))
result, err := resource.FieldsFromStruct(i)
if err != nil {
return nil, err
}

for key, field := range resource.IterFields(result) {
switch {
case key.String() == "name":
if key.String() == "name" {
field.Hyperlink = i.hyperlink()
case key.String() == "metro":
if i.MetroName != "" {
field.Links = append(field.Links, resource.Link{
Type: "metro",
Key: i.MetroName,
})
}
case key.String() == "service":
nameField, _ := field.Get("name")
uuidField, _ := field.Get("uuid")
name, _ := nameField.Value.(string)
uuid, _ := uuidField.Value.(string)
if name != "" || uuid != "" {
field.Links = append(field.Links, resource.Link{
Type: "service",
Key: multimetro.Key{
Metro: i.Metro.Name,
Name: name,
UUID: uuid,
}.String(),
})
}
case key.MatchesString("volumes.*"):
// Add link to volume resource
nameField, _ := field.Get("name")
uuidField, _ := field.Get("uuid")
name, _ := nameField.Value.(string)
uuid, _ := uuidField.Value.(string)
if name != "" || uuid != "" {
field.Links = append(field.Links, resource.Link{
Type: "volume",
Key: multimetro.Key{
Metro: i.Metro.Name,
Name: name,
UUID: uuid,
}.String(),
})
}
case key.String() == "image":
if i.Image.Reference != nil {
field.Links = append(field.Links, resource.Link{
Type: "image",
Key: i.Image.Reference.String(),
})
}
}
}

Expand Down Expand Up @@ -782,7 +733,7 @@ func (Instance) Create(ctx context.Context, fields []resource.Field) ([]resource
name := field.Create.Set.(string)
req.Name = &name
case "metro":
metro = field.Create.Set.(string)
metro = string(field.Create.Set.(LinkName[Metro]))
case "image":
req.Image = new(field.Create.Set.(types.ImageRef[reference.Named]).Reference.String())
case "runtime.args":
Expand Down
Loading
Loading