• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vnc_api.VirtualMachineInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vnc_api.vnc_api.VirtualMachineInterface的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachineInterface类的具体用法?Python VirtualMachineInterface怎么用?Python VirtualMachineInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VirtualMachineInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_virtual_port_group_delete

    def test_virtual_port_group_delete(self):
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj)
        self.api.virtual_network_create(vn)

        vpg_name = "vpg-" + self.id()
        vpg_obj = VirtualPortGroup(vpg_name)
        self.api.virtual_port_group_create(vpg_obj)

        vmi_id_list = []
        for i in range(self.VMI_NUM):
            vmi_obj = VirtualMachineInterface(self.id() + str(i),
                                              parent_obj=proj_obj)
            vmi_obj.set_virtual_network(vn)
            vmi_id_list.append(
                self.api.virtual_machine_interface_create(vmi_obj))
            vpg_obj.add_virtual_machine_interface(vmi_obj)
            self.api.virtual_port_group_update(vpg_obj)
            self.api.ref_relax_for_delete(vpg_obj.uuid, vmi_id_list[i])

        # Make sure when VPG doesn't get deleted, since associated VMIs
        # still refers it.
        with ExpectedException(BadRequest):
            self.api.virtual_port_group_delete(id=vpg_obj.uuid)

        # Cleanup
        for i in range(self.VMI_NUM):
            self.api.virtual_machine_interface_delete(id=vmi_id_list[i])

        self.api.virtual_port_group_delete(id=vpg_obj.uuid)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:32,代码来源:test_virtual_port_group.py


