1/* 2Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package object 18 19import ( 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 27type HostDatastoreSystem struct { 28 Common 29} 30 31func NewHostDatastoreSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostDatastoreSystem { 32 return &HostDatastoreSystem{ 33 Common: NewCommon(c, ref), 34 } 35} 36 37func (s HostDatastoreSystem) CreateLocalDatastore(ctx context.Context, name string, path string) (*Datastore, error) { 38 req := types.CreateLocalDatastore{ 39 This: s.Reference(), 40 Name: name, 41 Path: path, 42 } 43 44 res, err := methods.CreateLocalDatastore(ctx, s.Client(), &req) 45 if err != nil { 46 return nil, err 47 } 48 49 return NewDatastore(s.Client(), res.Returnval), nil 50} 51 52func (s HostDatastoreSystem) CreateNasDatastore(ctx context.Context, spec types.HostNasVolumeSpec) (*Datastore, error) { 53 req := types.CreateNasDatastore{ 54 This: s.Reference(), 55 Spec: spec, 56 } 57 58 res, err := methods.CreateNasDatastore(ctx, s.Client(), &req) 59 if err != nil { 60 return nil, err 61 } 62 63 return NewDatastore(s.Client(), res.Returnval), nil 64} 65 66func (s HostDatastoreSystem) CreateVmfsDatastore(ctx context.Context, spec types.VmfsDatastoreCreateSpec) (*Datastore, error) { 67 req := types.CreateVmfsDatastore{ 68 This: s.Reference(), 69 Spec: spec, 70 } 71 72 res, err := methods.CreateVmfsDatastore(ctx, s.Client(), &req) 73 if err != nil { 74 return nil, err 75 } 76 77 return NewDatastore(s.Client(), res.Returnval), nil 78} 79 80func (s HostDatastoreSystem) Remove(ctx context.Context, ds *Datastore) error { 81 req := types.RemoveDatastore{ 82 This: s.Reference(), 83 Datastore: ds.Reference(), 84 } 85 86 _, err := methods.RemoveDatastore(ctx, s.Client(), &req) 87 if err != nil { 88 return err 89 } 90 91 return nil 92} 93 94func (s HostDatastoreSystem) QueryAvailableDisksForVmfs(ctx context.Context) ([]types.HostScsiDisk, error) { 95 req := types.QueryAvailableDisksForVmfs{ 96 This: s.Reference(), 97 } 98 99 res, err := methods.QueryAvailableDisksForVmfs(ctx, s.Client(), &req) 100 if err != nil { 101 return nil, err 102 } 103 104 return res.Returnval, nil 105} 106 107func (s HostDatastoreSystem) QueryVmfsDatastoreCreateOptions(ctx context.Context, devicePath string) ([]types.VmfsDatastoreOption, error) { 108 req := types.QueryVmfsDatastoreCreateOptions{ 109 This: s.Reference(), 110 DevicePath: devicePath, 111 } 112 113 res, err := methods.QueryVmfsDatastoreCreateOptions(ctx, s.Client(), &req) 114 if err != nil { 115 return nil, err 116 } 117 118 return res.Returnval, nil 119} 120