github.com/vmware/govmomi@v0.43.0/object/namespace_manager.go (about) 1 /* 2 Copyright (c) 2016-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 object 18 19 import ( 20 "context" 21 22 "github.com/vmware/govmomi/vim25" 23 "github.com/vmware/govmomi/vim25/methods" 24 "github.com/vmware/govmomi/vim25/types" 25 ) 26 27 type DatastoreNamespaceManager struct { 28 Common 29 } 30 31 func NewDatastoreNamespaceManager(c *vim25.Client) *DatastoreNamespaceManager { 32 n := DatastoreNamespaceManager{ 33 Common: NewCommon(c, *c.ServiceContent.DatastoreNamespaceManager), 34 } 35 36 return &n 37 } 38 39 // CreateDirectory creates a top-level directory on the given vsan datastore, using 40 // the given user display name hint and opaque storage policy. 41 func (nm DatastoreNamespaceManager) CreateDirectory(ctx context.Context, ds *Datastore, displayName string, policy string) (string, error) { 42 43 req := &types.CreateDirectory{ 44 This: nm.Reference(), 45 Datastore: ds.Reference(), 46 DisplayName: displayName, 47 Policy: policy, 48 } 49 50 resp, err := methods.CreateDirectory(ctx, nm.c, req) 51 if err != nil { 52 return "", err 53 } 54 55 return resp.Returnval, nil 56 } 57 58 // DeleteDirectory deletes the given top-level directory from a vsan datastore. 59 func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Datacenter, datastorePath string) error { 60 61 req := &types.DeleteDirectory{ 62 This: nm.Reference(), 63 DatastorePath: datastorePath, 64 } 65 66 if dc != nil { 67 ref := dc.Reference() 68 req.Datacenter = &ref 69 } 70 71 if _, err := methods.DeleteDirectory(ctx, nm.c, req); err != nil { 72 return err 73 } 74 75 return nil 76 } 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 }