def integration_test_connect_B(self):
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port)
        vm_uuid = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Boris', 'Boris2-win7').config.uuid

        mapping = VmNetworkMapping()
        mapping.vlan_id = '114'
        # mapping.dv_port_name = 65
        mapping.dv_switch_name = 'dvSwitch'
        mapping.dv_switch_path = 'QualiSB'
        mapping.vlan_spec = 'Trunk'

        vlan_spec = VlanSpecFactory()
        range_fac = VLanIdRangeParser()
        synchronous_task_waiter = SynchronousTaskWaiter()
        name_gen = DvPortGroupNameGenerator()
        mapper = VnicToNetworkMapper(name_gen)
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service, synchronous_task_waiter)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(py_vmomi_service,
                                                                                  synchronous_task_waiter,
                                                                                  mapper,
                                                                                  VNicService())
        connector = VirtualSwitchToMachineConnector(dv_port_group_creator, virtual_machine_port_group_configurer)

        command = VirtualSwitchConnectCommand(py_vmomi_service, connector, name_gen, vlan_spec, range_fac, Mock())

        command.connect_to_networks(si, vm_uuid, [mapping], 'QualiSB/anetwork', [])
    def integration_test_connect_A(self):
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password,
                                      cred.port)
        synchronous_task_waiter = SynchronousTaskWaiter()
        mapper = VnicToNetworkMapper(DvPortGroupNameGenerator())
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service,
                                                   synchronous_task_waiter)
        port_group_name_generator = DvPortGroupNameGenerator()
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(
            py_vmomi_service, synchronous_task_waiter, mapper, VNicService(),
            port_group_name_generator)

        mapping = VmNetworkMapping()
        mapping.vlan_id = [vim.NumericRange(start=65, end=65)]
        mapping.dv_port_name = DvPortGroupNameGenerator(
        ).generate_port_group_name(65, 'Trunk')
        mapping.dv_switch_name = 'dvSwitch'
        mapping.dv_switch_path = 'QualiSB'
        mapping.vlan_spec = vim.dvs.VmwareDistributedVirtualSwitch.TrunkVlanSpec(
        )
        connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)

        vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Raz', '2')

        # Act
        connector.connect_by_mapping(si, vm, [mapping], None, [])

        pass
    def integration_test_connect_A(self):
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port)
        synchronous_task_waiter = SynchronousTaskWaiter()
        mapper = VnicToNetworkMapper(DvPortGroupNameGenerator())
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service, synchronous_task_waiter)
        port_group_name_generator = DvPortGroupNameGenerator()
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(py_vmomi_service,
                                                                                  synchronous_task_waiter,
                                                                                  mapper,
                                                                                  VNicService(),
                                                                                  port_group_name_generator)

        mapping = VmNetworkMapping()
        mapping.vlan_id = [vim.NumericRange(start=65, end=65)]
        mapping.dv_port_name = DvPortGroupNameGenerator().generate_port_group_name(65, 'Trunk')
        mapping.dv_switch_name = 'dvSwitch'
        mapping.dv_switch_path = 'QualiSB'
        mapping.port_group_path = 'QualiSB'
        mapping.vlan_spec = vim.dvs.VmwareDistributedVirtualSwitch.TrunkVlanSpec()
        connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator,
            virtual_machine_port_group_configurer)

        vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Raz', '2')

        # Act
        connector.connect_by_mapping(si, vm, [mapping], None, [])

        pass
Exemplo n.º 4
0
    def test_connect_vnic_to_network(self):
        # arrange
        connect_command = VirtualSwitchConnectCommand(
            self.pv_service, self.dv_connector, self.dv_port_name_gen,
            self.vlan_spec_factory, self.vlan_id_range_parser)
        mapping = VmNetworkMapping()
        mapping.vnic_name = 'name'
        mapping.vlan_id = 'vlan_id'
        mapping.vlan_spec = 'trunc'
        mapping.dv_port_name = 'port_name'
        mapping.network = Mock()

        # act
        connect_results = connect_command.connect_to_networks(
            si=self.si,
            logger=Mock(),
            vm_uuid=self.vm_uuid,
            vm_network_mappings=[mapping],
            default_network_name='default_network',
            reserved_networks=[],
            dv_switch_name='')

        # assert
        self.assertTrue(
            self.vlan_id_range_parser.parse_vlan_id.called_with(self.vlan_id))
        self.assertTrue(
            self.dv_port_name_gen.generate_port_group_name.called_with(
                self.vlan_id, self.vlan_spec_factory))
        self.assertTrue(
            self.vlan_spec_factory.get_vlan_spec.called_with(self.spec_type))
        self.assertTrue(
            self.dv_connector.connect_by_mapping.called_with(
                self.si, self.vm, [mapping]))
        self.assertEqual(connect_results[0].mac_address, 'AA-BB')
