コード例 #1
0
ファイル: iscsi.py プロジェクト: avirambh/cinder
    def create_export(self, context, volume, volume_path, conf):
        """Creates an export for a logical volume."""
        iscsi_name = "%s%s" % (conf.iscsi_target_prefix,
                               volume['name'])
        max_targets = conf.safe_get('iscsi_num_targets')
        (iscsi_target, lun) = self._get_target_and_lun(context,
                                                       volume,
                                                       max_targets)

        current_chap_auth = self._get_target_chap_auth(iscsi_name)
        if current_chap_auth:
            (chap_username, chap_password) = current_chap_auth
        else:
            chap_username = utils.generate_username()
            chap_password = utils.generate_password()
        chap_auth = self._iscsi_authentication('IncomingUser',
                                               chap_username,
                                               chap_password)
        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       0,
                                       volume_path,
                                       chap_auth,
                                       write_cache=
                                       conf.iscsi_write_cache)
        data = {}
        data['location'] = self._iscsi_location(
            conf.iscsi_ip_address, tid, iscsi_name, conf.iscsi_port, lun)

        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', chap_username, chap_password)
        return data
コード例 #2
0
ファイル: scst.py プロジェクト: abusse/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        iscsi_target, lun = self._get_target_and_lun(context, volume)
        if self.target_name is None:
            iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                                   volume['name'])
        else:
            iscsi_name = self.target_name

        if self.chap_username and self.chap_password:
            chap_username = self.chap_username
            chap_password = self.chap_password
        else:
            chap_username = vutils.generate_username()
            chap_password = vutils.generate_password()

        chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
                                               chap_password)
        tid = self.create_iscsi_target(iscsi_name, volume['id'], iscsi_target,
                                       lun, volume_path, chap_auth)

        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', chap_username, chap_password)
        return data
コード例 #3
0
ファイル: windows.py プロジェクト: kvchampa/cinder
    def create_export(self, context, volume, connector):
        """Driver entry point to get the export info for a new volume."""
        # Since the iSCSI targets are not reused, being deleted when the
        # volume is detached, we should clean up existing targets before
        # creating a new one.
        self.remove_export(context, volume)

        target_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                                volume['name'])
        updates = {'provider_location': target_name}
        self.utils.create_iscsi_target(target_name)

        if self.configuration.use_chap_auth:
            chap_username = (self.configuration.chap_username or
                             utils.generate_username())
            chap_password = (self.configuration.chap_password or
                             utils.generate_password())

            self.utils.set_chap_credentials(target_name,
                                            chap_username,
                                            chap_password)

            updates['provider_auth'] = ' '.join(('CHAP',
                                                 chap_username,
                                                 chap_password))
        # Get the disk to add
        vol_name = volume['name']
        self.utils.add_disk_to_target(vol_name, target_name)

        return updates
コード例 #4
0
ファイル: scst.py プロジェクト: Datera/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        iscsi_target, lun = self._get_target_and_lun(context, volume)
        if self.target_name is None:
            iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                                   volume['name'])
        else:
            iscsi_name = self.target_name

        if self.chap_username and self.chap_password:
            chap_auth = (self.chap_username, self.chap_password)
        else:
            chap_auth = self._get_target_chap_auth(context, iscsi_name)
            if not chap_auth:
                chap_auth = (vutils.generate_username(),
                             vutils.generate_password())
        tid = self.create_iscsi_target(iscsi_name, volume['id'], iscsi_target,
                                       lun, volume_path, chap_auth)

        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', *chap_auth)
        return data
コード例 #5
0
ファイル: windows.py プロジェクト: kvchampa/cinder
    def create_export(self, context, volume, connector):
        """Driver entry point to get the export info for a new volume."""
        # Since the iSCSI targets are not reused, being deleted when the
        # volume is detached, we should clean up existing targets before
        # creating a new one.
        self.remove_export(context, volume)

        target_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                                volume['name'])
        updates = {'provider_location': target_name}
        self.utils.create_iscsi_target(target_name)

        if self.configuration.use_chap_auth:
            chap_username = (self.configuration.chap_username
                             or utils.generate_username())
            chap_password = (self.configuration.chap_password
                             or utils.generate_password())

            self.utils.set_chap_credentials(target_name, chap_username,
                                            chap_password)

            updates['provider_auth'] = ' '.join(
                ('CHAP', chap_username, chap_password))
        # Get the disk to add
        vol_name = volume['name']
        self.utils.add_disk_to_target(vol_name, target_name)

        return updates
