Skip to content

Commit 2c2d11c

Browse files
committed
govc: Add datastore.cp disk format and adapter options
Same '-a' and '-d' flags as datastore.disk.create Fixes #3748 Signed-off-by: Doug MacEachern <[email protected]>
1 parent c803ab8 commit 2c2d11c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

cli/datastore/cp.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/vmware/govmomi/cli"
1313
"github.com/vmware/govmomi/cli/flags"
1414
"github.com/vmware/govmomi/object"
15+
"github.com/vmware/govmomi/vim25/types"
1516
)
1617

1718
type cp struct {
@@ -30,6 +31,7 @@ type target struct {
3031

3132
kind bool
3233
force bool
34+
spec types.VirtualDiskSpec
3335
}
3436

3537
func (cmd *target) FileManager() (*object.DatastoreFileManager, error) {
@@ -71,6 +73,8 @@ func (cmd *target) Register(ctx context.Context, f *flag.FlagSet) {
7173

7274
f.BoolVar(&cmd.kind, "t", true, "Use file type to choose disk or file manager")
7375
f.BoolVar(&cmd.force, "f", false, "If true, overwrite any identically named file at the destination")
76+
f.StringVar(&cmd.spec.AdapterType, "a", string(types.VirtualDiskAdapterTypeLsiLogic), "Disk adapter")
77+
f.StringVar(&cmd.spec.DiskType, "d", string(types.VirtualDiskTypeThin), "Disk format")
7478
}
7579

7680
func (cmd *target) Process(ctx context.Context) error {
@@ -130,7 +134,9 @@ func (cmd *cp) Run(ctx context.Context, f *flag.FlagSet) error {
130134

131135
cp := m.CopyFile
132136
if cmd.kind {
133-
cp = m.Copy
137+
cp = func(ctx context.Context, src string, dst string) error {
138+
return m.Copy(ctx, src, dst, &cmd.spec)
139+
}
134140
}
135141

136142
logger := cmd.ProgressLogger(fmt.Sprintf("Copying %s to %s...", src, dst))

govc/USAGE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ Examples:
13101310
govc datastore.cp disks/disk1.vmdk -ds-target NFS-2 disks/disk2.vmdk
13111311
13121312
Options:
1313+
-a=lsiLogic Disk adapter
1314+
-d=thin Disk format
13131315
-dc-target= Datacenter destination (defaults to -dc)
13141316
-ds= Datastore [GOVC_DATASTORE]
13151317
-ds-target= Datastore destination (defaults to -ds)
@@ -1536,6 +1538,8 @@ Examples:
15361538
govc datastore.mv -f my.vmx foo/foo.vmx
15371539
15381540
Options:
1541+
-a=lsiLogic Disk adapter
1542+
-d=thin Disk format
15391543
-dc-target= Datacenter destination (defaults to -dc)
15401544
-ds= Datastore [GOVC_DATASTORE]
15411545
-ds-target= Datastore destination (defaults to -ds)

govc/test/datastore.bats

+3
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ upload_file() {
363363
run govc datastore.rm -dc DC1 -ds LocalDS_1 "$clone"
364364
assert_success
365365
done
366+
367+
run govc datastore.cp -dc DC0 -ds LocalDS_0 -d preallocated "$vmdk" "$id/$id-thick.vmdk"
368+
assert_success
366369
}
367370

368371
@test "datastore.disk.info" {

0 commit comments

Comments
 (0)