TVD: Make sure lbaas subnet belongs to the correct plugin
When creating a loadbalancer via TVD, we need to verify that the assigned subnet belong to the same plugin as the lasdbalancer Change-Id: Ia4a288177b06e5e795b3b7753d8571b36700f5b3
This commit is contained in:
parent
a6ae3c4b96
commit
4dd13ea065
@ -429,9 +429,12 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return (ports if not fields else
|
||||
[db_utils.resource_fields(port, fields) for port in ports])
|
||||
|
||||
def _get_subnet_plugin_by_id(self, context, subnet_id):
|
||||
db_subnet = self._get_subnet(context, subnet_id)
|
||||
return self._get_plugin_from_net_id(context, db_subnet['network_id'])
|
||||
|
||||
def get_subnet(self, context, id, fields=None):
|
||||
db_subnet = self._get_subnet(context, id)
|
||||
p = self._get_plugin_from_net_id(context, db_subnet['network_id'])
|
||||
p = self._get_subnet_plugin_by_id(context, id)
|
||||
return p.get_subnet(context, id, fields=fields)
|
||||
|
||||
def get_subnets(self, context, filters=None, fields=None, sorts=None,
|
||||
@ -464,8 +467,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return subnets
|
||||
|
||||
def delete_subnet(self, context, id):
|
||||
db_subnet = self._get_subnet(context, id)
|
||||
p = self._get_plugin_from_net_id(context, db_subnet['network_id'])
|
||||
p = self._get_subnet_plugin_by_id(context, id)
|
||||
p.delete_subnet(context, id)
|
||||
|
||||
def _get_subnet_plugin(self, context, subnet_data):
|
||||
@ -492,8 +494,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
return p.create_subnet_bulk(context, subnets)
|
||||
|
||||
def update_subnet(self, context, id, subnet):
|
||||
db_subnet = self._get_subnet(context, id)
|
||||
p = self._get_plugin_from_net_id(context, db_subnet['network_id'])
|
||||
p = self._get_subnet_plugin_by_id(context, id)
|
||||
return p.update_subnet(context, id, subnet)
|
||||
|
||||
def get_router_availability_zones(self, router):
|
||||
|
@ -16,6 +16,8 @@
|
||||
from oslo_log import helpers as log_helpers
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron_lib import exceptions as n_exc
|
||||
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -39,9 +41,17 @@ class EdgeLoadBalancerManager(base_mgr.LoadbalancerBaseManager):
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, lb):
|
||||
p = self.core_plugin._get_plugin_from_project(context,
|
||||
lb.tenant_id)
|
||||
return p.lbv2_driver.loadbalancer.create(context, lb)
|
||||
# verify that the subnet belongs to the same plugin as the lb
|
||||
lb_p = self.core_plugin._get_plugin_from_project(context,
|
||||
lb.tenant_id)
|
||||
subnet_p = self.core_plugin._get_subnet_plugin_by_id(
|
||||
context, lb.vip_subnet_id)
|
||||
if lb_p.plugin_type() != subnet_p.plugin_type():
|
||||
self.lbv2_driver.load_balancer.failed_completion(context, lb)
|
||||
msg = (_('Subnet must belong to the plugin %s, as the '
|
||||
'loadbalancer.') % lb_p.plugin_type())
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
return lb_p.lbv2_driver.loadbalancer.create(context, lb)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_lb, new_lb):
|
||||
|
Loading…
Reference in New Issue
Block a user