Skip to content

Commit

Permalink
feat: add ova ProductSection to ova provider server resp
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Shad Nik <[email protected]>
  • Loading branch information
arturshadnik committed Nov 28, 2024
1 parent 4d6a3f1 commit 1945072
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/ova-provider-server/ova-provider-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type VirtualSystem struct {
OsType string `xml:"osType,attr"`
} `xml:"OperatingSystemSection"`
HardwareSection VirtualHardwareSection `xml:"VirtualHardwareSection"`
Product ProductSection `xml:"ProductSection"`
}

type Envelope struct {
Expand All @@ -119,6 +120,28 @@ type Envelope struct {
References References `xml:"References"`
}

type ProductSection struct {
Property []Property `xml:"Property"`
}

type Property struct {
Key string `xml:"key,attr"`
Type string `xml:"type,attr"`
Qualifiers *string `xml:"qualifiers,attr"`
UserConfigurable *bool `xml:"userConfigurable,attr"`
Default *string `xml:"value,attr"`
Password *bool `xml:"password,attr"`

Label *string `xml:"Label"`
Description *string `xml:"Description"`

Values []PropertyConfigurationValue `xml:"Value"`
}

type PropertyConfigurationValue struct {
Value string `xml:"value,attr"`
}

// vm struct
type VM struct {
Name string
Expand Down Expand Up @@ -147,6 +170,7 @@ type VM struct {
NICs []NIC
Disks []VmDisk
Networks []VmNetwork
Product ProductSection
}

// Virtual Disk.
Expand Down Expand Up @@ -440,6 +464,7 @@ func convertToVmStruct(envelope []Envelope, ovaPath []string) ([]VM, error) {
OvaPath: ovaPath[i],
Name: virtualSystem.Name,
OsType: virtualSystem.OperatingSystemSection.OsType,
Product: virtualSystem.Product,
}

for _, item := range virtualSystem.HardwareSection.Items {
Expand Down
37 changes: 37 additions & 0 deletions pkg/controller/provider/container/ova/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ type VM struct {
Name string `json:"Name"`
Description string `json:"Description"`
} `json:"Networks"`
Product struct {
Property []struct {
Key string `json:"Key"`
Type string `json:"Type"`
Qualifiers *string `json:"Qualifiers"`
UserConfigurable *bool `json:"UserConfigurable"`
Default *string `json:"Default"`
Password *bool `json:"Password"`
Label *string `json:"Label"`
Description *string `json:"Description"`
Values []struct {
Value string `json:"Value"`
} `json:"Values"`
} `json:"Property"`
} `json:"Product"`
}

// Apply to (update) the model.
Expand Down Expand Up @@ -91,6 +106,7 @@ func (r *VM) ApplyTo(m *model.VM) {
r.addDisks(m)
r.addDevices(m)
r.addNetworks(m)
r.addProduct(m)
}

func (r *VM) addNICs(m *model.VM) {
Expand Down Expand Up @@ -162,6 +178,27 @@ func (r *VM) addNetworks(m *model.VM) {
}
}

func (r *VM) addProduct(m *model.VM) {
m.Product = model.Product{}
for _, property := range r.Product.Property {
values := []model.PropertyConfigurationValue{}
for _, value := range property.Values {
values = append(values, model.PropertyConfigurationValue{Value: value.Value})
}
m.Product.Property = append(m.Product.Property, model.Property{
Key: property.Key,
Type: property.Type,
Qualifiers: property.Qualifiers,
UserConfigurable: property.UserConfigurable,
Default: property.Default,
Password: property.Password,
Label: property.Label,
Description: property.Description,
Values: values,
})
}
}

// Network.
type Network struct {
ID string `json:"ID"`
Expand Down
23 changes: 23 additions & 0 deletions pkg/controller/provider/model/ova/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ type VM struct {
Disks []Disk `sql:""`
Networks []Network `sql:""`
Concerns []Concern `sql:""`
Product Product `sql:""`
}

type Product struct {
Property []Property `sql:""`
}

type Property struct {
Key string `sql:""`
Type string `sql:""`
Qualifiers *string `sql:""`
UserConfigurable *bool `sql:""`
Default *string `sql:""`
Password *bool `sql:""`

Label *string `sql:""`
Description *string `sql:""`

Values []PropertyConfigurationValue `sql:""`
}

type PropertyConfigurationValue struct {
Value string `sql:""`
}

// Virtual Disk.
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/provider/web/ova/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ type VM struct {
NICs []model.NIC `json:"nics"`
Disks []model.Disk `json:"disks"`
Networks []model.Network `json:"networks"`
Product model.Product `json:"product"`
}

// Build the resource using the model.
Expand Down Expand Up @@ -255,6 +256,7 @@ func (r *VM) With(m *model.VM) {
r.OvaPath = m.OvaPath
r.Disks = m.Disks
r.Networks = m.Networks
r.Product = m.Product
}

// Build self link (URI).
Expand Down

0 comments on commit 1945072

Please sign in to comment.