示例#1
0
    def disconnect_volume_fc(self, volume, connector):
        """Delete map between a volume and a host for FC."""
        wwns = connector['wwpns']
        volume_name = huawei_utils.encode_name(volume.id)
        metadata = huawei_utils.get_volume_metadata(volume)
        lun_id = metadata['remote_lun_id']
        host_name = connector['host']
        left_lunnum = -1
        lungroup_id = None
        view_id = None

        LOG.info(_LI('terminate_connection_fc: volume name: %(volume)s, '
                     'wwpns: %(wwns)s, '
                     'lun_id: %(lunid)s.'),
                 {'volume': volume_name,
                  'wwns': wwns,
                  'lunid': lun_id},)

        host_name = huawei_utils.encode_host_name(host_name)
        hostid = self.rmt_client.get_host_id_by_name(host_name)
        if hostid:
            mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid
            view_id = self.rmt_client.find_mapping_view(
                mapping_view_name)
            if view_id:
                lungroup_id = self.rmt_client.find_lungroup_from_map(
                    view_id)

        if lun_id and self.rmt_client.check_lun_exist(lun_id):
            if lungroup_id:
                lungroup_ids = self.rmt_client.get_lungroupids_by_lunid(
                    lun_id)
                if lungroup_id in lungroup_ids:
                    self.rmt_client.remove_lun_from_lungroup(
                        lungroup_id, lun_id)
                else:
                    LOG.warning(_LW("Lun is not in lungroup. "
                                    "Lun id: %(lun_id)s, "
                                    "lungroup id: %(lungroup_id)s"),
                                {"lun_id": lun_id,
                                 "lungroup_id": lungroup_id})

        (tgt_port_wwns, init_targ_map) = (
            self.rmt_client.get_init_targ_map(wwns))

        hostid = self.rmt_client.get_host_id_by_name(host_name)
        if hostid:
            mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid
            view_id = self.rmt_client.find_mapping_view(
                mapping_view_name)
            if view_id:
                lungroup_id = self.rmt_client.find_lungroup_from_map(
                    view_id)
        if lungroup_id:
            left_lunnum = self.rmt_client.get_lunnum_from_lungroup(
                lungroup_id)

        if int(left_lunnum) > 0:
            info = {'driver_volume_type': 'fibre_channel',
                    'data': {}}
        else:
            info = {'driver_volume_type': 'fibre_channel',
                    'data': {'target_wwn': tgt_port_wwns,
                             'initiator_target_map': init_targ_map}, }

        return info
示例#2
0
    def disconnect_volume_fc(self, volume, connector):
        """Delete map between a volume and a host for FC."""
        wwns = connector['wwpns']
        volume_name = huawei_utils.encode_name(volume['id'])
        metadata = huawei_utils.get_volume_metadata(volume)
        lun_id = metadata['remote_lun_id']
        host_name = connector['host']
        left_lunnum = -1
        lungroup_id = None
        view_id = None

        LOG.info(
            _LI('terminate_connection_fc: volume name: %(volume)s, '
                'wwpns: %(wwns)s, '
                'lun_id: %(lunid)s.'),
            {
                'volume': volume_name,
                'wwns': wwns,
                'lunid': lun_id
            },
        )

        host_name = huawei_utils.encode_host_name(host_name)
        hostid = self.rmt_client.get_host_id_by_name(host_name)
        if hostid:
            mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid
            view_id = self.rmt_client.find_mapping_view(mapping_view_name)
            if view_id:
                lungroup_id = self.rmt_client.find_lungroup_from_map(view_id)

        if lun_id and self.rmt_client.check_lun_exist(lun_id):
            if lungroup_id:
                lungroup_ids = self.rmt_client.get_lungroupids_by_lunid(lun_id)
                if lungroup_id in lungroup_ids:
                    self.rmt_client.remove_lun_from_lungroup(
                        lungroup_id, lun_id)
                else:
                    LOG.warning(
                        _LW("Lun is not in lungroup. "
                            "Lun id: %(lun_id)s, "
                            "lungroup id: %(lungroup_id)s"), {
                                "lun_id": lun_id,
                                "lungroup_id": lungroup_id
                            })

        (tgt_port_wwns,
         init_targ_map) = (self.rmt_client.get_init_targ_map(wwns))

        hostid = self.rmt_client.get_host_id_by_name(host_name)
        if hostid:
            mapping_view_name = constants.MAPPING_VIEW_PREFIX + hostid
            view_id = self.rmt_client.find_mapping_view(mapping_view_name)
            if view_id:
                lungroup_id = self.rmt_client.find_lungroup_from_map(view_id)
        if lungroup_id:
            left_lunnum = self.rmt_client.get_lunnum_from_lungroup(lungroup_id)

        if int(left_lunnum) > 0:
            info = {'driver_volume_type': 'fibre_channel', 'data': {}}
        else:
            info = {
                'driver_volume_type': 'fibre_channel',
                'data': {
                    'target_wwn': tgt_port_wwns,
                    'initiator_target_map': init_targ_map
                },
            }

        return info