Exemplo n.º 5
0
 def _create_map(self, vlan_id, mode, vnic_name):
     vnic_to_network = VmNetworkMapping()
     vnic_to_network.vnic_name = self._validate_vnic_name(vnic_name)
     vnic_to_network.dv_switch_path = self.dv_switch_path
     vnic_to_network.dv_switch_name = self.dv_switch_name
     vnic_to_network.vlan_id = vlan_id
     vnic_to_network.vlan_spec = mode
     return vnic_to_network
 def _create_map(self, vlan_id, mode, vnic_name):
     vnic_to_network = VmNetworkMapping()
     vnic_to_network.vnic_name = self._validate_vnic_name(vnic_name)
     vnic_to_network.dv_switch_path = self.dv_switch_path
     vnic_to_network.dv_switch_name = self.dv_switch_name
     vnic_to_network.port_group_path = self.port_group_path
     vnic_to_network.vlan_id = vlan_id
     vnic_to_network.vlan_spec = mode
     return vnic_to_network
Exemplo n.º 7
0
    def test_connect_vnic_to_network(self):
        # arrange
        connect_command = VirtualSwitchConnectCommand(self.pv_service, self.dv_connector, self.dv_port_name_gen,
                                                      self.vlan_spec_factory, self.vlan_id_range_parser)
        mapping = VmNetworkMapping()
        mapping.vnic_name = 'name'
        mapping.vlan_id = 'vlan_id'
        mapping.vlan_spec = 'trunc'
        mapping.dv_port_name = 'port_name'
        mapping.network = Mock()

        # act
        connect_results = connect_command.connect_to_networks(si=self.si,
                                                              logger=Mock(),
                                                              vm_uuid=self.vm_uuid,
                                                              vm_network_mappings=[mapping],
                                                              default_network_name='default_network',
                                                              reserved_networks=[])

        # assert
        self.assertTrue(self.vlan_id_range_parser.parse_vlan_id.called_with(self.vlan_id))
        self.assertTrue(
            self.dv_port_name_gen.generate_port_group_name.called_with(self.vlan_id, self.vlan_spec_factory))
        self.assertTrue(self.vlan_spec_factory.get_vlan_spec.called_with(self.spec_type))
        self.assertTrue(self.dv_connector.connect_by_mapping.called_with(self.si, self.vm, [mapping]))
        self.assertEqual(connect_results[0].mac_address, 'AA-BB')
    def integration_test_connect_B(self):
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password,
                                      cred.port)
        vm_uuid = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Boris',
                                                   'Boris2-win7').config.uuid

        mapping = VmNetworkMapping()
        mapping.vlan_id = '114'
        # mapping.dv_port_name = 65
        mapping.dv_switch_name = 'dvSwitch'
        mapping.dv_switch_path = 'QualiSB'
        mapping.vlan_spec = 'Trunk'

        vlan_spec = VlanSpecFactory()
        range_fac = VLanIdRangeParser()
        synchronous_task_waiter = SynchronousTaskWaiter()
        name_gen = DvPortGroupNameGenerator()
        mapper = VnicToNetworkMapper(name_gen)
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service,
                                                   synchronous_task_waiter)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(
            py_vmomi_service, synchronous_task_waiter, mapper, VNicService())
        connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)

        command = VirtualSwitchConnectCommand(py_vmomi_service, connector,
                                              name_gen, vlan_spec, range_fac,
                                              Mock())

        command.connect_to_networks(si, vm_uuid, [mapping], 'QualiSB/anetwork',
                                    [])