コード例 #6
0
ファイル: tgt.py プロジェクト: sasimpson/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                               volume['name'])
        iscsi_target, lun = self._get_target_and_lun(context, volume)

        # Verify we haven't setup a CHAP creds file already
        # if DNE no big deal, we'll just create it
        current_chap_auth = self._get_target_chap_auth(iscsi_name)
        if current_chap_auth:
            (chap_username, chap_password) = current_chap_auth
        else:
            chap_username = vutils.generate_username()
            chap_password = vutils.generate_password()
        chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
                                               chap_password)
        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        iscsi_write_cache = self.configuration.get('iscsi_write_cache', 'on')
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       0,
                                       volume_path,
                                       chap_auth,
                                       iscsi_write_cache=iscsi_write_cache)
        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication('CHAP', chap_username,
                                                  chap_password)
        return data
コード例 #7
0
ファイル: iscsi.py プロジェクト: j-griffith/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        # 'iscsi_name': 'iqn.2010-10.org.openstack:volume-00000001'
        iscsi_name = "%s%s" % (self.configuration.target_prefix,
                               volume['name'])
        iscsi_target, lun = self._get_target_and_lun(context, volume)

        # Verify we haven't setup a CHAP creds file already
        # if DNE no big deal, we'll just create it
        chap_auth = self._get_target_chap_auth(context, volume)
        if not chap_auth:
            chap_auth = (vutils.generate_username(),
                         vutils.generate_password())

        # Get portals ips and port
        portals_config = self._get_portals_config()

        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       lun,
                                       volume_path,
                                       chap_auth,
                                       **portals_config)
        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.target_ip_address, tid, iscsi_name, lun,
            self.configuration.iscsi_secondary_ip_addresses)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', *chap_auth)
        return data
コード例 #8
0
    def create_export(self, context, volume, connector):
        """Driver entry point to get the export info for a new volume."""
        target_name = self._get_target_name(volume)
        updates = {}

        if not self._tgt_utils.iscsi_target_exists(target_name):
            self._tgt_utils.create_iscsi_target(target_name)
            updates['provider_location'] = target_name

            if self.configuration.use_chap_auth:
                chap_username = (self.configuration.chap_username
                                 or utils.generate_username())
                chap_password = (self.configuration.chap_password
                                 or utils.generate_password())

                self._tgt_utils.set_chap_credentials(target_name,
                                                     chap_username,
                                                     chap_password)

                updates['provider_auth'] = ' '.join(
                    ('CHAP', chap_username, chap_password))

        # This operation is idempotent
        self._tgt_utils.add_disk_to_target(volume.name, target_name)

        return updates
コード例 #9
0
ファイル: windows.py プロジェクト: NetApp/cinder
    def create_export(self, context, volume, connector):
        """Driver entry point to get the export info for a new volume."""
        target_name = self._get_target_name(volume)
        updates = {}

        if not self._tgt_utils.iscsi_target_exists(target_name):
            self._tgt_utils.create_iscsi_target(target_name)
            updates['provider_location'] = target_name

            if self.configuration.use_chap_auth:
                chap_username = (self.configuration.chap_username or
                                 utils.generate_username())
                chap_password = (self.configuration.chap_password or
                                 utils.generate_password())

                self._tgt_utils.set_chap_credentials(target_name,
                                                     chap_username,
                                                     chap_password)

                updates['provider_auth'] = ' '.join(('CHAP',
                                                     chap_username,
                                                     chap_password))

        # This operation is idempotent
        self._tgt_utils.add_disk_to_target(volume['name'], target_name)

        return updates
コード例 #10
0
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        # 'iscsi_name': 'iqn.2010-10.org.openstack:volume-00000001'
        iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                               volume['name'])
        iscsi_target, lun = self._get_target_and_lun(context, volume)

        # Verify we haven't setup a CHAP creds file already
        # if DNE no big deal, we'll just create it
        chap_auth = self._get_target_chap_auth(context, volume)
        if not chap_auth:
            chap_auth = (vutils.generate_username(),
                         vutils.generate_password())

        # Get portals ips and port
        portals_config = self._get_portals_config()

        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        tid = self.create_iscsi_target(iscsi_name, iscsi_target, lun,
                                       volume_path, chap_auth,
                                       **portals_config)
        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun,
            self.configuration.iscsi_secondary_ip_addresses)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication('CHAP', *chap_auth)
        return data
