Skip to content

Commit

Permalink
Merge pull request #3576 from dougm/issue-3572
Browse files Browse the repository at this point in the history
vcsim: support clearing ManagedBy field
  • Loading branch information
dougm authored Oct 6, 2024
2 parents 9d9997a + 7daac37 commit 3177dc0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6477,6 +6477,7 @@ Options:
-iommu-enabled=<nil> Enable IOMMU
-latency= Latency sensitivity (low|normal|medium|high|custom)
-m=0 Size in MB of memory
-managed-by= Set or clear managed by VC Extension
-mem.limit=<nil> Memory limit in MB
-mem.reservation=<nil> Memory reservation in MB
-mem.shares= Memory shares level or number
Expand Down
15 changes: 15 additions & 0 deletions govc/test/vm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ load test_helper
run govc object.collect -s "vm/$id" config.uuid
assert_success "$uuid"

run govc vm.change -vm $id -managed-by com.vmware.govmomi.simulator
assert_success

run govc vm.info -json $id
assert_success

run govc object.collect -s "vm/$id" config.managedBy.extensionKey
assert_success com.vmware.govmomi.simulator

run govc vm.change -vm $id -managed-by -
assert_success

run govc object.collect -s "vm/$id" config.managedBy
assert_success ""

nid=$(new_id)
run govc vm.change -name $nid -vm $id
assert_success
Expand Down
14 changes: 14 additions & 0 deletions govc/vm/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type change struct {
extraConfigFile extraConfigFile
Latency string
hwUpgradePolicy string
managedBy string
}

func init() {
Expand Down Expand Up @@ -160,6 +161,7 @@ func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
f.StringVar(&cmd.Latency, "latency", "", fmt.Sprintf("Latency sensitivity (%s)", strings.Join(latencyLevels, "|")))
f.StringVar(&cmd.Annotation, "annotation", "", "VM description")
f.StringVar(&cmd.Uuid, "uuid", "", "BIOS UUID")
f.StringVar(&cmd.managedBy, "managed-by", "", "Set or clear managed by VC Extension")
f.Var(&cmd.extraConfig, "e", "ExtraConfig. <key>=<value>")
f.Var(&cmd.extraConfigFile, "f", "ExtraConfig. <key>=<absolute path to file>")

Expand Down Expand Up @@ -234,6 +236,18 @@ func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

if cmd.managedBy != "" {
// From the VirtualMachineConfigSpec doc:
// To unset this field pass a ManagedByInfo object with an empty extensionKey
if cmd.managedBy == "-" {
cmd.managedBy = ""
}
cmd.ManagedBy = &types.ManagedByInfo{
Type: vm.Reference().Type,
ExtensionKey: cmd.managedBy,
}
}

task, err := vm.Reconfigure(ctx, cmd.VirtualMachineConfigSpec)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions simulator/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ func (vm *VirtualMachine) apply(spec *types.VirtualMachineConfigSpec) {
}

if spec.ManagedBy != nil {
if spec.ManagedBy.ExtensionKey == "" {
spec.ManagedBy = nil
}
vm.Config.ManagedBy = spec.ManagedBy
vm.Summary.Config.ManagedBy = spec.ManagedBy
}

if spec.BootOptions != nil {
Expand Down

0 comments on commit 3177dc0

Please sign in to comment.