diff --git a/nova/api/openstack/compute/plugins/v3/networks.py b/nova/api/openstack/compute/plugins/v3/networks.py index a3c823feb3db..f509cc4e1cac 100644 --- a/nova/api/openstack/compute/plugins/v3/networks.py +++ b/nova/api/openstack/compute/plugins/v3/networks.py @@ -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 diff --git a/nova/api/openstack/compute/plugins/v3/tenant_networks.py b/nova/api/openstack/compute/plugins/v3/tenant_networks.py index 0261cedb075b..1218cbd16a18 100644 --- a/nova/api/openstack/compute/plugins/v3/tenant_networks.py +++ b/nova/api/openstack/compute/plugins/v3/tenant_networks.py @@ -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):