Skip to content

Commit

Permalink
govc: add disk.create '-profile' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Sep 4, 2024
1 parent ea3cf25 commit 8fd8691
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 15 additions & 2 deletions govc/disk/create.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2018 VMware, Inc. All Rights Reserved.
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -34,6 +34,7 @@ type disk struct {
*flags.DatastoreFlag
*flags.ResourcePoolFlag
*flags.StoragePodFlag
*flags.StorageProfileFlag

size units.ByteSize
keep *bool
Expand All @@ -50,6 +51,9 @@ func (cmd *disk) Register(ctx context.Context, f *flag.FlagSet) {
cmd.StoragePodFlag, ctx = flags.NewStoragePodFlag(ctx)
cmd.StoragePodFlag.Register(ctx, f)

cmd.StorageProfileFlag, ctx = flags.NewStorageProfileFlag(ctx)
cmd.StorageProfileFlag.Register(ctx, f)

cmd.ResourcePoolFlag, ctx = flags.NewResourcePoolFlag(ctx)
cmd.ResourcePoolFlag.Register(ctx, f)

Expand All @@ -65,6 +69,9 @@ func (cmd *disk) Process(ctx context.Context) error {
if err := cmd.StoragePodFlag.Process(ctx); err != nil {
return err
}
if err := cmd.StorageProfileFlag.Process(ctx); err != nil {
return err
}
return cmd.ResourcePoolFlag.Process(ctx)
}

Expand Down Expand Up @@ -108,12 +115,18 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
}
}

profile, err := cmd.StorageProfileSpec(ctx)
if err != nil {
return err
}

m := vslm.NewObjectManager(c)

spec := types.VslmCreateSpec{
Name: name,
CapacityInMB: int64(cmd.size) / units.MB,
KeepAfterDeleteVm: cmd.keep,
Profile: profile,
BackingSpec: &types.VslmCreateSpecDiskFileBackingSpec{
VslmCreateSpecBackingSpec: types.VslmCreateSpecBackingSpec{
Datastore: ds.Reference(),
Expand Down
7 changes: 7 additions & 0 deletions govc/test/disk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ load test_helper

run govc disk.rm "$id"
assert_failure

name=$(new_id)
run govc disk.create -profile enoent "$name"
assert_failure # profile does not exist

run govc disk.create -profile "vSAN Default Storage Policy" "$name"
assert_success
}

@test "disk.create -datastore-cluster" {
Expand Down

0 comments on commit 8fd8691

Please sign in to comment.