示例#1
0
 def test_update_v3_tags_update(self):
     tags = [{
         'scope': 'os-neutron-net-id',
         'tag': 'X' * 40
     }, {
         'scope': 'os-project-id',
         'tag': 'Y' * 40
     }, {
         'scope': 'os-project-name',
         'tag': 'Z' * 40
     }, {
         'scope': 'os-api-version',
         'tag': version.version_info.release_string()
     }]
     resources = [{'resource_type': 'os-project-id', 'tag': 'A' * 40}]
     tags = utils.update_v3_tags(tags, resources)
     expected = [{
         'scope': 'os-neutron-net-id',
         'tag': 'X' * 40
     }, {
         'scope': 'os-project-id',
         'tag': 'A' * 40
     }, {
         'scope': 'os-project-name',
         'tag': 'Z' * 40
     }, {
         'scope': 'os-api-version',
         'tag': version.version_info.release_string()
     }]
     self.assertEqual(sorted(expected), sorted(tags))
示例#2
0
    def update(self, lport_id, vif_uuid,
               name=None, admin_state=None,
               address_bindings=None, switch_profile_ids=None,
               tags_update=None,
               attachment_type=nsx_constants.ATTACHMENT_VIF,
               parent_vif_id=None, parent_tag=None):
        lport = self.get(lport_id)
        tags = lport.get('tags', [])
        if tags_update:
            tags = utils.update_v3_tags(tags, tags_update)
        attachment = self._prepare_attachment(vif_uuid, parent_vif_id,
                                              parent_tag, address_bindings,
                                              attachment_type)
        lport.update(self._build_body_attrs(
            display_name=name,
            admin_state=admin_state, tags=tags,
            address_bindings=address_bindings,
            switch_profile_ids=switch_profile_ids,
            attachment=attachment))

        # If revision_id of the payload that we send is older than what NSX has
        # then we will get a 412: Precondition Failed. In that case we need to
        # re-fetch, patch the response and send it again with the
        # new revision_id
        return self._client.update(lport_id, body=lport)
示例#3
0
    def update(self, lport_id, vif_uuid,
               name=None, admin_state=None,
               address_bindings=None, switch_profile_ids=None,
               resources=None,
               attachment_type=nsx_constants.ATTACHMENT_VIF,
               parent_name=None, parent_tag=None):
        lport = self.get(lport_id)
        tags = lport.get('tags', [])
        if resources:
            tags = utils.update_v3_tags(tags, resources)
        attachment = self._prepare_attachment(vif_uuid, parent_name,
                                              parent_tag, address_bindings,
                                              attachment_type)
        lport.update(self._build_body_attrs(
            display_name=name,
            admin_state=admin_state, tags=tags,
            address_bindings=address_bindings,
            switch_profile_ids=switch_profile_ids,
            attachment=attachment))

        # If revision_id of the payload that we send is older than what NSX has
        # then we will get a 412: Precondition Failed. In that case we need to
        # re-fetch, patch the response and send it again with the
        # new revision_id
        return self._client.update(lport_id, body=lport)
示例#4
0
 def test_update_v3_tags_repetitive_scopes_remove(self):
     tags = [{'scope': 'os-neutron-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-neutron-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')))
示例#5
0
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'])
        lport = port_client.get(lport_id)
        criteria_tags = nsxlib.get_lport_tags_for_security_groups(secgroups)
        lport['tags'] = utils.update_v3_tags(lport.get('tags', []),
                                             criteria_tags)
        port_client._client.update(lport_id, body=lport)
示例#6
0
 def test_update_v3_tags_removal(self):
     tags = [{'scope': 'os-neutron-net-id', 'tag': 'X' * 40},
             {'scope': 'os-project-id', 'tag': 'Y' * 40},
             {'scope': 'os-project-name', 'tag': 'Z' * 40},
             {'scope': 'os-api-version',
              'tag': version.version_info.release_string()}]
     resources = [{'scope': 'os-neutron-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': version.version_info.release_string()}]
     self.assertEqual(sorted(expected, key=lambda x: x.get('tag')),
                      sorted(tags, key=lambda x: x.get('tag')))