Beispiel #1
0
 def delete_volume(self, volume):
     ldev = self.get_ldev(volume)
     if ldev is None:
         LOG.warning(basic_lib.set_msg(304, method='delete_volume',
                                       id=volume['id']))
         return
     self.add_volinfo(ldev, volume['id'])
     if not self.volume_info[ldev]['in_use'].lock.acquire(False):
         desc = self.volume_info[ldev]['in_use'].desc
         basic_lib.output_err(660, desc=desc)
         raise exception.VolumeIsBusy(volume_name=volume['name'])
     try:
         is_vvol = self.get_volume_is_vvol(volume)
         try:
             self.delete_ldev(ldev, is_vvol)
         except exception.HBSDNotFound:
             with self.volinfo_lock:
                 if ldev in self.volume_info:
                     self.volume_info.pop(ldev)
             LOG.warning(basic_lib.set_msg(
                 305, type='volume', id=volume['id']))
         except exception.HBSDBusy:
             raise exception.VolumeIsBusy(volume_name=volume['name'])
     finally:
         if ldev in self.volume_info:
             self.volume_info[ldev]['in_use'].lock.release()
Beispiel #2
0
 def delete_snapshot(self, snapshot):
     ldev = self.get_ldev(snapshot)
     if ldev is None:
         msg = basic_lib.set_msg(
             304, method='delete_snapshot', id=snapshot['id'])
         LOG.warning(msg)
         return
     self.add_volinfo(ldev, id=snapshot['id'], type='snapshot')
     if not self.volume_info[ldev]['in_use'].lock.acquire(False):
         desc = self.volume_info[ldev]['in_use'].desc
         basic_lib.output_err(660, desc=desc)
         raise exception.SnapshotIsBusy(snapshot_name=snapshot['name'])
     try:
         is_vvol = self.get_snapshot_is_vvol(snapshot)
         try:
             self.delete_ldev(ldev, is_vvol)
         except exception.HBSDNotFound:
             with self.volinfo_lock:
                 if ldev in self.volume_info:
                     self.volume_info.pop(ldev)
             msg = basic_lib.set_msg(
                 305, type='snapshot', id=snapshot['id'])
             LOG.warning(msg)
         except exception.HBSDBusy:
             raise exception.SnapshotIsBusy(snapshot_name=snapshot['name'])
     finally:
         if ldev in self.volume_info:
             self.volume_info[ldev]['in_use'].lock.release()
 def _fill_groups(self, hgs, ports, target_iqn, target_alias, add_iqn):
     for port in ports:
         added_hostgroup = False
         added_user = False
         LOG.debug('Create target (hgs: %(hgs)s port: %(port)s '
                   'target_iqn: %(tiqn)s target_alias: %(alias)s '
                   'add_iqn: %(aiqn)s)' %
                   {'hgs': hgs, 'port': port, 'tiqn': target_iqn,
                    'alias': target_alias, 'aiqn': add_iqn})
         gid = self.common.command.get_gid_from_targetiqn(
             target_iqn, target_alias, port)
         if gid is None:
             for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                 gid = None
                 try:
                     gid = self._get_unused_gid_iscsi(port)
                     self.common.command.comm_add_hostgrp_iscsi(
                         port, gid, target_alias, target_iqn)
                     added_hostgroup = True
                 except exception.HBSDNotFound:
                     msg = basic_lib.set_msg(312, resource='GID')
                     LOG.warning(msg)
                     continue
                 except Exception as ex:
                     msg = basic_lib.set_msg(
                         309, port=port, alias=target_alias,
                         reason=six.text_type(ex))
                     LOG.warning(msg)
                     break
                 else:
                     LOG.debug('Completed to add target'
                               '(port: %(port)s gid: %(gid)d)'
                               % {'port': port, 'gid': gid})
                     break
         if gid is None:
             LOG.error(_LE('Failed to add target(port: %s)') % port)
             continue
         try:
             if added_hostgroup:
                 if self.configuration.hitachi_auth_method:
                     added_user = self.common.command.set_chap_authention(
                         port, gid)
                 self.common.command.comm_set_hostgrp_reportportal(
                     port, target_alias)
             self._add_initiator(hgs, port, gid, add_iqn)
         except Exception as ex:
             msg = basic_lib.set_msg(
                 316, port=port, reason=six.text_type(ex))
             LOG.warning(msg)
             if added_hostgroup:
                 if added_user:
                     self._delete_chap_user(port)
                 self._delete_iscsi_target(port, gid, target_alias)
Beispiel #4
0
    def output_param_to_log(self, storage_protocol):
        essential_inherited_param = ['volume_backend_name', 'volume_driver']
        conf = self.configuration

        msg = basic_lib.set_msg(1, config_group=conf.config_group)
        LOG.info(msg)
        version = self.command.get_comm_version()
        if conf.hitachi_unit_name:
            prefix = 'HSNM2 version'
        else:
            prefix = 'RAID Manager version'
        LOG.info('\t%-35s%s' % (prefix + ': ', six.text_type(version)))
        for param in essential_inherited_param:
            value = conf.safe_get(param)
            LOG.info('\t%-35s%s' % (param + ': ', six.text_type(value)))
        for opt in volume_opts:
            if not opt.secret:
                value = getattr(conf, opt.name)
                LOG.info('\t%-35s%s' % (opt.name + ': ',
                         six.text_type(value)))

        if storage_protocol == 'iSCSI':
            value = getattr(conf, 'hitachi_group_request')
            LOG.info('\t%-35s%s' % ('hitachi_group_request: ',
                     six.text_type(value)))
