Skip to content

Commit 6ac91ac

Browse files
committed
vcsim: add vslm VStorageObjectManager (aka FCD Global Catalog) support
govc: make datastore (-ds flag) optional in (most) disk commands Fixes #2542 Signed-off-by: Doug MacEachern <[email protected]>
1 parent 8eb362f commit 6ac91ac

25 files changed

+1053
-371
lines changed

cli/disk/attach.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package disk
186

@@ -22,7 +10,6 @@ import (
2210

2311
"github.com/vmware/govmomi/cli"
2412
"github.com/vmware/govmomi/cli/flags"
25-
"github.com/vmware/govmomi/vim25/mo"
2613
)
2714

2815
type attach struct {
@@ -67,7 +54,7 @@ func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error {
6754
return flag.ErrHelp
6855
}
6956

70-
ds, err := cmd.DatastoreIfSpecified()
57+
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
7158
if err != nil {
7259
return err
7360
}
@@ -77,21 +64,7 @@ func (cmd *attach) Run(ctx context.Context, f *flag.FlagSet) error {
7764
return err
7865
}
7966

80-
if ds == nil {
81-
var props mo.VirtualMachine
82-
err = vm.Properties(ctx, vm.Reference(), []string{"datastore"}, &props)
83-
if err != nil {
84-
return err
85-
}
86-
if len(props.Datastore) != 1 {
87-
ds, err = cmd.Datastore() // likely results in MultipleFoundError
88-
if err != nil {
89-
return err
90-
}
91-
}
92-
}
93-
9467
id := f.Arg(0)
9568

96-
return vm.AttachDisk(ctx, id, ds, 0, nil)
69+
return m.AttachDisk(ctx, vm, id)
9770
}

cli/disk/create.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package disk
186

@@ -27,7 +15,6 @@ import (
2715
"github.com/vmware/govmomi/units"
2816
"github.com/vmware/govmomi/vim25/mo"
2917
"github.com/vmware/govmomi/vim25/types"
30-
"github.com/vmware/govmomi/vslm"
3118
)
3219

3320
type disk struct {
@@ -92,7 +79,7 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
9279
return flag.ErrHelp
9380
}
9481

95-
c, err := cmd.DatastoreFlag.Client()
82+
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
9683
if err != nil {
9784
return err
9885
}
@@ -120,8 +107,6 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
120107
return err
121108
}
122109

123-
m := vslm.NewObjectManager(c)
124-
125110
spec := types.VslmCreateSpec{
126111
Name: name,
127112
CapacityInMB: int64(cmd.size) / units.MB,
@@ -136,25 +121,17 @@ func (cmd *disk) Run(ctx context.Context, f *flag.FlagSet) error {
136121
}
137122

138123
if cmd.StoragePodFlag.Isset() {
139-
if err = m.PlaceDisk(ctx, &spec, pool.Reference()); err != nil {
124+
if err = m.ObjectManager.PlaceDisk(ctx, &spec, pool.Reference()); err != nil {
140125
return err
141126
}
142127
}
143128

144-
task, err := m.CreateDisk(ctx, spec)
145-
if err != nil {
146-
return nil
147-
}
148-
149-
logger := cmd.DatastoreFlag.ProgressLogger(fmt.Sprintf("Creating %s...", spec.Name))
150-
151-
res, err := task.WaitForResult(ctx, logger)
152-
logger.Wait()
129+
obj, err := m.CreateDisk(ctx, spec)
153130
if err != nil {
154131
return err
155132
}
156133

157-
fmt.Println(res.Result.(types.VStorageObject).Config.Id.Id)
134+
fmt.Println(obj.Config.Id.Id)
158135

159136
return nil
160137
}

cli/disk/detach.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package disk
186

cli/disk/ls.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package disk
186

@@ -30,7 +18,6 @@ import (
3018
"github.com/vmware/govmomi/fault"
3119
"github.com/vmware/govmomi/units"
3220
"github.com/vmware/govmomi/vim25/types"
33-
"github.com/vmware/govmomi/vslm"
3421
)
3522

3623
type ls struct {
@@ -123,23 +110,13 @@ func (r *lsResult) Dump() interface{} {
123110
}
124111

125112
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
126-
c, err := cmd.Client()
127-
if err != nil {
128-
return err
129-
}
130-
131-
ds, err := cmd.Datastore()
113+
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
132114
if err != nil {
133115
return err
134116
}
135117

136-
m := vslm.NewObjectManager(c)
137118
if cmd.r {
138-
task, err := m.ReconcileDatastoreInventory(ctx, ds)
139-
if err != nil {
140-
return err
141-
}
142-
if err = task.Wait(ctx); err != nil {
119+
if err = m.ReconcileDatastoreInventory(ctx); err != nil {
143120
return err
144121
}
145122
}
@@ -151,7 +128,7 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
151128
filterNotFound = true
152129
var oids []types.ID
153130
if cmd.category == "" {
154-
oids, err = m.List(ctx, ds)
131+
oids, err = m.List(ctx)
155132
} else {
156133
oids, err = m.ListAttachedObjects(ctx, cmd.category, cmd.tag)
157134
}
@@ -165,7 +142,7 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
165142
}
166143

167144
for _, id := range ids {
168-
o, err := m.Retrieve(ctx, ds, id)
145+
o, err := m.Retrieve(ctx, id)
169146
if err != nil {
170147
if filterNotFound && fault.Is(err, &types.NotFound{}) {
171148
// The case when an FCD is deleted by something other than DeleteVStorageObject_Task, such as VM destroy

0 commit comments

Comments
 (0)