コード例 #11
0
ファイル: iscsi.py プロジェクト: AsherBond/cinder
    def create_export(self, context, volume, volume_path, conf):
        """Creates an export for a logical volume."""
        iscsi_name = "%s%s" % (conf.iscsi_target_prefix,
                               volume['name'])
        max_targets = conf.safe_get('iscsi_num_targets')
        (iscsi_target, lun) = self._get_target_and_lun(context,
                                                       volume,
                                                       max_targets)

        chap_username = utils.generate_username()
        chap_password = utils.generate_password()
        chap_auth = self._iscsi_authentication('IncomingUser',
                                               chap_username,
                                               chap_password)
        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       0,
                                       volume_path,
                                       chap_auth,
                                       write_cache=
                                       conf.iscsi_write_cache)
        data = {}
        data['location'] = self._iscsi_location(
            conf.iscsi_ip_address, tid, iscsi_name, conf.iscsi_port, lun)
        data['auth'] = self._iscsi_authentication(
            'CHAP', chap_username, chap_password)
        return data
コード例 #12
0
ファイル: tgt.py プロジェクト: Qeas/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                               volume['name'])
        iscsi_target, lun = self._get_target_and_lun(context, volume)

        # Verify we haven't setup a CHAP creds file already
        # if DNE no big deal, we'll just create it
        current_chap_auth = self._get_target_chap_auth(iscsi_name)
        if current_chap_auth:
            (chap_username, chap_password) = current_chap_auth
        else:
            chap_username = vutils.generate_username()
            chap_password = vutils.generate_password()
        chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
                                               chap_password)
        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        iscsi_write_cache = self.configuration.get('iscsi_write_cache', 'on')
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       0,
                                       volume_path,
                                       chap_auth,
                                       iscsi_write_cache=iscsi_write_cache)
        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun,
            self.configuration.iscsi_secondary_ip_addresses)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', chap_username, chap_password)
        return data
コード例 #13
0
    def _create_export(self, context, volume):
        """Creates an export for a logical volume.""" 
        if volume['name'] is None:
            return None
#         devmeg=zfscm.DEVList()
#         devname=devmeg.get_devname_by_volumename(volume['name'])   
#         volume_path = "/dev/%s" % devname 
        volume_path="/dev/" + self.poolname + "/" + volume['name']
        
        #data = self.target_helper.create_export(context,
        #                                        volume,
        #                                        volume_path,
        #                                        self.configuration)
        conf=self.configuration
        iscsi_name = "%s%s" % (conf.iscsi_target_prefix,
                               volume['name'])
        max_targets = conf.safe_get('iscsi_num_targets')
        (iscsi_target, lun) = self.target_helper._get_target_and_lun(context,
                                                       volume,
                                                       max_targets)
        try:
            current_chap_auth = self.target_helper._get_target_chap_auth(context,iscsi_name)
        except:
            current_chap_auth = self._getzfs_target_chap_auth(context,iscsi_name)
            pass
                      
        if current_chap_auth:
            (chap_username, chap_password) = current_chap_auth
        else:
            chap_username = cutils.generate_username()
            chap_password = cutils.generate_password()
        chap_auth = self.target_helper._iscsi_authentication('IncomingUser',
                                               chap_username,
                                               chap_password)
        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        
        tid = self.targetbase.create_iscsi_target(iscsi_name,iscsi_target, 0,
                                       volume_path,
                                       chap_auth,
                                       write_cache=conf.iscsi_write_cache)
        data = {}
        data['location'] = self.target_helper._iscsi_location(
            conf.iscsi_ip_address, tid, iscsi_name, conf.iscsi_port, lun)
        data['auth'] = self.target_helper._iscsi_authentication(
            'CHAP', chap_username, chap_password)

        return {
            'provider_location': data['location'],
            'provider_auth': data['auth'],
        }
