示例#1
0
def _xml_read(root, element, check=None):
    """Read an xml element.

    :param root: XML object
    :param element: string desired tag
    :param check: string if present, throw exception if element missing
    """

    val = root.findtext(element)

    # mandatory parameter not found
    if val is None and check:
        LOG.error("Mandatory parameter not found: %(p)s", {'p': element})
        raise exception.ParameterNotFound(param=element)

    # tag not found
    if val is None:
        return None

    svc_tag_pattern = re.compile("svc_[0-3]$")
    # tag found but empty parameter.
    if not val.strip():
        if svc_tag_pattern.search(element):
            return ""
        LOG.error("Parameter not found: %(param)s", {'param': element})
        raise exception.ParameterNotFound(param=element)

    LOG.debug("%(element)s: %(val)s", {
        'element': element,
        'val': val if element != 'password' else '***'
    })

    return val.strip()
示例#2
0
def _xml_read(root, element, check=None):
    """Read an xml element."""

    val = root.findtext(element)

    # mandatory parameter not found
    if val is None and check:
        raise exception.ParameterNotFound(param=element)

    # tag not found
    if val is None:
        return None

    svc_tag_pattern = re.compile("svc_.$")
    # tag found but empty parameter.
    if not val.strip():
        if svc_tag_pattern.search(element):
            return ""
        raise exception.ParameterNotFound(param=element)

    LOG.debug(_LI("%(element)s: %(val)s"), {
        'element': element,
        'val': val if element != 'password' else '***'
    })

    return val.strip()
 def _check_flags(self):
     for flag in ['nec_ismcli_fip', 'nec_ismcli_user']:
         if getattr(self._local_conf, flag, '') == '':
             raise exception.ParameterNotFound(param=flag)
     if (getattr(self._local_conf, 'nec_ismcli_password', '') == '' and
             getattr(self._local_conf, 'nec_ismcli_privkey', '') == ''):
         msg = _('nec_ismcli_password nor nec_ismcli_privkey')
         raise exception.ParameterNotFound(param=msg)
示例#4
0
文件: nfs.py 项目: bopopescu/devstack
    def _get_service(self, volume):
        """Get the available service parameters for a given volume using
           its type.

        :param volume: dictionary volume reference
        """

        label = None
        if volume['volume_type']:
            label = volume['volume_type']['name']
        label = label or 'default'
        if label not in self.config['services'].keys():
            # default works if no match is found
            label = 'default'
        if label in self.config['services'].keys():
            svc = self.config['services'][label]
            LOG.info("Get service: %s->%s" % (label, svc['fslabel']))
            service = (svc['hdp'], svc['path'], svc['fslabel'])
        else:
            LOG.info(
                _LI("Available services: %s") % self.config['services'].keys())
            LOG.error(_LE("No configuration found for service: %s") % label)
            raise exception.ParameterNotFound(param=label)

        return service
示例#5
0
    def check_for_setup_error(self):
        fip = self._configuration.safe_get('nec_ismcli_fip')
        user = self._configuration.safe_get('nec_ismcli_user')
        pw = self._configuration.safe_get('nec_ismcli_password')
        key = self._configuration.safe_get('nec_ismcli_privkey')
        pools = self._configuration.safe_get('nec_pools')

        if fip is None or fip == '':
            raise exception.ParameterNotFound(param='nec_ismcli_fip')
        if user is None or user == '':
            raise exception.ParameterNotFound(param='nec_ismcli_user')
        if (pw is None or pw == '') and (key is None or key == ''):
            msg = _('nec_ismcli_password nor nec_ismcli_privkey')
            raise exception.ParameterNotFound(param=msg)
        if pools is None or len(pools) == 0:
            raise exception.ParameterNotFound(param='nec_pools')
示例#6
0
文件: nfs.py 项目: bopopescu/devstack
    def do_setup(self, context):
        """Perform internal driver setup."""

        self.context = context
        self._load_shares_config(
            getattr(self.configuration, self.driver_prefix + '_shares_config'))
        LOG.info("Review shares: %s" % self.shares)

        nfs_info = self._get_nfs_info()

        for share in self.shares:
            #export = share.split(':')[1]
            if share in nfs_info.keys():
                LOG.info("share: %s -> %s" % (share, nfs_info[share]['path']))

                for svc in self.config['services'].keys():
                    if share == self.config['services'][svc]['hdp']:
                        self.config['services'][svc]['path'] = \
                            nfs_info[share]['path']
                        # don't overwrite HDP value
                        self.config['services'][svc]['fsid'] = \
                            nfs_info[share]['hdp']
                        self.config['services'][svc]['fslabel'] = \
                            nfs_info[share]['fslabel']
                        LOG.info("Save service info for %s -> %s, %s" %
                                 (svc, nfs_info[share]['hdp'],
                                  nfs_info[share]['path']))
                        break
                if share != self.config['services'][svc]['hdp']:
                    LOG.error(
                        "NFS share %s has no service entry: %s -> %s" %
                        (share, svc, self.config['services'][svc]['hdp']))
                    raise exception.ParameterNotFound(param=svc)
            else:
                LOG.info("share: %s incorrect entry" % share)
