Skip to content

Commit 0633de5

Browse files
committed
vcsim: add DatastoreNamespaceManager
api: add DatastoreNamespaceManager.ConvertNamespacePathToUuidPath
1 parent cc02310 commit 0633de5

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

internal/helpers.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Copyright (c) 2020-2023 VMware, Inc. All Rights Reserved.
2+
Copyright (c) 2020-2024 VMware, Inc. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,6 +24,7 @@ import (
2424
"net/url"
2525
"os"
2626
"path"
27+
"slices"
2728

2829
"github.com/vmware/govmomi/vim25"
2930
"github.com/vmware/govmomi/vim25/mo"
@@ -51,6 +52,15 @@ func InventoryPath(entities []mo.ManagedEntity) string {
5152
return val
5253
}
5354

55+
var vsanFS = []string{
56+
string(types.HostFileSystemVolumeFileSystemTypeVsan),
57+
string(types.HostFileSystemVolumeFileSystemTypeVVOL),
58+
}
59+
60+
func IsDatastoreVSAN(ds mo.Datastore) bool {
61+
return slices.Contains(vsanFS, ds.Summary.Type)
62+
}
63+
5464
func HostSystemManagementIPs(config []types.VirtualNicManagerNetConfig) []net.IP {
5565
var ips []net.IP
5666

object/namespace_manager.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
2+
Copyright (c) 2016-2024 VMware, Inc. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -74,3 +74,22 @@ func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Dat
7474

7575
return nil
7676
}
77+
78+
func (nm DatastoreNamespaceManager) ConvertNamespacePathToUuidPath(ctx context.Context, dc *Datacenter, datastoreURL string) (string, error) {
79+
req := &types.ConvertNamespacePathToUuidPath{
80+
This: nm.Reference(),
81+
NamespaceUrl: datastoreURL,
82+
}
83+
84+
if dc != nil {
85+
ref := dc.Reference()
86+
req.Datacenter = &ref
87+
}
88+
89+
res, err := methods.ConvertNamespacePathToUuidPath(ctx, nm.c, req)
90+
if err != nil {
91+
return "", err
92+
}
93+
94+
return res.Returnval, nil
95+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
*/
16+
17+
package simulator
18+
19+
import (
20+
"strings"
21+
22+
"github.com/vmware/govmomi/internal"
23+
"github.com/vmware/govmomi/vim25/methods"
24+
"github.com/vmware/govmomi/vim25/mo"
25+
"github.com/vmware/govmomi/vim25/soap"
26+
"github.com/vmware/govmomi/vim25/types"
27+
)
28+
29+
type DatastoreNamespaceManager struct {
30+
mo.DatastoreNamespaceManager
31+
}
32+
33+
func (m *DatastoreNamespaceManager) ConvertNamespacePathToUuidPath(ctx *Context, req *types.ConvertNamespacePathToUuidPath) soap.HasFault {
34+
body := new(methods.ConvertNamespacePathToUuidPathBody)
35+
36+
if req.Datacenter == nil {
37+
body.Fault_ = Fault("", &types.InvalidArgument{InvalidProperty: "datacenterRef"})
38+
return body
39+
}
40+
41+
dc := ctx.Map.Get(*req.Datacenter).(*Datacenter)
42+
43+
var ds *Datastore
44+
for _, ref := range dc.Datastore {
45+
ds = ctx.Map.Get(ref).(*Datastore)
46+
if strings.HasPrefix(req.NamespaceUrl, ds.Summary.Url) {
47+
break
48+
}
49+
ds = nil
50+
}
51+
52+
if ds == nil {
53+
body.Fault_ = Fault("", &types.InvalidDatastorePath{DatastorePath: req.NamespaceUrl})
54+
return body
55+
}
56+
57+
if !internal.IsDatastoreVSAN(ds.Datastore) {
58+
body.Fault_ = Fault("", &types.InvalidDatastore{Datastore: &ds.Self})
59+
return body
60+
}
61+
62+
body.Res = &types.ConvertNamespacePathToUuidPathResponse{
63+
Returnval: req.NamespaceUrl,
64+
}
65+
66+
return body
67+
}

simulator/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ var kinds = map[string]reflect.Type{
238238
"CustomizationSpecManager": reflect.TypeOf((*CustomizationSpecManager)(nil)).Elem(),
239239
"Datacenter": reflect.TypeOf((*Datacenter)(nil)).Elem(),
240240
"Datastore": reflect.TypeOf((*Datastore)(nil)).Elem(),
241+
"DatastoreNamespaceManager": reflect.TypeOf((*DatastoreNamespaceManager)(nil)).Elem(),
241242
"DistributedVirtualPortgroup": reflect.TypeOf((*DistributedVirtualPortgroup)(nil)).Elem(),
242243
"DistributedVirtualSwitch": reflect.TypeOf((*DistributedVirtualSwitch)(nil)).Elem(),
243244
"DistributedVirtualSwitchManager": reflect.TypeOf((*DistributedVirtualSwitchManager)(nil)).Elem(),

0 commit comments

Comments
 (0)