Skip to content

Commit 6ac91ac

Browse files
committedJan 13, 2025·
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 <dougm@broadcom.com>
1 parent 8eb362f commit 6ac91ac

25 files changed

+1053
-371
lines changed
 

‎cli/disk/attach.go

+5-32
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

+7-30
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

+3-15
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

+7-30
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

‎cli/disk/manager.go

+309
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package disk
6+
7+
import (
8+
"context"
9+
"errors"
10+
"os"
11+
"time"
12+
13+
"github.com/vmware/govmomi/cli/flags"
14+
"github.com/vmware/govmomi/object"
15+
"github.com/vmware/govmomi/vim25"
16+
"github.com/vmware/govmomi/vim25/types"
17+
"github.com/vmware/govmomi/vslm"
18+
vslmtypes "github.com/vmware/govmomi/vslm/types"
19+
)
20+
21+
// Manager provides a layer for switching between Virtual Storage Object Manager (VSOM)
22+
// and Virtual Storage Lifecycle Manager (VSLM). The majority of VSOM methods require a
23+
// Datastore param, and most VSLM methods do not as it uses the "Global Catalog".
24+
// VSOM was introduced in vSphere 6.5 (11/2016) and VSLM in vSphere 6.7 U2 (04/2019).
25+
// The govc disk commands were introduced prior to 6.7 U2 and continue to use VSOM
26+
// when an optional Datastore (-ds flag) is provided. Otherwise, VSLM global methods
27+
// are used when a Datastore is not specified.
28+
// Also note that VSOM methods can be used when connected directly to an ESX hosts,
29+
// but VSLM global methods require vCenter.
30+
// A disk managed by these methods are also known as a "First Class Disk" (FCD).
31+
type Manager struct {
32+
Client *vim25.Client
33+
Datastore *object.Datastore
34+
ObjectManager *vslm.ObjectManager
35+
GlobalObjectManager *vslm.GlobalObjectManager
36+
}
37+
38+
var (
39+
// vslm does not have a PropertyCollector, the Wait func polls via VslmQueryInfo
40+
taskTimeout = time.Hour
41+
42+
// Some methods require a Datastore param regardless using vsom or vslm.
43+
// By default we use Global vslm for those methods, use vsom when this is "false".
44+
useGlobal = os.Getenv("GOVC_GLOBAL_VSLM") != "false"
45+
)
46+
47+
func NewManagerFromFlag(ctx context.Context, cmd *flags.DatastoreFlag) (*Manager, error) {
48+
c, err := cmd.Client()
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
ds, err := cmd.DatastoreIfSpecified()
54+
if err != nil {
55+
return nil, err
56+
}
57+
58+
return NewManager(ctx, c, ds)
59+
}
60+
61+
func NewManager(ctx context.Context, c *vim25.Client, ds *object.Datastore) (*Manager, error) {
62+
m := &Manager{
63+
Client: c,
64+
Datastore: ds,
65+
ObjectManager: vslm.NewObjectManager(c),
66+
}
67+
68+
if ds == nil {
69+
if err := m.initGlobalManager(ctx); err != nil {
70+
return nil, err
71+
}
72+
}
73+
74+
return m, nil
75+
}
76+
77+
func (m *Manager) initGlobalManager(ctx context.Context) error {
78+
if m.GlobalObjectManager == nil {
79+
vc, err := vslm.NewClient(ctx, m.Client)
80+
if err != nil {
81+
return err
82+
}
83+
m.GlobalObjectManager = vslm.NewGlobalObjectManager(vc)
84+
}
85+
return nil
86+
}
87+
88+
func (m *Manager) CreateDisk(ctx context.Context, spec types.VslmCreateSpec) (*types.VStorageObject, error) {
89+
if useGlobal && m.Client.IsVC() {
90+
if err := m.initGlobalManager(ctx); err != nil {
91+
return nil, err
92+
}
93+
task, err := m.GlobalObjectManager.CreateDisk(ctx, spec)
94+
if err != nil {
95+
return nil, err
96+
}
97+
res, err := task.Wait(ctx, taskTimeout)
98+
if err != nil {
99+
return nil, err
100+
}
101+
102+
obj := res.(types.VStorageObject)
103+
return &obj, nil
104+
}
105+
106+
task, err := m.ObjectManager.CreateDisk(ctx, spec)
107+
if err != nil {
108+
return nil, err
109+
}
110+
res, err := task.WaitForResult(ctx)
111+
if err != nil {
112+
return nil, err
113+
}
114+
obj := res.Result.(types.VStorageObject)
115+
return &obj, nil
116+
}
117+
118+
func (m *Manager) Delete(ctx context.Context, id string) error {
119+
if m.Datastore != nil {
120+
task, err := m.ObjectManager.Delete(ctx, m.Datastore, id)
121+
if err != nil {
122+
return err
123+
}
124+
return task.Wait(ctx)
125+
}
126+
127+
task, err := m.GlobalObjectManager.Delete(ctx, types.ID{Id: id})
128+
if err != nil {
129+
return err
130+
}
131+
_, err = task.Wait(ctx, taskTimeout)
132+
return err
133+
}
134+
135+
func (m *Manager) Retrieve(ctx context.Context, id string) (*types.VStorageObject, error) {
136+
if m.Datastore != nil {
137+
return m.ObjectManager.Retrieve(ctx, m.Datastore, id)
138+
}
139+
return m.GlobalObjectManager.Retrieve(ctx, types.ID{Id: id})
140+
}
141+
142+
func (m *Manager) List(ctx context.Context) ([]types.ID, error) {
143+
if m.Datastore != nil {
144+
return m.ObjectManager.List(ctx, m.Datastore)
145+
}
146+
147+
// TODO: move this logic to vslm.GlobalObjectManager
148+
// Need to better understand the QuerySpec + implement in vcsim.
149+
// For now we just want the complete list of IDs (govc disk.ls)
150+
maxResults := int32(100)
151+
152+
spec := vslmtypes.VslmVsoVStorageObjectQuerySpec{
153+
QueryField: string(vslmtypes.VslmVsoVStorageObjectQuerySpecQueryFieldEnumId),
154+
QueryOperator: string(vslmtypes.VslmVsoVStorageObjectQuerySpecQueryOperatorEnumGreaterThan),
155+
}
156+
var query []vslmtypes.VslmVsoVStorageObjectQuerySpec
157+
var ids []types.ID
158+
159+
for {
160+
res, err := m.GlobalObjectManager.ListObjectsForSpec(ctx, query, maxResults)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
ids = append(ids, res.Id...)
166+
167+
if res.AllRecordsReturned {
168+
break
169+
}
170+
171+
spec.QueryValue = []string{ids[len(ids)-1].Id}
172+
173+
query = []vslmtypes.VslmVsoVStorageObjectQuerySpec{spec}
174+
}
175+
176+
return ids, nil
177+
}
178+
179+
func (m *Manager) RegisterDisk(ctx context.Context, path, name string) (*types.VStorageObject, error) {
180+
if useGlobal && m.Client.IsVC() {
181+
if err := m.initGlobalManager(ctx); err != nil {
182+
return nil, err
183+
}
184+
return m.GlobalObjectManager.RegisterDisk(ctx, path, name) // VslmRegisterDisk
185+
}
186+
return m.ObjectManager.RegisterDisk(ctx, path, name) // RegisterDisk
187+
}
188+
189+
func (m *Manager) CreateSnapshot(ctx context.Context, id, desc string) (types.ID, error) {
190+
if m.Datastore != nil {
191+
task, err := m.ObjectManager.CreateSnapshot(ctx, m.Datastore, id, desc)
192+
if err != nil {
193+
return types.ID{}, err
194+
}
195+
res, err := task.WaitForResult(ctx, nil)
196+
if err != nil {
197+
return types.ID{}, err
198+
}
199+
return res.Result.(types.ID), nil
200+
}
201+
202+
task, err := m.GlobalObjectManager.CreateSnapshot(ctx, types.ID{Id: id}, desc)
203+
if err != nil {
204+
return types.ID{}, err
205+
}
206+
res, err := task.Wait(ctx, taskTimeout)
207+
if err != nil {
208+
return types.ID{}, err
209+
}
210+
return res.(types.ID), err
211+
}
212+
213+
func (m *Manager) DeleteSnapshot(ctx context.Context, id, sid string) error {
214+
if m.Datastore != nil {
215+
task, err := m.ObjectManager.DeleteSnapshot(ctx, m.Datastore, id, sid)
216+
if err != nil {
217+
return err
218+
}
219+
return task.Wait(ctx)
220+
}
221+
222+
task, err := m.GlobalObjectManager.DeleteSnapshot(ctx, types.ID{Id: id}, types.ID{Id: sid})
223+
if err != nil {
224+
return err
225+
}
226+
_, err = task.Wait(ctx, taskTimeout)
227+
return err
228+
}
229+
230+
func (m *Manager) RetrieveSnapshotInfo(ctx context.Context, id string) ([]types.VStorageObjectSnapshotInfoVStorageObjectSnapshot, error) {
231+
if m.Datastore != nil {
232+
info, err := m.ObjectManager.RetrieveSnapshotInfo(ctx, m.Datastore, id)
233+
if err != nil {
234+
return nil, err
235+
}
236+
return info.Snapshots, nil
237+
}
238+
239+
return m.GlobalObjectManager.RetrieveSnapshotInfo(ctx, types.ID{Id: id})
240+
}
241+
242+
func (m *Manager) AttachTag(ctx context.Context, id string, tag types.VslmTagEntry) error {
243+
if useGlobal && m.Client.IsVC() {
244+
if err := m.initGlobalManager(ctx); err != nil {
245+
return err
246+
}
247+
// TODO: use types.VslmTagEntry
248+
return m.GlobalObjectManager.AttachTag(ctx, types.ID{Id: id}, tag.ParentCategoryName, tag.TagName)
249+
}
250+
return m.ObjectManager.AttachTag(ctx, id, tag)
251+
}
252+
253+
func (m *Manager) DetachTag(ctx context.Context, id string, tag types.VslmTagEntry) error {
254+
if useGlobal && m.Client.IsVC() {
255+
if err := m.initGlobalManager(ctx); err != nil {
256+
return err
257+
}
258+
// TODO: use types.VslmTagEntry
259+
return m.GlobalObjectManager.DetachTag(ctx, types.ID{Id: id}, tag.ParentCategoryName, tag.TagName)
260+
}
261+
return m.ObjectManager.DetachTag(ctx, id, tag)
262+
}
263+
264+
func (m *Manager) ListAttachedObjects(ctx context.Context, category, tag string) ([]types.ID, error) {
265+
if m.Datastore != nil {
266+
// ListVStorageObjectsAttachedToTag
267+
return m.ObjectManager.ListAttachedObjects(ctx, category, tag)
268+
}
269+
270+
// VslmListVStorageObjectsAttachedToTag
271+
return m.GlobalObjectManager.ListAttachedObjects(ctx, category, tag)
272+
}
273+
274+
func (m *Manager) ListAttachedTags(ctx context.Context, id string) ([]types.VslmTagEntry, error) {
275+
if m.Datastore != nil {
276+
// ListTagsAttachedToVStorageObject
277+
return m.ObjectManager.ListAttachedTags(ctx, id)
278+
}
279+
280+
// VslmListTagsAttachedToVStorageObject
281+
return m.GlobalObjectManager.ListAttachedTags(ctx, types.ID{Id: id})
282+
}
283+
284+
func (m *Manager) ReconcileDatastoreInventory(ctx context.Context) error {
285+
if m.Datastore != nil {
286+
// ReconcileDatastoreInventory_Task
287+
task, err := m.ObjectManager.ReconcileDatastoreInventory(ctx, m.Datastore)
288+
if err != nil {
289+
return err
290+
}
291+
return task.Wait(ctx)
292+
}
293+
294+
// VslmReconcileDatastoreInventory_Task also requires a Datastore
295+
return errors.New("-R requires -ds") // TODO
296+
}
297+
298+
func (m *Manager) AttachDisk(ctx context.Context, vm *object.VirtualMachine, id string) error {
299+
if m.Datastore != nil {
300+
return vm.AttachDisk(ctx, id, m.Datastore, 0, nil)
301+
}
302+
303+
task, err := m.GlobalObjectManager.AttachDisk(ctx, types.ID{Id: id}, vm, 0, nil)
304+
if err != nil {
305+
return err
306+
}
307+
_, err = task.Wait(ctx, taskTimeout)
308+
return err
309+
}