示例#7
0
    def _get_service(self, volume):
        """Get service parameters.

        Get the available service parameters for a given volume using
        its type.

        :param volume: dictionary volume reference
        :returns: Tuple containing the service parameters (label,
        export path and export file system) or error if no configuration is
        found.
        :raises ParameterNotFound:
        """
        LOG.debug("_get_service: volume: %(vol)s", {'vol': volume})
        label = utils.extract_host(volume.host, level='pool')

        if label in self.config['services'].keys():
            svc = self.config['services'][label]
            LOG.debug("_get_service: %(lbl)s->%(svc)s", {
                'lbl': label,
                'svc': svc['export']['fs']
            })
            service = (svc['hdp'], svc['export']['path'], svc['export']['fs'])
        else:
            LOG.info("Available services: %(svc)s",
                     {'svc': self.config['services'].keys()})
            LOG.error("No configuration found for service: %(lbl)s",
                      {'lbl': label})
            raise exception.ParameterNotFound(param=label)

        return service
示例#8
0
    def _get_service(self, volume):
        """Get service parameters.

        Get the available service parameters for a given volume using
        its type.

        :param volume: dictionary volume reference
        """

        LOG.debug("_get_service: volume: %s", volume)
        label = utils.extract_host(volume['host'], level='pool')

        if label in self.config['services'].keys():
            svc = self.config['services'][label]
            LOG.info(_LI("Get service: %(lbl)s->%(svc)s"), {
                'lbl': label,
                'svc': svc['fslabel']
            })
            service = (svc['hdp'], svc['path'], svc['fslabel'])
        else:
            LOG.info(_LI("Available services: %s"),
                     self.config['services'].keys())
            LOG.error(_LE("No configuration found for service: %s"), label)
            raise exception.ParameterNotFound(param=label)

        return service
示例#9
0
    def retype(self,
               context,
               topic,
               volume_id,
               request_spec,
               filter_properties=None):
        """Schedule the modification of a volume's type.

        :param context: the request context
        :param topic: the topic listened on
        :param volume_id: the ID of the volume to retype
        :param request_spec: parameters for this retype request
        :param filter_properties: parameters to filter by
        """

        self._wait_for_scheduler()

        def _retype_volume_set_error(self, context, ex, request_spec,
                                     volume_ref, msg, reservations):
            if reservations:
                QUOTAS.rollback(context, reservations)
            previous_status = (volume_ref.previous_status or volume_ref.status)
            volume_state = {'volume_state': {'status': previous_status}}
            self._set_volume_state_and_notify('retype', volume_state, context,
                                              ex, request_spec, msg)

        volume_ref = db.volume_get(context, volume_id)
        reservations = request_spec.get('quota_reservations')
        new_type = request_spec.get('volume_type')
        if new_type is None:
            msg = _('New volume type not specified in request_spec.')
            ex = exception.ParameterNotFound(param='volume_type')
            _retype_volume_set_error(self, context, ex, request_spec,
                                     volume_ref, msg, reservations)

        # Default migration policy is 'never'
        migration_policy = request_spec.get('migration_policy')
        if not migration_policy:
            migration_policy = 'never'

        try:
            tgt_host = self.driver.find_retype_host(context, request_spec,
                                                    filter_properties,
                                                    migration_policy)
        except exception.NoValidHost as ex:
            msg = (_("Could not find a host for volume %(volume_id)s with "
                     "type %(type_id)s.") % {
                         'type_id': new_type['id'],
                         'volume_id': volume_id
                     })
            _retype_volume_set_error(self, context, ex, request_spec,
                                     volume_ref, msg, reservations)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _retype_volume_set_error(self, context, ex, request_spec,
                                         volume_ref, None, reservations)
        else:
            volume_rpcapi.VolumeAPI().retype(context, volume_ref,
                                             new_type['id'], tgt_host,
                                             migration_policy, reservations)
示例#10
0
文件: nfs.py 项目: bopopescu/devstack
def _xml_read(root, element, check=None):
    """Read an xml element.

    :param root: XML object
    :param element: string desired tag
    :param check: string if present, throw exception if element missing
    """

    try:
        val = root.findtext(element)
        LOG.info(
            _LI("%(element)s: %(val)s") % {
                'element': element,
                'val': val
            })
        if val:
            return val.strip()
        if check:
            raise exception.ParameterNotFound(param=element)
        return None
    except ETree.ParseError:
        if check:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("XML exception reading parameter: %s") % element)
        else:
            LOG.info(_LI("XML exception reading parameter: %s") % element)
            return None
