def update(self, context, old_lb, new_lb, completor): vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server app_client = self.core_plugin.nsxlib.load_balancer.application_profile if new_lb['name'] != old_lb['name']: for listener in new_lb['listeners']: binding = nsx_db.get_nsx_lbaas_listener_binding( context.session, new_lb['id'], listener['id']) if binding: vs_id = binding['lb_vs_id'] app_profile_id = binding['app_profile_id'] new_lb_name = new_lb['name'][:utils.MAX_TAG_LEN] try: # Update tag on virtual server with new lb name vs = vs_client.get(vs_id) updated_tags = utils.update_v3_tags( vs['tags'], [{'scope': lb_const.LB_LB_NAME, 'tag': new_lb_name}]) vs_client.update(vs_id, tags=updated_tags) # Update tag on application profile with new lb name app_profile = app_client.get(app_profile_id) app_client.update( app_profile_id, tags=updated_tags, resource_type=app_profile['resource_type']) except nsxlib_exc.ManagerError: with excutils.save_and_reraise_exception(): completor(success=False) LOG.error('Failed to update tag %(tag)s for lb ' '%(lb)s', {'tag': updated_tags, 'lb': new_lb['name']}) completor(success=True)
def test_update_v3_tags_repetitive_scopes_remove(self): tags = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-security-group', 'tag': 'SG1'}, {'scope': 'os-security-group', 'tag': 'SG2'}] tags_update = [{'scope': 'os-security-group', 'tag': None}] tags = utils.update_v3_tags(tags, tags_update) expected = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}] self.assertEqual(sorted(expected, key=lambda x: x.get('tag')), sorted(tags, key=lambda x: x.get('tag')))
def test_update_v3_tags_repetitive_scopes_remove(self): tags = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-security-group', 'tag': 'SG1'}, {'scope': 'os-security-group', 'tag': 'SG2'}] tags_update = [{'scope': 'os-security-group', 'tag': None}] tags = utils.update_v3_tags(tags, tags_update) expected = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}] self.assertEqual(sorted(expected, key=lambda x: x.get('tag')), sorted(tags, key=lambda x: x.get('tag')))
def test_update_v3_tags_removal(self): tags = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-api-version', 'tag': nsxlib_testcase.PLUGIN_VER}] resources = [{'scope': 'os-net-id', 'tag': ''}] tags = utils.update_v3_tags(tags, resources) expected = [{'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-api-version', 'tag': nsxlib_testcase.PLUGIN_VER}] self.assertEqual(sorted(expected, key=lambda x: x.get('tag')), sorted(tags, key=lambda x: x.get('tag')))
def test_update_v3_tags_removal(self): tags = [{'scope': 'os-net-id', 'tag': 'X' * 40}, {'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-api-version', 'tag': nsxlib_testcase.PLUGIN_VER}] resources = [{'scope': 'os-net-id', 'tag': ''}] tags = utils.update_v3_tags(tags, resources) expected = [{'scope': 'os-project-id', 'tag': 'Y' * 40}, {'scope': 'os-project-name', 'tag': 'Z' * 40}, {'scope': 'os-api-version', 'tag': nsxlib_testcase.PLUGIN_VER}] self.assertEqual(sorted(expected, key=lambda x: x.get('tag')), sorted(tags, key=lambda x: x.get('tag')))
def _update_ports_dynamic_criteria_tags(): port_client, _ = ports.get_port_and_profile_clients() for port in neutron_db.get_ports(): secgroups = neutron_sg.get_port_security_groups(port['id']) # Nothing to do with ports that are not associated with any sec-group. if not secgroups: continue _, lport_id = neutron_db.get_lswitch_and_lport_id(port['id']) try: lport = port_client.get(lport_id) except exc.ResourceNotFound: LOG.warning( _LW("Failed to update logical-port %s, resource " "doesn't exists on backend."), lport_id) continue criteria_tags = nsxlib.ns_group.get_lport_tags(secgroups) lport['tags'] = nsxlib_utils.update_v3_tags(lport.get('tags', []), criteria_tags) port_client._client.update(lport_id, body=lport)
def update(self, context, old_lb, new_lb): vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server app_client = self.core_plugin.nsxlib.load_balancer.application_profile if new_lb.name != old_lb.name: for listener in new_lb.listeners: binding = nsx_db.get_nsx_lbaas_listener_binding( context.session, new_lb.id, listener.id) if binding: vs_id = binding['lb_vs_id'] app_profile_id = binding['app_profile_id'] new_lb_name = new_lb.name[:utils.MAX_TAG_LEN] try: # Update tag on virtual server with new lb name vs = vs_client.get(vs_id) updated_tags = utils.update_v3_tags( vs['tags'], [{ 'scope': lb_const.LB_LB_NAME, 'tag': new_lb_name }]) vs_client.update(vs_id, tags=updated_tags) # Update tag on application profile with new lb name app_profile = app_client.get(app_profile_id) app_client.update( app_profile_id, tags=updated_tags, resource_type=app_profile['resource_type']) except nsxlib_exc.ManagerError: with excutils.save_and_reraise_exception(): self.lbv2_driver.pool.failed_completion( context, new_lb) LOG.error( 'Failed to update tag %(tag)s for lb ' '%(lb)s', { 'tag': updated_tags, 'lb': new_lb.name }) self.lbv2_driver.load_balancer.successful_completion(context, new_lb)