From e9ac7331f596865228a743dd4ed70da24afb3fc1 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 7 Dec 2016 04:09:48 -0800 Subject: [PATCH] NSX|V: improve support of bulk subnets This addresses a number of issues: 1. The base code would have a open transaction for the bulk creation. This would cause problems with the resources created for the edges. 2. In the event of one of the subnet created fails then the resources created would not be cleaned up. Change-Id: I3741257a9861e8e27a56772893e624d4c60e2292 --- vmware_nsx/plugins/nsx_v/plugin.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 7841f2a2cd..555b22a205 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -1921,6 +1921,28 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, "6.2.3 or higher") raise n_exc.InvalidInput(error_message=err_msg) + def create_subnet_bulk(self, context, subnets): + + collection = "subnets" + items = subnets[collection] + new_subnets = [] + for item in items: + try: + s = self.create_subnet(context, item) + new_subnets.append(s) + except Exception as e: + LOG.error(_LE('Unable to create bulk subnets. Failed to ' + 'create item %(item)s. Rolling back. ' + 'Error: %(e)s'), {'item': item, 'e': e}) + for subnet in new_subnets: + s_id = subnet['id'] + try: + self.delete_subnet(context, s_id) + except Exception: + LOG.error(_LE('Unable to delete subnet %s'), s_id) + raise + return new_subnets + def create_subnet(self, context, subnet): """Create subnet on nsx_v provider network.