示例#11
0
文件: swift.py 项目: blakelai/cinder
    def __init__(self, context, db_driver=None):
        self.context = context
        self.swift_url = '%s%s' % (CONF.backup_swift_url,
                                   self.context.project_id)
        self.az = CONF.storage_availability_zone
        self.data_block_size_bytes = CONF.backup_swift_object_size
        self.swift_attempts = CONF.backup_swift_retry_attempts
        self.swift_backoff = CONF.backup_swift_retry_backoff
        self.compressor = \
            self._get_compressor(CONF.backup_compression_algorithm)
        LOG.debug('Connect to %s in "%s" mode' % (CONF.backup_swift_url,
                                                  CONF.backup_swift_auth))
        if CONF.backup_swift_auth == 'single_user':
            if CONF.backup_swift_user is None:
                LOG.error(_("single_user auth mode enabled, "
                            "but %(param)s not set")
                          % {'param': 'backup_swift_user'})
                raise exception.ParameterNotFound(param='backup_swift_user')
            self.conn = swift.Connection(authurl=CONF.backup_swift_url,
                                         user=CONF.backup_swift_user,
                                         key=CONF.backup_swift_key,
                                         retries=self.swift_attempts,
                                         starting_backoff=self.swift_backoff)
        else:
            self.conn = swift.Connection(retries=self.swift_attempts,
                                         preauthurl=self.swift_url,
                                         preauthtoken=self.context.auth_token,
                                         starting_backoff=self.swift_backoff)

        super(SwiftBackupDriver, self).__init__(db_driver)
示例#12
0
    def do_setup(self, context):
        """Setup and verify HDS HNAS storage connection."""

        self.context = context
        (self.arid, self.hnas_name, self.lumax) = self._array_info_get()
        self._check_hdp_list()

        service_list = self.config['services'].keys()
        for svc in service_list:
            svc = self.config['services'][svc]
            pool = {}
            pool['pool_name'] = svc['volume_type']
            pool['service_label'] = svc['volume_type']
            pool['hdp'] = svc['hdp']

            self.pools.append(pool)

        LOG.info(_LI("Configured pools: %s"), self.pools)

        iscsi_info = self._get_iscsi_info()
        LOG.info(_LI("do_setup: %s"), iscsi_info)
        for svc in self.config['services'].keys():
            svc_ip = self.config['services'][svc]['iscsi_ip']
            if svc_ip in iscsi_info.keys():
                LOG.info(_LI("iSCSI portal found for service: %s"), svc_ip)
                self.config['services'][svc]['port'] = \
                    iscsi_info[svc_ip]['port']
                self.config['services'][svc]['ctl'] = iscsi_info[svc_ip]['ctl']
                self.config['services'][svc]['iscsi_port'] = \
                    iscsi_info[svc_ip]['iscsi_port']
            else:  # config iscsi address not found on device!
                LOG.error(_LE("iSCSI portal not found "
                              "for service: %s"), svc_ip)
                raise exception.ParameterNotFound(param=svc_ip)
示例#13
0
def _read_config(xml_config_file):
    """Read hds driver specific xml config file."""
    try:
        root = ETree.parse(xml_config_file).getroot()
    except Exception:
        raise exception.NotFound(message='config file not found: '
                                 + xml_config_file)
    config = {}
    arg_prereqs = ['mgmt_ip0', 'mgmt_ip1', 'username', 'password']
    for req in arg_prereqs:
        config[req] = _xml_read(root, req, 'check')

    config['hdp'] = {}
    config['services'] = {}
    for svc in ['svc_0', 'svc_1', 'svc_2', 'svc_3']:  # min one needed
        if _xml_read(root, svc) is None:
            continue
        service = {}
        service['label'] = svc
        for arg in ['volume_type', 'hdp', 'iscsi_ip']:  # none optional
            service[arg] = _xml_read(root, svc + '/' + arg, 'check')
        config['services'][service['volume_type']] = service
        config['hdp'][service['hdp']] = service['hdp']

    if config['services'].keys() is None:  # at least one service required!
        raise exception.ParameterNotFound(param="No service found")

    config['snapshot_hdp'] = _xml_read(root, 'snapshot/hdp', 'check')

    for arg in ['hus_cmd', 'lun_start', 'lun_end']:  # optional
        config[arg] = _xml_read(root, arg) or HUS_DEFAULT_CONFIG[arg]

    return config
