|
|
|
@ -1457,14 +1457,43 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|
|
|
|
sgids = self._get_security_groups_on_port(context, port_compat) |
|
|
|
|
self._process_port_create_security_group(context, port_dict, sgids) |
|
|
|
|
|
|
|
|
|
def allocate_ips_for_ports(self, context, ports): |
|
|
|
|
for port in ports: |
|
|
|
|
port['port']['id'] = ( |
|
|
|
|
port['port'].get('id') or uuidutils.generate_uuid()) |
|
|
|
|
|
|
|
|
|
# Call IPAM to allocate IP addresses |
|
|
|
|
try: |
|
|
|
|
port['ipams'] = self.ipam.allocate_ips_for_port(context, port) |
|
|
|
|
|
|
|
|
|
port['ip_allocation'] = (ipalloc_apidef. |
|
|
|
|
IP_ALLOCATION_IMMEDIATE) |
|
|
|
|
except ipam_exc.DeferIpam: |
|
|
|
|
port['ip_allocation'] = (ipalloc_apidef. |
|
|
|
|
IP_ALLOCATION_DEFERRED) |
|
|
|
|
return ports |
|
|
|
|
|
|
|
|
|
@utils.transaction_guard |
|
|
|
|
@db_api.retry_if_session_inactive() |
|
|
|
|
def create_port_bulk(self, context, ports): |
|
|
|
|
# TODO(njohnston): Break this up into smaller functions. |
|
|
|
|
port_list = ports.get('ports') |
|
|
|
|
for port in port_list: |
|
|
|
|
self._before_create_port(context, port) |
|
|
|
|
|
|
|
|
|
port_list = self.allocate_ips_for_ports(context, port_list) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
return self._create_port_bulk(context, port_list) |
|
|
|
|
except Exception: |
|
|
|
|
with excutils.save_and_reraise_exception(): |
|
|
|
|
# If any issue happened allocated IP addresses needs to be |
|
|
|
|
# deallocated now |
|
|
|
|
for port in port_list: |
|
|
|
|
self.ipam.deallocate_ips_from_port( |
|
|
|
|
context, port, port['ipams']) |
|
|
|
|
|
|
|
|
|
@db_api.retry_if_session_inactive() |
|
|
|
|
def _create_port_bulk(self, context, port_list): |
|
|
|
|
# TODO(njohnston): Break this up into smaller functions. |
|
|
|
|
port_data = [] |
|
|
|
|
network_cache = dict() |
|
|
|
|
macs = self._generate_macs(len(port_list)) |
|
|
|
@ -1517,31 +1546,25 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|
|
|
|
# Create the Port object |
|
|
|
|
db_port_obj = ports_obj.Port(context, |
|
|
|
|
mac_address=eui_mac_address, |
|
|
|
|
id=uuidutils.generate_uuid(), |
|
|
|
|
id=port['port']['id'], |
|
|
|
|
**bulk_port_data) |
|
|
|
|
db_port_obj.create() |
|
|
|
|
|
|
|
|
|
# Call IPAM to allocate IP addresses |
|
|
|
|
try: |
|
|
|
|
# TODO(njohnston): IPAM allocation needs to be revamped to |
|
|
|
|
# be bulk-friendly. |
|
|
|
|
ips = self.ipam.allocate_ips_for_port_and_store( |
|
|
|
|
context, port, db_port_obj['id']) |
|
|
|
|
ipam_fixed_ips = [] |
|
|
|
|
for ip in ips: |
|
|
|
|
fixed_ip = ports_obj.IPAllocation( |
|
|
|
|
port_id=db_port_obj['id'], |
|
|
|
|
subnet_id=ip['subnet_id'], |
|
|
|
|
network_id=network_id, |
|
|
|
|
ip_address=ip['ip_address']) |
|
|
|
|
ipam_fixed_ips.append(fixed_ip) |
|
|
|
|
|
|
|
|
|
db_port_obj['fixed_ips'] = ipam_fixed_ips |
|
|
|
|
db_port_obj['ip_allocation'] = (ipalloc_apidef. |
|
|
|
|
IP_ALLOCATION_IMMEDIATE) |
|
|
|
|
except ipam_exc.DeferIpam: |
|
|
|
|
db_port_obj['ip_allocation'] = (ipalloc_apidef. |
|
|
|
|
IP_ALLOCATION_DEFERRED) |
|
|
|
|
# Call IPAM to store allocated IP addresses |
|
|
|
|
ipams = port.pop("ipams") |
|
|
|
|
self.ipam.store_ip_allocation_for_port( |
|
|
|
|
context, ipams, network_id, port) |
|
|
|
|
ipam_fixed_ips = [] |
|
|
|
|
for ip in ipams: |
|
|
|
|
fixed_ip = ports_obj.IPAllocation( |
|
|
|
|
port_id=db_port_obj['id'], |
|
|
|
|
subnet_id=ip['subnet_id'], |
|
|
|
|
network_id=network_id, |
|
|
|
|
ip_address=ip['ip_address']) |
|
|
|
|
ipam_fixed_ips.append(fixed_ip) |
|
|
|
|
|
|
|
|
|
db_port_obj['fixed_ips'] = ipam_fixed_ips |
|
|
|
|
db_port_obj['ip_allocation'] = port.pop('ip_allocation') |
|
|
|
|
|
|
|
|
|
fixed_ips = pdata.get('fixed_ips') |
|
|
|
|
if validators.is_attr_set(fixed_ips) and not fixed_ips: |
|
|
|
|