github.com/vmware/govmomi@v0.51.0/cli/disk/attach.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 attach struct { 16 *flags.VirtualMachineFlag 17 *flags.DatastoreFlag 18 } 19 20 func init() { 21 cli.Register("disk.attach", &attach{}) 22 } 23 24 func (cmd *attach) Register(ctx context.Context, f *flag.FlagSet) { 25 cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) 26 cmd.VirtualMachineFlag.Register(ctx, f) 27 cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx) 28 cmd.DatastoreFlag.Register(ctx, f) 29 } 30 31 func (cmd *attach) Process(ctx context.Context) error { 32 if err := cmd.VirtualMachineFlag.Process(ctx); err != nil { 33 return err 34 } 35 return cmd.DatastoreFlag.Process(ctx) 36 } 37 38 func (cmd *attach) Usage() string { 39 return "ID" 40 } 41 42 func (cmd *attach) Description() string { 43 return `Attach disk ID on VM. 44 45 See also: govc vm.disk.attach 46 47 Examples: 48 govc disk.attach -vm $vm ID 49 govc disk.attach -vm $vm -ds $ds ID` 50 } 51 52 func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error { 53 if f.NArg() != 1 { 54 return flag.ErrHelp 55 } 56 57 m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag) 58 if err != nil { 59 return err 60 } 61 62 vm, err := cmd.VirtualMachine() 63 if err != nil { 64 return err 65 } 66 67 id := f.Arg(0) 68 69 return m.AttachDisk(ctx, vm, id) 70 }