Merge "Update location info to include object owner"
This commit is contained in:
commit
8d2b74fbec
@ -78,7 +78,8 @@ class Normalizer(object):
|
||||
return ret
|
||||
|
||||
def _normalize_image(self, image):
|
||||
new_image = munch.Munch(location=self.current_location)
|
||||
new_image = munch.Munch(
|
||||
location=self._get_current_location(project_id=image.get('owner')))
|
||||
properties = image.pop('properties', {})
|
||||
visibility = image.pop('visibility', None)
|
||||
if visibility:
|
||||
@ -119,11 +120,11 @@ class Normalizer(object):
|
||||
if not rules and 'rules' in group:
|
||||
rules = group.pop('rules')
|
||||
group['security_group_rules'] = self._normalize_secgroup_rules(rules)
|
||||
# neutron sets these. we don't care about it, but let's be the same
|
||||
project_id = group.get('project_id', group.get('tenant_id', ''))
|
||||
group['location'] = self._get_current_location(project_id=project_id)
|
||||
# neutron sets these. we don't care about it, but let's be the same
|
||||
group['tenant_id'] = project_id
|
||||
group['project_id'] = project_id
|
||||
group['location'] = self.current_location
|
||||
return munch.Munch(group)
|
||||
|
||||
def _normalize_secgroup_rules(self, rules):
|
||||
@ -144,7 +145,6 @@ class Normalizer(object):
|
||||
def _normalize_secgroup_rule(self, rule):
|
||||
ret = munch.Munch()
|
||||
ret['id'] = rule['id']
|
||||
ret['location'] = self.current_location
|
||||
ret['direction'] = rule.get('direction', 'ingress')
|
||||
ret['ethertype'] = rule.get('ethertype', 'IPv4')
|
||||
port_range_min = rule.get(
|
||||
@ -164,9 +164,10 @@ class Normalizer(object):
|
||||
'security_group_id', rule.get('parent_group_id'))
|
||||
ret['remote_group_id'] = rule.get('remote_group_id')
|
||||
project_id = rule.get('project_id', rule.get('tenant_id', ''))
|
||||
ret['location'] = self._get_current_location(project_id=project_id)
|
||||
# neutron sets these. we don't care about it, but let's be the same
|
||||
ret['tenant_id'] = project_id
|
||||
ret['project_id'] = project_id
|
||||
ret['remote_group_id'] = rule.get('remote_group_id')
|
||||
return ret
|
||||
|
||||
def _normalize_servers(self, servers):
|
||||
@ -187,7 +188,8 @@ class Normalizer(object):
|
||||
|
||||
server['region'] = self.region_name
|
||||
server['cloud'] = self.name
|
||||
server['location'] = self.current_location
|
||||
server['location'] = self._get_current_location(
|
||||
project_id=server.get('tenant_id'))
|
||||
|
||||
az = server.get('OS-EXT-AZ:availability_zone', None)
|
||||
if az:
|
||||
|
@ -416,21 +416,43 @@ class OpenStackCloud(_normalize.Normalizer):
|
||||
@property
|
||||
def current_project(self):
|
||||
'''Return a ``munch.Munch`` describing the current project'''
|
||||
auth_args = self.cloud_config.config.get('auth', {})
|
||||
return munch.Munch(
|
||||
id=self.current_project_id,
|
||||
name=auth_args.get('project_name'),
|
||||
domain_id=auth_args.get('domain_id'),
|
||||
domain_name=auth_args.get('domain_name'),
|
||||
return self._get_project_info()
|
||||
|
||||
def _get_project_info(self, project_id=None):
|
||||
project_info = munch.Munch(
|
||||
id=project_id,
|
||||
name=None,
|
||||
domain_id=None,
|
||||
domain_name=None,
|
||||
)
|
||||
if not project_id or project_id == self.current_project_id:
|
||||
# If we don't have a project_id parameter, it means a user is
|
||||
# directly asking what the current state is.
|
||||
# Alternately, if we have one, that means we're calling this
|
||||
# from within a normalize function, which means the object has
|
||||
# a project_id associated with it. If the project_id matches
|
||||
# the project_id of our current token, that means we can supplement
|
||||
# the info with human readable info about names if we have them.
|
||||
# If they don't match, that means we're an admin who has pulled
|
||||
# an object from a different project, so adding info from the
|
||||
# current token would be wrong.
|
||||
auth_args = self.cloud_config.config.get('auth', {})
|
||||
project_info['id'] = self.current_project_id
|
||||
project_info['name'] = auth_args.get('project_name')
|
||||
project_info['domain_id'] = auth_args.get('project_domain_id')
|
||||
project_info['domain_name'] = auth_args.get('project_domain_name')
|
||||
return project_info
|
||||
|
||||
@property
|
||||
def current_location(self):
|
||||
'''Return a ``munch.Munch`` explaining the current cloud location.'''
|
||||
return self._get_current_location()
|
||||
|
||||
def _get_current_location(self, project_id=None):
|
||||
return munch.Munch(
|
||||
cloud=self.name,
|
||||
region_name=self.region_name,
|
||||
project=self.current_project,
|
||||
project=self._get_project_info(project_id),
|
||||
)
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user