Beispiel #5
0
    def add_hostgroup_master(self, hgs, master_wwns, host_ip, security_ports):
        target_ports = self.configuration.hitachi_target_ports
        group_request = self.configuration.hitachi_group_request
        wwns = []
        for wwn in master_wwns:
            wwns.append(wwn.lower())
        if target_ports and group_request:
            host_grp_name = '%s%s' % (basic_lib.NAME_PREFIX, host_ip)
            for port in security_ports:
                wwns_copy = wwns[:]
                for hostgroup in hgs:
                    if (hostgroup['port'] == port and
                            hostgroup['initiator_wwn'].lower() in wwns_copy):
                        wwns_copy.remove(hostgroup['initiator_wwn'].lower())
                if wwns_copy:
                    try:
                        self._fill_group(hgs, port, host_grp_name, wwns_copy)
                    except Exception as ex:
                        LOG.warning(_('Failed to add host group: %s') %
                                    six.text_type(ex))
                        msg = basic_lib.set_msg(
                            308, port=port, name=host_grp_name)
                        LOG.warning(msg)

        if not hgs:
            msg = basic_lib.output_err(649)
            raise exception.HBSDError(message=msg)
 def _delete_iscsi_target(self, port, target_no, target_alias):
     ret, _stdout, _stderr = self.common.command.delete_iscsi_target(
         port, target_no, target_alias)
     if ret:
         msg = basic_lib.set_msg(
             307, port=port, tno=target_no, alias=target_alias)
         LOG.warning(msg)
Beispiel #7
0
    def terminate_connection(self, volume, connector, **kwargs):
        self.do_setup_status.wait()
        ldev = self.common.get_ldev(volume)
        if ldev is None:
            msg = basic_lib.set_msg(302, volume_id=volume["id"])
            LOG.warning(msg)
            return

        if "wwpns" not in connector:
            msg = basic_lib.output_err(650, resource="HBA")
            raise exception.HBSDError(message=msg)

        hostgroups = []
        self._get_hostgroup_info(hostgroups, connector["wwpns"], login=False)
        if not hostgroups:
            msg = basic_lib.output_err(649)
            raise exception.HBSDError(message=msg)

        self.common.add_volinfo(ldev, volume["id"])
        with nested(self.common.volume_info[ldev]["lock"], self.common.volume_info[ldev]["in_use"]):
            self._terminate_connection(ldev, connector, hostgroups)
            properties = self._get_properties(volume, hostgroups, terminate=True)
            LOG.debug("Terminate volume_info: %s" % self.common.volume_info)

        return {"driver_volume_type": "fibre_channel", "data": properties}
Beispiel #8
0
    def unmanage(self, volume):
        """Remove the specified volume from Cinder management."""

        ldev = self.get_ldev(volume)

        if ldev is None:
            return

        self.add_volinfo(ldev, volume['id'])
        if not self.volume_info[ldev]['in_use'].lock.acquire(False):
            desc = self.volume_info[ldev]['in_use'].desc
            basic_lib.output_err(660, desc=desc)
            raise exception.HBSDVolumeIsBusy(volume_name=volume['name'])

        is_vvol = self.get_volume_is_vvol(volume)
        if is_vvol:
            basic_lib.output_err(706, volume_id=volume['id'],
                                 volume_type=basic_lib.NORMAL_VOLUME_TYPE)
            raise exception.HBSDVolumeIsBusy(volume_name=volume['name'])
        try:
            self._unmanage(volume, ldev)
        except exception.HBSDBusy:
            raise exception.HBSDVolumeIsBusy(volume_name=volume['name'])
        else:
            msg = basic_lib.set_msg(5, volume_id=volume['id'], ldev=ldev)
            LOG.info(msg)
        finally:
            if ldev in self.volume_info:
                self.volume_info[ldev]['in_use'].lock.release()
Beispiel #9
0
 def _delete_hostgroup(self, port, gid, host_grp_name):
     try:
         self.common.command.comm_del_hostgrp(port, gid, host_grp_name)
     except Exception:
         with excutils.save_and_reraise_exception():
             LOG.warning(basic_lib.set_msg(
                 306, port=port, gid=gid, name=host_grp_name))
Beispiel #10
0
    def _initialize_connection(self, ldev, connector, src_hgs=None):
        LOG.debug("Call _initialize_connection "
                  "(config_group: %(group)s ldev: %(ldev)d)",
                  {'group': self.configuration.config_group, 'ldev': ldev})
        if src_hgs is self.pair_hostgroups:
            hostgroups = src_hgs
        else:
            hostgroups = []
            security_ports = self._get_hostgroup_info(
                hostgroups, connector['wwpns'], login=True)
            self.add_hostgroup_master(hostgroups, connector['wwpns'],
                                      connector['ip'], security_ports)

        if src_hgs is self.pair_hostgroups:
            try:
                self._add_lun(hostgroups, ldev)
            except exception.HBSDNotFound:
                LOG.warning(basic_lib.set_msg(311, ldev=ldev))
                for i in range(self.max_hostgroups + 1):
                    self.pair_hostnum += 1
                    pair_hostgroups = []
                    try:
                        self.add_hostgroup_pair(pair_hostgroups)
                        self.pair_hostgroups.extend(pair_hostgroups)
                    except exception.HBSDNotFound:
                        if i >= self.max_hostgroups:
                            msg = basic_lib.output_err(648, resource='GID')
                            raise exception.HBSDError(message=msg)
                    else:
                        break
                self.pair_initialize_connection(ldev)
        else:
            self._add_lun(hostgroups, ldev)

        return hostgroups
