def DisableMultipath(naa): client = MultipathClient() with open(util.MULTIPATH_CONF, 'r') as fd: multipath_config_string = fd.read() _config = config.Configuration.from_multipathd_conf( multipath_config_string) # delete whitelist wwid white_list = _config.whitelist.wwid multipath_list = _config.multipaths # check naa if ('"%s"' % naa) not in white_list: raise store_exception.StoreInvalidException(naa) white_list.remove('"%s"' % naa) # delete multipath section if have for multipath in multipath_list: if naa == multipath.wwid.strip('"'): multipath_list.remove(multipath) break # reconfigure client.write_to_multipathd_conf(_config) util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD) logging.info("Naa %s is disable multipath." % naa)
def SetPolicy(naa, policy): client = MultipathClient() with open(util.MULTIPATH_CONF, 'r') as fd: multipath_config_string = fd.read() _config = config.Configuration.from_multipathd_conf( multipath_config_string) white_list = _config.whitelist.wwid multipath_list = _config.multipaths # check naa if ('"%s"' % naa) not in white_list: raise store_exception.StoreInvalidException(naa) # delete old multipath section for multipath in multipath_list: if naa == multipath.wwid.strip('"'): multipath_list.remove(multipath) break # new multipath section new_section = config.MultipathEntry() if policy == adp_pb2.DEFAULT: logging.info("Naa %s policy change to DEFAULT." % naa) if policy == adp_pb2.RECENTLY_USED: new_section.wwid = '"%s"' % naa new_section.path_grouping_policy = '"failover"' new_section.failback = '"manual"' multipath_list.append(new_section) logging.info("Naa %s policy change to RECENTLY_USED." % naa) if policy == adp_pb2.FIXED: new_section.wwid = '"%s"' % naa new_section.path_grouping_policy = '"failover"' new_section.failback = '"immediate"' multipath_list.append(new_section) logging.info("Naa %s policy change to FIXED." % naa) if policy == adp_pb2.LOOP: new_section.wwid = '"%s"' % naa new_section.path_grouping_policy = '"multibus"' multipath_list.append(new_section) logging.info("Naa %s policy change to LOOP." % naa) if policy == adp_pb2.OPTIMAL: new_section.wwid = '"%s"' % naa new_section.path_grouping_policy = '"group_by_prio"' new_section.prio = '"alua"' new_section.failback = '"immediate"' multipath_list.append(new_section) logging.info("Naa %s policy change to OPTIMAL." % naa) # reconfigure client.write_to_multipathd_conf(_config) util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD)
def GetMultipathJson(): client = MultipathClient() json_string = '' try: json_string = client._send_and_receive("show multipaths json") except errors.TimeoutExpired: logging.error(traceback.format_exc()) except errors.ConnectionError: logging.error(traceback.format_exc()) finally: return json_string
def SetDefaultConfig(): # get default_multipath.conf client = MultipathClient() with open(DEFAULT_CONFIG, 'r') as fd: default_config_string = fd.read() logging.info("default_config_string is %s" % default_config_string) default_config = config.Configuration.from_multipathd_conf( default_config_string) # write to /etc/multipath.conf client.write_to_multipathd_conf(default_config) # reconfigure util.StoreCmdRun("%s reconfigure " % util.MULTIPATHD)
def get_all_multipath_block_devices(self): from infi.multipathtools import MultipathClient from infi.multipathtools.connection import UnixDomainSocket client = MultipathClient(UnixDomainSocket(timeout=120)) if not client.is_running(): logger.warning("multipathd is not running") return [] devices = self._get_list_of_active_devices(client) result = [] logger.debug("Got {} devices from multipath client".format(len(devices))) for mpath_device in devices: block_dev = self.sysfs.find_block_device_by_devno(mpath_device.major_minor) if block_dev is not None: result.append(LinuxNativeMultipathBlockDevice(self.sysfs, block_dev, mpath_device)) living_devices = filter(lambda device: device._is_there_atleast_one_path_up(), result) return living_devices
def EnableMultipath(naa): client = MultipathClient() with open(util.MULTIPATH_CONF, 'r') as fd: multipath_config_string = fd.read() _config = config.Configuration.from_multipathd_conf( multipath_config_string) # check naa if ('"%s"' % naa) in _config.whitelist.wwid: logging.info('naa %s is already set multipath.' % naa) else: _config.whitelist.wwid.append('"%s"' % naa) client.write_to_multipathd_conf(_config) # reconfigure util.StoreCmdRun("%s reconfigure" % util.MULTIPATHD) logging.info("Naa %s is enable multipath." % naa)
def get_all_multipath_block_devices(self): from infi.multipathtools import MultipathClient client = MultipathClient() if not client.is_running(): logger.info("MultipathD is not running") return [] try: devices = self._get_list_of_active_devices(client) except IOError: raise DeviceDisappeared() result = [] logger.debug("Got {} devices from multipath client".format(len(devices))) for mpath_device in devices: block_dev = self.sysfs.find_block_device_by_devno(mpath_device.major_minor) if block_dev is not None: result.append(LinuxNativeMultipathBlockDevice(self.sysfs, block_dev, mpath_device)) living_devices = filter(lambda device: device._is_there_atleast_one_path_up(), result) return living_devices
def _GetConfigByMultipathd(): ''' get config by multipathd ''' m_config = config.Configuration() client = MultipathClient() flag = False try: m_config = client.get_multipathd_conf() return m_config except errors.TimeoutExpired: flag = True logging.error(traceback.format_exc()) except errors.ConnectionError: flag = True logging.error(traceback.format_exc()) finally: if flag: raise store_exception.StoreMultipathdException( "Multipatd Exception.")
def get_all_multipath_block_devices(self): from infi.multipathtools import MultipathClient from infi.multipathtools.connection import UnixDomainSocket client = MultipathClient(UnixDomainSocket(timeout=120)) if not client.is_running(): logger.warning("multipathd is not running") return [] devices = self._get_list_of_active_devices(client) result = [] logger.debug("Got {} devices from multipath client".format( len(devices))) for mpath_device in devices: block_dev = self.sysfs.find_block_device_by_devno( mpath_device.major_minor) if block_dev is not None: result.append( LinuxNativeMultipathBlockDevice(self.sysfs, block_dev, mpath_device)) living_devices = [ device for device in result if device._is_there_atleast_one_path_up() ] return living_devices