Beispiel #1
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)
Beispiel #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)
Beispiel #3
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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #8
0
    def delete(self, config):

        saved_err = None

        if self.target is None:
            self.load_config()
            # Ignore errors. Target was probably not setup. Try to clean up
            # disks.

        if self.target:
            try:
                self.target.delete()
            except RTSLibError as err:
                self.logger.error("lio target deletion failed {}".format(err))
                saved_err = err
                # drop down and try to delete disks

        for disk in config.config['targets'][self.iqn]['disks']:
            so = lookup_storage_object_by_disk(config, disk)
            if so is None:
                self.logger.debug("lio disk lookup failed {}")
                # SO may not have got setup. Ignore.
                continue
            if so.status == 'activated':
                # Still mapped so ignore.
                continue

            try:
                so.delete()
            except RTSLibError as err:
                self.logger.error("lio disk deletion failed {}".format(err))
                if saved_err is None:
                    saved_err = err
                # Try the other disks.

        if saved_err:
            raise RTSLibError(saved_err)
Beispiel #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))