Add port_ids, device_ids to IP address uniformally
This commit is contained in:
@@ -35,14 +35,6 @@ attr_dict[RESOURCE_NAME] = {'allow_post': True,
|
||||
LOG = logging.getLogger("quantum.quark.api.extensions.ip_addresses")
|
||||
|
||||
|
||||
def ip_dict(address):
|
||||
return dict(subnet_id=address["subnet_id"],
|
||||
network_id=address["network_id"],
|
||||
id=address["id"],
|
||||
address=address["address"],
|
||||
port_id=address["port_id"])
|
||||
|
||||
|
||||
class IpAddressesController(wsgi.Controller):
|
||||
|
||||
def __init__(self, plugin):
|
||||
|
@@ -1001,22 +1001,30 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2,
|
||||
|
||||
port = None
|
||||
ip_dict = ip_address["ip_address"]
|
||||
port_id = ip_dict.get('port_id')
|
||||
port_ids = ip_dict.get('port_ids')
|
||||
network_id = ip_dict.get('network_id')
|
||||
device_id = ip_dict.get('device_id')
|
||||
device_ids = ip_dict.get('device_ids')
|
||||
ip_version = ip_dict.get('version')
|
||||
ip_address = ip_dict.get('ip_address')
|
||||
|
||||
if network_id and device_id:
|
||||
port = db_api.port_find(
|
||||
context, network_id=network_id, device_id=device_id,
|
||||
tenant_id=context.tenant_id, scope=db_api.ONE)
|
||||
elif port_id:
|
||||
port = db_api.port_find(context, id=port_id, scope=db_api.ONE)
|
||||
ports = []
|
||||
if network_id and device_ids:
|
||||
for device_id in device_ids:
|
||||
port = db_api.port_find(
|
||||
context, network_id=network_id, device_id=device_id,
|
||||
tenant_id=context.tenant_id, scope=db_api.ONE)
|
||||
ports.append(port)
|
||||
elif port_ids:
|
||||
for port_id in port_ids:
|
||||
port = db_api.port_find(context, id=port_id,
|
||||
tenant_id=context.tenant_id,
|
||||
scope=db_api.ONE)
|
||||
ports.append(port)
|
||||
|
||||
if not port:
|
||||
raise exceptions.PortNotFound(port_id=port_id,
|
||||
if not ports:
|
||||
raise exceptions.PortNotFound(port_id=port_ids,
|
||||
net_id=network_id)
|
||||
|
||||
address = self.ipam_driver.allocate_ip_address(
|
||||
context,
|
||||
port['network_id'],
|
||||
@@ -1024,7 +1032,10 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2,
|
||||
self.ipam_reuse_after,
|
||||
ip_version,
|
||||
ip_address)
|
||||
port["ip_addresses"].append(address)
|
||||
|
||||
for port in ports:
|
||||
port["ip_addresses"].append(address)
|
||||
|
||||
return self._make_ip_dict(address)
|
||||
|
||||
def update_ip_address(self, context, id, ip_address):
|
||||
|
@@ -867,7 +867,7 @@ class TestIpAddresses(TestQuarkPlugin):
|
||||
tenant_id=self.context.tenant_id)
|
||||
with self._stubs(port=port, addr=ip):
|
||||
ip_address = dict(network_id=ip["network_id"],
|
||||
device_id=4)
|
||||
device_ids=[4])
|
||||
response = self.plugin.create_ip_address(
|
||||
self.context, dict(ip_address=ip_address))
|
||||
|
||||
@@ -882,7 +882,7 @@ class TestIpAddresses(TestQuarkPlugin):
|
||||
ip = dict(id=1, address=3232235876, address_readable="192.168.1.100",
|
||||
subnet_id=1, network_id=2, version=4)
|
||||
with self._stubs(port=port, addr=ip):
|
||||
ip_address = dict(port_id=port["id"])
|
||||
ip_address = dict(port_ids=[port["id"]])
|
||||
response = self.plugin.create_ip_address(
|
||||
self.context, dict(ip_address=ip_address))
|
||||
|
||||
|
Reference in New Issue
Block a user