Skip to content

Commit

Permalink
fix: govc: disambiguate vm/host search flags in vm.migrate
Browse files Browse the repository at this point in the history
PR #2850 fix a search flag issue with the vm.clone command, but caused an issue with the vm.migrate command.
Rather than embed the SearchFlag directly, vm.migrate needs to embed the VirtualMachineFlag

Issue #2849
  • Loading branch information
dougm committed Jun 1, 2022
1 parent 0f1f07e commit 310516e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5905,6 +5905,7 @@ Options:
-host= Host system [GOVC_HOST]
-pool= Resource pool [GOVC_RESOURCE_POOL]
-priority=defaultPriority The task priority
-vm= Virtual machine [GOVC_VM]
```

## vm.network.add
Expand Down
2 changes: 1 addition & 1 deletion govc/test/vm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ load test_helper
vm="DC0_H0_VM0"
clone=$(new_id)

run govc vm.clone -vm "$vm" -annotation $$ "$clone"
run govc vm.clone -vm "$vm" -host.ipath /DC0/host/DC0_C0/DC0_C0_H0 -annotation $$ "$clone"
assert_success

backing=$(govc device.info -json -vm "$clone" disk-* | jq .Devices[].Backing)
Expand Down
11 changes: 7 additions & 4 deletions govc/vm/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type migrate struct {
*flags.ResourcePoolFlag
*flags.HostSystemFlag
*flags.DatastoreFlag
*flags.SearchFlag
*flags.VirtualMachineFlag

priority types.VirtualMachineMovePriority
spec types.VirtualMachineRelocateSpec
Expand All @@ -46,8 +46,8 @@ func (cmd *migrate) Register(ctx context.Context, f *flag.FlagSet) {
cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
cmd.FolderFlag.Register(ctx, f)

cmd.SearchFlag, ctx = flags.NewSearchFlag(ctx, flags.SearchVirtualMachines)
cmd.SearchFlag.Register(ctx, f)
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
cmd.VirtualMachineFlag.Register(ctx, f)

cmd.ResourcePoolFlag, ctx = flags.NewResourcePoolFlag(ctx)
cmd.ResourcePoolFlag.Register(ctx, f)
Expand All @@ -65,6 +65,9 @@ func (cmd *migrate) Process(ctx context.Context) error {
if err := cmd.FolderFlag.Process(ctx); err != nil {
return err
}
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
return err
}
if err := cmd.ResourcePoolFlag.Process(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +112,7 @@ func (cmd *migrate) relocate(ctx context.Context, vm *object.VirtualMachine) err
}

func (cmd *migrate) Run(ctx context.Context, f *flag.FlagSet) error {
vms, err := cmd.VirtualMachines(f.Args())
vms, err := cmd.VirtualMachineFlag.VirtualMachines(f.Args())
if err != nil {
return err
}
Expand Down

0 comments on commit 310516e

Please sign in to comment.