示例#14
0
def _read_config(xml_config_file):
    """Read hds driver specific xml config file.

    :param xml_config_file: string filename containing XML configuration
    """

    if not os.access(xml_config_file, os.R_OK):
        msg = (_("Can't open config file: %s") % xml_config_file)
        raise exception.NotFound(message=msg)

    try:
        root = ETree.parse(xml_config_file).getroot()
    except Exception:
        msg = (_("Error parsing config file: %s") % xml_config_file)
        raise exception.ConfigNotFound(message=msg)

    # mandatory parameters
    config = {}
    arg_prereqs = ['mgmt_ip0', 'username']
    for req in arg_prereqs:
        config[req] = _xml_read(root, req, 'check')

    # optional parameters
    opt_parameters = ['hnas_cmd', 'ssh_enabled', 'cluster_admin_ip0']
    for req in opt_parameters:
        config[req] = _xml_read(root, req)

    if config['ssh_enabled'] == 'True':
        config['ssh_private_key'] = _xml_read(root, 'ssh_private_key', 'check')
        config['password'] = _xml_read(root, 'password')
        config['ssh_port'] = _xml_read(root, 'ssh_port')
        if config['ssh_port'] is None:
            config['ssh_port'] = HNAS_DEFAULT_CONFIG['ssh_port']
    else:
        # password is mandatory when not using SSH
        config['password'] = _xml_read(root, 'password', 'check')

    if config['hnas_cmd'] is None:
        config['hnas_cmd'] = HNAS_DEFAULT_CONFIG['hnas_cmd']

    config['hdp'] = {}
    config['services'] = {}

    # min one needed
    for svc in ['svc_0', 'svc_1', 'svc_2', 'svc_3']:
        if _xml_read(root, svc) is None:
            continue
        service = {'label': svc}

        # none optional
        for arg in ['volume_type', 'hdp']:
            service[arg] = _xml_read(root, svc + '/' + arg, 'check')
        config['services'][service['volume_type']] = service
        config['hdp'][service['hdp']] = service['hdp']

    # at least one service required!
    if config['services'].keys() is None:
        raise exception.ParameterNotFound(param="No service found")

    return config
示例#15
0
 def __init__(self, *args, **kwargs):
     """Initialize, read different config parameters."""
     super(HUSDriver, self).__init__(*args, **kwargs)
     self.driver_stats = {}
     self.context = {}
     self.bend = factory_bend()
     self.configuration.append_config_values(HUS_OPTS)
     self.config = _read_config(self.configuration.hds_cinder_config_file)
     (self.arid, self.hus_name, self.lumax) = self._array_info_get()
     self._check_hdp_list()
     start = self.config['lun_start']
     end = self.config['lun_end']
     maxlun = self.lumax
     (self.start, self.end) = _do_lu_range_check(start, end, maxlun)
     iscsi_info = self._get_iscsi_info()
     for svc in self.config['services'].keys():
         svc_ip = self.config['services'][svc]['iscsi_ip']
         if svc_ip in iscsi_info.keys():
             self.config['services'][svc]['port'] = (
                 iscsi_info[svc_ip]['port'])
             self.config['services'][svc]['ctl'] = iscsi_info[svc_ip]['ctl']
             self.config['services'][svc]['iscsi_port'] = (
                 iscsi_info[svc_ip]['iscsi_port'])
         else:          # config iscsi address not found on device!
             LOG.error(_("iSCSI portal not found for service: %s") % svc_ip)
             raise exception.ParameterNotFound(param=svc_ip)
     return
示例#16
0
 def __init__(self, context, db_driver=None):
     chunk_size_bytes = CONF.backup_swift_object_size
     sha_block_size_bytes = CONF.backup_swift_block_size
     backup_default_container = CONF.backup_swift_container
     enable_progress_timer = CONF.backup_swift_enable_progress_timer
     super(SwiftBackupDriver, self).__init__(context, chunk_size_bytes,
                                             sha_block_size_bytes,
                                             backup_default_container,
                                             enable_progress_timer,
                                             db_driver)
     if CONF.backup_swift_url is None:
         self.swift_url = None
         info = CONF.swift_catalog_info
         try:
             service_type, service_name, endpoint_type = info.split(':')
         except ValueError:
             raise exception.BackupDriverException(_(
                 "Failed to parse the configuration option "
                 "'swift_catalog_info', must be in the form "
                 "<service_type>:<service_name>:<endpoint_type>"))
         for entry in context.service_catalog:
             if entry.get('type') == service_type:
                 self.swift_url = entry.get(
                     'endpoints')[0].get(endpoint_type)
     else:
         self.swift_url = '%s%s' % (CONF.backup_swift_url,
                                    context.project_id)
     if self.swift_url is None:
         raise exception.BackupDriverException(_(
             "Could not determine which Swift endpoint to use. This can "
             " either be set in the service catalog or with the "
             " cinder.conf config option 'backup_swift_url'."))
     LOG.debug("Using swift URL %s", self.swift_url)
     self.swift_attempts = CONF.backup_swift_retry_attempts
     self.swift_backoff = CONF.backup_swift_retry_backoff
     LOG.debug('Connect to %s in "%s" mode', CONF.backup_swift_url,
               CONF.backup_swift_auth)
     if CONF.backup_swift_auth == 'single_user':
         if CONF.backup_swift_user is None:
             LOG.error(_LE("single_user auth mode enabled, "
                           "but %(param)s not set"),
                       {'param': 'backup_swift_user'})
             raise exception.ParameterNotFound(param='backup_swift_user')
         self.conn = swift.Connection(
             authurl=CONF.backup_swift_url,
             auth_version=CONF.backup_swift_auth_version,
             tenant_name=CONF.backup_swift_tenant,
             user=CONF.backup_swift_user,
             key=CONF.backup_swift_key,
             retries=self.swift_attempts,
             starting_backoff=self.swift_backoff,
             cacert=CONF.backup_swift_ca_cert_file)
     else:
         self.conn = swift.Connection(retries=self.swift_attempts,
                                      preauthurl=self.swift_url,
                                      preauthtoken=self.context.auth_token,
                                      starting_backoff=self.swift_backoff,
                                      cacert=CONF.backup_swift_ca_cert_file)