示例#3
0
    def connect_volume_fc(self, volume, connector):
        """Create map between a volume and a host for FC."""
        wwns = connector['wwpns']
        volume_name = huawei_utils.encode_name(volume.id)

        LOG.info(_LI(
            'initialize_connection_fc, initiator: %(wwpns)s,'
            ' volume name: %(volume)s.'),
            {'wwpns': wwns,
             'volume': volume_name})

        metadata = huawei_utils.get_volume_metadata(volume)
        lun_id = metadata['remote_lun_id']

        if lun_id is None:
            lun_id = self.rmt_client.get_lun_id_by_name(volume_name)
        if lun_id is None:
            msg = _("Can't get volume id. Volume name: %s.") % volume_name
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)

        original_host_name = connector['host']
        host_name = huawei_utils.encode_host_name(original_host_name)
        host_id = self.client.add_host_with_check(host_name,
                                                  original_host_name)

        # Create hostgroup if not exist.
        host_id = self.rmt_client.add_host_with_check(
            host_name, original_host_name)

        online_wwns_in_host = (
            self.rmt_client.get_host_online_fc_initiators(host_id))
        online_free_wwns = self.rmt_client.get_online_free_wwns()
        for wwn in wwns:
            if (wwn not in online_wwns_in_host
                    and wwn not in online_free_wwns):
                wwns_in_host = (
                    self.rmt_client.get_host_fc_initiators(host_id))
                iqns_in_host = (
                    self.rmt_client.get_host_iscsi_initiators(host_id))
                if not (wwns_in_host or iqns_in_host):
                    self.rmt_client.remove_host(host_id)

                msg = _('Can not add FC port to host.')
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)

        for wwn in wwns:
            if wwn in online_free_wwns:
                self.rmt_client.add_fc_port_to_host(host_id, wwn)

        (tgt_port_wwns, init_targ_map) = (
            self.rmt_client.get_init_targ_map(wwns))

        # Add host into hostgroup.
        hostgroup_id = self.rmt_client.add_host_to_hostgroup(host_id)
        map_info = self.rmt_client.do_mapping(lun_id,
                                              hostgroup_id,
                                              host_id)
        if not map_info:
            msg = _('Map info is None due to array version '
                    'not supporting hypermetro.')
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)

        host_lun_id = self.rmt_client.get_host_lun_id(host_id, lun_id)

        # Return FC properties.
        fc_info = {'driver_volume_type': 'fibre_channel',
                   'data': {'target_lun': int(host_lun_id),
                            'target_discovered': True,
                            'target_wwn': tgt_port_wwns,
                            'volume_id': volume.id,
                            'initiator_target_map': init_targ_map,
                            'map_info': map_info},
                   }

        LOG.info(_LI('Remote return FC info is: %s.'), fc_info)

        return fc_info
示例#4
0
    def connect_volume_fc(self, volume, connector):
        """Create map between a volume and a host for FC."""
        wwns = connector['wwpns']
        volume_name = huawei_utils.encode_name(volume['id'])

        LOG.info(
            _LI('initialize_connection_fc, initiator: %(wwpns)s,'
                ' volume name: %(volume)s.'), {
                    'wwpns': wwns,
                    'volume': volume_name
                })

        metadata = huawei_utils.get_volume_metadata(volume)
        lun_id = metadata['remote_lun_id']

        if lun_id is None:
            lun_id = self.rmt_client.get_lun_id_by_name(volume_name)
        if lun_id is None:
            msg = _("Can't get volume id. Volume name: %s.") % volume_name
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)

        original_host_name = connector['host']
        host_name = huawei_utils.encode_host_name(original_host_name)
        host_id = self.client.add_host_with_check(host_name,
                                                  original_host_name)

        # Create hostgroup if not exist.
        host_id = self.rmt_client.add_host_with_check(host_name,
                                                      original_host_name)

        online_wwns_in_host = (
            self.rmt_client.get_host_online_fc_initiators(host_id))
        online_free_wwns = self.rmt_client.get_online_free_wwns()
        for wwn in wwns:
            if (wwn not in online_wwns_in_host
                    and wwn not in online_free_wwns):
                wwns_in_host = (
                    self.rmt_client.get_host_fc_initiators(host_id))
                iqns_in_host = (
                    self.rmt_client.get_host_iscsi_initiators(host_id))
                if not (wwns_in_host or iqns_in_host):
                    self.rmt_client.remove_host(host_id)

                msg = _('Can not add FC port to host.')
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)

        for wwn in wwns:
            if wwn in online_free_wwns:
                self.rmt_client.add_fc_port_to_host(host_id, wwn)

        (tgt_port_wwns,
         init_targ_map) = (self.rmt_client.get_init_targ_map(wwns))

        # Add host into hostgroup.
        hostgroup_id = self.rmt_client.add_host_to_hostgroup(host_id)
        map_info = self.rmt_client.do_mapping(lun_id, hostgroup_id, host_id)
        host_lun_id = self.rmt_client.get_host_lun_id(host_id, lun_id)

        # Return FC properties.
        fc_info = {
            'driver_volume_type': 'fibre_channel',
            'data': {
                'target_lun': int(host_lun_id),
                'target_discovered': True,
                'target_wwn': tgt_port_wwns,
                'volume_id': volume['id'],
                'initiator_target_map': init_targ_map,
                'map_info': map_info
            },
        }

        LOG.info(_LI('Remote return FC info is: %s.'), fc_info)

        return fc_info