示例2: test_disable_port_security_with_empty_allowed_address_pair_list

    def test_disable_port_security_with_empty_allowed_address_pair_list(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self._vnc_lib.virtual_network_create(vn)
        addr_pair = AllowedAddressPairs()

        vmi1 = VirtualMachineInterface(
            'vmi1-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=False,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi1.set_virtual_network(vn)
        self._vnc_lib.virtual_machine_interface_create(vmi1)

        addr_pair = AllowedAddressPairs(
            allowed_address_pair=[
                AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
                                   mac='02:ce:1b:d7:a6:e7')])
        vmi2 = VirtualMachineInterface(
            'vmi2-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=True,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi2.set_virtual_network(vn)
        self._vnc_lib.virtual_machine_interface_create(vmi2)

        addr_pair = AllowedAddressPairs()
        vmi2.set_virtual_machine_interface_allowed_address_pairs(addr_pair)
        self._vnc_lib.virtual_machine_interface_update(vmi2)

        vmi2.set_port_security_enabled(False)
        self._vnc_lib.virtual_machine_interface_update(vmi2)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:33,代码来源:test_virtual_machine_interface.py


示例3: test_dedicated_tag_and_refs_deleted

    def test_dedicated_tag_and_refs_deleted(self):
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
        self._vnc_lib.virtual_network_create(vn)
        vmi_ids = []
        for i in range(3):
            vmi = VirtualMachineInterface(
                '%s-vmi%d' % (self.id(), i), parent_obj=self.project)
            vmi.add_virtual_network(vn)
            vmi_ids.append(self._vnc_lib.virtual_machine_interface_create(vmi))
        neutron_fg = self.create_resource(
            'firewall_group',
            self.project_id,
            extra_res_fields={
                'ports': vmi_ids,
            },
        )

        tag_fq_name = self._get_tag_fq_name(neutron_fg, self.project)
        try:
            self._vnc_lib.tag_read(tag_fq_name)
        except NoIdError:
            msg = ("Dedicated Tag %s for firewall group %s was not created" %
                   (':'.join(tag_fq_name), neutron_fg['id']))
            self.fail(msg)

        self.delete_resource('firewall_group', self.project_id,
                             neutron_fg['id'])
        self.assertRaises(NoIdError, self._vnc_lib.tag_read, tag_fq_name)
开发者ID:rombie,项目名称:contrail-controller,代码行数:28,代码来源:test_firewall.py


示例4: test_firewall_group_port_association

    def test_firewall_group_port_association(self):
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
        self._vnc_lib.virtual_network_create(vn)
        vmi_ids = []
        for i in range(3):
            vmi = VirtualMachineInterface(
                '%s-vmi%d' % (self.id(), i), parent_obj=self.project)
            vmi.add_virtual_network(vn)
            vmi_ids.append(self._vnc_lib.virtual_machine_interface_create(vmi))

        neutron_fg = self.create_resource(
            'firewall_group',
            self.project_id,
            extra_res_fields={
                'ports': vmi_ids[:-1],
            },
        )
        self.assertEquals(set(neutron_fg['ports']), set(vmi_ids[:-1]))

        neutron_fg = self.update_resource(
            'firewall_group',
            neutron_fg['id'],
            self.project_id,
            extra_res_fields={
                'ports': vmi_ids[1:],
            },
        )
        self.assertEquals(set(neutron_fg['ports']), set(vmi_ids[1:]))
开发者ID:rombie,项目名称:contrail-controller,代码行数:28,代码来源:test_firewall.py


示例5: test_valid_sub_interface_vlan_tag_id

    def test_valid_sub_interface_vlan_tag_id(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)

        test_suite = [
            (None, None),
            (VMIPT(None), None),
            (VMIPT(sub_interface_vlan_tag=None), None),
            (VMIPT(sub_interface_vlan_tag=-42), BadRequest),
            (VMIPT(sub_interface_vlan_tag=4095), BadRequest),
            (VMIPT(sub_interface_vlan_tag='fo'), BadRequest),
            (VMIPT(sub_interface_vlan_tag='42'), None),
            (VMIPT(sub_interface_vlan_tag=42), None),
        ]

        for (vmipt, result) in test_suite:
            vmi = VirtualMachineInterface('%s-vmi' % self.id(),
                                          parent_obj=project)
            vmi.set_virtual_network(vn)
            vmi.set_virtual_machine_interface_properties(vmipt)
            if result and issubclass(result, Exception):
                self.assertRaises(result,
                                  self.api.virtual_machine_interface_create,
                                  vmi)
            else:
                self.api.virtual_machine_interface_create(vmi)
                self.api.virtual_machine_interface_delete(id=vmi.uuid)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:29,代码来源:test_virtual_machine_interface.py


示例6: _create_virtual_interface

    def _create_virtual_interface(self, project, vip_id, subnet_id,
                                  ip_address):
        network_id = utils.get_subnet_network_id(self._api, subnet_id)
        try:
            vnet = self._api.virtual_network_read(id=network_id)
        except NoIdError:
            raise n_exc.NetworkNotFound(net_id=network_id)

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.set_virtual_network(vnet)

        sg_obj = SecurityGroup("default", project)
        vmi.add_security_group(sg_obj)
        self._api.virtual_machine_interface_create(vmi)

        iip_obj = InstanceIp(name=vip_id)
        iip_obj.set_virtual_network(vnet)
        iip_obj.set_virtual_machine_interface(vmi)
        if ip_address and ip_address != attributes.ATTR_NOT_SPECIFIED:
            iip_obj.set_instance_ip_address(ip_address)
        self._api.instance_ip_create(iip_obj)
        iip = self._api.instance_ip_read(id=iip_obj.uuid)
        vip_address = iip.get_instance_ip_address()

        return vmi, vip_address
开发者ID:leonstack,项目名称:contrail-neutron-plugin,代码行数:25,代码来源:virtual_ip.py


示例7: test_create_pool

    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
开发者ID:achanda,项目名称:contrail-neutron-plugin,代码行数:59,代码来源:test_driver.py


示例8: test_firewall_group_status

    def test_firewall_group_status(self):
        neutron_fg = self.create_resource(
            'firewall_group',
            self.project_id,
            extra_res_fields={
                'admin_state_up': False,
            },
        )
        self.assertEquals(neutron_fg['status'], constants.DOWN)

        neutron_fg = self.update_resource(
            'firewall_group',
            neutron_fg['id'],
            self.project_id,
            extra_res_fields={
                'admin_state_up': True,
            },
        )
        self.assertEquals(neutron_fg['status'], constants.INACTIVE)

        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)
        self._vnc_lib.virtual_machine_interface_create(vmi)
        neutron_fg = self.update_resource(
            'firewall_group',
            neutron_fg['id'],
            self.project_id,
            extra_res_fields={
                'ports': [vmi.uuid],
            },
        )
        self.assertEquals(neutron_fg['status'], constants.INACTIVE)

        fp = FirewallPolicy('%s-fp' % self.id(), parent_obj=self.project)
        self._vnc_lib.firewall_policy_create(fp)
        neutron_fg = self.update_resource(
            'firewall_group',
            neutron_fg['id'],
            self.project_id,
            extra_res_fields={
                'egress_firewall_policy_id': fp.uuid,
            },
        )
        self.assertEquals(neutron_fg['status'], constants.ACTIVE)

        neutron_fg = self.update_resource(
            'firewall_group',
            neutron_fg['id'],
            self.project_id,
            extra_res_fields={
                'ports': [],
            },
        )
        self.assertEquals(neutron_fg['status'], constants.INACTIVE)
开发者ID:rombie,项目名称:contrail-controller,代码行数:57,代码来源:test_firewall.py


示例9: test_asn

    def test_asn(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
        ident_name = self.get_obj_imid(vn1_obj)
        gevent.sleep(2)
        ifmap_ident = self.assertThat(FakeIfmapClient._graph, Contains(ident_name))

        self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:64512:8000001')

        # create router1
        r1_name = self.id() + 'router1'
        router1 = self.create_bgp_router(r1_name, 'contrail')
        self.check_bgp_asn(router1.get_fq_name(), 64512)

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(vmi_name, parent_type='project',
                                      fq_name=['default-domain',
                                               'default-project', vmi_name])
        vmi.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create logical router
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        lr.add_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_create(lr)
        self.check_lr_asn(lr.get_fq_name(), 'target:64512:8000002')

        #update global system config but dont change asn value for equality path
        gs = self._vnc_lib.global_system_config_read(
            fq_name=['default-global-system-config'])
        gs.set_autonomous_system(64512)
        self._vnc_lib.global_system_config_update(gs)

        # check route targets
        self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:64512:8000001')
        self.check_bgp_asn(router1.get_fq_name(), 64512)
        self.check_lr_asn(lr.get_fq_name(), 'target:64512:8000002')

        #update ASN value
        gs = self._vnc_lib.global_system_config_read(
            fq_name=[u'default-global-system-config'])
        gs.set_autonomous_system(50000)
        self._vnc_lib.global_system_config_update(gs)

        # check new route targets
        self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:50000:8000001')
        self.check_bgp_asn(router1.get_fq_name(), 50000)
        self.check_lr_asn(lr.get_fq_name(), 'target:50000:8000002')

        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_ri_is_deleted(fq_name=vn1_obj.fq_name+[vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=router1.uuid)
开发者ID:Pojen-Huang,项目名称:contrail-controller,代码行数:57,代码来源:test_bgp.py


示例10: test_asn

    def test_asn(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
        self.assertTill(self.vnc_db_has_ident, obj=vn1_obj)

        ri_target = self.check_ri_target(self.get_ri_name(vn1_obj))

        # create router1
        r1_name = self.id() + 'router1'
        router1 = self.create_bgp_router(r1_name, 'contrail')
        self.check_bgp_asn(router1.get_fq_name(), 64512)

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(vmi_name, parent_type='project',
                                      fq_name=['default-domain',
                                               'default-project', vmi_name])
        vmi.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create logical router
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        lr.add_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_create(lr)
        lr_target = self.check_lr_target(lr.get_fq_name())

        #update global system config but dont change asn value for equality path
        gs = self._vnc_lib.global_system_config_read(
            fq_name=['default-global-system-config'])
        gs.set_autonomous_system(64512)
        self._vnc_lib.global_system_config_update(gs)

        # check route targets
        self.check_ri_target(self.get_ri_name(vn1_obj), ri_target)
        self.check_bgp_asn(router1.get_fq_name(), 64512)
        self.check_lr_target(lr.get_fq_name(), lr_target)

        #update ASN value
        gs = self._vnc_lib.global_system_config_read(
            fq_name=[u'default-global-system-config'])
        gs.set_autonomous_system(50000)
        self._vnc_lib.global_system_config_update(gs)

        # check new route targets
        self.check_ri_target(self.get_ri_name(vn1_obj), ri_target.replace('64512', '50000'))
        self.check_bgp_asn(router1.get_fq_name(), 50000)
        self.check_lr_target(lr.get_fq_name(), lr_target.replace('64512', '50000'))

        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_ri_is_deleted(fq_name=vn1_obj.fq_name+[vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=router1.uuid)
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:55,代码来源:test_bgp.py


示例11: _create_vmi

    def _create_vmi(self, pod_task_id, vm_obj, vn_obj):
        proj_fq_name = vnc_mesos_config.cluster_project_fq_name('default')
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)

        vmi_prop = None
        obj_uuid = str(uuid.uuid1())
        vmi_obj = VirtualMachineInterface(
            name=vm_obj.name, parent_obj=proj_obj,
            virtual_machine_interface_properties=vmi_prop,
            display_name=vm_obj.name)

        vmi_obj.uuid = obj_uuid
        vmi_obj.set_virtual_network(vn_obj)
        vmi_obj.set_virtual_machine(vm_obj)
        vmi_obj.add_annotations(KeyValuePair(key='index', value='0/1'))
        vmi_obj.port_security_enabled = True
        VirtualMachineInterfaceMM.add_annotations(self, vmi_obj, pod_task_id)

        try:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
        except RefsExistError:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)

        VirtualMachineInterfaceMM.locate(vmi_uuid)
        return vmi_uuid
开发者ID:Juniper,项目名称:contrail-controller,代码行数:25,代码来源:vnc_pod_task.py


示例12: test_subnet_type_validation

    def test_subnet_type_validation(self):
        test_suite = [
            (SubnetType('0', 0), ('0.0.0.0', 0)),
            (SubnetType('1.1.1.1'), BadRequest),
            (SubnetType('1.1.1.1', 24), ('1.1.1.0', 24)),
            (SubnetType('1.1.1.1', '24'), ('1.1.1.0', 24)),
            (SubnetType('1.1.1.1', 32), ('1.1.1.1', 32)),
            (SubnetType('1.1.1.e', 32), BadRequest),
            (SubnetType('1.1.1.1', '32e'), BadRequest),
            (SubnetType('1.1.1.0,2.2.2.0', 24), BadRequest),
            (SubnetType(''), BadRequest),
            (SubnetType('', 30), BadRequest),
            (SubnetType('::', 0), ('::', 0)),
            (SubnetType('::'), BadRequest),
            (SubnetType('dead::beef', 128), ('dead::beef', 128)),
            (SubnetType('dead::beef', '128'), ('dead::beef', 128)),
            (SubnetType('dead::beef', 96), ('dead::', 96)),
            (SubnetType('dead::beez', 96), BadRequest),
            (SubnetType('dead::beef', '96e'), BadRequest),
            (SubnetType('dead::,beef::', 64), BadRequest),
        ]

        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self.api.virtual_network_create(vn)
        vmi = VirtualMachineInterface('vmi-%s' % self.id(), parent_obj=project)
        vmi.set_virtual_network(vn)
        self.api.virtual_machine_interface_create(vmi)

        for subnet, expected_result in test_suite:
            aaps = AllowedAddressPairs(
                allowed_address_pair=[AllowedAddressPair(ip=subnet)])
            vmi.set_virtual_machine_interface_allowed_address_pairs(aaps)
            if (type(expected_result) == type and
                    issubclass(expected_result, Exception)):
                self.assertRaises(
                    expected_result,
                    self.api.virtual_machine_interface_update,
                    vmi)
            else:
                self.api.virtual_machine_interface_update(vmi)
                vmi = self.api.virtual_machine_interface_read(id=vmi.uuid)
                returned_apps = vmi.\
                    get_virtual_machine_interface_allowed_address_pairs().\
                    get_allowed_address_pair()
                self.assertEqual(len(returned_apps), 1)
                returned_subnet = returned_apps[0].get_ip()
                self.assertEqual(returned_subnet.ip_prefix,
                                 expected_result[0])
                self.assertEqual(returned_subnet.ip_prefix_len,
                                 expected_result[1])
开发者ID:Juniper,项目名称:contrail-controller,代码行数:52,代码来源:test_vnc_cfg_api_server.py


示例13: create_virtual_machine

 def create_virtual_machine(self, name, vn, ipaddress):
     vm_instance = VirtualMachine(name)
     self._vnc_lib.virtual_machine_create(vm_instance)
     fq_name = [name, '0']
     vmi = VirtualMachineInterface(parent_type='virtual-machine', fq_name=fq_name)
     vmi.set_virtual_network(vn)
     self._vnc_lib.virtual_machine_interface_create(vmi)
     ip = InstanceIp(vm_instance.name + '.0')
     ip.set_virtual_machine_interface(vmi)
     ip.set_virtual_network(vn)
     ip.set_instance_ip_address(ipaddress)
     self._vnc_lib.instance_ip_create(ip)
     return vm_instance
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:13,代码来源:test_case.py


示例14: test_port_security_and_allowed_address_pairs

    def test_port_security_and_allowed_address_pairs(self):
        project = Project('%s-project' % self.id())
        self.api.project_create(project)
        vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
        self._vnc_lib.virtual_network_create(vn)
        addr_pair = AllowedAddressPairs(
            allowed_address_pair=[
                AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
                                   mac='02:ce:1b:d7:a6:e7')])
        msg = (r"^Allowed address pairs are not allowed when port security is "
               "disabled$")

        vmi = VirtualMachineInterface(
            'vmi-%s' % self.id(),
            parent_obj=project,
            port_security_enabled=False,
            virtual_machine_interface_allowed_address_pairs=addr_pair)
        vmi.set_virtual_network(vn)
        with self.assertRaisesRegexp(BadRequest, msg):
            self._vnc_lib.virtual_machine_interface_create(vmi)

        vmi = VirtualMachineInterface('vmi-%s' % self.id(), parent_obj=project,
                                      port_security_enabled=False)
        vmi.set_virtual_network(vn)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # updating a port with allowed address pair should throw an exception
        # when port security enabled is set to false
        vmi.virtual_machine_interface_allowed_address_pairs = addr_pair
        with self.assertRaisesRegexp(BadRequest, msg):
            self._vnc_lib.virtual_machine_interface_update(vmi)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:31,代码来源:test_virtual_machine_interface.py


示例15: _create_virtual_interface

    def _create_virtual_interface(self, project, vip_id, subnet_id,
                                  ip_address):
        network_id = utils.get_subnet_network_id(self._api, subnet_id)
        try:
            vnet = self._api.virtual_network_read(id=network_id)
        except NoIdError:
            raise n_exc.NetworkNotFound(net_id=network_id)

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.set_virtual_network(vnet)
        try:
            vmi.set_virtual_machine_interface_device_owner(n_constants.DEVICE_OWNER_LOADBALANCER)
        except AttributeError:
            # DEVICE_OWNER_LOADBALANCER is only supported from JUNO onwards
            pass

        sg_obj = SecurityGroup("default", project)
        vmi.add_security_group(sg_obj)
        self._api.virtual_machine_interface_create(vmi)

        iip_obj = InstanceIp(name=vip_id)
        iip_obj.set_virtual_network(vnet)
        iip_obj.set_virtual_machine_interface(vmi)
        if ip_address and ip_address != attributes.ATTR_NOT_SPECIFIED:
            iip_obj.set_instance_ip_address(ip_address)
        self._api.instance_ip_create(iip_obj)
        iip = self._api.instance_ip_read(id=iip_obj.uuid)
        vip_address = iip.get_instance_ip_address()

        return vmi, vip_address
开发者ID:tcpcloud,项目名称:contrail-neutron-plugin,代码行数:30,代码来源:virtual_ip.py


示例16: create_virtual_machine

    def create_virtual_machine(self, name, vn, ipaddress):
        vm = VirtualMachine(name)
        self._vnc_lib.virtual_machine_create(vm)
        VirtualMachineKM.locate(vm.uuid)

        vmi = VirtualMachineInterface(
            parent_type='virtual-machine', fq_name=[name, '0'])
        vmi.set_virtual_machine(vm)
        vmi.set_virtual_network(vn)
        self._vnc_lib.virtual_machine_interface_create(vmi)
        VirtualMachineInterfaceKM.locate(vmi.uuid)

        ip = InstanceIp(vm.name + '.0')
        ip.set_virtual_machine_interface(vmi)
        ip.set_virtual_network(vn)
        ip.set_instance_ip_address(ipaddress)
        self._vnc_lib.instance_ip_create(ip)
        InstanceIpKM.locate(ip.uuid)

        return vm, vmi, ip
开发者ID:Juniper,项目名称:contrail-controller,代码行数:20,代码来源:test_case.py


示例17: test_logical_router

    def test_logical_router(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(vmi_name, parent_type='project', fq_name=['default-domain', 'default-project', vmi_name])
        vmi.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create logical router
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        lr.set_configured_route_target_list(rtgt_list)
        lr.add_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_create(lr)

        ri_name = self.get_ri_name(vn1_obj)
        self.check_route_target_in_routing_instance(ri_name,rtgt_list.get_route_target())

        rtgt_list.add_route_target('target:1:2')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())

        rtgt_list.delete_route_target('target:1:1')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())

        lr.del_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_update(lr)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_vn_is_deleted(uuid=vn1_obj.uuid)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_lr_is_deleted(uuid=lr.uuid)
        self.check_rt_is_deleted(name='target:64512:8000002')
开发者ID:Pojen-Huang,项目名称:contrail-controller,代码行数:40,代码来源:test_bgp.py


示例18: test_bgpaas_shared

    def test_bgpaas_shared(self):
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name1 = self.id() + 'p1'
        port_obj1 = VirtualMachineInterface(port_name1, parent_obj=project_obj)
        port_obj1.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj1)
        port_name2 = self.id() + 'p2'
        port_obj2 = VirtualMachineInterface(port_name2, parent_obj=project_obj)
        port_obj2.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj2)

        # Create a shared BGPaaS server. It means BGP Router object
        # does not get created for VMI on the network.
        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
                               autonomous_system=64512, bgpaas_shared=True,
                               bgpaas_ip_address = '1.1.1.1')

        bgpaas.add_virtual_machine_interface(port_obj1)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())

        router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + bgpaas_name
        router2_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + 'bgpaas-server'
        
        # Check for two BGP routers - one with the BGPaaS name and not with Port name
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        # check whether shared IP address is assigned to the BGP rotuer 
        self.check_bgp_router_ip(router1_name, '1.1.1.1')

        # Add a new VMI to the BGPaaS. This should not create a new BGP router
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name_str=bgpaas.get_fq_name_str())
        bgpaas.add_virtual_machine_interface(port_obj2)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)

        # Check for the absence of BGP router along with the new VMI.
        router3_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name2
        try:
            bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=router3_name)
        except NoIdError:
            print 'Second BGP Router not created for second port - PASS'
        else:
            assert(True)

        bgpaas.del_virtual_machine_interface(port_obj1)
        bgpaas.del_virtual_machine_interface(port_obj2)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj1.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj2.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name+[vn1_obj.name])
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:60,代码来源:test_bgp.py


