def retrieve_ip_allocation_info(l2_plugin, context, neutron_port): """Retrieves ip allocation info for a specific port if any.""" try: subnet_id = neutron_port["fixed_ips"][0]["subnet_id"] except (KeyError, IndexError): LOG.info(_("No ip allocation set")) return subnet = l2_plugin._get_subnet(context, subnet_id) allocated_ip = neutron_port["fixed_ips"][0]["ip_address"] is_gw_port = neutron_port["device_owner"] == "network:router_gateway" gateway_ip = subnet["gateway_ip"] ip_allocation_info = h_info.IpAllocationInfo( is_gw=is_gw_port, ip_version=subnet["ip_version"], prefix=subnet["cidr"].split("/")[1], ip_address=allocated_ip, port_id=neutron_port["id"], gateway_ip=gateway_ip) return ip_allocation_info
def retrieve_ip_allocation_info(context, neutron_port): """Retrieves ip allocation info for a specific port if any.""" try: subnet_id = neutron_port["fixed_ips"][0]["subnet_id"] except (KeyError, IndexError): LOG.info(_("No ip allocation set")) return subnet = retrieve_subnet(context, subnet_id) allocated_ip = neutron_port["fixed_ips"][0]["ip_address"] is_gw_port = ( neutron_port["device_owner"] == constants.DEVICE_OWNER_ROUTER_GW) gateway_ip = subnet["gateway_ip"] ip_allocation_info = h_info.IpAllocationInfo( is_gw=is_gw_port, ip_version=subnet["ip_version"], prefix=subnet["cidr"].split("/")[1], ip_address=allocated_ip, port_id=neutron_port["id"], gateway_ip=gateway_ip) return ip_allocation_info