def __call__(self): conf = config("config-flags") if not conf: return {} conf = config_flags_parser(conf) if type(conf) != dict: log("Provided config-flags is not a dictionary - ignoring", level=WARNING) return {} permitted = self.permitted_sections if permitted: diff = set(conf.keys()).difference(set(permitted)) if diff: log( "Config-flags contains invalid keys '%s' - they will be " "ignored" % (", ".join(diff)), level=WARNING, ) ceph_conf = {} for key in conf: if permitted and key not in permitted: log("Ignoring key '%s'" % key, level=WARNING) continue ceph_conf[key] = conf[key] return ceph_conf
def planner_ex_pools(cls): conf = config('planner') if conf == 'storage_capacity_balance': conf = config_flags_parser(config('planner-config')) ex_pools = conf.get('ex_pools', None) if not ex_pools: log('Provided planner-config dictionary does not contain key ' 'ex_pools - ignoring', level=WARNING) else: return ex_pools
def planner_parallelization(cls): conf = config('planner') if conf == 'weight': conf = config_flags_parser(config('planner-config')) parallelization = conf.get('parallelization', None) if not parallelization: log('Provided planner-config dictionary does not contain key ' 'parallelization - ignoring', level=WARNING) else: return parallelization
def planner_check_optimize_metadata(cls): conf = config('planner') if conf == 'basic': conf = config_flags_parser(config('planner-config')) check_optimize_metadata = conf.get('check_optimize_metadata', None) if not check_optimize_metadata: log('Provided planner-config dictionary does not contain key ' 'check_optimize_metadata - ignoring', level=WARNING) else: return check_optimize_metadata
def planner_weights(cls): conf = config('planner') if conf in ['weight', 'workload_stabilization']: conf = config_flags_parser(config('planner-config')) weights = conf.get('weights', None) if not weights: log('Provided planner-config dictionary does not contain key ' 'weights - ignoring', level=WARNING) else: return weights
def get_os_credentials(self): ident_creds = config_flags_parser(self.charm_config['os-credentials']) # Check that auth_url is in the credentials from the config if not ident_creds.get('auth_url'): raise CSCCredentialsError('auth_url') creds = {} all_attrs = ('username password region_name auth_url' ' project_name domain').split() missing = [k for k in all_attrs if k not in ident_creds] # Check that there's no missing mandatory parameter if missing: raise CSCCredentialsError(', '.join(missing)) # Strip the auth_url as it might contain quotes ident_creds['auth_url'] = ident_creds['auth_url'].strip('\"\'') creds.update(dict([(k, ident_creds.get(k)) for k in all_attrs])) return creds
def custom_assess_status_check(self): """Verify that the configuration provided is valid and thus the service is ready to go. This will return blocked if the configuration is not valid for the service. :returns (status: string, message: string): the status, and message if there is a problem. Or (None, None) if there are no issues. """ datasources = self.options.datasources if not datasources: return 'blocked', 'datasources not set' if not set(datasources.split(',')).issubset( ['gnocchi', 'ceilometer', 'grafana']): return ('blocked', 'Provided datasources {} does not contain valid options' .format(datasources)) if 'grafana' in datasources: if not self.grafana_configuration_complete(): return ('blocked', 'grafana datasource requires all grafana related ' 'options to be set') planner = self.options.planner if planner not in [ 'weight', 'workload_stabilization', 'basic', 'storage_capacity_balance']: return ('blocked', 'Invalid planner: {}. Available options are: ' 'weights, workload_stabilization, basic, ' 'storage_capacity_balance'.format(planner)) planner_config = config_flags_parser(self.options.planner_config) planner_config_values = { 'weight': {'weights', 'parallelization'}, 'workload_stabilization': {'weights'}, 'basic': {'check_optimize_metadata'}, 'storage_capacity_balance': {'ex_pools'}, } if planner_config.keys() != planner_config_values[planner]: return ('blocked', 'Provided planner {} must contain only the following ' 'configuration attributes: {}'.format( planner, ', '.join(planner_config_values[planner]))) return None, None
def __call__(self): """Return the 'default_availability_zone' from the principal that this ovs unit is attached to (as a subordinate) and the 'dns_domain' from the neutron-plugin-api relations (if one is set). :returns: {} if no relation set, or {'availability_zone': availability_zone from principal relation} """ ctxt = super(DHCPAgentContext, self).__call__() dnsmasq_flags = config('dnsmasq-flags') if dnsmasq_flags: ctxt['dnsmasq_flags'] = config_flags_parser(dnsmasq_flags) ctxt['dns_servers'] = config('dns-servers') neutron_api_settings = NeutronAPIContext()() if neutron_api_settings.get('dns_domain'): ctxt['dns_domain'] = neutron_api_settings.get('dns_domain') ctxt['instance_mtu'] = config('instance-mtu') return ctxt
def __call__(self): """Return the 'default_availability_zone' from the principal that this ovs unit is attached to (as a subordinate) and the 'dns_domain' from the neutron-plugin-api relations (if one is set). :returns: {} if no relation set, or {'availability_zone': availability_zone from principal relation} """ # as ovs is a subordinate charm, it should only have one relation to # its principal charm. Thus we can take the 1st (only) element in each # list. rids = relation_ids('neutron-plugin') ctxt = {} if rids: rid = rids[0] units = related_units(rid) if units: availability_zone = relation_get( 'default_availability_zone', rid=rid, unit=units[0]) if availability_zone: ctxt['availability_zone'] = availability_zone dnsmasq_flags = config('dnsmasq-flags') if dnsmasq_flags: ctxt['dnsmasq_flags'] = config_flags_parser(dnsmasq_flags) ctxt['dns_servers'] = config('dns-servers') neutron_api_settings = NeutronAPIContext()() if neutron_api_settings.get('dns_domain'): ctxt['dns_domain'] = neutron_api_settings.get('dns_domain') ctxt['instance_mtu'] = config('instance-mtu') return ctxt
def ldap_options(self): return os_utils.config_flags_parser( hookenv.config('ldap-config-flags') )