示例19: create_virtual_machine

    def create_virtual_machine(self, name, vn, ipaddress):
        vm = VirtualMachine(name)
        self._vnc_lib.virtual_machine_create(vm)
        VirtualMachineKM.locate(vm.uuid)

        vmi = VirtualMachineInterface(
            parent_type='virtual-machine', fq_name=[name, '0'])
        vmi.set_virtual_machine(vm)
        vmi.set_virtual_network(vn)
        if DBBaseKM.is_nested():
            vmi.set_virtual_machine_interface_bindings(
                KeyValuePairs([KeyValuePair('host_id', 'WHATEVER')]))
        self._vnc_lib.virtual_machine_interface_create(vmi)
        VirtualMachineInterfaceKM.locate(vmi.uuid)

        ip = InstanceIp(vm.name + '.0')
        ip.set_virtual_machine_interface(vmi)
        ip.set_virtual_network(vn)
        ip.set_instance_ip_address(ipaddress)
        self._vnc_lib.instance_ip_create(ip)
        InstanceIpKM.locate(ip.uuid)

        return vm, vmi, ip
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:23,代码来源:test_case.py


示例20: _create_vmi

    def _create_vmi(self, pod_name, pod_namespace, pod_id, vm_obj, vn_obj,
                    parent_vmi, idx, nw_name=''):
        proj_fq_name = vnc_kube_config.cluster_project_fq_name(pod_namespace)
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)

        vmi_prop = None
        if self._is_pod_nested() and parent_vmi:
            # Pod is nested.
            # Allocate a vlan-id for this pod from the vlan space managed
            # in the VMI of the underlay VM.
            parent_vmi = VirtualMachineInterfaceKM.get(parent_vmi.uuid)
            vlan_id = parent_vmi.alloc_vlan()
            vmi_prop = VirtualMachineInterfacePropertiesType(
                sub_interface_vlan_tag=vlan_id)

        obj_uuid = str(uuid.uuid1())
        name = VncCommon.make_name(pod_name, obj_uuid)
        vmi_obj = VirtualMachineInterface(
            name=name, parent_obj=proj_obj,
            virtual_machine_interface_properties=vmi_prop,
            display_name=name)

        vmi_obj.uuid = obj_uuid
        vmi_obj.set_virtual_network(vn_obj)
        vmi_obj.set_virtual_machine(vm_obj)
        self._associate_security_groups(vmi_obj, proj_obj, pod_namespace)
        vmi_obj.port_security_enabled = True
        VirtualMachineInterfaceKM.add_annotations(self, vmi_obj, pod_namespace,
                                        pod_name, index=idx, network=nw_name)

        try:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
        except RefsExistError:
            vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)

        VirtualMachineInterfaceKM.locate(vmi_uuid)
        return vmi_uuid
开发者ID:rombie,项目名称:contrail-controller,代码行数:37,代码来源:vnc_pod.py



注:本文中的vnc_api.vnc_api.VirtualMachineInterface类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vnc_api.VirtualNetwork类代码示例发布时间:2022-05-26
下一篇:
Python vnc_api.ServiceInstance类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap