Skip to content

Commit

Permalink
govc: add vm.disk.attach '-profile' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Sep 4, 2024
1 parent 51105db commit e73c34f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions govc/vm/disk/attach.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-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 All @@ -30,6 +30,7 @@ import (
type attach struct {
*flags.DatastoreFlag
*flags.VirtualMachineFlag
*flags.StorageProfileFlag

persist bool
link bool
Expand All @@ -48,6 +49,8 @@ func (cmd *attach) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatastoreFlag.Register(ctx, f)
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
cmd.VirtualMachineFlag.Register(ctx, f)
cmd.StorageProfileFlag, ctx = flags.NewStorageProfileFlag(ctx)
cmd.StorageProfileFlag.Register(ctx, f)

f.BoolVar(&cmd.persist, "persist", true, "Persist attached disk")
f.BoolVar(&cmd.link, "link", true, "Link specified disk")
Expand All @@ -64,6 +67,9 @@ func (cmd *attach) Process(ctx context.Context) error {
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
return err
}
if err := cmd.StorageProfileFlag.Process(ctx); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -129,5 +135,10 @@ func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error {
backing.DiskMode = cmd.mode
}

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

return vm.AddDeviceWithProfile(ctx, profile, disk)
}

0 comments on commit e73c34f

Please sign in to comment.