github.com/vmware/govmomi@v0.37.2/object/host_storage_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  	"errors"
    22  
    23  	"github.com/vmware/govmomi/vim25"
    24  	"github.com/vmware/govmomi/vim25/methods"
    25  	"github.com/vmware/govmomi/vim25/types"
    26  )
    27  
    28  type HostStorageSystem struct {
    29  	Common
    30  }
    31  
    32  func NewHostStorageSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostStorageSystem {
    33  	return &HostStorageSystem{
    34  		Common: NewCommon(c, ref),
    35  	}
    36  }
    37  
    38  func (s HostStorageSystem) RetrieveDiskPartitionInfo(ctx context.Context, devicePath string) (*types.HostDiskPartitionInfo, error) {
    39  	req := types.RetrieveDiskPartitionInfo{
    40  		This:       s.Reference(),
    41  		DevicePath: []string{devicePath},
    42  	}
    43  
    44  	res, err := methods.RetrieveDiskPartitionInfo(ctx, s.c, &req)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	if res.Returnval == nil || len(res.Returnval) == 0 {
    50  		return nil, errors.New("no partition info")
    51  	}
    52  
    53  	return &res.Returnval[0], nil
    54  }
    55  
    56  func (s HostStorageSystem) ComputeDiskPartitionInfo(ctx context.Context, devicePath string, layout types.HostDiskPartitionLayout) (*types.HostDiskPartitionInfo, error) {
    57  	req := types.ComputeDiskPartitionInfo{
    58  		This:       s.Reference(),
    59  		DevicePath: devicePath,
    60  		Layout:     layout,
    61  	}
    62  
    63  	res, err := methods.ComputeDiskPartitionInfo(ctx, s.c, &req)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  
    68  	return &res.Returnval, nil
    69  }
    70  
    71  func (s HostStorageSystem) UpdateDiskPartitionInfo(ctx context.Context, devicePath string, spec types.HostDiskPartitionSpec) error {
    72  	req := types.UpdateDiskPartitions{
    73  		This:       s.Reference(),
    74  		DevicePath: devicePath,
    75  		Spec:       spec,
    76  	}
    77  
    78  	_, err := methods.UpdateDiskPartitions(ctx, s.c, &req)
    79  	return err
    80  }
    81  
    82  func (s HostStorageSystem) RescanAllHba(ctx context.Context) error {
    83  	req := types.RescanAllHba{
    84  		This: s.Reference(),
    85  	}
    86  
    87  	_, err := methods.RescanAllHba(ctx, s.c, &req)
    88  	return err
    89  }
    90  
    91  func (s HostStorageSystem) Refresh(ctx context.Context) error {
    92  	req := types.RefreshStorageSystem{
    93  		This: s.Reference(),
    94  	}
    95  
    96  	_, err := methods.RefreshStorageSystem(ctx, s.c, &req)
    97  	return err
    98  }
    99  
   100  func (s HostStorageSystem) RescanVmfs(ctx context.Context) error {
   101  	req := types.RescanVmfs{
   102  		This: s.Reference(),
   103  	}
   104  
   105  	_, err := methods.RescanVmfs(ctx, s.c, &req)
   106  	return err
   107  }
   108  
   109  func (s HostStorageSystem) MarkAsSsd(ctx context.Context, uuid string) (*Task, error) {
   110  	req := types.MarkAsSsd_Task{
   111  		This:         s.Reference(),
   112  		ScsiDiskUuid: uuid,
   113  	}
   114  
   115  	res, err := methods.MarkAsSsd_Task(ctx, s.c, &req)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  
   120  	return NewTask(s.c, res.Returnval), nil
   121  }
   122  
   123  func (s HostStorageSystem) MarkAsNonSsd(ctx context.Context, uuid string) (*Task, error) {
   124  	req := types.MarkAsNonSsd_Task{
   125  		This:         s.Reference(),
   126  		ScsiDiskUuid: uuid,
   127  	}
   128  
   129  	res, err := methods.MarkAsNonSsd_Task(ctx, s.c, &req)
   130  	if err != nil {
   131  		return nil, err
   132  	}
   133  
   134  	return NewTask(s.c, res.Returnval), nil
   135  }
   136  
   137  func (s HostStorageSystem) MarkAsLocal(ctx context.Context, uuid string) (*Task, error) {
   138  	req := types.MarkAsLocal_Task{
   139  		This:         s.Reference(),
   140  		ScsiDiskUuid: uuid,
   141  	}
   142  
   143  	res, err := methods.MarkAsLocal_Task(ctx, s.c, &req)
   144  	if err != nil {
   145  		return nil, err
   146  	}
   147  
   148  	return NewTask(s.c, res.Returnval), nil
   149  }
   150  
   151  func (s HostStorageSystem) MarkAsNonLocal(ctx context.Context, uuid string) (*Task, error) {
   152  	req := types.MarkAsNonLocal_Task{
   153  		This:         s.Reference(),
   154  		ScsiDiskUuid: uuid,
   155  	}
   156  
   157  	res, err := methods.MarkAsNonLocal_Task(ctx, s.c, &req)
   158  	if err != nil {
   159  		return nil, err
   160  	}
   161  
   162  	return NewTask(s.c, res.Returnval), nil
   163  }
   164  
   165  func (s HostStorageSystem) AttachScsiLun(ctx context.Context, uuid string) error {
   166  	req := types.AttachScsiLun{
   167  		This:    s.Reference(),
   168  		LunUuid: uuid,
   169  	}
   170  
   171  	_, err := methods.AttachScsiLun(ctx, s.c, &req)
   172  
   173  	return err
   174  }
   175  
   176  func (s HostStorageSystem) QueryUnresolvedVmfsVolumes(ctx context.Context) ([]types.HostUnresolvedVmfsVolume, error) {
   177  	req := &types.QueryUnresolvedVmfsVolume{
   178  		This: s.Reference(),
   179  	}
   180  
   181  	res, err := methods.QueryUnresolvedVmfsVolume(ctx, s.Client(), req)
   182  	if err != nil {
   183  		return nil, err
   184  	}
   185  	return res.Returnval, nil
   186  }
   187  
   188  func (s HostStorageSystem) UnmountVmfsVolume(ctx context.Context, vmfsUuid string) error {
   189  	req := &types.UnmountVmfsVolume{
   190  		This:     s.Reference(),
   191  		VmfsUuid: vmfsUuid,
   192  	}
   193  
   194  	_, err := methods.UnmountVmfsVolume(ctx, s.Client(), req)
   195  	if err != nil {
   196  		return err
   197  	}
   198  
   199  	return nil
   200  }