Ejemplo n.º 1
0
    def initialize_connection(self, volume, connector):
        """Create FC connection between a volume and a host."""
        LOG.debug(
            'initialize_connection: volume name: %(vol)s, '
            'host: %(host)s, initiator: %(wwn)s' % {
                'vol': volume['name'],
                'host': connector['host'],
                'wwn': connector['wwpns']
            })
        lun_id = self.sshclient.check_volume_exist_on_array(volume)
        if not lun_id:
            msg = _("Volume %s not exists on the array.") % volume['id']
            raise exception.VolumeBackendAPIException(data=msg)

        self.sshclient.update_login_info()
        # First, add a host if it is not added before.
        host_id = self.sshclient.add_host(connector['host'], connector['ip'])
        # Then, add free FC ports to the host.
        wwns = connector['wwpns']
        if not self.zm:
            self.zm = fczm_utils.create_zone_manager()
        if self.zm:
            # Use FC switch
            zone_helper = fc_zone_helper.FCZoneHelper(self.zm, self.sshclient)
            port_list = self.sshclient.get_all_fc_ports_from_array()
            (tgt_port_wwns, init_targ_map) = zone_helper.build_ini_tgt_map(
                wwns, host_id, port_list, True)

        else:
            free_wwns = self.sshclient.get_connected_free_wwns()
            for wwn in free_wwns:
                if wwn in wwns:
                    self.sshclient.add_fc_port_to_host(host_id, wwn)
            fc_port_details = self.sshclient.get_host_port_details(host_id)
            tgt_port_wwns = self._get_tgt_fc_port_wwns(fc_port_details)

        LOG.debug('initialize_connection: Target FC ports WWNS: %s' %
                  tgt_port_wwns)

        try:
            hostlun_id = self.sshclient.map_volume(host_id, lun_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                # Remove the FC port from the host if the map failed.
                self._remove_fc_ports(host_id, wwns)

        properties = {}
        properties['target_discovered'] = False
        properties['target_wwn'] = tgt_port_wwns
        properties['target_lun'] = int(hostlun_id)
        properties['volume_id'] = volume['id']

        return {'driver_volume_type': 'fibre_channel', 'data': properties}
Ejemplo n.º 2
0
    def initialize_connection(self, volume, connector):
        """Create FC connection between a volume and a host."""
        LOG.debug('initialize_connection: volume name: %(vol)s, '
                  'host: %(host)s, initiator: %(wwn)s'
                  % {'vol': volume['name'],
                     'host': connector['host'],
                     'wwn': connector['wwpns']})
        lun_id = self.sshclient.check_volume_exist_on_array(volume)
        if not lun_id:
            msg = _("Volume %s not exists on the array.") % volume['id']
            raise exception.VolumeBackendAPIException(data=msg)

        self.sshclient.update_login_info()
        # First, add a host if it is not added before.
        host_id = self.sshclient.add_host(connector['host'], connector['ip'])
        # Then, add free FC ports to the host.
        wwns = connector['wwpns']
        if not self.zm:
            self.zm = fczm_utils.create_zone_manager()
        if self.zm:
            # Use FC switch
            zone_helper = fc_zone_helper.FCZoneHelper(self.zm, self.sshclient)
            port_list = self.sshclient.get_all_fc_ports_from_array()
            (tgt_port_wwns,
             init_targ_map) = zone_helper.build_ini_tgt_map(wwns, host_id,
                                                            port_list, True)

        else:
            free_wwns = self.sshclient.get_connected_free_wwns()
            for wwn in free_wwns:
                if wwn in wwns:
                    self.sshclient.add_fc_port_to_host(host_id, wwn)
            fc_port_details = self.sshclient.get_host_port_details(host_id)
            tgt_port_wwns = self._get_tgt_fc_port_wwns(fc_port_details)

        LOG.debug('initialize_connection: Target FC ports WWNS: %s'
                  % tgt_port_wwns)

        try:
            hostlun_id = self.sshclient.map_volume(host_id, lun_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                # Remove the FC port from the host if the map failed.
                self._remove_fc_ports(host_id, wwns)

        properties = {}
        properties['target_discovered'] = False
        properties['target_wwn'] = tgt_port_wwns
        properties['target_lun'] = int(hostlun_id)
        properties['volume_id'] = volume['id']

        return {'driver_volume_type': 'fibre_channel',
                'data': properties}
Ejemplo n.º 3
0
    def _delete_zone_and_remove_initiators(self, wwns, host_id):
        if host_id is None:
            return

        self._remove_fc_ports(host_id, wwns)

        if not self.zm:
            self.zm = fczm_utils.create_zone_manager()
        if self.zm:
            # Use FC switch, need to delete zone
            # Use FC switch
            zone_helper = fc_zone_helper.FCZoneHelper(self.zm, self.sshclient)
            port_list = self.sshclient.get_all_fc_ports_from_array()
            (tgt_port_wwns, init_targ_map) = zone_helper.build_ini_tgt_map(
                wwns, host_id, port_list, True)
            self.zm.delete_connection(init_targ_map)
Ejemplo n.º 4
0
    def _delete_zone_and_remove_initiators(self, wwns, host_id):
        if host_id is None:
            return

        self._remove_fc_ports(host_id, wwns)

        if not self.zm:
            self.zm = fczm_utils.create_zone_manager()
        if self.zm:
            # Use FC switch, need to delete zone
            # Use FC switch
            zone_helper = fc_zone_helper.FCZoneHelper(self.zm, self.sshclient)
            port_list = self.sshclient.get_all_fc_ports_from_array()
            (tgt_port_wwns,
             init_targ_map) = zone_helper.build_ini_tgt_map(wwns, host_id,
                                                            port_list, True)
            self.zm.delete_connection(init_targ_map)