コード例 #14
0
    def initialize_connection(self, volume, connector, **kwargs):
        """Attach volume to initiator/host.

        Creates a profile for the initiator, and adds the new profile to the
        target ACL.

        """

        # generate a CHAP secret here -- there is no way to retrieve an
        # existing CHAP secret over the Blockbridge API, so it must be
        # supplied by the volume driver.
        export_params = {
            'chap_user': (kwargs.get('user',
                                     volume_utils.generate_username(16))),
            'chap_secret': (kwargs.get('password',
                                       volume_utils.generate_password(32))),
        }

        LOG.debug("Configuring export for %(initiator)s",
                  connector,
                  resource=volume)

        rsp = self._create_export(volume['id'],
                                  connector['initiator'],
                                  export_params,
                                  user_id=volume['user_id'],
                                  project_id=volume['project_id'])

        # combine locally generated chap credentials with target iqn/lun to
        # present the attach properties.
        target_portal = "%s:%s" % (rsp['target_ip'], rsp['target_port'])

        properties = {
            'target_discovered': False,
            'target_portal': target_portal,
            'target_iqn': rsp['target_iqn'],
            'target_lun': rsp['target_lun'],
            'volume_id': volume['id'],
            'auth_method': 'CHAP',
            'auth_username': rsp['initiator_login'],
            'auth_password': export_params['chap_secret'],
        }

        LOG.debug("Attach properties: %(properties)s",
                  {'properties': properties})

        return {
            'driver_volume_type': 'iscsi',
            'data': properties,
        }
コード例 #15
0
ファイル: blockbridge.py プロジェクト: C2python/cinder
    def initialize_connection(self, volume, connector, **kwargs):
        """Attach volume to initiator/host.

        Creates a profile for the initiator, and adds the new profile to the
        target ACL.

        """

        # generate a CHAP secret here -- there is no way to retrieve an
        # existing CHAP secret over the Blockbridge API, so it must be
        # supplied by the volume driver.
        export_params = {
            'chap_user': (
                kwargs.get('user', volume_utils.generate_username(16))),
            'chap_secret': (
                kwargs.get('password', volume_utils.generate_password(32))),
        }

        LOG.debug("Configuring export for %(initiator)s", connector,
                  resource=volume)

        rsp = self._create_export(volume['id'],
                                  connector['initiator'],
                                  export_params,
                                  user_id=volume['user_id'],
                                  project_id=volume['project_id'])

        # combine locally generated chap credentials with target iqn/lun to
        # present the attach properties.
        target_portal = "%s:%s" % (rsp['target_ip'], rsp['target_port'])

        properties = {
            'target_discovered': False,
            'target_portal': target_portal,
            'target_iqn': rsp['target_iqn'],
            'target_lun': rsp['target_lun'],
            'volume_id': volume['id'],
            'auth_method': 'CHAP',
            'auth_username': rsp['initiator_login'],
            'auth_password': export_params['chap_secret'],
        }

        LOG.debug("Attach properties: %(properties)s",
                  {'properties': properties})

        return {
            'driver_volume_type': 'iscsi',
            'data': properties,
        }
コード例 #16
0
ファイル: iscsi.py プロジェクト: rchurch-wrs/stx-cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        # 'iscsi_name': 'iqn.2010-10.org.openstack:volume-00000001'
        iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                               volume['name'])
        iscsi_target, lun = self._get_target_and_lun(context, volume)

        # Verify we haven't setup a CHAP creds file already
        # if DNE no big deal, we'll just create it
        chap_auth = self._get_target_chap_auth(context, volume)
        if not chap_auth:
            auth = volume['provider_auth']
            if auth:
                (auth_method, auth_username, auth_secret) = auth.split()
                if auth_method == 'CHAP':
                    chap_auth = (auth_username, auth_secret)
                else:
                    LOG.error("Failed create_export. "
                              "Invalid auth_method: %(a)s for volume: %(v)s",
                              {"a": auth_method, "v": volume['id']})
                    return
            else:
                chap_auth = (vutils.generate_username(),
                             vutils.generate_password())

        # Get portals ips and port
        portals_config = self._get_portals_config()

        # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
        # should clean this all up at some point in the future
        LOG.info(("Creating volume export for %(uuid)s target:%(target)s "
                  "lun:%(lun)s path:%(volume_path)s"),
                 {"uuid": volume['id'], "target": iscsi_target, "lun": lun,
                  "volume_path": volume_path})
        tid = self.create_iscsi_target(iscsi_name,
                                       iscsi_target,
                                       lun,
                                       volume_path,
                                       chap_auth,
                                       **portals_config)
        LOG.info("Volume export for %s created", volume['id'])
        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.iscsi_ip_address, tid, iscsi_name, lun,
            self.configuration.iscsi_secondary_ip_addresses)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication(
            'CHAP', *chap_auth)
        return data
