def get_backend_configuration(backend_name): """Get a cDOT configuration object for a specific backend.""" config_stanzas = CONF.list_all_sections() if backend_name not in config_stanzas: msg = _("Could not find backend stanza %(backend_name)s in " "configuration. Available stanzas are %(stanzas)s") params = { "stanzas": config_stanzas, "backend_name": backend_name, } raise exception.ConfigNotFound(message=msg % params) config = configuration.Configuration(driver.volume_opts, config_group=backend_name) config.append_config_values(na_opts.netapp_proxy_opts) config.append_config_values(na_opts.netapp_connection_opts) config.append_config_values(na_opts.netapp_transport_opts) config.append_config_values(na_opts.netapp_basicauth_opts) config.append_config_values(na_opts.netapp_provisioning_opts) config.append_config_values(na_opts.netapp_cluster_opts) config.append_config_values(na_opts.netapp_san_opts) config.append_config_values(na_opts.netapp_replication_opts) config.append_config_values(na_opts.netapp_support_opts) return config
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
def _check_configuration(): """Raises error if any required configuration flag is missing.""" required_flags = ['backup_share'] for flag in required_flags: if not getattr(CONF, flag, None): raise exception.ConfigNotFound( _('Required flag %s is not set') % flag)
def __init__(self, context, db=None, backup_path=None): chunk_size_bytes = CONF.backup_file_size sha_block_size_bytes = CONF.backup_sha_block_size_bytes backup_default_container = CONF.backup_container enable_progress_timer = CONF.backup_enable_progress_timer super(PosixBackupDriver, self).__init__(context, chunk_size_bytes, sha_block_size_bytes, backup_default_container, enable_progress_timer, db) self.backup_path = backup_path if not backup_path: self.backup_path = CONF.backup_posix_path if not self.backup_path: raise exception.ConfigNotFound(path='backup_path') LOG.debug("Using backup repository: %s", self.backup_path)
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
def get_backend_configuration(backend_name, backend_opts=None): """Get a configuration object for a specific backend.""" config_stanzas = CONF.list_all_sections() if backend_name not in config_stanzas: msg = _("Could not find backend stanza %(backend_name)s in " "configuration. Available stanzas are %(stanzas)s") params = { "stanzas": config_stanzas, "backend_name": backend_name, } raise exception.ConfigNotFound(message=msg % params) config = configuration.Configuration(driver.volume_opts, config_group=backend_name) if backend_opts: config.append_config_values(backend_opts) return config
def find_config(config_path): """Find a configuration file using the given hint. :param config_path: Full or relative path to the config. :returns: Full path of the config, if it exists. :raises: `cinder.exception.ConfigNotFound` """ possible_locations = [ config_path, os.path.join(CONF.state_path, "etc", "cinder", config_path), os.path.join(CONF.state_path, "etc", config_path), os.path.join(CONF.state_path, config_path), "/etc/cinder/%s" % config_path, ] for path in possible_locations: if os.path.exists(path): return os.path.abspath(path) raise exception.ConfigNotFound(path=os.path.abspath(config_path))
def _check_configuration(): """Raises error if any required configuration flag is missing.""" required_flags = ['glusterfs_backup_share'] for flag in required_flags: if not getattr(CONF, flag, None): raise exception.ConfigNotFound(path=flag)
def read_xml_config(xml_config_file, svc_params, optional_params): """Read Hitachi driver specific xml config file. :param xml_config_file: string filename containing XML configuration :param svc_params: parameters to configure the services .. code:: python ['volume_type', 'hdp'] :param optional_params: parameters to configure that are not mandatory .. code:: python ['ssc_cmd', 'cluster_admin_ip0', 'chap_enabled'] """ if not os.access(xml_config_file, os.R_OK): msg = (_("Can't find HNAS configurations on cinder.conf neither " "on the path %(xml)s.") % { 'xml': xml_config_file }) LOG.error(msg) raise exception.ConfigNotFound(message=msg) else: LOG.warning( "This XML configuration file %(xml)s is deprecated. " "Please, move all the configurations to the " "cinder.conf file. If you keep both configuration " "files, the options set on cinder.conf will be " "used.", {'xml': xml_config_file}) try: root = ETree.parse(xml_config_file).getroot() except ETree.ParseError: msg = (_("Error parsing config file: %(xml_config_file)s") % { 'xml_config_file': xml_config_file }) LOG.error(msg) raise exception.ConfigNotFound(message=msg) # mandatory parameters for NFS config = {} arg_prereqs = ['mgmt_ip0', 'username'] for req in arg_prereqs: config[req] = _xml_read(root, req, 'check') # optional parameters for NFS for req in optional_params: config[req] = _xml_read(root, req) if config[req] is None and HNAS_DEFAULT_CONFIG.get(req) is not None: config[req] = HNAS_DEFAULT_CONFIG.get(req) config['ssh_private_key'] = _xml_read(root, 'ssh_private_key') config['password'] = _xml_read(root, 'password') if config['ssh_private_key'] is None and config['password'] is None: msg = _("Missing authentication option (passw or private key file).") LOG.error(msg) raise exception.ConfigNotFound(message=msg) if _xml_read(root, 'ssh_port') is not None: config['ssh_port'] = int(_xml_read(root, 'ssh_port')) else: config['ssh_port'] = HNAS_DEFAULT_CONFIG['ssh_port'] config['fs'] = {} 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 svc_params: service[arg] = _xml_read(root, svc + '/' + arg, 'check') # Backward compatibility with volume_type service.setdefault('pool_name', service.pop('volume_type', None)) config['services'][service['pool_name']] = service config['fs'][service['hdp']] = service['hdp'] # at least one service required! if not config['services'].keys(): LOG.error("No service found in xml config file") raise exception.ParameterNotFound(param="svc_0") return config