Skip to content

Commit

Permalink
Support Creating/Reconfiguring a simulator VM with VApp properties
Browse files Browse the repository at this point in the history
Currently, the simulator ignores any VApp properties in the VM
creation and Reconfigure workflows.

This change enables users to instantiate or Reconfigure a simulator VM
with VApp properties set. This commit also adds tests to validate the
workflows.

Closes: #2642
  • Loading branch information
aruneshpa committed Nov 12, 2021
1 parent f0985ac commit d3eaa9b
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 0 deletions.
55 changes: 55 additions & 0 deletions simulator/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,55 @@ func (vm *VirtualMachine) apply(spec *types.VirtualMachineConfigSpec) {
vm.Config.Modified = time.Now()
}

// updateVAppProperty updates the simulator VM with the specified VApp properties.
func (vm *VirtualMachine) updateVAppProperty(spec *types.VmConfigSpec) types.BaseMethodFault {
ps := make([]types.VAppPropertyInfo, 0)

if vm.Config.VAppConfig != nil && vm.Config.VAppConfig.GetVmConfigInfo() != nil {
ps = vm.Config.VAppConfig.GetVmConfigInfo().Property
}

for _, prop := range spec.Property {
var foundIndex int
exists := false
// Check if the specified property exists or not. This helps rejecting invalid
// operations (e.g., Adding a VApp property that already exists)
for i, p := range ps {
if p.Key == prop.Info.Key {
exists = true
foundIndex = i
break
}
}

switch prop.Operation {
case types.ArrayUpdateOperationAdd:
if exists {
return new(types.InvalidArgument)
}
ps = append(ps, *prop.Info)
case types.ArrayUpdateOperationEdit:
if !exists {
return new(types.InvalidArgument)
}
ps[foundIndex] = *prop.Info
case types.ArrayUpdateOperationRemove:
if !exists {
return new(types.InvalidArgument)
}
ps = append(ps[:foundIndex], ps[foundIndex+1:]...)
}
}

if vm.Config.VAppConfig == nil {
vm.Config.VAppConfig = &types.VmConfigInfo{}
}

vm.Config.VAppConfig.GetVmConfigInfo().Property = ps

return nil
}

var extraConfigAlias = map[string]string{
"ip0": "SET.guest.ipAddress",
}
Expand Down Expand Up @@ -413,6 +462,12 @@ func (vm *VirtualMachine) configure(ctx *Context, spec *types.VirtualMachineConf
}
}

if spec.VAppConfig != nil {
if err := vm.updateVAppProperty(spec.VAppConfig.GetVmConfigSpec()); err != nil {
return err
}
}

return vm.configureDevices(ctx, spec)
}

Expand Down
Loading

0 comments on commit d3eaa9b

Please sign in to comment.