def find_disk_drive_by_block_access_path(self, path): from infi.storagemodel import get_storage_model scsi = get_storage_model().get_scsi() multipath = get_storage_model().get_native_multipath() storage_device = filter(lambda device: device.get_block_access_path() == path, scsi.get_all_scsi_block_devices() + multipath.get_all_multipath_block_devices())[0] return LinuxDiskDrive(storage_device, path)
def find_disk_drive_by_block_access_path(self, path): from infi.storagemodel import get_storage_model scsi = get_storage_model().get_scsi() multipath = get_storage_model().get_native_multipath() all_devices = scsi.get_all_scsi_block_devices() + multipath.get_all_multipath_block_devices() storage_device = [device for device in all_devices if device.get_block_access_path() == path][0] return WindowsDiskDrive(storage_device, path)
def terminate_connection(cinder_volume, connector): from infi.storagemodel import get_storage_model for item in connector["wwns"] + connector["wwpns"]: assert isinstance(item, basestring) cls.volume_driver_by_type[cinder_volume.volume_type].terminate_connection(cinder_volume, connector) get_storage_model().refresh()
def console_script(): from platform import system from sys import stderr from logging import DEBUG, basicConfig if system() != "Linux": print "This script is for Linux only" basicConfig(stream=stderr, level=DEBUG) from infi.storagemodel import get_storage_model get_storage_model().rescan_and_wait_for(wait_on_rescan=True)
def console_script(): from platform import system from sys import stderr from logging import DEBUG, basicConfig if system() != "Linux": print("This script is for Linux only") basicConfig(stream=stderr, level=DEBUG, datefmt='%Y-%m-%d %H:%M:%S %z', format='%(asctime)-25s %(levelname)-8s %(name)-50s %(message)s') from infi.storagemodel import get_storage_model get_storage_model().rescan_and_wait_for(wait_for_completion=True)
def main(): from infi.storagemodel import get_storage_model print("\nPython Inquiry utility, Version V0.1 (using storagemodel by INFINIDAT)\n") print("-----------------------------------------------------------------------------------------------------------------------------------------------") print("DEVICE \t:VEND \t:PROD \t:REV \t:SER NUM \t:CAP(kb) \t:PATHS") print("-----------------------------------------------------------------------------------------------------------------------------------------------") logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("inq") model = get_storage_model() scsi = model.get_scsi() mpio = model.get_native_multipath() mpaths = mpio.get_all_multipath_block_devices() block_devices = scsi.get_all_scsi_block_devices() non_mp_disks = mpio.filter_non_multipath_scsi_block_devices(block_devices) all_devices = non_mp_disks + mpaths try: all_devices.extend(model.get_veritas_multipath().get_all_multipath_block_devices()) except: logger.exception("an error ocurred when fetching veritas multipath devices") for device in all_devices: try: print_device_details(device) except: logger.exception("an error ocurred when printing device details")
def __call__(self): from infi.storagemodel import get_storage_model model = get_storage_model() scsi = model.get_scsi() [device.get_scsi_test_unit_ready() for device in scsi.get_all_storage_controller_devices()] [device.get_scsi_test_unit_ready() for device in scsi.get_all_scsi_block_devices()] return True
def __call__(self): from infi.storagemodel import get_storage_model model = get_storage_model() multipath = model.get_native_multipath() [device.get_scsi_test_unit_ready() for device in multipath.get_all_multipath_block_devices()] [device.get_scsi_test_unit_ready() for device in multipath.get_all_multipath_storage_controller_devices()] return True
def test_get_sda(self): from infi.storagemodel import get_storage_model model = get_storage_model() block_devices = model.get_scsi().get_all_scsi_block_devices() disk = block_devices[0].get_disk_drive() self.assertFalse(disk.is_empty()) partition_table = disk.get_partition_table() self.assertEqual(len(partition_table.get_partitions()), 3) size = disk.get_size_in_bytes()
def get_disk_drive(self): # pragma: no cover """ Returns a `infi.storagemodel.base.disk.DiskDrive` instance. Raises `infi.storagemodel.base.disk.NoSuchDisk` if not found. """ from infi.storagemodel import get_storage_model model = get_storage_model().get_disk() return model.find_disk_drive_by_block_access_path(self.get_block_access_path())
def test_cached_methods(self): raise unittest.SkipTest("Skipping this test because _create_disk_model is not implemented on Windows and Linux for now") from infi.pyutils.lazy import populate_cache from infi.storagemodel import get_storage_model model = get_storage_model() scsi = model.get_scsi() native_multipath = model.get_native_multipath() devices = scsi.get_all_scsi_block_devices() + native_multipath.get_all_multipath_block_devices() for device in devices: populate_cache(device)
def _get_volume(self): from infi.wioctl.api import WindowsException from infi.storagemodel import get_storage_model from infi.diskmanagement.disk import Volume func = gevent_wrapper.defer(Volume.get_from_disk_and_partition) try: return func(self._partition_object._disk, self._partition_object, get_storage_model()._create_mount_manager().mount_manager) except WindowsException: logger.exception("get_volume caught WindowsException") raise RescanIsNeeded()
def __call__(self): from .. import get_storage_model model = get_storage_model() block_devices = model.get_scsi().get_all_scsi_block_devices() mp_devices = model.get_native_multipath().get_all_multipath_block_devices() non_mp_devices = model.get_native_multipath().filter_non_multipath_scsi_block_devices(block_devices) devices = mp_devices + non_mp_devices for device in devices: device.get_scsi_test_unit_ready() return any([device.get_scsi_serial_number() == self.scsi_serial_number \ for device in devices])
def veritas_multipathing_context(output): if "windows" in get_platform_string(): raise SkipTest with patch('infi.storagemodel.unix.veritas_multipath.VeritasMultipathClient.read_paths_list') as read_paths_list: with patch('infi.storagemodel.linux.sysfs.Sysfs.find_scsi_disk_by_hctl') as find_scsi_disk_by_hctl: with patch('infi.storagemodel.base.scsi.SCSIModel.find_scsi_block_device_by_block_access_path') as find_func: find_func.return_value = MockSCSIBlockDevice(None) find_scsi_disk_by_hctl.return_value = None read_paths_list.return_value = output sm = get_storage_model() clear_cache(sm) yield sm.get_veritas_multipath()
def test_cached_methods(self): raise unittest.SkipTest( "Skipping this test because _create_disk_model is not implemented on Windows and Linux for now" ) from infi.pyutils.lazy import populate_cache from infi.storagemodel import get_storage_model model = get_storage_model() scsi = model.get_scsi() native_multipath = model.get_native_multipath() devices = scsi.get_all_scsi_block_devices( ) + native_multipath.get_all_multipath_block_devices() for device in devices: populate_cache(device)
def __call__(self): from infi.storagemodel import get_storage_model model = get_storage_model() scsi = model.get_scsi() [ device.get_scsi_test_unit_ready() for device in scsi.get_all_storage_controller_devices() ] [ device.get_scsi_test_unit_ready() for device in scsi.get_all_scsi_block_devices() ] return True
def __call__(self): from infi.storagemodel import get_storage_model model = get_storage_model() multipath = model.get_native_multipath() [ device.get_scsi_test_unit_ready() for device in multipath.get_all_multipath_block_devices() ] [ device.get_scsi_test_unit_ready() for device in multipath.get_all_multipath_storage_controller_devices() ] return True
def __call__(self): from .. import get_storage_model model = get_storage_model() self._build_product() logger.debug("Working on: {!r}".format(self)) logger.debug("Looking for all scsi block devices") logger.debug("Expecting to find {} matches".format(len(self._expected_mappings))) for device in self._get_chain_of_devices(model): logger.debug("Found device: {!r}".format(device)) if self._is_fc_connectivity_a_match(device): logger.debug("Connectivity matches, only {} more to go".format(self._expected_mappings)) for device in model.get_native_multipath().get_all_multipath_block_devices(): logger.debug("Found device: {!r}".format(device)) for path in device.get_paths(): if self._is_fc_connectivity_a_match(path): logger.debug("Connectivity matches, only {} more to go".format(self._expected_mappings)) if self._expected_mappings: logger.debug("Did not find all the mappings, {} missing".format(len(self._expected_mappings))) return False logger.debug("Found all expected mappings") return True
def __call__(self): from .. import get_storage_model model = get_storage_model() self._build_product() initial_count = len(self._expected_mappings) logger.debug("Working on: {!r}".format(self)) logger.debug("Looking for all scsi block devices") logger.debug("Expecting to not find {} matches".format(initial_count)) for device in self._get_chain_of_devices(model): logger.debug("Found device: {!r}".format(device)) if self._is_fc_connectivity_a_match(device): logger.debug("Found a connectivity match I wasn't supposed to find") return False for device in model.get_native_multipath().get_all_multipath_block_devices(): logger.debug("Found device: {!r}".format(device)) for path in device.get_paths(): if self._is_fc_connectivity_a_match(path): logger.debug("Found a connectivity match I wasn't supposed to find") return False logger.debug("Did not find any of the expected mappings") return True
def main(): from infi.storagemodel import get_storage_model print("\nPython Inquiry utility, Version V0.1 (using storagemodel by INFINIDAT)\n") print("-----------------------------------------------------------------------------------------------------------------------------------------------") print("DEVICE \t:VEND \t:PROD \t:REV \t:SER NUM \t:CAP(kb) \t:PATHS") print("-----------------------------------------------------------------------------------------------------------------------------------------------") model = get_storage_model() scsi = model.get_scsi() mpio = model.get_native_multipath() mpaths = mpio.get_all_multipath_block_devices() block_devices = scsi.get_all_scsi_block_devices() non_mp_disks = mpio.filter_non_multipath_scsi_block_devices(block_devices) all_devices = non_mp_disks + mpaths for device in all_devices: try: print_device_details(device) except: pass
def __call__(self): from .. import get_storage_model model = get_storage_model() self._build_product() initial_count = len(self._expected_mappings) logger.debug("Working on: {!r}".format(self)) logger.debug("Looking for all scsi block devices") logger.debug("Expecting to not find {} matches".format(initial_count)) for device in self._get_chain_of_devices(model): logger.debug("Found device: {!r}".format(device)) if self._is_fc_connectivity_a_match(device): logger.debug( "Found a connectivity match I wasn't supposed to find") return False for device in model.get_native_multipath( ).get_all_multipath_block_devices(): logger.debug("Found device: {!r}".format(device)) for path in device.get_paths(): if self._is_fc_connectivity_a_match(path): logger.debug( "Found a connectivity match I wasn't supposed to find") return False logger.debug("Did not find any of the expected mappings") return True
def devlist(): # pylint: disable=R912 from infi.storagemodel import get_storage_model from infi.storagemodel.vendor.infinidat.infinibox import vid_pid as infinibox_vid_pid model = get_storage_model() scsi_block_devices = model.get_scsi().get_all_scsi_block_devices() mp_devices = model.get_native_multipath().get_all_multipath_block_devices() non_mp_devices = model.get_native_multipath( ).filter_non_multipath_scsi_block_devices(scsi_block_devices) def print_header(header): print("%s\n%s" % (header, '=' * len(header))) print_header("Multipath Devices") def print_infinidat_device(device): print("skipping") def print_multipath_device(device): from infi.storagemodel.base.multipath import FailoverOnly, WeightedPaths, RoundRobinWithSubset print("{name}\t{size}MB\t{vid}\t{pid}\t{policy}\t{path_count}".format( name=device.get_display_name(), size=device.get_size_in_bytes() / 1024 / 1024, vid=device.get_scsi_vendor_id(), pid=device.get_scsi_product_id(), policy=device.get_policy().get_display_name(), path_count=len(device.get_paths()))) for path in device.get_paths(): print("\t\t{id}\t{state}\t{hctl!r}".format( id=path.get_display_name(), state=path.get_state(), hctl=path.get_hctl())), if isinstance(device.get_policy(), FailoverOnly): print("\t" + ("Active" if path.get_path_id() == device.get_policy().active_path_id else "Standby")) elif isinstance(device.get_policy(), RoundRobinWithSubset): print("\t" + ("Active" if path.get_path_id() in device.get_policy().active_path_ids else "Standby")) elif isinstance(device.get_policy(), WeightedPaths): print("\t" + "Weight " + str(device.get_policy().weights[path.get_path_id()])) else: print('') print("\t\t\t{} <--> {}".format( path.get_connectivity().get_initiator_wwn(), path.get_connectivity().get_target_wwn())) for device in model.get_native_multipath().filter_vendor_specific_devices( mp_devices, infinibox_vid_pid): print_multipath_device(device) print_infinidat_device(device) mp_devices.remove(device) for device in mp_devices: print_multipath_device(device) def print_non_multipath_device(device): from infi.storagemodel.connectivity import FCConnectivity print("{name}\t{size}MB\t{vid}\t{pid}\t{hctl}".format( name=device.get_display_name(), size=device.get_size_in_bytes() / 1024 / 1024, vid=device.get_scsi_vendor_id(), pid=device.get_scsi_product_id(), hctl=device.get_hctl())) if isinstance(device.get_connectivity(), FCConnectivity): print("\t{} <-->".format( device.get_connectivity().get_initiator_wwn(), device.get_connectivity().get_target_wwn())) print_header("Non-Multipath Devices") for device in model.get_scsi().filter_vendor_specific_devices( non_mp_devices, infinibox_vid_pid): print_non_multipath_device(device) print_infinidat_device(device) non_mp_devices.remove(device) for device in non_mp_devices: print_non_multipath_device(device)
def test_rescan__wait_for_completion(self): from infi.storagemodel import get_storage_model get_storage_model().rescan_and_wait_for(wait_on_rescan=True)
def test_rescan__timeout(self): from infi.storagemodel import get_storage_model from infi.storagemodel.errors import TimeoutError from infi.storagemodel.predicates import DiskExists self.assertRaises(TimeoutError, get_storage_model().rescan_and_wait_for, *(DiskExists("fooBar"), 1))
def setUp(self): try: self.model = get_storage_model() except ImportError: raise unittest.SkipTest() self.scsi = self.model.get_scsi()
def test_rescan__nothing(self): from infi.storagemodel import get_storage_model get_storage_model().rescan_and_wait_for()
def get_disk_drive(self): # pragma: no cover """:returns: a :class:`.DiskDevice` object :raises: NoSuchDisk""" from infi.storagemodel import get_storage_model model = get_storage_model().get_disk() return model.find_disk_drive_by_block_access_path(self.get_block_access_path())
def test_rescan__wait_for_completion(self): from infi.storagemodel import get_storage_model get_storage_model().rescan_and_wait_for(wait_for_completion=True)
def setUp(self): from infi.storagemodel import get_storage_model try: _ = get_storage_model() except ImportError: raise unittest.SkipTest("Unsupported Platform")
def devlist(): # pylint: disable=R912 from infi.storagemodel import get_storage_model from infi.storagemodel.vendor.infinidat.infinibox import vid_pid as infinibox_vid_pid model = get_storage_model() scsi_block_devices = model.get_scsi().get_all_scsi_block_devices() mp_devices = model.get_native_multipath().get_all_multipath_block_devices() non_mp_devices = model.get_native_multipath().filter_non_multipath_scsi_block_devices(scsi_block_devices) def print_header(header): print "%s\n%s" % (header, '=' * len(header)) print_header("Multipath Devices") def print_infinidat_device(device): print "skipping" def print_multipath_device(device): from infi.storagemodel.base.multipath import FailoverOnly, WeightedPaths, RoundRobinWithSubset print "{name}\t{size}MB\t{vid}\t{pid}\t{policy}\t{path_count}".format(name=device.get_display_name(), size=device.get_size_in_bytes() / 1024 / 1024, vid=device.get_scsi_vendor_id(), pid=device.get_scsi_product_id(), policy=device.get_policy().get_display_name(), path_count=len(device.get_paths())) for path in device.get_paths(): print "\t\t{id}\t{state}\t{hctl!r}".format(id=path.get_display_name(), state=path.get_state(), hctl=path.get_hctl()), if isinstance(device.get_policy(), FailoverOnly): print "\t" + ("Active" if path.get_path_id() == device.get_policy().active_path_id else "Standby") elif isinstance(device.get_policy(), RoundRobinWithSubset): print "\t" + ("Active" if path.get_path_id() in device.get_policy().active_path_ids else "Standby") elif isinstance(device.get_policy(), WeightedPaths): print "\t" + "Weight " + str(device.get_policy().weights[path.get_path_id()]) else: print '' print "\t\t\t{} <--> {}".format(path.get_connectivity().get_initiator_wwn(), path.get_connectivity().get_target_wwn()) for device in model.get_native_multipath().filter_vendor_specific_devices(mp_devices, infinibox_vid_pid): print_multipath_device(device) print_infinidat_device(device) mp_devices.remove(device) for device in mp_devices: print_multipath_device(device) def print_non_multipath_device(device): from infi.storagemodel.connectivity import FCConnectivity print "{name}\t{size}MB\t{vid}\t{pid}\t{hctl}".format(name=device.get_display_name(), size=device.get_size_in_bytes() / 1024 / 1024, vid=device.get_scsi_vendor_id(), pid=device.get_scsi_product_id(), hctl=device.get_hctl()) if isinstance(device.get_connectivity(), FCConnectivity): print "\t{} <-->".format(device.get_connectivity().get_initiator_wwn(), device.get_connectivity().get_target_wwn()) print_header("Non-Multipath Devices") for device in model.get_scsi().filter_vendor_specific_devices(non_mp_devices, infinibox_vid_pid): print_non_multipath_device(device) print_infinidat_device(device) non_mp_devices.remove(device) for device in non_mp_devices: print_non_multipath_device(device)
def get_disk_drive(self): """Returns a `infi.storagemodel.base.disk.DiskDrive` object, or raises `infi.storagemodel.base.disk.NoSuchDisk`""" from infi.storagemodel import get_storage_model model = get_storage_model().get_disk() return model.find_disk_drive_by_block_access_path(self.get_block_access_path())
def get_disk_drive(self): """Returns a `infi.storagemodel.base.disk.DiskDrive` object, or raises `infi.storagemodel.base.disk.NoSuchDisk`""" from infi.storagemodel import get_storage_model model = get_storage_model().get_disk() return model.find_disk_drive_by_block_access_path( self.get_block_access_path())