github.com/vmware/govmomi@v0.37.2/object/host_datastore_system.go (about)

     1  /*
     2  Copyright (c) 2015 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 HostDatastoreSystem struct {
    28  	Common
    29  }
    30  
    31  func NewHostDatastoreSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostDatastoreSystem {
    32  	return &HostDatastoreSystem{
    33  		Common: NewCommon(c, ref),
    34  	}
    35  }
    36  
    37  func (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  
    52  func (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  
    66  func (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  
    80  func (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  
    94  func (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  
   107  func (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  
   121  func (s HostDatastoreSystem) ResignatureUnresolvedVmfsVolumes(ctx context.Context, devicePaths []string) (*Task, error) {
   122  	req := &types.ResignatureUnresolvedVmfsVolume_Task{
   123  		This: s.Reference(),
   124  		ResolutionSpec: types.HostUnresolvedVmfsResignatureSpec{
   125  			ExtentDevicePath: devicePaths,
   126  		},
   127  	}
   128  
   129  	res, err := methods.ResignatureUnresolvedVmfsVolume_Task(ctx, s.Client(), req)
   130  	if err != nil {
   131  		return nil, err
   132  	}
   133  
   134  	return NewTask(s.c, res.Returnval), nil
   135  }