當前位置: 首頁>>代碼示例>>Python>>正文


Python VirtualMachineInterface.get_tag_refs方法代碼示例

本文整理匯總了Python中vnc_api.vnc_api.VirtualMachineInterface.get_tag_refs方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualMachineInterface.get_tag_refs方法的具體用法?Python VirtualMachineInterface.get_tag_refs怎麽用?Python VirtualMachineInterface.get_tag_refs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vnc_api.vnc_api.VirtualMachineInterface的用法示例。


在下文中一共展示了VirtualMachineInterface.get_tag_refs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_multiple_firewall_group_port_association

# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import get_tag_refs [as 別名]
    def test_multiple_firewall_group_port_association(self):
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
        self._vnc_lib.virtual_network_create(vn)
        vmi = VirtualMachineInterface('%s-vmi' % self.id(),
                                      parent_obj=self.project)
        vmi.add_virtual_network(vn)
        vmi_id = self._vnc_lib.virtual_machine_interface_create(vmi)

        neutron_fg1 = self.create_resource(
            'firewall_group',
            self.project_id,
            extra_res_fields={
                'name': '%s-fg1' % self.id(),
                'ports': [vmi_id],
            },
        )
        neutron_fg2 = self.create_resource(
            'firewall_group',
            self.project_id,
            extra_res_fields={
                'name': '%s-fg2' % self.id(),
            },
        )
        tag1_fq_name = self._get_tag_fq_name(neutron_fg1, self.project)
        tag2_fq_name = self._get_tag_fq_name(neutron_fg2, self.project)
        self.assertEquals(set(neutron_fg1['ports']), set([vmi_id]))
        vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
        tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
        self.assertEquals(len(tag_refs), 1)
        self.assertEquals(tag1_fq_name, tag_refs[0])

        neutron_fg2 = self.update_resource(
            'firewall_group',
            neutron_fg2['id'],
            self.project_id,
            extra_res_fields={
                'ports': [vmi_id],
            },
        )
        neutron_fg1 = self.read_resource('firewall_group', neutron_fg1['id'])
        self.assertEquals(set(neutron_fg1['ports']), set([vmi_id]))
        self.assertEquals(set(neutron_fg2['ports']), set([vmi_id]))
        vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
        tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
        self.assertEquals(len(tag_refs), 2)
        self.assertIn(tag1_fq_name, tag_refs)
        self.assertIn(tag2_fq_name, tag_refs)

        neutron_fg1 = self.update_resource(
            'firewall_group',
            neutron_fg1['id'],
            self.project_id,
            extra_res_fields={
                'ports': [],
            },
        )
        neutron_fg2 = self.read_resource('firewall_group', neutron_fg2['id'])
        self.assertFalse(neutron_fg1['ports'])
        self.assertEquals(set(neutron_fg2['ports']), set([vmi_id]))
        vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
        tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
        self.assertEquals(len(tag_refs), 1)
        self.assertEquals(tag2_fq_name, tag_refs[0])
開發者ID:rombie,項目名稱:contrail-controller,代碼行數:65,代碼來源:test_firewall.py


注:本文中的vnc_api.vnc_api.VirtualMachineInterface.get_tag_refs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。