示例#17
0
    def import_vm_from_glance(self, **kwargs):
        '''
        :param kwargs:
        :return:
        '''
        LOG.debug(_("[VRM-CINDER] start import_vm_from_glance()"))
        uri = self.site_uri + '/vms/action/import'
        method = 'POST'
        new_url = self._generate_url(uri)
        link_nfs = kwargs.get('linkClone')
        if link_nfs:
            name = kwargs.get('image_id')
        else:
            name = kwargs.get('volume_id')

        is_template = kwargs.get("is_template")
        if is_template is None:
            template = 'false'
        else:
            template = 'true'

        if CONF.glance_host is None or str(CONF.glance_port) is None \
                or FC_DRIVER_CONF.glance_server_ip is None:
            LOG.error(
                _("[VRM-CINDER] params is None,"
                  "glance_host: %s; glance_port: %s; glance_ip: %s"),
                CONF.glance_host, str(CONF.glance_port),
                FC_DRIVER_CONF.glance_server_ip)
            raise exception.ParameterNotFound(param='glance_host or '
                                              'glance_port or glance_ip')

        endpoint = CONF.glance_host + ":" + str(CONF.glance_port)
        token = kwargs.get('auth_token')
        serviceIp = FC_DRIVER_CONF.glance_server_ip
        body = {
            'name': 'cinder-vm-' + name,
            'group': 'FSP',
            'description': 'cinder-glance-vm',
            'autoBoot': 'false',
            'location': kwargs.get("cluster_urn"),
            'osOptions': self._combine_os_options(**kwargs),
            'protocol': "glance",
            'vmConfig': self._combine_vmConfig_4_import(**kwargs),
            'isTemplate': template,
            'glanceConfig': {
                'imageID': kwargs.get('image_id'),
                'endPoint': endpoint,
                'serverIp': serviceIp,
                'token': token
            }
        }
        resp, body = self.vrmhttpclient.request(new_url,
                                                method,
                                                body=json.dumps(body))
        task_uri = body.get('taskUri')
        self.task_proxy.wait_task(task_uri=task_uri)
        LOG.debug(_("[VRM-CINDER] end import_vm_from_glance()"))
        return body.get('urn')
示例#18
0
    def export_vm_to_uds(self, **kwargs):
        '''

        :param kwargs:
        :return:
        '''
        LOG.debug(_("[VRM-CINDER] start export_vm_to_uds"))
        uri = '/vms'
        method = 'POST'
        path = self.site_uri + uri + '/' + kwargs.get(
            'vm_id') + '/action/export'
        new_url = self._generate_url(path)

        if FC_DRIVER_CONF.s3_store_access_key_for_cinder is None \
                or FC_DRIVER_CONF.s3_store_secret_key_for_cinder is None \
                or FC_DRIVER_CONF.uds_port is None or FC_DRIVER_CONF.uds_ip is None \
                or FC_DRIVER_CONF.uds_bucket_name is None:
            LOG.error(
                _("[VRM-CINDER] some params is None, please check: "
                  "s3_store_access_key_for_cinder, "
                  "s3_store_secret_key_for_cinder, uds_port, uds_ip, uds_bucket_name"
                  ))
            raise exception.ParameterNotFound(
                param='s3_store_access_key_for_cinder '
                'or s3_store_secret_key_for_cinder or'
                'uds_port or uds_serverIp or uds_bucket_name')

        uds_name = FC_DRIVER_CONF.s3_store_access_key_for_cinder
        uds_password = FC_DRIVER_CONF.s3_store_secret_key_for_cinder
        port = FC_DRIVER_CONF.uds_port
        serverIp = FC_DRIVER_CONF.uds_ip
        bucketName = FC_DRIVER_CONF.uds_bucket_name
        key = kwargs.get('image_id')

        format = 'xml' if FC_DRIVER_CONF.export_version == 'v1.2' else 'ovf'
        body = {
            'name': kwargs.get('image_id'),
            'format': format,
            'protocol': 'uds',
            'isOverwrite': 'false',
            'vmConfig': self._combine_vmConfig_4_export(**kwargs),
            's3Config': {
                'serverIp': serverIp,
                'port': port,
                'accessKey': uds_name,
                'secretKey': uds_password,
                'bucketName': bucketName,
                'key': key
            }
        }
        resp, body = self.vrmhttpclient.request(new_url,
                                                method,
                                                body=json.dumps(body))
        task_uri = body.get('taskUri')
        self.task_proxy.wait_task(task_uri=task_uri)
        LOG.debug(_("[VRM-CINDER] end export_vm_to_uds"))
        return body.get('urn')
