github.com/vmware/govmomi@v0.37.2/simulator/host_storage_system.go (about)

     1  /*
     2  Copyright (c) 2020 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 simulator
    18  
    19  import (
    20  	"github.com/vmware/govmomi/simulator/esx"
    21  	"github.com/vmware/govmomi/vim25/methods"
    22  	"github.com/vmware/govmomi/vim25/mo"
    23  	"github.com/vmware/govmomi/vim25/soap"
    24  	"github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  type HostStorageSystem struct {
    28  	mo.HostStorageSystem
    29  
    30  	Host *mo.HostSystem
    31  	HBA  []types.BaseHostHostBusAdapter
    32  }
    33  
    34  func NewHostStorageSystem(h *mo.HostSystem) *HostStorageSystem {
    35  	s := &HostStorageSystem{Host: h}
    36  
    37  	s.StorageDeviceInfo = &esx.HostStorageDeviceInfo
    38  
    39  	s.HBA = fibreChannelHBA
    40  
    41  	return s
    42  }
    43  
    44  // RescanAllHba swaps HostStorageSystem.HBA and StorageDeviceInfo.HostBusAdapter.
    45  // This allows testing HBA with and without Fibre Channel data.
    46  func (s *HostStorageSystem) RescanAllHba(ctx *Context, _ *types.RescanAllHba) soap.HasFault {
    47  	hba := s.StorageDeviceInfo.HostBusAdapter
    48  	s.StorageDeviceInfo.HostBusAdapter = s.HBA
    49  	s.HBA = hba
    50  
    51  	ctx.WithLock(s.Host, func() {
    52  		s.Host.Config.StorageDevice.HostBusAdapter = s.StorageDeviceInfo.HostBusAdapter
    53  	})
    54  
    55  	return &methods.RescanAllHbaBody{
    56  		Res: new(types.RescanAllHbaResponse),
    57  	}
    58  }
    59  
    60  func (s *HostStorageSystem) RescanVmfs(*Context, *types.RescanVmfs) soap.HasFault {
    61  	return &methods.RescanVmfsBody{Res: new(types.RescanVmfsResponse)}
    62  }
    63  
    64  func (s *HostStorageSystem) RefreshStorageSystem(*Context, *types.RefreshStorageSystem) soap.HasFault {
    65  	return &methods.RefreshStorageSystemBody{Res: new(types.RefreshStorageSystemResponse)}
    66  }
    67  
    68  // HBA with FibreChannel data, see RescanAllHba()
    69  var fibreChannelHBA = []types.BaseHostHostBusAdapter{
    70  	&types.HostBlockHba{
    71  		HostHostBusAdapter: types.HostHostBusAdapter{
    72  			Key:    "key-vim.host.BlockHba-vmhba0",
    73  			Device: "vmhba0",
    74  			Bus:    0,
    75  			Status: "unknown",
    76  			Model:  "Lewisburg SATA AHCI Controller",
    77  			Driver: "vmw_ahci",
    78  			Pci:    "0000:00:11.5",
    79  		},
    80  	},
    81  	&types.HostBlockHba{
    82  		HostHostBusAdapter: types.HostHostBusAdapter{
    83  			Key:    "key-vim.host.BlockHba-vmhba1",
    84  			Device: "vmhba1",
    85  			Bus:    0,
    86  			Status: "unknown",
    87  			Model:  "Lewisburg SATA AHCI Controller",
    88  			Driver: "vmw_ahci",
    89  			Pci:    "0000:00:17.0",
    90  		},
    91  	},
    92  	&types.HostFibreChannelHba{
    93  		HostHostBusAdapter: types.HostHostBusAdapter{
    94  			Key:    "key-vim.host.FibreChannelHba-vmhba2",
    95  			Device: "vmhba2",
    96  			Bus:    59,
    97  			Status: "online",
    98  			Model:  "Emulex LightPulse LPe32000 PCIe Fibre Channel Adapter",
    99  			Driver: "lpfc",
   100  			Pci:    "0000:3b:00.0",
   101  		},
   102  		PortWorldWideName: 1152922127287604726,
   103  		NodeWorldWideName: 2305843631894451702,
   104  		PortType:          "unknown",
   105  		Speed:             16,
   106  	},
   107  	&types.HostFibreChannelHba{
   108  		HostHostBusAdapter: types.HostHostBusAdapter{
   109  			Key:    "key-vim.host.FibreChannelHba-vmhba3",
   110  			Device: "vmhba3",
   111  			Bus:    95,
   112  			Status: "online",
   113  			Model:  "Emulex LightPulse LPe32000 PCIe Fibre Channel Adapter",
   114  			Driver: "lpfc",
   115  			Pci:    "0000:5f:00.0",
   116  		},
   117  		PortWorldWideName: 1152922127287604554,
   118  		NodeWorldWideName: 2305843631894451530,
   119  		PortType:          "unknown",
   120  		Speed:             16,
   121  	},
   122  	&types.HostSerialAttachedHba{
   123  		HostHostBusAdapter: types.HostHostBusAdapter{
   124  			Key:    "key-vim.host.SerialAttachedHba-vmhba4",
   125  			Device: "vmhba4",
   126  			Bus:    24,
   127  			Status: "unknown",
   128  			Model:  "PERC H330 Adapter",
   129  			Driver: "lsi_mr3",
   130  			Pci:    "0000:18:00.0",
   131  		},
   132  		NodeWorldWideName: "5d0946606e78ac00",
   133  	},
   134  }