Beispiel #11
0
    def manage_existing(self, volume, existing_ref):
        """Manage an existing Hitachi storage volume.

        existing_ref is a dictionary of the form:

        For HUS 100 Family:

        .. code-block:: default

            {
                'ldev': <logical device number on storage>,
                'unit_name': <storage device name>
            }

        For VSP G1000/VSP/HUS VM:

        .. code-block:: default

            {
                'ldev': <logical device number on storage>,
                'serial_number': <product number of storage system>
            }

        """

        ldev = self._string2int(existing_ref.get('ldev'))

        LOG.info(basic_lib.set_msg(4, volume_id=volume['id'], ldev=ldev))

        return {'provider_location': ldev}
Beispiel #12
0
    def output_param_to_log(self, storage_protocol):
        essential_inherited_param = ['volume_backend_name', 'volume_driver']
        conf = self.configuration

        LOG.info(basic_lib.set_msg(1, config_group=conf.config_group))
        version = self.command.get_comm_version()
        if conf.hitachi_unit_name:
            prefix = 'HSNM2 version'
        else:
            prefix = 'RAID Manager version'
        LOG.info(_LI('\t%(prefix)-35s : %(version)s'),
                 {'prefix': prefix, 'version': version})
        for param in essential_inherited_param:
            value = conf.safe_get(param)
            LOG.info(_LI('\t%(param)-35s : %(value)s'),
                     {'param': param, 'value': value})
        for opt in volume_opts:
            if not opt.secret:
                value = getattr(conf, opt.name)
                LOG.info(_LI('\t%(name)-35s : %(value)s'),
                         {'name': opt.name, 'value': value})

        if storage_protocol == 'iSCSI':
            value = getattr(conf, 'hitachi_group_request')
            LOG.info(_LI('\t%(request)-35s : %(value)s'),
                     {'request': 'hitachi_group_request', 'value': value})
Beispiel #13
0
    def terminate_connection(self, volume, connector, **kwargs):
        self.do_setup_status.wait()
        ldev = self.common.get_ldev(volume)
        if ldev is None:
            LOG.warning(basic_lib.set_msg(302, volume_id=volume['id']))
            return

        if 'wwpns' not in connector:
            msg = basic_lib.output_err(650, resource='HBA')
            raise exception.HBSDError(message=msg)

        hostgroups = []
        self._get_hostgroup_info(hostgroups,
                                 connector['wwpns'], login=False)
        if not hostgroups:
            msg = basic_lib.output_err(649)
            raise exception.HBSDError(message=msg)

        self.common.add_volinfo(ldev, volume['id'])
        with self.common.volume_info[ldev]['lock'],\
                self.common.volume_info[ldev]['in_use']:
            self._terminate_connection(ldev, connector, hostgroups)
            properties = self._get_properties(volume, hostgroups,
                                              terminate=True)
            LOG.debug('Terminate volume_info: %s', self.common.volume_info)

        return {
            'driver_volume_type': 'fibre_channel',
            'data': properties
        }