示例#19
0
 def _check_hdp_list(self):
     """Verify all HDPs specified in the configuration exist."""
     hdpl = self._get_hdp_list()
     lst = self.config['hdp'].keys()
     lst.extend([self.config['snapshot_hdp'], ])
     for hdp in lst:
         if hdp not in hdpl:
             LOG.error(_("HDP not found: %s") % hdp)
             err = "HDP not found: " + hdp
             raise exception.ParameterNotFound(param=err)
示例#20
0
    def __init__(self,
                 ip,
                 port,
                 conn_timeout,
                 login,
                 password=None,
                 privatekey=None,
                 *args,
                 **kwargs):
        self.ip = ip
        self.port = port
        self.login = login
        self.password = password
        self.conn_timeout = conn_timeout if conn_timeout else None
        self.privatekey = privatekey
        self.hosts_key_file = None
        self.current_size = 0

        # Validate good config setting here.
        # Paramiko handles the case where the file is inaccessible.
        if not CONF.ssh_hosts_key_file:
            raise exception.ParameterNotFound(param='ssh_hosts_key_file')
        elif not os.path.isfile(CONF.ssh_hosts_key_file):
            # If using the default path, just create the file.
            if CONF.state_path in CONF.ssh_hosts_key_file:
                open(CONF.ssh_hosts_key_file, 'a').close()
            else:
                msg = (_("Unable to find ssh_hosts_key_file: %s") %
                       CONF.ssh_hosts_key_file)
                raise exception.InvalidInput(reason=msg)

        if 'hosts_key_file' in kwargs.keys():
            self.hosts_key_file = kwargs.pop('hosts_key_file')
            LOG.info(
                "Secondary ssh hosts key file %(kwargs)s will be "
                "loaded along with %(conf)s from /etc/cinder.conf.", {
                    'kwargs': self.hosts_key_file,
                    'conf': CONF.ssh_hosts_key_file
                })

        LOG.debug(
            "Setting strict_ssh_host_key_policy to '%(policy)s' "
            "using ssh_hosts_key_file '%(key_file)s'.", {
                'policy': CONF.strict_ssh_host_key_policy,
                'key_file': CONF.ssh_hosts_key_file
            })

        self.strict_ssh_host_key_policy = CONF.strict_ssh_host_key_policy

        if not self.hosts_key_file:
            self.hosts_key_file = CONF.ssh_hosts_key_file
        else:
            self.hosts_key_file += ',' + CONF.ssh_hosts_key_file

        super(SSHPool, self).__init__(*args, **kwargs)
示例#21
0
    def do_setup(self, context):
        """Perform internal driver setup."""

        self.context = context
        self._load_shares_config(getattr(self.configuration,
                                         self.driver_prefix +
                                         '_shares_config'))
        LOG.info(_LI("Review shares: %s"), self.shares)

        nfs_info = self._get_nfs_info()

        LOG.debug("nfs_info: %s", nfs_info)

        for share in self.shares:
            if share in nfs_info.keys():
                LOG.info(_LI("share: %(share)s -> %(info)s"),
                         {'share': share, 'info': nfs_info[share]['path']})

                for svc in self.config['services'].keys():
                    if share == self.config['services'][svc]['hdp']:
                        self.config['services'][svc]['path'] = \
                            nfs_info[share]['path']
                        # don't overwrite HDP value
                        self.config['services'][svc]['fsid'] = \
                            nfs_info[share]['hdp']
                        self.config['services'][svc]['fslabel'] = \
                            nfs_info[share]['fslabel']
                        LOG.info(_LI("Save service info for"
                                     " %(svc)s -> %(hdp)s, %(path)s"),
                                 {'svc': svc, 'hdp': nfs_info[share]['hdp'],
                                  'path': nfs_info[share]['path']})
                        break
                if share != self.config['services'][svc]['hdp']:
                    LOG.error(_LE("NFS share %(share)s has no service entry:"
                                  " %(svc)s -> %(hdp)s"),
                              {'share': share, 'svc': svc,
                               'hdp': self.config['services'][svc]['hdp']})
                    raise exception.ParameterNotFound(param=svc)
            else:
                LOG.info(_LI("share: %s incorrect entry"), share)

        LOG.debug("self.config['services'] = %s", self.config['services'])

        service_list = self.config['services'].keys()
        for svc in service_list:
            svc = self.config['services'][svc]
            pool = {}
            pool['pool_name'] = svc['volume_type']
            pool['service_label'] = svc['volume_type']
            pool['hdp'] = svc['hdp']

            self.pools.append(pool)

        LOG.info(_LI("Configured pools: %s"), self.pools)
