namespace_manager.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2015 VMware, Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package object
  14. import (
  15. "context"
  16. "github.com/vmware/govmomi/vim25"
  17. "github.com/vmware/govmomi/vim25/methods"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type DatastoreNamespaceManager struct {
  21. Common
  22. }
  23. func NewDatastoreNamespaceManager(c *vim25.Client) *DatastoreNamespaceManager {
  24. n := DatastoreNamespaceManager{
  25. Common: NewCommon(c, *c.ServiceContent.DatastoreNamespaceManager),
  26. }
  27. return &n
  28. }
  29. // CreateDirectory creates a top-level directory on the given vsan datastore, using
  30. // the given user display name hint and opaque storage policy.
  31. func (nm DatastoreNamespaceManager) CreateDirectory(ctx context.Context, ds *Datastore, displayName string, policy string) (string, error) {
  32. req := &types.CreateDirectory{
  33. This: nm.Reference(),
  34. Datastore: ds.Reference(),
  35. DisplayName: displayName,
  36. Policy: policy,
  37. }
  38. resp, err := methods.CreateDirectory(ctx, nm.c, req)
  39. if err != nil {
  40. return "", err
  41. }
  42. return resp.Returnval, nil
  43. }
  44. // DeleteDirectory deletes the given top-level directory from a vsan datastore.
  45. func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Datacenter, datastorePath string) error {
  46. req := &types.DeleteDirectory{
  47. This: nm.Reference(),
  48. DatastorePath: datastorePath,
  49. }
  50. if dc != nil {
  51. ref := dc.Reference()
  52. req.Datacenter = &ref
  53. }
  54. if _, err := methods.DeleteDirectory(ctx, nm.c, req); err != nil {
  55. return err
  56. }
  57. return nil
  58. }