Merge "Fix v2.1 os-tenant-networks/networks API"

This commit is contained in:
Jenkins 2015-01-23 04:28:36 +00:00 committed by Gerrit Code Review
commit 516c4c875c
2 changed files with 14 additions and 7 deletions

View File

@ -47,7 +47,7 @@ def network_dict(context, network):
if context.is_admin:
fields += admin_fields
# TODO(mriedem): Remove the NovaObject type check once the
# neutronv2 API is returning Network objects from get/get_all.
# network.create API is returning objects.
is_obj = isinstance(network, base_obj.NovaObject)
result = {}
for field in fields:
@ -56,14 +56,18 @@ def network_dict(context, network):
# before the objects conversion.
if is_obj and isinstance(network.fields[field].AUTO_TYPE,
obj_fields.IPAddress):
val = network.get(field)
# NOTE(danms): Here, network should be an object, which could
# have come from neutron and thus be missing most of the
# attributes. Providing a default to get() avoids trying to
# lazy-load missing attributes.
val = network.get(field, None)
if val is not None:
result[field] = str(network.get(field))
result[field] = str(val)
else:
result[field] = val
else:
# It's either not an object or it's not an IPAddress field.
result[field] = network.get(field)
result[field] = network.get(field, None)
uuid = network.get('uuid')
if uuid:
result['id'] = uuid

View File

@ -50,9 +50,12 @@ authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
def network_dict(network):
return {"id": network.get("uuid") or network.get("id"),
"cidr": str(network.get("cidr")),
"label": network.get("label")}
# NOTE(danms): Here, network should be an object, which could have come
# from neutron and thus be missing most of the attributes. Providing a
# default to get() avoids trying to lazy-load missing attributes.
return {"id": network.get("uuid", None) or network.get("id", None),
"cidr": str(network.get("cidr", None)),
"label": network.get("label", None)}
class TenantNetworkController(wsgi.Controller):