示例#22
0
    def retype(self, context, volume, request_spec, filter_properties=None):
        """Schedule the modification of a volume's type.

        :param context: the request context
        :param volume: the volume object to retype
        :param request_spec: parameters for this retype request
        :param filter_properties: parameters to filter by
        """

        self._wait_for_scheduler()

        def _retype_volume_set_error(self,
                                     context,
                                     ex,
                                     request_spec,
                                     volume_ref,
                                     reservations,
                                     msg=None):
            if reservations:
                QUOTAS.rollback(context, reservations)
            previous_status = (volume_ref.previous_status or volume_ref.status)
            volume_state = {'volume_state': {'status': previous_status}}
            self._set_volume_state_and_notify('retype', volume_state, context,
                                              ex, request_spec, msg)

        reservations = request_spec.get('quota_reservations')
        old_reservations = request_spec.get('old_reservations', None)
        new_type = request_spec.get('volume_type')
        if new_type is None:
            msg = _('New volume type not specified in request_spec.')
            ex = exception.ParameterNotFound(param='volume_type')
            _retype_volume_set_error(self, context, ex, request_spec, volume,
                                     reservations, msg)

        # Default migration policy is 'never'
        migration_policy = request_spec.get('migration_policy')
        if not migration_policy:
            migration_policy = 'never'

        try:
            tgt_backend = self.driver.find_retype_backend(
                context, request_spec, filter_properties, migration_policy)
        except Exception as ex:
            # Not having a valid host is an expected exception, so we don't
            # reraise on it.
            reraise = not isinstance(ex, exception.NoValidBackend)
            with excutils.save_and_reraise_exception(reraise=reraise):
                _retype_volume_set_error(self, context, ex, request_spec,
                                         volume, reservations)
        else:
            volume_rpcapi.VolumeAPI().retype(context, volume, new_type['id'],
                                             tgt_backend, migration_policy,
                                             reservations, old_reservations)
示例#23
0
 def _get_service(self, volume):
     """Get the available service parameters for a given volume type."""
     label = None
     if volume['volume_type']:
         label = volume['volume_type']['name']
     label = label or 'default'
     if label in self.config['services'].keys():
         svc = self.config['services'][label]
         service = (svc['iscsi_ip'], svc['iscsi_port'], svc['ctl'],
                    svc['port'], svc['hdp'])  # ip, ipp, ctl, port, hdp
     else:
         LOG.error(_("No configuration found for service: %s") % label)
         raise exception.ParameterNotFound(param=label)
     return service
示例#24
0
    def _check_fs_list(self):
        """Verifies the FSs list in HNAS.

        Verify that all FSs specified in the configuration files actually
        exists on the storage.
        """
        fs_list = self.config['fs'].keys()

        for fs in fs_list:
            if not self.backend.get_fs_info(fs):
                msg = (_("File system not found or not mounted: %(fs)s") %
                       {'fs': fs})
                LOG.error(msg)
                raise exception.ParameterNotFound(param=msg)
示例#25
0
    def _check_hdp_list(self):
        """Verify HDPs in HNAS array.

        Verify that all HDPs specified in the configuration files actually
        exists on the storage.
        """

        hdpl = self._get_hdp_list()
        lst = self.config['hdp'].keys()

        for hdp in lst:
            if hdp not in hdpl:
                LOG.error(_LE("HDP not found: %s"), hdp)
                err = "HDP not found: " + hdp
                raise exception.ParameterNotFound(param=err)
示例#26
0
def _xml_read(root, element, check=None):
    """Read an xml element."""
    try:
        val = root.findtext(element)
        LOG.info(_("%(element)s: %(val)s") % {'element': element, 'val': val})
        if val:
            return val.strip()
        if check:
            raise exception.ParameterNotFound(param=element)
        return None
    except ETree.ParseError as e:
        if check:
            with excutils.save_and_reraise_exception():
                LOG.error(_("XML exception reading parameter: %s") % element)
        else:
            LOG.info(_("XML exception reading parameter: %s") % element)
            return None
