Skip to content

Commit

Permalink
vcsim: add DatastoreNamespaceManager
Browse files Browse the repository at this point in the history
api: add DatastoreNamespaceManager.ConvertNamespacePathToUuidPath
  • Loading branch information
dougm committed Aug 2, 2024
1 parent cc02310 commit 0633de5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
14 changes: 12 additions & 2 deletions internal/helpers.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2020-2023 VMware, Inc. All Rights Reserved.
Copyright (c) 2020-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 @@ -24,6 +24,7 @@ import (
"net/url"
"os"
"path"
"slices"

"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/mo"
Expand Down Expand Up @@ -51,6 +52,15 @@ func InventoryPath(entities []mo.ManagedEntity) string {
return val
}

var vsanFS = []string{
string(types.HostFileSystemVolumeFileSystemTypeVsan),
string(types.HostFileSystemVolumeFileSystemTypeVVOL),
}

func IsDatastoreVSAN(ds mo.Datastore) bool {
return slices.Contains(vsanFS, ds.Summary.Type)
}

func HostSystemManagementIPs(config []types.VirtualNicManagerNetConfig) []net.IP {
var ips []net.IP

Expand Down
23 changes: 21 additions & 2 deletions object/namespace_manager.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Copyright (c) 2016-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 Down Expand Up @@ -74,3 +74,22 @@ func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Dat

return nil
}

func (nm DatastoreNamespaceManager) ConvertNamespacePathToUuidPath(ctx context.Context, dc *Datacenter, datastoreURL string) (string, error) {
req := &types.ConvertNamespacePathToUuidPath{
This: nm.Reference(),
NamespaceUrl: datastoreURL,
}

if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}

res, err := methods.ConvertNamespacePathToUuidPath(ctx, nm.c, req)
if err != nil {
return "", err
}

return res.Returnval, nil
}
67 changes: 67 additions & 0 deletions simulator/datastore_namespace_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (c) 2024-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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package simulator

import (
"strings"

"github.com/vmware/govmomi/internal"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
)

type DatastoreNamespaceManager struct {
mo.DatastoreNamespaceManager
}

func (m *DatastoreNamespaceManager) ConvertNamespacePathToUuidPath(ctx *Context, req *types.ConvertNamespacePathToUuidPath) soap.HasFault {
body := new(methods.ConvertNamespacePathToUuidPathBody)

if req.Datacenter == nil {
body.Fault_ = Fault("", &types.InvalidArgument{InvalidProperty: "datacenterRef"})
return body
}

dc := ctx.Map.Get(*req.Datacenter).(*Datacenter)

var ds *Datastore
for _, ref := range dc.Datastore {
ds = ctx.Map.Get(ref).(*Datastore)
if strings.HasPrefix(req.NamespaceUrl, ds.Summary.Url) {
break
}
ds = nil
}

if ds == nil {
body.Fault_ = Fault("", &types.InvalidDatastorePath{DatastorePath: req.NamespaceUrl})
return body
}

if !internal.IsDatastoreVSAN(ds.Datastore) {
body.Fault_ = Fault("", &types.InvalidDatastore{Datastore: &ds.Self})
return body
}

body.Res = &types.ConvertNamespacePathToUuidPathResponse{
Returnval: req.NamespaceUrl,
}

return body
}
1 change: 1 addition & 0 deletions simulator/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ var kinds = map[string]reflect.Type{
"CustomizationSpecManager": reflect.TypeOf((*CustomizationSpecManager)(nil)).Elem(),
"Datacenter": reflect.TypeOf((*Datacenter)(nil)).Elem(),
"Datastore": reflect.TypeOf((*Datastore)(nil)).Elem(),
"DatastoreNamespaceManager": reflect.TypeOf((*DatastoreNamespaceManager)(nil)).Elem(),
"DistributedVirtualPortgroup": reflect.TypeOf((*DistributedVirtualPortgroup)(nil)).Elem(),
"DistributedVirtualSwitch": reflect.TypeOf((*DistributedVirtualSwitch)(nil)).Elem(),
"DistributedVirtualSwitchManager": reflect.TypeOf((*DistributedVirtualSwitchManager)(nil)).Elem(),
Expand Down

0 comments on commit 0633de5

Please sign in to comment.