コード例 #17
0
    def _target_create(self, identifier):
        if not identifier:
            err = _('Param [identifier] is invalid.')
            raise exception.InvalidParameterValue(err=err)

        # 0 for no auth, 1 for single chap, 2 for mutual chap
        auth_type = 0
        chap_username = ''
        chap_password = ''
        provider_auth = ''
        if self.config.safe_get('use_chap_auth') and self.config.use_chap_auth:
            auth_type = 1
            chap_username = (self.config.safe_get('chap_username') or
                             volutils.generate_username(12))
            chap_password = (self.config.safe_get('chap_password') or
                             volutils.generate_password())
            provider_auth = ' '.join(('CHAP', chap_username, chap_password))

        trg_prefix = self.config.safe_get('iscsi_target_prefix')
        trg_name = (self.TARGET_NAME_PREFIX + '%s') % identifier
        iqn = trg_prefix + trg_name

        try:
            out = self.exec_webapi('SYNO.Core.ISCSI.Target',
                                   'create',
                                   1,
                                   name=trg_name,
                                   iqn=iqn,
                                   auth_type=auth_type,
                                   user=chap_username,
                                   password=chap_password,
                                   max_sessions=0)

            self.check_response(out)

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception(_LE('Failed to _target_create. [%s]'),
                              identifier)

        if not self.check_value_valid(out, ['data', 'target_id']):
            msg = _('Failed to get target_id of target [%s]') % trg_name
            raise exception.VolumeDriverException(message=msg)

        trg_id = out['data']['target_id']

        return iqn, trg_id, provider_auth
コード例 #18
0
 def create_export(self, context, volume, volume_path):
     """Creates an export for a logical volume."""
     iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                            volume['name'])
     iscsi_target, lun = self._get_target_and_lun(context, volume)
     chap_username = vutils.generate_username()
     chap_password = vutils.generate_password()
     chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
                                            chap_password)
     # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
     # should clean this all up at some point in the future
     tid = self.create_iscsi_target(iscsi_name, iscsi_target, 0,
                                    volume_path, chap_auth)
     data = {}
     data['location'] = self._iscsi_location(
         self.configuration.iscsi_ip_address, tid, iscsi_name, lun)
     LOG.debug('Set provider_location to: %s', data['location'])
     data['auth'] = self._iscsi_authentication('CHAP', chap_username,
                                               chap_password)
     return data
コード例 #19
0
ファイル: infinidat.py プロジェクト: ebalduf/cinder-backports
 def _initialize_connection_iscsi(self, volume, connector):
     volume_name = self._make_volume_name(volume)
     infinidat_volume = self._get_infinidat_volume_by_name(volume_name)
     port = iqn.IQN(connector['initiator'])
     infinidat_host = self._get_or_create_host(port)
     if self.configuration.use_chap_auth:
         chap_username = (self.configuration.chap_username or
                          vol_utils.generate_username())
         chap_password = (self.configuration.chap_password or
                          vol_utils.generate_password())
         infinidat_host.update_fields(
             security_method='CHAP',
             security_chap_inbound_username=chap_username,
             security_chap_inbound_secret=chap_password)
     mapping = self._get_or_create_mapping(infinidat_host,
                                           infinidat_volume)
     lun = mapping.get_lun()
     netspace_names = self.configuration.infinidat_iscsi_netspaces
     target_portals = []
     target_iqns = []
     target_luns = []
     for netspace_name in netspace_names:
         netspace = self._get_iscsi_network_space(netspace_name)
         target_portals.append(self._get_iscsi_portal(netspace))
         target_iqns.append(netspace.get_properties().iscsi_iqn)
         target_luns.append(lun)
     result_data = dict(target_discovered=True,
                        target_portal=target_portals[0],
                        target_iqn=target_iqns[0],
                        target_lun=target_luns[0])
     if len(target_portals) > 1:
         # multiple network spaces defined
         result_data.update(dict(target_portals=target_portals,
                                 target_iqns=target_iqns,
                                 target_luns=target_luns))
     if self.configuration.use_chap_auth:
         result_data.update(dict(auth_method='CHAP',
                                 auth_username=chap_username,
                                 auth_password=chap_password))
     return dict(driver_volume_type='iscsi',
                 data=result_data)
