TVD: Make sure subnets project is the same as the network

before creating a subnet, we should validate that the current tenant
project plugin is the same as the plugin the network was created with.

Change-Id: I3dcb4dca89313ec4359f2b467de5635ec2479cec
This commit is contained in:
Adit Sarfaty 2018-02-09 15:57:29 +02:00
parent 6030d61b1d
commit fd7c93b2dd

View File

@ -464,16 +464,27 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
p = self._get_plugin_from_net_id(context, db_subnet['network_id'])
p.delete_subnet(context, id)
def _get_subnet_plugin(self, context, subnet_data):
# get the plugin of the associated network
net_id = subnet_data['network_id']
net_plugin = self._get_plugin_from_net_id(context, net_id)
# make sure it matches the plugin of the current tenant
tenant_id = subnet_data['tenant_id']
tenant_plugin = self._get_plugin_from_project(context, tenant_id)
if tenant_plugin.plugin_type() != net_plugin.plugin_type():
err_msg = (_('Subnet should belong to the %s plugin '
'as the network') % net_plugin.plugin_type())
raise n_exc.InvalidInput(error_message=err_msg)
return net_plugin
def create_subnet(self, context, subnet):
id = subnet['subnet']['network_id']
p = self._get_plugin_from_net_id(context, id)
p = self._get_subnet_plugin(context, subnet['subnet'])
return p.create_subnet(context, subnet)
def create_subnet_bulk(self, context, subnets):
# look at the first subnet to find out the project & plugin
items = subnets['subnets']
id = items[0]['subnet']['network_id']
p = self._get_plugin_from_net_id(context, id)
p = self._get_subnet_plugin(context, items[0]['subnet'])
return p.create_subnet_bulk(context, subnets)
def update_subnet(self, context, id, subnet):