Skip to content

Commit a447f4d

Browse files
committedJan 2, 2025·
api: Fix OVF param to use interface
The OVF import function now uses BaseOvfCreateImportSpec and all of its callers needed to be updated. Signed-off-by: akutz <andrew.kutz@broadcom.com>
1 parent 17b5c08 commit a447f4d

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed
 

‎ovf/importer/importer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (imp *Importer) Import(ctx context.Context, fpath string, opts Options) (*t
126126
}
127127

128128
m := ovf.NewManager(imp.Client)
129-
spec, err := m.CreateImportSpec(ctx, string(o), imp.ResourcePool, imp.Datastore, cisp)
129+
spec, err := m.CreateImportSpec(ctx, string(o), imp.ResourcePool, imp.Datastore, &cisp)
130130
if err != nil {
131131
return nil, err
132132
}

‎ovf/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (m *Manager) CreateDescriptor(ctx context.Context, obj mo.Reference, cdp ty
5252
}
5353

5454
// CreateImportSpec wraps methods.CreateImportSpec
55-
func (m *Manager) CreateImportSpec(ctx context.Context, ovfDescriptor string, resourcePool mo.Reference, datastore mo.Reference, cisp types.OvfCreateImportSpecParams) (*types.OvfCreateImportSpecResult, error) {
55+
func (m *Manager) CreateImportSpec(ctx context.Context, ovfDescriptor string, resourcePool mo.Reference, datastore mo.Reference, cisp types.BaseOvfCreateImportSpecParams) (*types.OvfCreateImportSpecResult, error) {
5656
req := types.CreateImportSpec{
5757
This: m.Reference(),
5858
OvfDescriptor: ovfDescriptor,

‎simulator/ovf_manager.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ func ovfNetwork(ctx *Context, req *types.CreateImportSpec, item ovf.ResourceAllo
5353
ref := ctx.Map.getEntityDatacenter(pool).defaultNetwork()[0] // Default to VM Network
5454
c := item.Connection[0]
5555

56-
for _, net := range req.Cisp.NetworkMapping {
56+
cisp := req.Cisp.GetOvfCreateImportSpecParams()
57+
58+
for _, net := range cisp.NetworkMapping {
5759
if net.Name == c {
5860
ref = net.Network
5961
break
@@ -109,12 +111,14 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
109111
return body
110112
}
111113

114+
cisp := req.Cisp.GetOvfCreateImportSpecParams()
115+
112116
ds := ctx.Map.Get(req.Datastore).(*Datastore)
113117
path := object.DatastorePath{Datastore: ds.Name}
114118
vapp := &types.VAppConfigSpec{}
115119
spec := &types.VirtualMachineImportSpec{
116120
ConfigSpec: types.VirtualMachineConfigSpec{
117-
Name: req.Cisp.EntityName,
121+
Name: cisp.EntityName,
118122
Version: esx.HardwareVersion,
119123
GuestId: string(types.VirtualMachineGuestOsIdentifierOtherGuest),
120124
Files: &types.VirtualMachineFileInfo{
@@ -148,7 +152,7 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
148152
key := product.Key(p)
149153
val := ""
150154

151-
for _, m := range req.Cisp.PropertyMapping {
155+
for _, m := range cisp.PropertyMapping {
152156
if m.Key == key {
153157
val = m.Value
154158
}
@@ -176,10 +180,10 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
176180
}
177181
}
178182

179-
if req.Cisp.DeploymentOption == "" && env.DeploymentOption != nil {
183+
if cisp.DeploymentOption == "" && env.DeploymentOption != nil {
180184
for _, c := range env.DeploymentOption.Configuration {
181185
if isTrue(c.Default) {
182-
req.Cisp.DeploymentOption = c.ID
186+
cisp.DeploymentOption = c.ID
183187
break
184188
}
185189
}
@@ -206,8 +210,8 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
206210
resources := make(map[string]types.BaseVirtualDevice)
207211

208212
for _, item := range hw.Item {
209-
if req.Cisp.DeploymentOption != "" && item.Configuration != nil {
210-
if req.Cisp.DeploymentOption != *item.Configuration {
213+
if cisp.DeploymentOption != "" && item.Configuration != nil {
214+
if cisp.DeploymentOption != *item.Configuration {
211215
continue
212216
}
213217
}
@@ -232,7 +236,7 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
232236

233237
upload := func(file ovf.File, c types.BaseVirtualDevice, n int) {
234238
result.FileItem = append(result.FileItem, types.OvfFileItem{
235-
DeviceId: fmt.Sprintf("/%s/%s:%d", req.Cisp.EntityName, device.Type(c), n),
239+
DeviceId: fmt.Sprintf("/%s/%s:%d", cisp.EntityName, device.Type(c), n),
236240
Path: file.Href,
237241
Size: int64(file.Size),
238242
CimType: int32(*item.ResourceType),
@@ -289,7 +293,7 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
289293
if len(item.HostResource) != 0 {
290294
for _, file := range env.References {
291295
if strings.HasSuffix(item.HostResource[0], file.ID) {
292-
path.Path = fmt.Sprintf("%s/_deviceImage%d.iso", req.Cisp.EntityName, ndev)
296+
path.Path = fmt.Sprintf("%s/_deviceImage%d.iso", cisp.EntityName, ndev)
293297
device.InsertIso(d, path.String())
294298
upload(file, d, ndev)
295299
break
@@ -303,10 +307,10 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
303307
if !ok {
304308
continue // Parent is unsupported()
305309
}
306-
path.Path = fmt.Sprintf("%s/disk-%d.vmdk", req.Cisp.EntityName, ndisk)
310+
path.Path = fmt.Sprintf("%s/disk-%d.vmdk", cisp.EntityName, ndisk)
307311
d := device.CreateDisk(c.(types.BaseVirtualController), ds.Reference(), path.String())
308312

309-
switch types.OvfCreateImportSpecParamsDiskProvisioningType(req.Cisp.DiskProvisioning) {
313+
switch types.OvfCreateImportSpecParamsDiskProvisioningType(cisp.DiskProvisioning) {
310314
case "",
311315
types.OvfCreateImportSpecParamsDiskProvisioningTypeMonolithicFlat,
312316
types.OvfCreateImportSpecParamsDiskProvisioningTypeFlat,
@@ -321,9 +325,9 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
321325
default:
322326
result.Error = append(result.Error, types.LocalizedMethodFault{
323327
Fault: &types.OvfUnsupportedDiskProvisioning{
324-
DiskProvisioning: req.Cisp.DiskProvisioning,
328+
DiskProvisioning: cisp.DiskProvisioning,
325329
},
326-
LocalizedMessage: "Disk provisioning type not supported: " + req.Cisp.DiskProvisioning,
330+
LocalizedMessage: "Disk provisioning type not supported: " + cisp.DiskProvisioning,
327331
})
328332
}
329333

@@ -349,7 +353,7 @@ func (m *OvfManager) CreateImportSpec(ctx *Context, req *types.CreateImportSpec)
349353

350354
spec.ConfigSpec.DeviceChange, _ = device.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
351355

352-
for _, p := range req.Cisp.PropertyMapping {
356+
for _, p := range cisp.PropertyMapping {
353357
spec.ConfigSpec.ExtraConfig = append(spec.ConfigSpec.ExtraConfig, &types.OptionValue{
354358
Key: p.Key,
355359
Value: p.Value,

‎vapi/simulator/simulator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ func (s *handler) libraryDeploy(ctx context.Context, c *vim25.Client, lib *libra
26142614
}
26152615

26162616
m := ovf.NewManager(c)
2617-
spec, err := m.CreateImportSpec(ctx, string(desc), pool, ds, cisp)
2617+
spec, err := m.CreateImportSpec(ctx, string(desc), pool, ds, &cisp)
26182618
if err != nil {
26192619
return nil, err
26202620
}

‎vmdk/import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func Import(ctx context.Context, c *vim25.Client, name string, datastore *object
263263
EntityName: disk.ImportName,
264264
}
265265

266-
spec, err := m.CreateImportSpec(ctx, descriptor, pool, datastore, params)
266+
spec, err := m.CreateImportSpec(ctx, descriptor, pool, datastore, &params)
267267
if err != nil {
268268
return err
269269
}

0 commit comments

Comments
 (0)
Please sign in to comment.