def delete_member(self, context, member, pool_mapping): LOG.debug('Deleting member %s', member) if pool_mapping: with locking.LockManager.get_lock(pool_mapping['edge_id']): edge_pool = self.vcns.get_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'])[1] for i, m in enumerate(edge_pool['member']): if m['name'] == lb_common.get_member_id(member['id']): edge_pool['member'].pop(i) break try: self.vcns.update_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'], edge_pool) member_ips = self._get_pool_member_ips( context, member['pool_id'], 'del', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], pool_mapping['edge_id'], self._get_lbaas_fw_section_id(), member_ips) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.member_failed(context, member) LOG.error(_LE('Failed to update member on edge: %s'), pool_mapping['edge_id']) lb_plugin = self._get_lb_plugin() lb_plugin._delete_db_member(context, member['id'])
def delete(self, context, pool, completor): lb_id = pool['loadbalancer_id'] lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, pool['id']) edge_id = lb_binding['edge_id'] if not pool_binding: completor(success=True) return edge_pool_id = pool_binding['edge_pool_id'] listeners_to_update = [] try: if pool['listeners']: for listener in pool['listeners']: # the pool session persistence may affect the associated # pool application profile if (pool['session_persistence'] and listener['default_pool'] and listener['default_pool']['id'] == pool['id']): listeners_to_update.append(listener) listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding( context.session, lb_id, listener['id']) vse = listener_mgr.listener_to_edge_vse( context, listener, lb_binding['vip_address'], None, listener_binding['app_profile_id']) with locking.LockManager.get_lock(edge_id): self.vcns.update_vip( edge_id, listener_binding['vse_id'], vse) self.vcns.delete_pool(edge_id, edge_pool_id) completor(success=True) nsxv_db.del_nsxv_lbaas_pool_binding( context.session, lb_id, pool['id']) for listener in listeners_to_update: # need to update the listeners too, now with no default pool listener['default_pool'] = None listener_mgr.update_app_profile( self.vcns, context, listener, edge_id) old_lb = lb_common.is_lb_on_router_edge( context, self.core_plugin, lb_binding['edge_id']) if old_lb: lb_common.update_pool_fw_rule(self.vcns, pool['id'], edge_id, self._get_lbaas_fw_section_id(), []) except nsxv_exc.VcnsApiException: completor(success=False) LOG.error('Failed to delete pool %s', pool['id'])
def delete(self, context, pool, completor): lb_id = pool['loadbalancer_id'] lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, pool['id']) edge_id = lb_binding['edge_id'] if not pool_binding: completor(success=True) return edge_pool_id = pool_binding['edge_pool_id'] listeners_to_update = [] try: if pool['listeners']: for listener in pool['listeners']: # the pool session persistence may affect the associated # pool application profile if (pool['session_persistence'] and listener['default_pool'] and listener['default_pool']['id'] == pool['id']): listeners_to_update.append(listener) listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding( context.session, lb_id, listener['id']) vse = listener_mgr.listener_to_edge_vse( context, listener, lb_binding['vip_address'], None, listener_binding['app_profile_id']) with locking.LockManager.get_lock(edge_id): self.vcns.update_vip( edge_id, listener_binding['vse_id'], vse) self.vcns.delete_pool(edge_id, edge_pool_id) completor(success=True) nsxv_db.del_nsxv_lbaas_pool_binding( context.session, lb_id, pool['id']) for listener in listeners_to_update: # need to update the listeners too, now with no default pool listener['default_pool'] = None listener_mgr.update_app_profile( self.vcns, context, listener, edge_id) old_lb = lb_common.is_lb_on_router_edge( context, self.core_plugin, lb_binding['edge_id']) if old_lb: lb_common.update_pool_fw_rule(self.vcns, pool['id'], edge_id, self._get_lbaas_fw_section_id(), []) except nsxv_exc.VcnsApiException: completor(success=False) LOG.error('Failed to delete pool %s', pool['id'])
def create_member(self, context, member, pool_mapping): LOG.debug('Creating member %s', member) with locking.LockManager.get_lock(pool_mapping['edge_id']): edge_pool = self.vcns.get_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'])[1] edge_member = convert_lbaas_member(member) if edge_pool['member']: edge_pool['member'].append(edge_member) else: edge_pool['member'] = [edge_member] try: self.vcns.update_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'], edge_pool) member_ips = self._get_pool_member_ips(context, member['pool_id'], 'add', member['address']) lb_common.update_pool_fw_rule(self.vcns, member['pool_id'], pool_mapping['edge_id'], self._get_lbaas_fw_section_id(), member_ips) self.lbv1_driver.member_successful(context, member) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.member_failed(context, member) LOG.error(_LE('Failed to create member on edge: %s'), pool_mapping['edge_id'])
def delete_member(self, context, member, pool_mapping): LOG.debug('Deleting member %s', member) if pool_mapping: with locking.LockManager.get_lock(pool_mapping['edge_id']): edge_pool = self.vcns.get_pool( pool_mapping['edge_id'], pool_mapping['edge_pool_id'])[1] for i, m in enumerate(edge_pool['member']): if m['name'] == lb_common.get_member_id(member['id']): edge_pool['member'].pop(i) break try: self.vcns.update_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'], edge_pool) member_ips = self._get_pool_member_ips( context, member['pool_id'], 'del', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], pool_mapping['edge_id'], self._get_lbaas_fw_section_id(), member_ips) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.member_failed(context, member) LOG.error(_LE('Failed to update member on edge: %s'), pool_mapping['edge_id']) lb_plugin = self._get_lb_plugin() lb_plugin._delete_db_member(context, member['id'])
def create_member(self, context, member, pool_mapping): LOG.debug('Creating member %s', member) with locking.LockManager.get_lock(pool_mapping['edge_id']): edge_pool = self.vcns.get_pool(pool_mapping['edge_id'], pool_mapping['edge_pool_id'])[1] edge_member = convert_lbaas_member(member) if edge_pool['member']: edge_pool['member'].append(edge_member) else: edge_pool['member'] = [edge_member] try: self.vcns.update_pool( pool_mapping['edge_id'], pool_mapping['edge_pool_id'], edge_pool) member_ips = self._get_pool_member_ips( context, member['pool_id'], 'add', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], pool_mapping['edge_id'], self._get_lbaas_fw_section_id(), member_ips) self.lbv1_driver.member_successful(context, member) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv1_driver.member_failed(context, member) LOG.error(_LE('Failed to create member on edge: %s'), pool_mapping['edge_id'])
def delete(self, context, member, completor): lb_id = self._get_pool_lb_id(member) lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, member['pool_id']) edge_id = lb_binding['edge_id'] old_lb = lb_common.is_lb_on_router_edge( context, self.core_plugin, edge_id) with locking.LockManager.get_lock(edge_id): if not cfg.CONF.nsxv.use_routers_as_lbaas_platform: # we should remove LB subnet interface if no members are # attached and this is not the LB's VIP interface remove_interface = True pool = member['pool'] subnet_id = member['subnet_id'] if subnet_id == pool['loadbalancer']['vip_subnet_id']: remove_interface = False else: for m in pool['members']: if (m['subnet_id'] == subnet_id and m['id'] != member['id']): remove_interface = False if remove_interface: lb_common.delete_lb_interface(context, self.core_plugin, lb_id, subnet_id) if not pool_binding: completor(success=True) return edge_pool_id = pool_binding['edge_pool_id'] edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1] for i, m in enumerate(edge_pool['member']): if m['name'] == lb_common.get_member_id(member['id']): edge_pool['member'].pop(i) break try: self.vcns.update_pool(edge_id, edge_pool_id, edge_pool) if old_lb: member_ips = self._get_pool_member_ips(member['pool'], 'del', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], edge_id, self._get_lbaas_fw_section_id(), member_ips) completor(success=True) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to delete member on edge: %s', edge_id)
def create(self, context, member, completor): lb_id = self._get_pool_lb_id(member) lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) edge_id = lb_binding['edge_id'] pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, member['pool_id']) if not pool_binding: completor(success=False) msg = _('Failed to create member on edge: %s. ' 'Binding not found') % edge_id LOG.error(msg) raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) edge_pool_id = pool_binding['edge_pool_id'] old_lb = lb_common.is_lb_on_router_edge(context, self.core_plugin, edge_id) with locking.LockManager.get_lock(edge_id): if not cfg.CONF.nsxv.use_routers_as_lbaas_platform and not old_lb: # Verify that Edge appliance is connected to the member's # subnet (only if this is a dedicated loadbalancer edge) if not lb_common.get_lb_interface(context, self.core_plugin, lb_id, member['subnet_id']): lb_common.create_lb_interface(context, self.core_plugin, lb_id, member['subnet_id'], member['tenant_id']) edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1] edge_member = { 'ipAddress': member['address'], 'weight': member['weight'], 'port': member['protocol_port'], 'monitorPort': member['protocol_port'], 'name': lb_common.get_member_id(member['id']), 'condition': 'enabled' if member['admin_state_up'] else 'disabled' } if edge_pool.get('member'): edge_pool['member'].append(edge_member) else: edge_pool['member'] = [edge_member] try: self.vcns.update_pool(edge_id, edge_pool_id, edge_pool) completor(success=True) if old_lb: member_ips = self._get_pool_member_ips( member['pool'], 'add', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], edge_id, self._get_lbaas_fw_section_id(), member_ips) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to create member on edge: %s', edge_id)
def delete(self, context, member, completor): lb_id = self._get_pool_lb_id(member) lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, member['pool_id']) edge_id = lb_binding['edge_id'] old_lb = lb_common.is_lb_on_router_edge(context, self.core_plugin, edge_id) with locking.LockManager.get_lock(edge_id): if not cfg.CONF.nsxv.use_routers_as_lbaas_platform: # we should remove LB subnet interface if no members are # attached and this is not the LB's VIP interface remove_interface = True pool = member['pool'] subnet_id = member['subnet_id'] if subnet_id == pool['loadbalancer']['vip_subnet_id']: remove_interface = False else: for m in pool['members']: if (m['subnet_id'] == subnet_id and m['id'] != member['id']): remove_interface = False if remove_interface: lb_common.delete_lb_interface(context, self.core_plugin, lb_id, subnet_id) if not pool_binding: completor(success=True) return edge_pool_id = pool_binding['edge_pool_id'] edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1] for i, m in enumerate(edge_pool['member']): if m['name'] == lb_common.get_member_id(member['id']): edge_pool['member'].pop(i) break try: self.vcns.update_pool(edge_id, edge_pool_id, edge_pool) if old_lb: member_ips = self._get_pool_member_ips( member['pool'], 'del', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], edge_id, self._get_lbaas_fw_section_id(), member_ips) completor(success=True) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to delete member on edge: %s', edge_id)
def create(self, context, member): listener = member.pool.listener lb_id = listener.loadbalancer_id lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, listener.id, member.pool_id) edge_id = lb_binding['edge_id'] edge_pool_id = pool_binding['edge_pool_id'] with locking.LockManager.get_lock(edge_id): edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1] edge_member = { 'ipAddress': member.address, 'weight': member.weight, 'port': member.protocol_port, 'monitorPort': member.protocol_port, 'name': lb_common.get_member_id(member.id), 'condition': 'enabled' if member.admin_state_up else 'disabled'} if edge_pool.get('member'): edge_pool['member'].append(edge_member) else: edge_pool['member'] = [edge_member] try: self.vcns.update_pool(edge_id, edge_pool_id, edge_pool) member_ips = self._get_pool_member_ips(member.pool, 'add', member.address) lb_common.update_pool_fw_rule(self.vcns, member.pool_id, edge_id, self._get_lbaas_fw_section_id(), member_ips) self.lbv2_driver.member.successful_completion(context, member) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): self.lbv2_driver.member.failed_completion(context, member) LOG.error(_LE('Failed to create member on edge: %s'), edge_id)
def test_update_pool_fw_rule_del(self): vip_ips = ['10.0.0.1', '11.0.0.1'] member_ips = ['10.0.0.10'] edge_fw_section = firewall_section_maker(vip_ips, ['10.0.0.10', '11.0.0.10']) edge_fw_updated_section = firewall_section_maker(vip_ips, member_ips) with self._mock_edge_driver_vcns('get_section') as mock_get_section, \ self._mock_edge_driver_vcns( 'update_section') as mock_update_section: tmp_get_ips = lb_common.get_edge_ip_addresses lb_common.get_edge_ip_addresses = mock.Mock() lb_common.get_edge_ip_addresses.return_value = vip_ips mock_get_section.return_value = (None, edge_fw_section) lb_common.update_pool_fw_rule( self.edge_driver.vcns, POOL_ID, EDGE_ID, '1111', member_ips) mock_update_section.assert_called_with( '/api/4.0/firewall/globalroot-0/config/layer3sections/1111', edge_fw_updated_section, None) lb_common.get_edge_ip_addresses = tmp_get_ips
def create(self, context, member, completor): lb_id = self._get_pool_lb_id(member) lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) edge_id = lb_binding['edge_id'] pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, member['pool_id']) if not pool_binding: completor(success=False) msg = _('Failed to create member on edge: %s. ' 'Binding not found') % edge_id LOG.error(msg) raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) edge_pool_id = pool_binding['edge_pool_id'] old_lb = lb_common.is_lb_on_router_edge( context, self.core_plugin, edge_id) with locking.LockManager.get_lock(edge_id): if not cfg.CONF.nsxv.use_routers_as_lbaas_platform and not old_lb: # Verify that Edge appliance is connected to the member's # subnet (only if this is a dedicated loadbalancer edge) if not lb_common.get_lb_interface( context, self.core_plugin, lb_id, member['subnet_id']): lb_common.create_lb_interface( context, self.core_plugin, lb_id, member['subnet_id'], member['tenant_id']) edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1] edge_member = { 'ipAddress': member['address'], 'weight': member['weight'], 'port': member['protocol_port'], 'monitorPort': member['protocol_port'], 'name': lb_common.get_member_id(member['id']), 'condition': 'enabled' if member['admin_state_up'] else 'disabled'} if edge_pool.get('member'): edge_pool['member'].append(edge_member) else: edge_pool['member'] = [edge_member] try: self.vcns.update_pool(edge_id, edge_pool_id, edge_pool) completor(success=True) if old_lb: member_ips = self._get_pool_member_ips(member['pool'], 'add', member['address']) lb_common.update_pool_fw_rule( self.vcns, member['pool_id'], edge_id, self._get_lbaas_fw_section_id(), member_ips) except nsxv_exc.VcnsApiException: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to create member on edge: %s', edge_id)