コード例 #20
0
 def _initialize_connection_iscsi(self, volume, connector):
     volume_name = self._make_volume_name(volume)
     infinidat_volume = self._get_infinidat_volume_by_name(volume_name)
     port = iqn.IQN(connector['initiator'])
     infinidat_host = self._get_or_create_host(port)
     if self.configuration.use_chap_auth:
         chap_username = (self.configuration.chap_username
                          or vol_utils.generate_username())
         chap_password = (self.configuration.chap_password
                          or vol_utils.generate_password())
         infinidat_host.update_fields(
             security_method='CHAP',
             security_chap_inbound_username=chap_username,
             security_chap_inbound_secret=chap_password)
     mapping = self._get_or_create_mapping(infinidat_host, infinidat_volume)
     lun = mapping.get_lun()
     netspace_names = self.configuration.infinidat_iscsi_netspaces
     target_portals = []
     target_iqns = []
     target_luns = []
     for netspace_name in netspace_names:
         netspace = self._get_iscsi_network_space(netspace_name)
         target_portals.append(self._get_iscsi_portal(netspace))
         target_iqns.append(netspace.get_properties().iscsi_iqn)
         target_luns.append(lun)
     result_data = dict(target_discovered=True,
                        target_portal=target_portals[0],
                        target_iqn=target_iqns[0],
                        target_lun=target_luns[0])
     if len(target_portals) > 1:
         # multiple network spaces defined
         result_data.update(
             dict(target_portals=target_portals,
                  target_iqns=target_iqns,
                  target_luns=target_luns))
     if self.configuration.use_chap_auth:
         result_data.update(
             dict(auth_method='CHAP',
                  auth_username=chap_username,
                  auth_password=chap_password))
     return dict(driver_volume_type='iscsi', data=result_data)
コード例 #21
0
ファイル: scst.py プロジェクト: zjjfeng111/cinder
    def create_export(self, context, volume, volume_path):
        """Creates an export for a logical volume."""
        iscsi_target, lun = self._get_target_and_lun(context, volume)
        iscsi_name = self._get_iscsi_name(volume)

        if self.chap_username and self.chap_password:
            chap_auth = (self.chap_username, self.chap_password)
        else:
            chap_auth = self._get_target_chap_auth(context, volume)
            if not chap_auth:
                chap_auth = (vutils.generate_username(),
                             vutils.generate_password())
        tid = self.create_iscsi_target(iscsi_name, volume['id'], iscsi_target,
                                       lun, volume_path, chap_auth)

        data = {}
        data['location'] = self._iscsi_location(
            self.configuration.target_ip_address, tid, iscsi_name, lun)
        LOG.debug('Set provider_location to: %s', data['location'])
        data['auth'] = self._iscsi_authentication('CHAP', *chap_auth)
        return data
コード例 #22
0
ファイル: tgt.py プロジェクト: NxtCloud/cinder
 def create_export(self, context, volume, volume_path):
     """Creates an export for a logical volume."""
     iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                            volume['name'])
     iscsi_target, lun = self._get_target_and_lun(context, volume)
     chap_username = vutils.generate_username()
     chap_password = vutils.generate_password()
     chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
                                            chap_password)
     # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need
     # should clean this all up at some point in the future
     tid = self.create_iscsi_target(iscsi_name,
                                    iscsi_target,
                                    0,
                                    volume_path,
                                    chap_auth)
     data = {}
     data['location'] = self._iscsi_location(
         self.configuration.iscsi_ip_address, tid, iscsi_name, lun)
     LOG.debug('Set provider_location to: %s', data['location'])
     data['auth'] = self._iscsi_authentication(
         'CHAP', chap_username, chap_password)
     return data
コード例 #23
0
ファイル: test_volume_utils.py プロジェクト: daming000/cinder
 def test_generate_username(self, mock_gen_pass):
     output = volume_utils.generate_username()
     self.assertEqual(mock_gen_pass.return_value, output)
コード例 #24
0
 def test_generate_username(self, mock_gen_pass):
     output = volume_utils.generate_username()
     self.assertEqual(mock_gen_pass.return_value, output)