github.com/vmware/govmomi@v0.51.0/cli/disk/detach.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package disk 6 7 import ( 8 "context" 9 "flag" 10 11 "github.com/vmware/govmomi/cli" 12 "github.com/vmware/govmomi/cli/flags" 13 ) 14 15 type detach struct { 16 *flags.VirtualMachineFlag 17 } 18 19 func init() { 20 cli.Register("disk.detach", &detach{}) 21 } 22 23 func (cmd *detach) Register(ctx context.Context, f *flag.FlagSet) { 24 cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) 25 cmd.VirtualMachineFlag.Register(ctx, f) 26 } 27 28 func (cmd *detach) Usage() string { 29 return "ID" 30 } 31 32 func (cmd *detach) Description() string { 33 return `Detach disk ID from VM. 34 35 See also: govc device.remove 36 37 Examples: 38 govc disk.detach -vm $vm ID` 39 } 40 41 func (cmd *detach) Run(ctx context.Context, f *flag.FlagSet) error { 42 if f.NArg() != 1 { 43 return flag.ErrHelp 44 } 45 46 vm, err := cmd.VirtualMachine() 47 if err != nil { 48 return err 49 } 50 51 id := f.Arg(0) 52 53 return vm.DetachDisk(ctx, id) 54 }