From 39f5225235b753d4644dc5cea8eb9e0ad61b897e Mon Sep 17 00:00:00 2001 From: Artur Shad Nik Date: Wed, 20 Nov 2024 10:41:32 -0800 Subject: [PATCH] feat: add ova ProductSection to ova provider server resp Signed-off-by: Artur Shad Nik --- .../ova-provider-server.go | 25 +++++++++++++ .../provider/container/ova/resource.go | 37 +++++++++++++++++++ pkg/controller/provider/model/ova/model.go | 23 ++++++++++++ pkg/controller/provider/web/ova/vm.go | 2 + 4 files changed, 87 insertions(+) diff --git a/cmd/ova-provider-server/ova-provider-server.go b/cmd/ova-provider-server/ova-provider-server.go index b62156e4d..2e404136b 100644 --- a/cmd/ova-provider-server/ova-provider-server.go +++ b/cmd/ova-provider-server/ova-provider-server.go @@ -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 { @@ -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 @@ -147,6 +170,7 @@ type VM struct { NICs []NIC Disks []VmDisk Networks []VmNetwork + Product ProductSection } // Virtual Disk. @@ -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 { diff --git a/pkg/controller/provider/container/ova/resource.go b/pkg/controller/provider/container/ova/resource.go index 45d310a8e..63eba6a81 100644 --- a/pkg/controller/provider/container/ova/resource.go +++ b/pkg/controller/provider/container/ova/resource.go @@ -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. @@ -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) { @@ -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"` diff --git a/pkg/controller/provider/model/ova/model.go b/pkg/controller/provider/model/ova/model.go index 142e99b3e..216f4270c 100644 --- a/pkg/controller/provider/model/ova/model.go +++ b/pkg/controller/provider/model/ova/model.go @@ -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. diff --git a/pkg/controller/provider/web/ova/vm.go b/pkg/controller/provider/web/ova/vm.go index d801f6b42..27e3f18d8 100644 --- a/pkg/controller/provider/web/ova/vm.go +++ b/pkg/controller/provider/web/ova/vm.go @@ -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. @@ -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).