Beispiel #14
0
    def set_chap_authention(self, port, gid):
        ctl_no = port[0]
        port_no = port[1]
        unit = self.unit_name
        auth_username = self.conf.hitachi_auth_user
        auth_password = self.conf.hitachi_auth_password
        add_chap_user = self.conf.hitachi_add_chap_user
        assign_flag = True
        added_flag = False
        opt = "-unit %s -refer %s %s -user %s" % (unit, ctl_no, port_no, auth_username)
        ret, stdout, stderr = self.exec_hsnm("auchapuser", opt, noretry=True)

        if ret:
            if not add_chap_user:
                msg = basic_lib.output_err(643, user=auth_username)
                raise exception.HBSDError(message=msg)

            root_helper = utils.get_root_helper()
            cmd = "%s env %s auchapuser -unit %s -add %s %s " "-tno %d -user %s" % (
                root_helper,
                SNM2_ENV,
                unit,
                ctl_no,
                port_no,
                gid,
                auth_username,
            )

            LOG.debug("Add CHAP user")
            loop = loopingcall.FixedIntervalLoopingCall(
                self._wait_for_add_chap_user, cmd, auth_username, auth_password, time.time()
            )

            added_flag = loop.start(interval=EXEC_INTERVAL).wait()

        else:
            lines = stdout.splitlines()[4:]
            for line in lines:
                if int(shlex.split(line)[0][0:3]) == gid:
                    assign_flag = False
                    break

        if assign_flag:
            opt = "-unit %s -assign %s %s -tno %d -user %s" % (unit, ctl_no, port_no, gid, auth_username)
            ret, stdout, stderr = self.exec_hsnm("auchapuser", opt)
            if ret:
                if added_flag:
                    _ret, _stdout, _stderr = self.delete_chap_user(port)
                    if _ret:
                        msg = basic_lib.set_msg(303, user=auth_username)
                        LOG.warning(msg)

                msg = basic_lib.output_err(600, cmd="auchapuser", ret=ret, out=stdout, err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        return added_flag
 def _fill_groups(self, hgs, ports, target_iqn, target_alias, add_iqn):
     for port in ports:
         added_hostgroup = False
         added_user = False
         LOG.debug(
             "Create target (hgs: %(hgs)s port: %(port)s "
             "target_iqn: %(tiqn)s target_alias: %(alias)s "
             "add_iqn: %(aiqn)s)",
             {"hgs": hgs, "port": port, "tiqn": target_iqn, "alias": target_alias, "aiqn": add_iqn},
         )
         gid = self.common.command.get_gid_from_targetiqn(target_iqn, target_alias, port)
         if gid is None:
             for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                 gid = None
                 try:
                     gid = self._get_unused_gid_iscsi(port)
                     self.common.command.comm_add_hostgrp_iscsi(port, gid, target_alias, target_iqn)
                     added_hostgroup = True
                 except exception.HBSDNotFound:
                     LOG.warning(basic_lib.set_msg(312, resource="GID"))
                     continue
                 except Exception as ex:
                     LOG.warning(basic_lib.set_msg(309, port=port, alias=target_alias, reason=ex))
                     break
                 else:
                     LOG.debug("Completed to add target" "(port: %(port)s gid: %(gid)d)", {"port": port, "gid": gid})
                     break
         if gid is None:
             LOG.error(_LE("Failed to add target(port: %s)"), port)
             continue
         try:
             if added_hostgroup:
                 if self.configuration.hitachi_auth_method:
                     added_user = self.common.command.set_chap_authention(port, gid)
                 self.common.command.comm_set_hostgrp_reportportal(port, target_alias)
             self._add_initiator(hgs, port, gid, add_iqn)
         except Exception as ex:
             LOG.warning(basic_lib.set_msg(316, port=port, reason=ex))
             if added_hostgroup:
                 if added_user:
                     self._delete_chap_user(port)
                 self._delete_iscsi_target(port, gid, target_alias)
    def terminate_connection(self, volume, connector, **kwargs):
        self.do_setup_status.wait()
        ldev = self.common.get_ldev(volume)
        if ldev is None:
            LOG.warning(basic_lib.set_msg(302, volume_id=volume["id"]))
            return

        if "initiator" not in connector:
            raise exception.HBSDError(message=basic_lib.output_err(650, resource="HBA"))

        hostgroups = []
        self._get_hostgroup_info_iscsi(hostgroups, connector["initiator"])
        if not hostgroups:
            raise exception.HBSDError(message=basic_lib.output_err(649))

        self.common.add_volinfo(ldev, volume["id"])
        with self.common.volume_info[ldev]["lock"], self.common.volume_info[ldev]["in_use"]:
            self._terminate_connection(ldev, connector, hostgroups)
    def copy_data(self, pvol, size, p_is_vvol, method):
        type = "Normal"
        is_vvol = method == "THIN"
        svol = self._create_volume(size, is_vvol=is_vvol)
        try:
            if p_is_vvol:
                self.copy_sync_data(pvol, svol, size)
            else:
                if is_vvol:
                    type = "V-VOL"
                self.copy_async_data(pvol, svol, is_vvol)
        except Exception:
            with excutils.save_and_reraise_exception():
                try:
                    self.delete_ldev(svol, is_vvol)
                except Exception as ex:
                    LOG.warning(basic_lib.set_msg(313, ldev=svol, reason=ex))

        return six.text_type(svol), type
Beispiel #18
0
 def create_ldev(self, size, ldev_range, pool_id, is_vvol):
     LOG.debug('create start (normal)')
     for i in basic_lib.DEFAULT_TRY_RANGE:
         LOG.debug('Try number: %(tries)s / %(max_tries)s',
                   {'tries': i + 1,
                    'max_tries': len(basic_lib.DEFAULT_TRY_RANGE)})
         new_ldev = self._get_unused_volume_num(ldev_range)
         try:
             self._add_ldev(new_ldev, size, pool_id, is_vvol)
         except exception.HBSDNotFound:
             LOG.warning(basic_lib.set_msg(312, resource='LDEV'))
             continue
         else:
             break
     else:
         msg = basic_lib.output_err(636)
         raise exception.HBSDError(message=msg)
     LOG.debug('create end (normal: %s)', new_ldev)
     self.init_volinfo(self.volume_info, new_ldev)
     return new_ldev
 def copy_async_data(self, pvol, svol, is_vvol):
     path_list = []
     driver = self.generated_from
     try:
         with self.pair_flock:
             self.delete_pair(pvol, all_split=False, is_vvol=is_vvol)
             paired_info = self.command.get_paired_info(pvol)
             if paired_info["pvol"] is None:
                 driver.pair_initialize_connection(pvol)
                 path_list.append(pvol)
             driver.pair_initialize_connection(svol)
             path_list.append(svol)
             self.command.comm_create_pair(pvol, svol, is_vvol)
     except Exception:
         with excutils.save_and_reraise_exception():
             for ldev in path_list:
                 try:
                     driver.pair_terminate_connection(ldev)
                 except Exception as ex:
                     LOG.warning(basic_lib.set_msg(310, ldev=ldev, reason=ex))
Beispiel #20
0
    def copy_data(self, pvol, size, p_is_vvol, method):
        type = 'Normal'
        is_vvol = method == 'THIN'
        svol = self._create_volume(size, is_vvol=is_vvol)
        try:
            if p_is_vvol:
                self.copy_sync_data(pvol, svol, size)
            else:
                if is_vvol:
                    type = 'V-VOL'
                self.copy_async_data(pvol, svol, is_vvol)
        except Exception:
            with excutils.save_and_reraise_exception():
                try:
                    self.delete_ldev(svol, is_vvol)
                except Exception as ex:
                    msg = basic_lib.set_msg(313,
                                            ldev=svol,
                                            reason=six.text_type(ex))
                    LOG.warning(msg)

        return six.text_type(svol), type
Beispiel #21
0
 def create_ldev(self, size, ldev_range, pool_id, is_vvol):
     LOG.debug('create start (normal)')
     for i in basic_lib.DEFAULT_TRY_RANGE:
         LOG.debug('Try number: %(tries)s / %(max_tries)s' % {
             'tries': i + 1,
             'max_tries': len(basic_lib.DEFAULT_TRY_RANGE)
         })
         new_ldev = self._get_unused_volume_num(ldev_range)
         try:
             self._add_ldev(new_ldev, size, pool_id, is_vvol)
         except exception.HBSDNotFound:
             msg = basic_lib.set_msg(312, resource='LDEV')
             LOG.warning(msg)
             continue
         else:
             break
     else:
         msg = basic_lib.output_err(636)
         raise exception.HBSDError(message=msg)
     LOG.debug('create end (normal: %s)' % six.text_type(new_ldev))
     self.init_volinfo(self.volume_info, new_ldev)
     return new_ldev
Beispiel #22
0
    def _initialize_connection(self, ldev, connector, src_hgs=None):
        LOG.debug(
            "Call _initialize_connection "
            "(config_group: %(group)s ldev: %(ldev)d)", {
                'group': self.configuration.config_group,
                'ldev': ldev
            })
        if src_hgs is self.pair_hostgroups:
            hostgroups = src_hgs
        else:
            hostgroups = []
            security_ports = self._get_hostgroup_info(hostgroups,
                                                      connector['wwpns'],
                                                      login=True)
            self.add_hostgroup_master(hostgroups, connector['wwpns'],
                                      connector['ip'], security_ports)

        if src_hgs is self.pair_hostgroups:
            try:
                self._add_lun(hostgroups, ldev)
            except exception.HBSDNotFound:
                LOG.warning(basic_lib.set_msg(311, ldev=ldev))
                for i in range(self.max_hostgroups + 1):
                    self.pair_hostnum += 1
                    pair_hostgroups = []
                    try:
                        self.add_hostgroup_pair(pair_hostgroups)
                        self.pair_hostgroups.extend(pair_hostgroups)
                    except exception.HBSDNotFound:
                        if i >= self.max_hostgroups:
                            msg = basic_lib.output_err(648, resource='GID')
                            raise exception.HBSDError(message=msg)
                    else:
                        break
                self.pair_initialize_connection(ldev)
        else:
            self._add_lun(hostgroups, ldev)

        return hostgroups
    def output_param_to_log(self, storage_protocol):
        essential_inherited_param = ["volume_backend_name", "volume_driver"]
        conf = self.configuration

        LOG.info(basic_lib.set_msg(1, config_group=conf.config_group))
        version = self.command.get_comm_version()
        if conf.hitachi_unit_name:
            prefix = "HSNM2 version"
        else:
            prefix = "RAID Manager version"
        LOG.info(_LI("\t%(prefix)-35s : %(version)s"), {"prefix": prefix, "version": version})
        for param in essential_inherited_param:
            value = conf.safe_get(param)
            LOG.info(_LI("\t%(param)-35s : %(value)s"), {"param": param, "value": value})
        for opt in volume_opts:
            if not opt.secret:
                value = getattr(conf, opt.name)
                LOG.info(_LI("\t%(name)-35s : %(value)s"), {"name": opt.name, "value": value})

        if storage_protocol == "iSCSI":
            value = getattr(conf, "hitachi_group_request")
            LOG.info(_LI("\t%(request)-35s : %(value)s"), {"request": "hitachi_group_request", "value": value})
Beispiel #24
0
 def copy_async_data(self, pvol, svol, is_vvol):
     path_list = []
     driver = self.generated_from
     try:
         with self.pair_flock:
             self.delete_pair(pvol, all_split=False, is_vvol=is_vvol)
             paired_info = self.command.get_paired_info(pvol)
             if paired_info['pvol'] is None:
                 driver.pair_initialize_connection(pvol)
                 path_list.append(pvol)
             driver.pair_initialize_connection(svol)
             path_list.append(svol)
             self.command.comm_create_pair(pvol, svol, is_vvol)
     except Exception:
         with excutils.save_and_reraise_exception():
             for ldev in path_list:
                 try:
                     driver.pair_terminate_connection(ldev)
                 except Exception as ex:
                     msg = basic_lib.set_msg(
                         310, ldev=ldev, reason=six.text_type(ex))
                     LOG.warning(msg)
    def terminate_connection(self, volume, connector, **kwargs):
        self.do_setup_status.wait()
        ldev = self.common.get_ldev(volume)
        if ldev is None:
            msg = basic_lib.set_msg(302, volume_id=volume['id'])
            LOG.warning(msg)
            return

        if 'initiator' not in connector:
            msg = basic_lib.output_err(650, resource='HBA')
            raise exception.HBSDError(message=msg)

        hostgroups = []
        self._get_hostgroup_info_iscsi(hostgroups,
                                       connector['initiator'])
        if not hostgroups:
            msg = basic_lib.output_err(649)
            raise exception.HBSDError(message=msg)

        self.common.add_volinfo(ldev, volume['id'])
        with self.common.volume_info[ldev]['lock'],\
                self.common.volume_info[ldev]['in_use']:
            self._terminate_connection(ldev, connector, hostgroups)
Beispiel #26
0
    def terminate_connection(self, volume, connector, **kwargs):
        self.do_setup_status.wait()
        ldev = self.common.get_ldev(volume)
        if ldev is None:
            msg = basic_lib.set_msg(302, volume_id=volume['id'])
            LOG.warning(msg)
            return

        if 'initiator' not in connector:
            msg = basic_lib.output_err(650, resource='HBA')
            raise exception.HBSDError(message=msg)

        hostgroups = []
        self._get_hostgroup_info_iscsi(hostgroups,
                                       connector['initiator'])
        if not hostgroups:
            msg = basic_lib.output_err(649)
            raise exception.HBSDError(message=msg)

        self.common.add_volinfo(ldev, volume['id'])
        with self.common.volume_info[ldev]['lock'],\
                self.common.volume_info[ldev]['in_use']:
            self._terminate_connection(ldev, connector, hostgroups)
Beispiel #27
0
    def _fill_group(self, hgs, port, host_grp_name, wwns):
        added_hostgroup = False
        LOG.debug('Create host group (hgs: %(hgs)s port: %(port)s '
                  'name: %(name)s wwns: %(wwns)s)'
                  % {'hgs': hgs, 'port': port,
                     'name': host_grp_name, 'wwns': wwns})
        gid = self._get_hgname_gid(port, host_grp_name)
        if gid is None:
            for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                try:
                    gid = self._get_unused_gid(port)
                    self._add_hostgroup(port, gid, host_grp_name)
                    added_hostgroup = True
                except exception.HBSDNotFound:
                    gid = None
                    msg = basic_lib.set_msg(312, resource='GID')
                    LOG.warning(msg)
                    continue
                else:
                    LOG.debug('Completed to add host target'
                              '(port: %(port)s gid: %(gid)d)'
                              % {'port': port, 'gid': gid})
                    break
            else:
                msg = basic_lib.output_err(641)
                raise exception.HBSDError(message=msg)

        try:
            if wwns:
                self._add_wwn(hgs, port, gid, wwns)
            else:
                hgs.append({'port': port, 'gid': gid, 'initiator_wwn': None,
                            'detected': True})
        except Exception:
            with excutils.save_and_reraise_exception():
                if added_hostgroup:
                    self._delete_hostgroup(port, gid, host_grp_name)
Beispiel #28
0
    def _fill_group(self, hgs, port, host_grp_name, wwns):
        added_hostgroup = False
        LOG.debug('Create host group (hgs: %(hgs)s port: %(port)s '
                  'name: %(name)s wwns: %(wwns)s)'
                  % {'hgs': hgs, 'port': port,
                     'name': host_grp_name, 'wwns': wwns})
        gid = self._get_hgname_gid(port, host_grp_name)
        if gid is None:
            for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                try:
                    gid = self._get_unused_gid(port)
                    self._add_hostgroup(port, gid, host_grp_name)
                    added_hostgroup = True
                except exception.HBSDNotFound:
                    gid = None
                    msg = basic_lib.set_msg(312, resource='GID')
                    LOG.warning(msg)
                    continue
                else:
                    LOG.debug('Completed to add host target'
                              '(port: %(port)s gid: %(gid)d)'
                              % {'port': port, 'gid': gid})
                    break
            else:
                msg = basic_lib.output_err(641)
                raise exception.HBSDError(message=msg)

        try:
            if wwns:
                self._add_wwn(hgs, port, gid, wwns)
            else:
                hgs.append({'port': port, 'gid': gid, 'initiator_wwn': None,
                            'detected': True})
        except Exception:
            with excutils.save_and_reraise_exception():
                if added_hostgroup:
                    self._delete_hostgroup(port, gid, host_grp_name)
Beispiel #29
0
    def _fill_group(self, hgs, port, host_grp_name, wwns):
        added_hostgroup = False
        LOG.debug(
            "Create host group (hgs: %(hgs)s port: %(port)s "
            "name: %(name)s wwns: %(wwns)s)" % {"hgs": hgs, "port": port, "name": host_grp_name, "wwns": wwns}
        )
        gid = self._get_hgname_gid(port, host_grp_name)
        if gid is None:
            for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                try:
                    gid = self._get_unused_gid(port)
                    self._add_hostgroup(port, gid, host_grp_name)
                    added_hostgroup = True
                except exception.HBSDNotFound:
                    gid = None
                    msg = basic_lib.set_msg(312, resource="GID")
                    LOG.warning(msg)
                    continue
                else:
                    LOG.debug(
                        "Completed to add host target" "(port: %(port)s gid: %(gid)d)" % {"port": port, "gid": gid}
                    )
                    break
            else:
                msg = basic_lib.output_err(641)
                raise exception.HBSDError(message=msg)

        try:
            if wwns:
                self._add_wwn(hgs, port, gid, wwns)
            else:
                hgs.append({"port": port, "gid": gid, "initiator_wwn": None, "detected": True})
        except Exception:
            with excutils.save_and_reraise_exception():
                if added_hostgroup:
                    self._delete_hostgroup(port, gid, host_grp_name)
Beispiel #30
0
    def output_param_to_log(self, storage_protocol):
        essential_inherited_param = ['volume_backend_name', 'volume_driver']
        conf = self.configuration

        msg = basic_lib.set_msg(1, config_group=conf.config_group)
        LOG.info(msg)
        version = self.command.get_comm_version()
        if conf.hitachi_unit_name:
            prefix = 'HSNM2 version'
        else:
            prefix = 'RAID Manager version'
        LOG.info('\t%-35s%s' % (prefix + ': ', six.text_type(version)))
        for param in essential_inherited_param:
            value = conf.safe_get(param)
            LOG.info('\t%-35s%s' % (param + ': ', six.text_type(value)))
        for opt in volume_opts:
            if not opt.secret:
                value = getattr(conf, opt.name)
                LOG.info('\t%-35s%s' % (opt.name + ': ', six.text_type(value)))

        if storage_protocol == 'iSCSI':
            value = getattr(conf, 'hitachi_group_request')
            LOG.info('\t%-35s%s' %
                     ('hitachi_group_request: ', six.text_type(value)))
Beispiel #31
0
    def comm_add_lun(self, command, hostgroups, ldev, is_once=False):
        unit = self.unit_name
        tmp_hostgroups = hostgroups[:]
        used_list = []
        is_ok = False
        hlu = None
        old_hlu = None
        for hostgroup in hostgroups:
            port = hostgroup["port"]
            gid = hostgroup["gid"]
            hlu = self.add_used_hlun(command, port, gid, used_list, ldev)
            # When 'hlu' or 'old_hlu' is 0, it should be true.
            # So, it cannot remove 'is not None'.
            if hlu is not None:
                if old_hlu is not None and old_hlu != hlu:
                    msg = basic_lib.output_err(648, resource="LUN (HLUN)")
                    raise exception.HBSDError(message=msg)
                is_ok = True
                hostgroup["lun"] = hlu
                tmp_hostgroups.remove(hostgroup)
                old_hlu = hlu
            else:
                hlu = old_hlu

        if not used_list:
            hlu = 0
        elif hlu is None:
            for i in range(MAX_HLUN + 1):
                if i not in used_list:
                    hlu = i
                    break
            else:
                raise exception.HBSDNotFound

        ret = 0
        stdout = None
        stderr = None
        invalid_hgs_str = None
        for hostgroup in tmp_hostgroups:
            port = hostgroup["port"]
            gid = hostgroup["gid"]
            ctl_no = port[0]
            port_no = port[1]
            if not hostgroup["detected"]:
                if invalid_hgs_str:
                    invalid_hgs_str = "%s, %s:%d" % (invalid_hgs_str, port, gid)
                else:
                    invalid_hgs_str = "%s:%d" % (port, gid)
                continue
            opt = "-unit %s -add %s %s %d %d %d" % (unit, ctl_no, port_no, gid, hlu, ldev)
            ret, stdout, stderr = self.exec_hsnm(command, opt)
            if ret == 0:
                is_ok = True
                hostgroup["lun"] = hlu
                if is_once:
                    break
            else:
                msg = basic_lib.set_msg(314, ldev=ldev, lun=hlu, port=port, id=gid)
                LOG.warning(msg)

        if not is_ok:
            if stderr:
                msg = basic_lib.output_err(600, cmd=command, ret=ret, out=stdout, err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
            else:
                msg = basic_lib.output_err(659, gid=invalid_hgs_str)
                raise exception.HBSDError(message=msg)
Beispiel #32
0
 def _delete_lun(self, hostgroups, ldev):
     try:
         self.common.command.comm_delete_lun(hostgroups, ldev)
     except exception.HBSDNotFound:
         LOG.warning(basic_lib.set_msg(301, ldev=ldev))
Beispiel #33
0
 def output_backend_available_once(self):
     if self.output_first:
         self.output_first = False
         msg = basic_lib.set_msg(
             3, config_group=self.configuration.config_group)
         LOG.warning(msg)
Beispiel #34
0
 def _fill_groups(self, hgs, ports, target_iqn, target_alias, add_iqn):
     for port in ports:
         added_hostgroup = False
         added_user = False
         LOG.debug(
             'Create target (hgs: %(hgs)s port: %(port)s '
             'target_iqn: %(tiqn)s target_alias: %(alias)s '
             'add_iqn: %(aiqn)s)' % {
                 'hgs': hgs,
                 'port': port,
                 'tiqn': target_iqn,
                 'alias': target_alias,
                 'aiqn': add_iqn
             })
         gid = self.common.command.get_gid_from_targetiqn(
             target_iqn, target_alias, port)
         if gid is None:
             for retry_cnt in basic_lib.DEFAULT_TRY_RANGE:
                 gid = None
                 try:
                     gid = self._get_unused_gid_iscsi(port)
                     self.common.command.comm_add_hostgrp_iscsi(
                         port, gid, target_alias, target_iqn)
                     added_hostgroup = True
                 except exception.HBSDNotFound:
                     msg = basic_lib.set_msg(312, resource='GID')
                     LOG.warning(msg)
                     continue
                 except Exception as ex:
                     msg = basic_lib.set_msg(309,
                                             port=port,
                                             alias=target_alias,
                                             reason=six.text_type(ex))
                     LOG.warning(msg)
                     break
                 else:
                     LOG.debug('Completed to add target'
                               '(port: %(port)s gid: %(gid)d)' % {
                                   'port': port,
                                   'gid': gid
                               })
                     break
         if gid is None:
             LOG.error(_('Failed to add target(port: %s)') % port)
             continue
         try:
             if added_hostgroup:
                 if self.configuration.hitachi_auth_method:
                     added_user = self.common.command.set_chap_authention(
                         port, gid)
                 self.common.command.comm_set_hostgrp_reportportal(
                     port, target_alias)
             self._add_initiator(hgs, port, gid, add_iqn)
         except Exception as ex:
             msg = basic_lib.set_msg(316,
                                     port=port,
                                     reason=six.text_type(ex))
             LOG.warning(msg)
             if added_hostgroup:
                 if added_user:
                     self._delete_chap_user(port)
                 self._delete_iscsi_target(port, gid, target_alias)
 def _delete_chap_user(self, port):
     ret, _stdout, _stderr = self.common.command.delete_chap_user(port)
     if ret:
         LOG.warning(basic_lib.set_msg(303, user=self.configuration.hitachi_auth_user))
Beispiel #36
0
 def _delete_chap_user(self, port):
     ret, _stdout, _stderr = self.common.command.delete_chap_user(port)
     if ret:
         LOG.warning(
             basic_lib.set_msg(303,
                               user=self.configuration.hitachi_auth_user))
Beispiel #37
0
 def _delete_lun_iscsi(self, hostgroups, ldev):
     try:
         self.common.command.comm_delete_lun_iscsi(hostgroups, ldev)
     except exception.HBSDNotFound:
         LOG.warning(basic_lib.set_msg(301, ldev=ldev))
Beispiel #38
0
 def output_backend_available_once(self):
     if self.output_first:
         self.output_first = False
         LOG.warning(
             basic_lib.set_msg(
                 3, config_group=self.configuration.config_group))
Beispiel #39
0
    def comm_add_lun(self, command, hostgroups, ldev, is_once=False):
        unit = self.unit_name
        tmp_hostgroups = hostgroups[:]
        used_list = []
        is_ok = False
        hlu = None
        old_hlu = None
        for hostgroup in hostgroups:
            port = hostgroup['port']
            gid = hostgroup['gid']
            hlu = self.add_used_hlun(command, port, gid, used_list, ldev)
            # When 'hlu' or 'old_hlu' is 0, it should be true.
            # So, it cannot remove 'is not None'.
            if hlu is not None:
                if old_hlu is not None and old_hlu != hlu:
                    msg = basic_lib.output_err(648, resource='LUN (HLUN)')
                    raise exception.HBSDError(message=msg)
                is_ok = True
                hostgroup['lun'] = hlu
                tmp_hostgroups.remove(hostgroup)
                old_hlu = hlu
            else:
                hlu = old_hlu

        if not used_list:
            hlu = 0
        elif hlu is None:
            for i in range(MAX_HLUN + 1):
                if i not in used_list:
                    hlu = i
                    break
            else:
                raise exception.HBSDNotFound

        ret = 0
        stdout = None
        stderr = None
        invalid_hgs_str = None
        for hostgroup in tmp_hostgroups:
            port = hostgroup['port']
            gid = hostgroup['gid']
            ctl_no = port[0]
            port_no = port[1]
            if not hostgroup['detected']:
                if invalid_hgs_str:
                    invalid_hgs_str = '%s, %s:%d' % (invalid_hgs_str, port,
                                                     gid)
                else:
                    invalid_hgs_str = '%s:%d' % (port, gid)
                continue
            opt = '-unit %s -add %s %s %d %d %d' % (unit, ctl_no, port_no, gid,
                                                    hlu, ldev)
            ret, stdout, stderr = self.exec_hsnm(command, opt)
            if ret == 0:
                is_ok = True
                hostgroup['lun'] = hlu
                if is_once:
                    break
            else:
                msg = basic_lib.set_msg(314,
                                        ldev=ldev,
                                        lun=hlu,
                                        port=port,
                                        id=gid)
                LOG.warning(msg)

        if not is_ok:
            if stderr:
                msg = basic_lib.output_err(600,
                                           cmd=command,
                                           ret=ret,
                                           out=stdout,
                                           err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
            else:
                msg = basic_lib.output_err(659, gid=invalid_hgs_str)
                raise exception.HBSDError(message=msg)