Skip to content

Commit aa8279b

Browse files
committedDec 20, 2024·
api: Support returning DS info when resolving lib stor
This patch updates the ResolveLibraryItemStorage method with the ability to return the resolve datastore information beyond just the resovled URIs. Now the datastore name, URL, and whether it supports top-level directory create can be returned. BREAKING: This change updates the signature for the ResolveLibraryItemStorage function. Signed-off-by: akutz <akutz@vmware.com>
1 parent 078eb5b commit aa8279b

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed
 

‎cli/library/info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (r infoResultsWriter) writeFile(
277277
}
278278
if r.cmd.Stor {
279279
label = "Resolved URI"
280-
err = r.cmd.pathFinder.ResolveLibraryItemStorage(r.ctx, nil, s)
280+
err = r.cmd.pathFinder.ResolveLibraryItemStorage(r.ctx, nil, nil, s)
281281
if err != nil {
282282
return err
283283
}

‎vapi/library/finder/path.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func (f *PathFinder) convertPath(
176176
// to the format that includes the datastore name, ex.
177177
// "[DATASTORE_NAME] contentlib-LIB_UUID/ITEM_UUID/file.vmdk".
178178
//
179+
// If datastoreMap is provided, then it will be updated with the datastores
180+
// involved in the resolver. The properties name, summary.url, and
181+
// capability.topLevelDirectoryCreateSupported will be available after the
182+
// resolver completes.
183+
//
179184
// If a storage item resides on a datastore that does not support the creation
180185
// of top-level directories, then this means the datastore is vSAN and the
181186
// storage item path needs to be further converted. If this occurs, then the
@@ -187,16 +192,18 @@ func (f *PathFinder) convertPath(
187192
func (f *PathFinder) ResolveLibraryItemStorage(
188193
ctx context.Context,
189194
datacenter *object.Datacenter,
195+
datastoreMap map[string]mo.Datastore,
190196
storage []library.Storage) error {
191197

192198
// TODO:
193199
// - reuse PathFinder.cache
194200
// - the transform here isn't Content Library specific, but is currently
195201
// the only known use case
196-
var (
197-
ids []types.ManagedObjectReference
202+
var ids []types.ManagedObjectReference
203+
204+
if datastoreMap == nil {
198205
datastoreMap = map[string]mo.Datastore{}
199-
)
206+
}
200207

201208
// Currently ContentLibrary only supports a single storage backing, but this
202209
// future proofs things.

‎vapi/library/finder/path_test.go

+41-2
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,55 @@ func TestResolveLibraryItemStorage(t *testing.T) {
4040
testCases := []struct {
4141
name string
4242
nilDatacenter bool
43+
datastoreMap map[string]mo.Datastore
4344
topLevelDirectoryCreateSupported *bool
4445
}{
4546
{
4647
name: "Nil datacenter and nil topLevelCreate",
4748
nilDatacenter: true,
49+
datastoreMap: nil,
4850
topLevelDirectoryCreateSupported: nil,
4951
},
5052
{
5153
name: "Nil datacenter and false topLevelCreate",
5254
nilDatacenter: true,
55+
datastoreMap: nil,
5356
topLevelDirectoryCreateSupported: types.New(false),
5457
},
5558
{
5659
name: "Nil datacenter and true topLevelCreate",
5760
nilDatacenter: true,
61+
datastoreMap: nil,
5862
topLevelDirectoryCreateSupported: types.New(true),
5963
},
6064
{
6165
name: "Non-nil datacenter and nil topLevelCreate",
6266
nilDatacenter: false,
67+
datastoreMap: nil,
6368
topLevelDirectoryCreateSupported: nil,
6469
},
6570
{
6671
name: "Non-Nil datacenter and false topLevelCreate",
6772
nilDatacenter: false,
73+
datastoreMap: nil,
6874
topLevelDirectoryCreateSupported: types.New(false),
6975
},
7076
{
7177
name: "Non-Nil datacenter and true topLevelCreate",
7278
nilDatacenter: false,
79+
datastoreMap: nil,
80+
topLevelDirectoryCreateSupported: types.New(true),
81+
},
82+
{
83+
name: "Nil datastoreMap",
84+
nilDatacenter: true,
85+
datastoreMap: nil,
86+
topLevelDirectoryCreateSupported: nil,
87+
},
88+
{
89+
name: "Non-Nil datastoreMap and true topLevelCreate",
90+
nilDatacenter: true,
91+
datastoreMap: map[string]mo.Datastore{},
7392
topLevelDirectoryCreateSupported: types.New(true),
7493
},
7594
}
@@ -105,7 +124,7 @@ func TestResolveLibraryItemStorage(t *testing.T) {
105124
ds.Properties(
106125
ctx,
107126
ds.Reference(),
108-
[]string{"name", "summary"},
127+
[]string{"name", "summary.url"},
109128
&moDS)) {
110129
t.FailNow()
111130
}
@@ -142,16 +161,36 @@ func TestResolveLibraryItemStorage(t *testing.T) {
142161
ds.Capability.TopLevelDirectoryCreateSupported = tc.topLevelDirectoryCreateSupported
143162
})
144163

164+
nilDSM := tc.datastoreMap == nil
165+
145166
if !assert.NoError(
146167
t,
147-
lf.ResolveLibraryItemStorage(ctx, dc, storage)) {
168+
lf.ResolveLibraryItemStorage(
169+
ctx,
170+
dc,
171+
tc.datastoreMap,
172+
storage)) {
148173

149174
t.FailNow()
150175
}
151176

152177
assert.Len(t, storage, 1)
153178
assert.Len(t, storage[0].StorageURIs, 2)
154179

180+
if nilDSM {
181+
assert.Nil(t, tc.datastoreMap)
182+
} else if assert.NotNil(t, tc.datastoreMap) {
183+
if assert.Len(t, tc.datastoreMap, 1) {
184+
dsv := ds.Reference().Value
185+
if assert.Contains(t, tc.datastoreMap, dsv) {
186+
ds := tc.datastoreMap[dsv]
187+
assert.Equal(t, ds.Name, dsName)
188+
assert.Equal(t, ds.Summary.Url, dsURL)
189+
assert.Equal(t, ds.Capability.TopLevelDirectoryCreateSupported, tc.topLevelDirectoryCreateSupported)
190+
}
191+
}
192+
}
193+
155194
for _, s := range storage {
156195
for _, u := range s.StorageURIs {
157196
var path object.DatastorePath

0 commit comments

Comments
 (0)
Please sign in to comment.