Skip to content

Commit

Permalink
govc: add library.deploy '-config' flag
Browse files Browse the repository at this point in the history
As this feature is unreleased, the VM_CLASS_AS_CONFIG env var must be set to enable.
  • Loading branch information
dougm committed May 16, 2022
1 parent 3325da0 commit 9d4ca65
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions govc/cli/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var aliases = map[string]string{}
// Setting the env var GOVC_SHOW_UNRELEASED=true enables any commands registered as unreleased.
var hideUnreleased = os.Getenv("GOVC_SHOW_UNRELEASED") != "true"

func ShowUnreleased() bool {
return !hideUnreleased
}

func Register(name string, c Command, unreleased ...bool) {
if len(unreleased) != 0 && unreleased[0] && hideUnreleased {
return
Expand Down
13 changes: 13 additions & 0 deletions govc/library/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type deploy struct {
*importx.OptionsFlag

profile string
config string
}

func init() {
Expand All @@ -61,6 +62,10 @@ func (cmd *deploy) Register(ctx context.Context, f *flag.FlagSet) {
cmd.OptionsFlag.Register(ctx, f)

f.StringVar(&cmd.profile, "profile", "", "Storage profile")

if cli.ShowUnreleased() {
f.StringVar(&cmd.config, "config", "", "VM config spec")
}
}

func (cmd *deploy) Process(ctx context.Context) error {
Expand Down Expand Up @@ -220,6 +225,14 @@ func (cmd *deploy) Run(ctx context.Context, f *flag.FlagSet) error {
FolderID: folder.Reference().Value,
},
}

if cmd.config != "" {
deploy.VmConfigSpec = &vcenter.VmConfigSpec{
Provider: "XML",
XML: cmd.config,
}
}

ref, err = m.DeployLibraryItem(ctx, item.ID, deploy)
if err != nil {
return err
Expand Down
16 changes: 16 additions & 0 deletions govc/test/library.bats
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,29 @@ EOF
run govc vm.info -r ttylinux2
assert_success
assert_matches DC0_DVPG0
assert_matches 32MB
assert_matches "1 vCPU"

run env GOVC_DATASTORE="" govc library.deploy "my-content/$TTYLINUX_NAME" ttylinux3 # datastore is not required
assert_success

run govc vm.destroy ttylinux ttylinux2 ttylinux3
assert_success

config=$(base64 <<<'
<obj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="vim25:VirtualMachineConfigSpec" xmlns:vim25="urn:vim25">
<numCPUs>4</numCPUs>
<memoryMB>2048</memoryMB>
</obj>')

run env GOVC_SHOW_UNRELEASED=true govc library.deploy -config "$config" "my-content/$TTYLINUX_NAME" ttylinux
assert_success

run govc vm.info -r ttylinux
assert_success
assert_matches 2048MB
assert_matches "4 vCPU"

item_id=$(govc library.info -json "/my-content/$TTYLINUX_NAME" | jq -r .[].id)

run govc datastore.rm "contentlib-$library_id/$item_id" # remove library files out-of-band, forcing a deploy error below
Expand Down

0 comments on commit 9d4ca65

Please sign in to comment.