‎cli/disk/register.go

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018 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

@@ -23,7 +11,6 @@ import (
2311

2412
"github.com/vmware/govmomi/cli"
2513
"github.com/vmware/govmomi/cli/flags"
26-
"github.com/vmware/govmomi/vslm"
2714
)
2815

2916
type register struct {
@@ -51,12 +38,15 @@ Examples:
5138
}
5239

5340
func (cmd *register) Run(ctx context.Context, f *flag.FlagSet) error {
54-
ds, err := cmd.Datastore()
41+
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
5542
if err != nil {
5643
return err
5744
}
5845

59-
m := vslm.NewObjectManager(ds.Client())
46+
ds, err := cmd.Datastore()
47+
if err != nil {
48+
return err
49+
}
6050

6151
path := ds.NewURL(f.Arg(0)).String()
6252

‎cli/disk/rm.go

+8-31
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
/*
2-
Copyright (c) 2018 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

197
import (
208
"context"
219
"flag"
22-
"fmt"
2310

2411
"github.com/vmware/govmomi/cli"
2512
"github.com/vmware/govmomi/cli/flags"
26-
"github.com/vmware/govmomi/vslm"
2713
)
2814

2915
type rm struct {
@@ -51,23 +37,14 @@ Examples:
5137
}
5238

5339
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
54-
ds, err := cmd.Datastore()
55-
if err != nil {
56-
return err
40+
if f.NArg() != 1 {
41+
return flag.ErrHelp
5742
}
5843

59-
id := f.Arg(0)
60-
61-
logger := cmd.ProgressLogger(fmt.Sprintf("Deleting %s...", id))
62-
defer logger.Wait()
63-
64-
m := vslm.NewObjectManager(ds.Client())
65-
66-
task, err := m.Delete(ctx, ds, id)
44+
m, err := NewManagerFromFlag(ctx, cmd.DatastoreFlag)
6745
if err != nil {
68-
fmt.Println(err)
46+
return err
6947
}
7048

71-
_, err = task.WaitForResult(ctx, logger)
72-
return err
49+
return m.Delete(ctx, f.Arg(0))
7350
}

‎cli/disk/snapshot/create.go

+8-29
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018 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 snapshot
186

@@ -22,9 +10,8 @@ import (
2210
"fmt"
2311

2412
"github.com/vmware/govmomi/cli"
13+
"github.com/vmware/govmomi/cli/disk"
2514
"github.com/vmware/govmomi/cli/flags"
26-
"github.com/vmware/govmomi/vim25/types"
27-
"github.com/vmware/govmomi/vslm"
2815
)
2916

3017
type create struct {
@@ -52,28 +39,20 @@ Examples:
5239
}
5340

5441
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
55-
ds, err := cmd.Datastore()
42+
m, err := disk.NewManagerFromFlag(ctx, cmd.DatastoreFlag)
5643
if err != nil {
5744
return err
5845
}
5946

60-
m := vslm.NewObjectManager(ds.Client())
6147
id := f.Arg(0)
48+
desc := f.Arg(1)
6249

63-
task, err := m.CreateSnapshot(ctx, ds, id, f.Arg(1))
64-
if err != nil {
65-
return err
66-
}
67-
68-
logger := cmd.ProgressLogger(fmt.Sprintf("Snapshot %s...", id))
69-
70-
res, err := task.WaitForResult(ctx, logger)
71-
logger.Wait()
50+
res, err := m.CreateSnapshot(ctx, id, desc)
7251
if err != nil {
7352
return err
7453
}
7554

76-
fmt.Println(res.Result.(types.ID).Id)
55+
fmt.Println(res.Id)
7756

7857
return nil
7958
}

‎cli/disk/snapshot/ls.go

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-2023 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 snapshot
186

@@ -26,9 +14,9 @@ import (
2614
"time"
2715

2816
"github.com/vmware/govmomi/cli"
17+
"github.com/vmware/govmomi/cli/disk"
2918
"github.com/vmware/govmomi/cli/flags"
3019
"github.com/vmware/govmomi/vim25/types"
31-
"github.com/vmware/govmomi/vslm"
3220
)
3321

3422
type ls struct {
@@ -55,7 +43,7 @@ func (cmd *ls) Description() string {
5543
return `List snapshots for disk ID on DS.
5644
5745
Examples:
58-
govc snapshot.disk.ls -l 9b06a8b-d047-4d3c-b15b-43ea9608b1a6`
46+
govc disk.snapshot.ls -l 9b06a8b-d047-4d3c-b15b-43ea9608b1a6`
5947
}
6048

6149
type lsResult struct {
@@ -83,17 +71,17 @@ func (r *lsResult) Dump() interface{} {
8371
}
8472

8573
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
86-
ds, err := cmd.Datastore()
74+
m, err := disk.NewManagerFromFlag(ctx, cmd.DatastoreFlag)
8775
if err != nil {
8876
return err
8977
}
9078

91-
m := vslm.NewObjectManager(ds.Client())
92-
info, err := m.RetrieveSnapshotInfo(ctx, ds, f.Arg(0))
79+
snapshots, err := m.RetrieveSnapshotInfo(ctx, f.Arg(0))
9380
if err != nil {
9481
return err
9582
}
9683

84+
info := &types.VStorageObjectSnapshotInfo{Snapshots: snapshots}
9785
res := lsResult{Info: info, cmd: cmd}
9886

9987
return cmd.WriteResult(&res)

‎cli/disk/snapshot/rm.go

+7-28
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
/*
2-
Copyright (c) 2018 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 snapshot
186

197
import (
208
"context"
219
"flag"
22-
"fmt"
2310

2411
"github.com/vmware/govmomi/cli"
12+
"github.com/vmware/govmomi/cli/disk"
2513
"github.com/vmware/govmomi/cli/flags"
26-
"github.com/vmware/govmomi/vslm"
2714
)
2815

2916
type rm struct {
@@ -51,21 +38,13 @@ Examples:
5138
}
5239

5340
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
54-
ds, err := cmd.Datastore()
41+
m, err := disk.NewManagerFromFlag(ctx, cmd.DatastoreFlag)
5542
if err != nil {
5643
return err
5744
}
5845

46+
id := f.Arg(0)
5947
sid := f.Arg(1)
60-
m := vslm.NewObjectManager(ds.Client())
61-
62-
task, err := m.DeleteSnapshot(ctx, ds, f.Arg(0), sid)
63-
if err != nil {
64-
return err
65-
}
66-
logger := cmd.ProgressLogger(fmt.Sprintf("Deleting %s...", sid))
67-
defer logger.Wait()
6848

69-
_, err = task.WaitForResult(ctx, logger)
70-
return err
49+
return m.DeleteSnapshot(ctx, id, sid)
7150
}

‎cli/disk/tags.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018 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

@@ -23,7 +11,6 @@ import (
2311
"github.com/vmware/govmomi/cli"
2412
"github.com/vmware/govmomi/cli/flags"
2513
"github.com/vmware/govmomi/vim25/types"
26-
"github.com/vmware/govmomi/vslm"
2714
)
2815

2916
type tags struct {
@@ -75,7 +62,11 @@ func (cmd *tags) Run(ctx context.Context, f *flag.FlagSet) error {
7562
return err
7663
}
7764

78-
m := vslm.NewObjectManager(c)
65+
m, err := NewManager(ctx, c, nil)
66+
if err != nil {
67+
return err
68+
}
69+
7970
cmd.TagName = f.Arg(0)
8071
method := m.DetachTag
8172
if cmd.attach {

‎govc/USAGE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ Usage: govc disk.snapshot.ls [OPTIONS] ID
22102210
List snapshots for disk ID on DS.
22112211
22122212
Examples:
2213-
govc snapshot.disk.ls -l 9b06a8b-d047-4d3c-b15b-43ea9608b1a6
2213+
govc disk.snapshot.ls -l 9b06a8b-d047-4d3c-b15b-43ea9608b1a6
22142214
22152215
Options:
22162216
-ds= Datastore [GOVC_DATASTORE]

‎govc/test/disk.bats

+71-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
load test_helper
44

55
@test "disk.ls" {
6-
vcsim_env
6+
vcsim_start -ds 2
77

88
run govc disk.ls
99
assert_success
1010

11+
run govc disk.ls -ds LocalDS_0
12+
assert_success
13+
1114
run govc disk.ls enoent
1215
assert_failure
1316
}
@@ -19,7 +22,7 @@ load test_helper
1922

2023
run govc disk.create -size 10M "$name"
2124
assert_success
22-
id="${lines[1]}"
25+
id="$output"
2326

2427
run govc disk.ls "$id"
2528
assert_success
@@ -124,14 +127,14 @@ load test_helper
124127

125128
run govc disk.create -size 10M "$name"
126129
assert_success
127-
id="${lines[1]}"
130+
id="$output"
128131

129132
run govc disk.snapshot.ls "$id"
130133
assert_success
131134

132135
run govc disk.snapshot.create "$id"
133136
assert_success
134-
sid="${lines[1]}"
137+
sid="$output"
135138

136139
govc disk.snapshot.ls "$id" | grep "$sid"
137140

@@ -160,7 +163,7 @@ load test_helper
160163

161164
run govc disk.create -size 10M "$name"
162165
assert_success
163-
id="${lines[1]}"
166+
id="$output"
164167

165168
run govc disk.ls "$id"
166169
assert_success
@@ -197,7 +200,7 @@ load test_helper
197200

198201
run govc disk.create -size 10M "$name"
199202
assert_success
200-
id="${lines[1]}"
203+
id="$output"
201204

202205
run govc disk.create -size 10M "$(new_id)"
203206
assert_success
@@ -226,3 +229,65 @@ load test_helper
226229
run govc disk.ls -R
227230
assert_success
228231
}
232+
233+
@test "disk global catalog" {
234+
vcsim_start -ds 3
235+
236+
run govc disk.create -ds LocalDS_0 -size 10M disk-0
237+
assert_success
238+
id0="$output"
239+
240+
run govc disk.create -ds LocalDS_1 -size 10M disk-1
241+
assert_success
242+
id1="$output"
243+
244+
run govc disk.snapshot.create "$id0" snapshot-0
245+
assert_success
246+
sid0="$output"
247+
248+
run govc disk.snapshot.ls "$id0"
249+
assert_success
250+
assert_matches "$sid0"
251+
assert_matches "snapshot-0"
252+
253+
run govc disk.snapshot.rm "$id0" "$sid0"
254+
assert_success
255+
sid0="$output"
256+
257+
run govc disk.ls
258+
assert_success
259+
[ ${#lines[@]} -eq 2 ]
260+
261+
run govc disk.ls -ds LocalDS_0
262+
assert_success
263+
[ ${#lines[@]} -eq 1 ]
264+
265+
run govc disk.ls -ds LocalDS_1
266+
assert_success
267+
[ ${#lines[@]} -eq 1 ]
268+
269+
run govc disk.ls -ds LocalDS_2
270+
assert_success
271+
[ ${#lines[@]} -eq 0 ]
272+
273+
vm=DC0_H0_VM0
274+
275+
run govc disk.attach -vm $vm "$id0"
276+
assert_success
277+
278+
run govc disk.detach -vm $vm "$id0"
279+
assert_success
280+
281+
run govc disk.rm -ds LocalDS_1 "$id0"
282+
assert_failure
283+
284+
run govc disk.rm -ds LocalDS_0 "$id0"
285+
assert_success
286+
287+
run govc disk.rm "$id1"
288+
assert_success
289+
290+
run govc disk.ls
291+
assert_success
292+
[ ${#lines[@]} -eq 0 ]
293+
}

‎govc/test/library.bats

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ EOF
468468
ds1=LocalDS_1
469469
ds2=LocalDS_2
470470
pool=DC0_C0/Resources
471+
export GOVC_NETWORK=/DC0/network/DC0_DVPG0
471472

472473
# Create a published library with OVA items
473474
govc library.create -ds $ds0 -pub ttylinux-pub-ovf

‎govc/test/test_helper.bash

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# set the following variables only if they've not been set
2-
export GOVC_DATASTORE=${GOVC_DATASTORE-datastore1}
3-
export GOVC_NETWORK=${GOVC_NETWORK-"VM Network"}
4-
51
export GOVC_INSECURE=true
62
export GOVC_PERSIST_SESSION=false
73
unset GOVC_URL
@@ -142,6 +138,8 @@ esx_env() {
142138
fi
143139

144140
export GOVC_URL=$GOVC_TEST_URL
141+
export GOVC_DATASTORE=${GOVC_DATASTORE-datastore1}
142+
export GOVC_NETWORK=${GOVC_NETWORK-"VM Network"}
145143
}
146144

147145
vcsim_env_todo() {

‎govc/test/vm.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ load test_helper
9595
}
9696

9797
@test "vm.create" {
98-
unset GOVC_DATASTORE
9998
vcsim_start
99+
export GOVC_NETWORK=/DC0/network/DC0_DVPG0
100100

101101
run govc cluster.create empty-cluster
102102
assert_success

‎simulator/registry.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2017-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 simulator
186

@@ -604,6 +592,11 @@ func (r *Registry) ExtensionManager() *ExtensionManager {
604592
return r.Get(r.content().ExtensionManager.Reference()).(*ExtensionManager)
605593
}
606594

595+
// VStorageObjectManager returns the VStorageObjectManager singleton
596+
func (r *Registry) VStorageObjectManager() *VcenterVStorageObjectManager {
597+
return r.Get(r.content().VStorageObjectManager.Reference()).(*VcenterVStorageObjectManager)
598+
}
599+
607600
func (r *Registry) MarshalJSON() ([]byte, error) {
608601
r.m.Lock()
609602
defer r.m.Unlock()

‎simulator/session_manager.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2017-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 simulator
186

@@ -420,6 +408,15 @@ func (c *Context) SetSession(session Session, login bool) {
420408
}
421409
}
422410

411+
// For returns a Context with Registry Map for the given path.
412+
// This is intended for calling into other namespaces internally,
413+
// such as vslm simulator methods calling vim25 methods for example.
414+
func (c *Context) For(path string) *Context {
415+
clone := *c
416+
clone.Map = c.svc.sdk[path]
417+
return &clone
418+
}
419+
423420
// WithLock holds a lock for the given object while the given function is run.
424421
// It will skip locking if this context already holds the given object's lock.
425422
func (c *Context) WithLock(obj mo.Reference, f func()) {

‎simulator/simulator.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2017-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 simulator
186

‎simulator/virtual_machine.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2017-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 simulator
186

@@ -2799,7 +2787,7 @@ func (vm *VirtualMachine) RemoveAllSnapshotsTask(ctx *Context, req *types.Remove
27992787
}
28002788

28012789
func (vm *VirtualMachine) fcd(ctx *Context, ds types.ManagedObjectReference, id types.ID) *VStorageObject {
2802-
m := ctx.Map.Get(*ctx.Map.content().VStorageObjectManager).(*VcenterVStorageObjectManager)
2790+
m := ctx.Map.VStorageObjectManager()
28032791
if ds.Value != "" {
28042792
return m.objects[ds][id]
28052793
}

‎simulator/vstorage_object_manager.go

+7-15
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 simulator
186

@@ -55,6 +43,10 @@ func (m *VcenterVStorageObjectManager) object(ds types.ManagedObjectReference, i
5543
return nil
5644
}
5745

46+
func (m *VcenterVStorageObjectManager) Catalog() map[types.ManagedObjectReference]map[types.ID]*VStorageObject {
47+
return m.objects
48+
}
49+
5850
func (m *VcenterVStorageObjectManager) ListVStorageObject(req *types.ListVStorageObject) soap.HasFault {
5951
body := &methods.ListVStorageObjectBody{
6052
Res: &types.ListVStorageObjectResponse{},

‎vcsim/main.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2017-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 main
186

@@ -56,6 +44,7 @@ import (
5644
_ "github.com/vmware/govmomi/vapi/vcenter/consumptiondomains/simulator"
5745
_ "github.com/vmware/govmomi/vapi/vm/simulator"
5846
_ "github.com/vmware/govmomi/vsan/simulator"
47+
_ "github.com/vmware/govmomi/vslm/simulator"
5948
)
6049

6150
var (

‎vslm/global_object_manager.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2019 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 vslm
186

@@ -397,7 +385,7 @@ func (this *GlobalObjectManager) DetachTag(ctx context.Context, id vim.ID, categ
397385
return err
398386
}
399387

400-
func (this *GlobalObjectManager) ListObjectsAttachedToTag(ctx context.Context, id vim.ID, category string, tag string) (
388+
func (this *GlobalObjectManager) ListAttachedObjects(ctx context.Context, category string, tag string) (
401389
[]vim.ID, error) {
402390
req := types.VslmListVStorageObjectsAttachedToTag{
403391
This: this.Reference(),
@@ -660,13 +648,13 @@ func (this *GlobalObjectManager) RetrieveObjects(ct context.Context, ids []vim.I
660648
}
661649

662650
func (this *GlobalObjectManager) AttachDisk(ct context.Context, id vim.ID, vm mo.Reference, controllerKey int32,
663-
unitNumber int32) (*Task, error) {
651+
unitNumber *int32) (*Task, error) {
664652
req := types.VslmAttachDisk_Task{
665653
This: this.Reference(),
666654
Id: id,
667655
Vm: vm.Reference(),
668656
ControllerKey: controllerKey,
669-
UnitNumber: &unitNumber,
657+
UnitNumber: unitNumber,
670658
}
671659

672660
res, err := methods.VslmAttachDisk_Task(ct, this.c, &req)

‎vslm/simulator/simulator.go

+509
Large diffs are not rendered by default.

‎vslm/simulator/simulator_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package simulator_test
6+
7+
import (
8+
"context"
9+
"testing"
10+
11+
"github.com/vmware/govmomi/fault"
12+
"github.com/vmware/govmomi/simulator"
13+
"github.com/vmware/govmomi/vim25"
14+
"github.com/vmware/govmomi/vim25/soap"
15+
"github.com/vmware/govmomi/vim25/types"
16+
"github.com/vmware/govmomi/vslm"
17+
)
18+
19+
func TestClientCookie(t *testing.T) {
20+
simulator.Test(func(ctx context.Context, vc *vim25.Client) {
21+
c, err := vslm.NewClient(ctx, vc)
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
26+
m := vslm.NewGlobalObjectManager(c)
27+
// Using default / expected Header.Cookie.XMLName = vcSessionCookie
28+
_, err = m.ListObjectsForSpec(ctx, nil, 1000)
29+
if err != nil {
30+
t.Fatal(err)
31+
}
32+
33+
// Using invalid Header.Cookie.XMLName = myCookie
34+
myCookie := vc.SessionCookie()
35+
myCookie.XMLName.Local = "myCookie"
36+
37+
c.Client.Cookie = func() *soap.HeaderElement {
38+
return myCookie
39+
}
40+
41+
_, err = m.ListObjectsForSpec(ctx, nil, 1000)
42+
if !fault.Is(err, &types.NotAuthenticated{}) {
43+
t.Errorf("err=%#v", err)
44+
}
45+
})
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.