Skip to content

Commit

Permalink
Fix govc vm.clone -annotation flag
Browse files Browse the repository at this point in the history
The VM annotation would only be set if -c or -m were also specified.

Add -annotation flag to vm.change command.

Fixes vmware#1116
  • Loading branch information
dougm committed May 4, 2018
1 parent 97807f4 commit 1e0a01f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion govc/test/vm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ load test_helper
run govc object.collect -s "vm/$id" config.memoryAllocation.reservation
assert_success 1024

run govc vm.change -annotation $$ -vm "$id"
assert_success

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

nid=$(new_id)
run govc vm.change -name $nid -vm $id
assert_success
Expand Down Expand Up @@ -571,9 +577,12 @@ load test_helper
vm=$(new_empty_vm)
clone=$(new_id)

run govc vm.clone -vm "$vm" "$clone"
run govc vm.clone -vm "$vm" -annotation $$ "$clone"
assert_success

run govc object.collect -s "/$GOVC_DATACENTER/vm/$clone" config.annotation
assert_success $$

clone=$(new_id)
run govc vm.clone -vm "$vm" -snapshot X "$clone"
assert_failure
Expand Down
1 change: 1 addition & 0 deletions govc/vm/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
f.Var(flags.NewInt32(&cmd.NumCPUs), "c", "Number of CPUs")
f.StringVar(&cmd.GuestId, "g", "", "Guest OS")
f.StringVar(&cmd.Name, "name", "", "Display name")
f.StringVar(&cmd.Annotation, "annotation", "", "VM description")
f.Var(&cmd.extraConfig, "e", "ExtraConfig. <key>=<value>")

f.Var(flags.NewOptionalBool(&cmd.NestedHVEnabled), "nested-hv-enabled", "Enable nested hardware-assisted virtualization")
Expand Down
2 changes: 1 addition & 1 deletion govc/vm/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (cmd *clone) Run(ctx context.Context, f *flag.FlagSet) error {
return err
}

if cmd.cpus > 0 || cmd.memory > 0 {
if cmd.cpus > 0 || cmd.memory > 0 || cmd.annotation != "" {
vmConfigSpec := types.VirtualMachineConfigSpec{}
if cmd.cpus > 0 {
vmConfigSpec.NumCPUs = int32(cmd.cpus)
Expand Down

0 comments on commit 1e0a01f

Please sign in to comment.