예제 #1
0
 def _set_alua_access_state(self, newstate):
     self._check_self()
     path = "%s/alua_access_state" % self.path
     try:
         fwrite(path, str(int(newstate)))
     except IOError as e:
         raise RTSLibError("Cannot change ALUA state: %s" % e)
예제 #2
0
 def _set_alua_access_type(self, access_type):
     self._check_self()
     path = "%s/alua_access_type" % self.path
     try:
         fwrite(path, str(int(access_type)))
     except IOError as e:
         raise RTSLibError("Cannot change ALUA access type: %s" % e)
예제 #3
0
    def __init__(self, storage_obj, name, tag=None):
        """
        @param storage_obj: backstore storage object to create ALUA group for
        @param name: name of ALUA group
        @param tag: target port group id. If not passed in, try to look
                    up existing ALUA TPG with the same name
        """

        # default_tg_pt_gp takes tag 1
        if tag is not None and (tag > 65535 or tag < 1):
            raise RTSLibError("The TPG Tag must be between 1 and 65535")

        super(ALUATargetPortGroup, self).__init__()
        self.name = name
        self.storage_obj = storage_obj

        self._path = "%s/alua/%s" % (storage_obj.path, name)

        if tag is not None:
            try:
                self._create_in_cfs_ine('create')
            except OSError as msg:
                raise RTSLibError(msg)

            try:
                fwrite("%s/tg_pt_gp_id" % self._path, tag)
            except IOError as msg:
                self.delete()
                raise RTSLibError("Cannot set id to %d: %s" % (tag, str(msg)))
        else:
            try:
                self._create_in_cfs_ine('lookup')
            except OSError as msg:
                raise RTSLibError(msg)
예제 #4
0
 def _set_nonop_delay_msecs(self, delay):
     self._check_self()
     path = "%s/nonop_delay_msecs" % self.path
     try:
         fwrite(path, str(int(delay)))
     except IOError as e:
         raise RTSLibError("Cannot set nonop_delay_msecs: %s" % e)
예제 #5
0
 def _set_alua_support_standby(self, enabled):
     self._check_self()
     path = "%s/alua_support_standby" % self.path
     try:
         fwrite(path, str(int(enabled)))
     except IOError as e:
         raise RTSLibError("Cannot set alua_support_standby: %s" % e)
예제 #6
0
 def _set_preferred(self, pref):
     self._check_self()
     path = "%s/preferred" % self.path
     try:
         fwrite(path, str(int(pref)))
     except IOError as e:
         raise RTSLibError("Cannot set preferred: %s" % e)
예제 #7
0
 def _set_alua_support_active_optimized(self, enabled):
     self._check_self()
     path = "%s/alua_support_active_optimized" % self.path
     try:
         fwrite(path, str(int(enabled)))
     except IOError as e:
         raise RTSLibError("Cannot set alua_support_active_optimized: %s" %
                           e)
예제 #8
0
def set_alua(lun, desired_state='standby'):
    """
    Sets the ALUA state of a LUN (active/standby)
    :param lun: LIO LUN object
    :param desired_state: active or standby state
    :return: None
    """

    alua_state_options = {
        "active": '0',
        "active/unoptimized": '1',
        "standby": '2'
    }
    configfs_path = lun.path
    lun_name = lun.name
    alua_access_state = 'alua/default_tg_pt_gp/alua_access_state'
    alua_access_type = 'alua/default_tg_pt_gp/alua_access_type'
    type_fullpath = os.path.join(configfs_path, alua_access_type)

    if fread(type_fullpath) != 'Implicit':
        logger.info(
            "(set_alua) Switching device alua access type to Implicit - i.e. active path set by gateways"
        )
        fwrite(type_fullpath, '1')
    else:
        logger.debug(
            "(set_alua) lun alua_access_type already set to Implicit - no change needed"
        )

    state_fullpath = os.path.join(configfs_path, alua_access_state)
    if fread(state_fullpath) != alua_state_options[desired_state]:
        logger.debug(
            "(set_alua) Updating alua_access_state for {} to {}".format(
                lun_name, desired_state))
        fwrite(state_fullpath, alua_state_options[desired_state])
    else:
        logger.debug(
            "(set_alua) Skipping alua update - already set to desired state '{}'"
            .format(desired_state))
예제 #9
0
 def bind_to_lun(self, mapped_lun):
     path = "%s/alua_tg_pt_gp" % mapped_lun.path
     try:
         fwrite(path, str(self.name))
     except IOError as msg:
         raise RTSLibError("Cannot set tpg: " % str(msg))