示例#27
0
文件: nfs.py 项目: bopopescu/devstack
def _read_config(xml_config_file):
    """Read hds driver specific xml config file.

    :param xml_config_file: string filename containing XML configuration
    """

    if not os.access(xml_config_file, os.R_OK):
        raise exception.NotFound(message=_LE('Can\'t open config file: ') +
                                 xml_config_file)

    try:
        root = ETree.parse(xml_config_file).getroot()
    except Exception:
        raise exception.ConfigNotFound(
            message=_LE('Error parsing config file: ') + xml_config_file)

    # mandatory parameters
    config = {}
    arg_prereqs = ['mgmt_ip0', 'username', 'password']
    for req in arg_prereqs:
        config[req] = _xml_read(root, req, 'check')

    # optional parameters
    config['hnas_cmd'] = _xml_read(root, 'hnas_cmd') or\
        HNAS_DEFAULT_CONFIG['hnas_cmd']

    config['hdp'] = {}
    config['services'] = {}

    # min one needed
    for svc in ['svc_0', 'svc_1', 'svc_2', 'svc_3']:
        if _xml_read(root, svc) is None:
            continue
        service = {'label': svc}

        # none optional
        for arg in ['volume_type', 'hdp']:
            service[arg] = _xml_read(root, svc + '/' + arg, 'check')
        config['services'][service['volume_type']] = service
        config['hdp'][service['hdp']] = service['hdp']

    # at least one service required!
    if config['services'].keys() is None:
        raise exception.ParameterNotFound(param="No service found")

    return config
示例#28
0
    def export_vm_to_glance(self, **kwargs):
        '''
        :param kwargs:
        :return:
        '''
        LOG.debug(_("[VRM-CINDER] start export_vm_to_glance"))
        uri = '/vms'
        method = 'POST'
        path = self.site_uri + uri + '/' + kwargs.get(
            'vm_id') + '/action/export'
        new_url = self._generate_url(path)
        if CONF.glance_host is None or str(CONF.glance_port) is None \
                or FC_DRIVER_CONF.glance_server_ip is None:
            LOG.error(
                _("[VRM-CINDER] params is None,"
                  "glance_host: %s; glance_port: %s; glance_ip: %s"),
                CONF.glance_host, str(CONF.glance_port),
                FC_DRIVER_CONF.glance_server_ip)
            raise exception.ParameterNotFound(param='glance_host or '
                                              'glance_port or glance_ip')

        endpoint = CONF.glance_host + ":" + str(CONF.glance_port)
        token = kwargs.get('auth_token')
        serviceIp = FC_DRIVER_CONF.glance_server_ip

        format = 'xml' if FC_DRIVER_CONF.export_version == 'v1.2' else 'ovf'
        body = {
            'name': kwargs.get('image_id'),
            'format': format,
            'protocol': 'glance',
            'isOverwrite': 'false',
            'vmConfig': self._combine_vmConfig_4_export(**kwargs),
            'glanceConfig': {
                'imageID': kwargs.get('image_id'),
                'endPoint': endpoint,
                'serverIp': serviceIp,
                'token': token
            }
        }
        resp, body = self.vrmhttpclient.request(new_url,
                                                method,
                                                body=json.dumps(body))
        task_uri = body.get('taskUri')
        self.task_proxy.wait_task(task_uri=task_uri)
        LOG.debug(_("[VRM-CINDER] end export_vm_to_glance"))
        return body.get('urn')
示例#29
0
    def _get_service(self, volume):
        """Get the available service parameters

           Get the available service parametersfor a given volume using its
           type.
           :param volume: dictionary volume reference
           :return HDP related to the service
        """

        label = utils.extract_host(volume['host'], level='pool')
        LOG.info(_LI("Using service label: %s"), label)

        if label in self.config['services'].keys():
            svc = self.config['services'][label]
            return svc['hdp']
        else:
            LOG.info(_LI("Available services: %s."),
                     self.config['services'].keys())
            LOG.error(_LE("No configuration found for service: %s."), label)
            raise exception.ParameterNotFound(param=label)
示例#30
0
    def do_setup(self, context):
        """Setup and verify HDS HNAS storage connection."""

        self.context = context
        (self.arid, self.hnas_name, self.lumax) = self._array_info_get()
        self._check_hdp_list()

        iscsi_info = self._get_iscsi_info()
        LOG.info(_("do_setup: %s") % iscsi_info)
        for svc in self.config['services'].keys():
            svc_ip = self.config['services'][svc]['iscsi_ip']
            if svc_ip in iscsi_info.keys():
                LOG.info(_("iSCSI portal found for service: %s") % svc_ip)
                self.config['services'][svc]['port'] = \
                    iscsi_info[svc_ip]['port']
                self.config['services'][svc]['ctl'] = iscsi_info[svc_ip]['ctl']
                self.config['services'][svc]['iscsi_port'] = \
                    iscsi_info[svc_ip]['iscsi_port']
            else:  # config iscsi address not found on device!
                LOG.error(_("iSCSI portal not found for service: %s") % svc_ip)
                raise exception.ParameterNotFound(param=svc_ip)