github.com/vmware/govmomi@v0.51.0/object/host_storage_system.go (about)

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