Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions cli/device/sata/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// © Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package sata

import (
"context"
"flag"
"fmt"

"github.com/vmware/govmomi/cli"
"github.com/vmware/govmomi/cli/flags"
)

type add struct {
*flags.VirtualMachineFlag
}

func init() {
cli.Register("device.sata.add", &add{})
}

func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
cmd.VirtualMachineFlag.Register(ctx, f)
}

func (cmd *add) Description() string {
return `Add SATA controller to VM.

Examples:
govc device.sata.add -vm $vm
govc device.info -vm $vm sata-*`
}

func (cmd *add) Process(ctx context.Context) error {
return cmd.VirtualMachineFlag.Process(ctx)
}

func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
vm, err := cmd.VirtualMachine()
if err != nil {
return err
}

if vm == nil {
return flag.ErrHelp
}

devices, err := vm.Device(ctx)
if err != nil {
return err
}

d, err := devices.CreateSATAController()
if err != nil {
return err
}

err = vm.AddDevice(ctx, d)
if err != nil {
return err
}
Comment on lines +61 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: consider changing this to if err := vm.AddDevice(ctx, d); err != nil { ... }?


devices, err = vm.Device(ctx)
if err != nil {
return err
}

devices = devices.SelectByType(d)

name := devices.Name(devices[len(devices)-1])

fmt.Println(name)

return nil
}
16 changes: 16 additions & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ but appear via `govc $cmd -h`:
- [device.pci.ls](#devicepcils)
- [device.pci.remove](#devicepciremove)
- [device.remove](#deviceremove)
- [device.sata.add](#devicesataadd)
- [device.scsi.add](#devicescsiadd)
- [device.serial.add](#deviceserialadd)
- [device.serial.connect](#deviceserialconnect)
Expand Down Expand Up @@ -2004,6 +2005,21 @@ Options:
-vm= Virtual machine [GOVC_VM]
```

## device.sata.add

```
Usage: govc device.sata.add [OPTIONS]

Add SATA controller to VM.

Examples:
govc device.sata.add -vm $vm
govc device.info -vm $vm sata-*

Options:
-vm= Virtual machine [GOVC_VM]
```

## device.scsi.add

```
Expand Down
1 change: 1 addition & 0 deletions govc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
_ "github.com/vmware/govmomi/cli/device/floppy"
_ "github.com/vmware/govmomi/cli/device/model"
_ "github.com/vmware/govmomi/cli/device/pci"
_ "github.com/vmware/govmomi/cli/device/sata"
_ "github.com/vmware/govmomi/cli/device/scsi"
_ "github.com/vmware/govmomi/cli/device/serial"
_ "github.com/vmware/govmomi/cli/device/usb"
Expand Down
13 changes: 13 additions & 0 deletions govc/test/device.bats
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ load test_helper
assert_failure "govc: device '$id' not found"
}

@test "device.sata" {
vcsim_env

vm=$(new_empty_vm)

run govc device.sata.add -vm $vm
assert_success
id=$output

result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
}

@test "device.scsi" {
vcsim_env

Expand Down
Loading