def get_default_domain(request, get_name=True): """Gets the default domain object to use when creating Identity object. Returns the domain context if is set, otherwise return the domain of the logon user. :param get_name: Whether to get the domain name from Keystone if the context isn't set. Setting this to False prevents an unnecessary call to Keystone if only the domain ID is needed. """ domain_id = request.session.get("domain_context", None) domain_name = request.session.get("domain_context_name", None) # if running in Keystone V3 or later if VERSIONS.active >= 3 and domain_id is None: # if no domain context set, default to user's domain domain_id = request.user.user_domain_id domain_name = request.user.user_domain_name if get_name: try: domain = domain_get(request, domain_id) domain_name = domain.name except Exception: LOG.warning("Unable to retrieve Domain: %s" % domain_id) domain = base.APIDictWrapper({"id": domain_id, "name": domain_name}) return domain
def storage_discovered_data(request): data = [] raw_data = storage_backends_list(request, True) for _raw_data in raw_data: for _tier in _raw_data.tiers: storage_specs = _raw_data.capability_specs.copy() storage_specs['storagesystem'] = _raw_data.name storage_specs['tier'] = _tier.get('name') storage_specs['id'] = _tier.get('id') storage_specs['total'] = " %s Kb" % \ storage_specs.pop('capacity_total_kb', 0) capability_specs = _tier.get('capability_specs', None) if capability_specs is not None: storage_specs['used'] = "%s Kb" % \ capability_specs.get('capacity_used_kb', 0) if capability_specs.get('data_protection', None) == 'replication': storage_specs['protection'] = "Replication(min_size: %s, " % \ capability_specs.get('replication_min_size') + \ "size: %s)" % capability_specs.get('replication_size') if capability_specs.get('data_protection', None) == \ 'erasure_code': storage_specs['protection'] ="Erasure(data: %s, " % \ capability_specs.get('k') + "parity: %s " % \ capability_specs.get('m') + "algo: %s)" % \ capability_specs.get('technique') data.append(storage_specs) return [base.APIDictWrapper(_data) for _data in data]
def get_default_domain(request): """Gets the default domain object to use when creating Identity object. Returns the domain context if is set, otherwise return the domain of the logon user. """ domain_id = request.session.get("domain_context", None) domain_name = request.session.get("domain_context_name", None) # if running in Keystone V3 or later if VERSIONS.active >= 3 and not domain_id: # if no domain context set, default to users' domain domain_id = request.user.user_domain_id try: domain = domain_get(request, domain_id) domain_name = domain.name except Exception: LOG.warning("Unable to retrieve Domain: %s" % domain_id) domain = base.APIDictWrapper({"id": domain_id, "name": domain_name}) return domain
def get_default_domain(request, get_name=True): """Gets the default domain object to use when creating Identity object. Returns the domain context if is set, otherwise return the domain of the logon user. :param get_name: Whether to get the domain name from Keystone if the context isn't set. Setting this to False prevents an unnecessary call to Keystone if only the domain ID is needed. """ domain_id = request.session.get("domain_context", None) domain_name = request.session.get("domain_context_name", None) # if running in Keystone V3 or later if VERSIONS.active >= 3 and domain_id is None: # if no domain context set, default to user's domain domain_id = request.user.user_domain_id domain_name = request.user.user_domain_name if get_name and not request.user.is_federated: try: domain = domain_get(request, domain_id) domain_name = domain.name except exceptions.NotAuthorized: # NOTE (knasim-wrs): Retrieving domain information # is an admin URL operation. As a pre-check, such # operations would be Forbidden if the logon user does # not have an 'admin' role on the current project. # # Since this can be a common occurence and can cause # incessant warning logging in the horizon logs, # we recognize this condition and return the user's # domain information instead. LOG.debug( "Cannot retrieve domain information for " "user (%(user)s) that does not have an admin role " "on project (%(project)s)", { 'user': request.user.username, 'project': request.user.project_name }) except Exception: LOG.warning("Unable to retrieve Domain: %s", domain_id) domain = base.APIDictWrapper({"id": domain_id, "name": domain_name}) return domain