def create(self, context, lb): edge_id = lb_common.get_lbaas_edge_id_for_subnet( context, self.core_plugin, lb.vip_subnet_id, lb.tenant_id) if not edge_id: msg = _( 'No suitable Edge found for subnet %s') % lb.vip_subnet_id raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) try: if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge( context.session, edge_id): lb_common.enable_edge_acceleration(self.vcns, edge_id) lb_common.add_vip_as_secondary_ip(self.vcns, edge_id, lb.vip_address) edge_fw_rule_id = lb_common.add_vip_fw_rule( self.vcns, edge_id, lb.id, lb.vip_address) nsxv_db.add_nsxv_lbaas_loadbalancer_binding( context.session, lb.id, edge_id, edge_fw_rule_id, lb.vip_address) self.lbv2_driver.load_balancer.successful_completion(context, lb) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv2_driver.load_balancer.failed_completion(context, lb) LOG.error(_LE('Failed to create pool %s'), lb.id)
def create(self, context, lb): edge_id = lb_common.get_lbaas_edge_id_for_subnet( context, self.core_plugin, lb.vip_subnet_id, lb.tenant_id) if not edge_id: msg = _( 'No suitable Edge found for subnet %s') % lb.vip_subnet_id raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) try: if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge( context.session, edge_id): lb_common.enable_edge_acceleration(self.vcns, edge_id) lb_common.add_vip_as_secondary_ip(self.vcns, edge_id, lb.vip_address) edge_fw_rule_id = lb_common.add_vip_fw_rule( self.vcns, edge_id, lb.id, lb.vip_address) nsxv_db.add_nsxv_lbaas_loadbalancer_binding( context.session, lb.id, edge_id, edge_fw_rule_id, lb.vip_address) self.lbv2_driver.load_balancer.successful_completion(context, lb) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv2_driver.load_balancer.failed_completion(context, lb) LOG.error(_LE('Failed to create pool %s'), lb.id)
def test_add_vip_as_secondary_ip(self): update_if = if_maker(['10.0.0.6', '10.0.0.8']) with self._mock_edge_driver_vcns('get_interfaces') as mock_get_if,\ self._mock_edge_driver_vcns( 'update_interface') as mock_update_if: mock_get_if.return_value = (None, if_list_maker(['10.0.0.6'])) lb_common.add_vip_as_secondary_ip( self.edge_driver.vcns, EDGE_ID, '10.0.0.8') mock_update_if.assert_called_with(EDGE_ID, update_if)
def create(self, context, lb, completor): sub_id = lb['vip_subnet_id'] if cfg.CONF.nsxv.use_routers_as_lbaas_platform: edge_id = lb_common.get_lbaas_edge_id_for_subnet( context, self.core_plugin, sub_id, lb['tenant_id']) if not edge_id: msg = _('No suitable Edge found for subnet %s') % sub_id raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) else: lb_size = self._get_lb_flavor_size(context, lb.get('flavor_id')) edge_id = lb_common.get_lbaas_edge_id(context, self.core_plugin, lb['id'], lb['vip_address'], sub_id, lb['tenant_id'], lb_size) if not edge_id: msg = _('Failed to allocate Edge on subnet %(sub)s for ' 'loadbalancer %(lb)s') % { 'sub': sub_id, 'lb': lb['id'] } raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) try: if cfg.CONF.nsxv.use_routers_as_lbaas_platform: if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge( context.session, edge_id): lb_common.enable_edge_acceleration(self.vcns, edge_id) lb_common.add_vip_as_secondary_ip(self.vcns, edge_id, lb['vip_address']) else: lb_common.enable_edge_acceleration(self.vcns, edge_id) edge_fw_rule_id = lb_common.add_vip_fw_rule( self.vcns, edge_id, lb['id'], lb['vip_address']) # set LB default rule if not cfg.CONF.nsxv.use_routers_as_lbaas_platform: lb_common.set_lb_firewall_default_rule(self.vcns, edge_id, 'accept') nsxv_db.add_nsxv_lbaas_loadbalancer_binding( context.session, lb['id'], edge_id, edge_fw_rule_id, lb['vip_address']) completor(success=True) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to create loadbalancer %s', lb['id'])
def create_vip(self, context, vip, pool_mapping): LOG.debug('Create VIP %s', vip) app_profile = convert_lbaas_app_profile( vip['id'], vip.get('session_persistence', {}), vip.get('protocol')) if not pool_mapping: msg = _('Pool %s in not mapped to any Edge appliance') % ( vip['pool_id']) raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) edge_id = pool_mapping['edge_id'] try: with locking.LockManager.get_lock(edge_id): h = (self.vcns.create_app_profile(edge_id, app_profile))[0] app_profile_id = lb_common.extract_resource_id(h['location']) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.vip_failed(context, vip) LOG.error(_LE('Failed to create app profile on edge: %s'), edge_id) edge_vip = convert_lbaas_vip(vip, app_profile_id, pool_mapping) try: lb_common.add_vip_as_secondary_ip(self.vcns, edge_id, vip['address']) with locking.LockManager.get_lock(edge_id): h = self.vcns.create_vip(edge_id, edge_vip)[0] edge_vip_id = lb_common.extract_resource_id(h['location']) edge_fw_rule_id = lb_common.add_vip_fw_rule(self.vcns, edge_id, vip['id'], vip['address']) self.lbv1_driver.create_vip_successful( context, vip, edge_id, app_profile_id, edge_vip_id, edge_fw_rule_id) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.vip_failed(context, vip) LOG.error(_LE('Failed to create vip on Edge: %s'), edge_id) with locking.LockManager.get_lock(edge_id): self.vcns.delete_app_profile(edge_id, app_profile_id)
def create_vip(self, context, vip, pool_mapping): LOG.debug('Create VIP %s', vip) app_profile = convert_lbaas_app_profile( vip['id'], vip.get('session_persistence', {}), vip.get('protocol')) if not pool_mapping: msg = _('Pool %s in not mapped to any Edge appliance') % ( vip['pool_id']) raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) edge_id = pool_mapping['edge_id'] try: with locking.LockManager.get_lock(edge_id): h = (self.vcns.create_app_profile(edge_id, app_profile))[0] app_profile_id = lb_common.extract_resource_id(h['location']) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.vip_failed(context, vip) LOG.error(_LE('Failed to create app profile on edge: %s'), edge_id) edge_vip = convert_lbaas_vip(vip, app_profile_id, pool_mapping) try: lb_common.add_vip_as_secondary_ip(self.vcns, edge_id, vip['address']) with locking.LockManager.get_lock(edge_id): h = self.vcns.create_vip(edge_id, edge_vip)[0] edge_vip_id = lb_common.extract_resource_id(h['location']) edge_fw_rule_id = lb_common.add_vip_fw_rule( self.vcns, edge_id, vip['id'], vip['address']) self.lbv1_driver.create_vip_successful(context, vip, edge_id, app_profile_id, edge_vip_id, edge_fw_rule_id) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.vip_failed(context, vip) LOG.error(_LE('Failed to create vip on Edge: %s'), edge_id) with locking.LockManager.get_lock(edge_id): self.vcns.delete_app_profile(edge_id, app_profile_id)