コード例 #1
0
    def setUp(self):
        self._si = None
        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'JustTestNeedToBeRemoved'
        self.vm_uuid = "422254d5-5226-946e-26fb-60c21898b731"

        self.vcenter_name = "QualiSB"
        self.dv_switch_path = 'QualiSB'
        self.network_path = 'QualiSB'

        self.dv_switch_name = 'dvSwitch-SergiiT'
        self.dv_port_group_name = 'aa-dvPortGroup3B'

        self.network = Mock()
        self.network.key = "network-key"
        self.network.name = "QS_123"
        self.network.config.distributedVirtualSwitch.uuid = "422254d5-5226-946e-26fb-60c21898b73f"
        self.py_vmomi_service = Mock()

        self.network2 = Mock()
        self.network2.key = "network2-key"
        self.network2.name = "QS_network2"
        self.network3 = Mock()
        self.network3.key = "network3-key"
        self.network3.name = "QS_network3"

        self.vm = Mock()
        self.vm.config.hardware = Mock()
        self.vnic = Mock(spec=vim.vm.device.VirtualEthernetCard)
        self.vnic.macAddress = True
        self.vnic.deviceInfo = Mock()
        self.vm.config.hardware.device = [self.vnic]
        self.py_vmomi_service.find_by_uuid = lambda a, b, c: self.vm
        self.py_vmomi_service.find_network_by_name = Mock(
            return_value=self.network)

        self.synchronous_task_waiter = Mock()
        self.synchronous_task_waiter.wait_for_task = Mock(
            return_value="TASK OK")
        self.si = Mock()

        mapping = {'vnic 1': (Mock(spec=vim.Network), None)}
        self.vnic_service = Mock()
        self.vnic_to_network_mapper = Mock()
        self.vnic_to_network_mapper.map_request_to_vnics = Mock(
            return_value=mapping)
        self.vnics = {'vnic 1': self.vnic}

        self.port_group_name_generator = DvPortGroupNameGenerator()

        self.vnic_service.map_vnics = Mock(return_value=self.vnics)
        self.configurer = VirtualMachinePortGroupConfigurer(
            self.py_vmomi_service, self.synchronous_task_waiter,
            self.vnic_to_network_mapper, self.vnic_service,
            self.port_group_name_generator)
コード例 #2
0
    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',
                                    [])
コード例 #3
0
    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
コード例 #4
0
    def setUp(self):
        self._si = None
        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'JustTestNeedToBeRemoved'
        self.vm_uuid = "422254d5-5226-946e-26fb-60c21898b731"

        self.vcenter_name = "QualiSB"
        self.port_group_path = 'QualiSB'
        self.dv_switch_path = 'QualiSB'
        self.network_path = 'QualiSB'

        self.dv_switch_name = 'dvSwitch-SergiiT'
        self.dv_port_group_name = 'aa-dvPortGroup3B'

        self.network = Mock()
        self.network.key = "network-key"
        self.network.name = "QS_123"
        self.network.config.distributedVirtualSwitch.uuid = "422254d5-5226-946e-26fb-60c21898b73f"
        self.py_vmomi_service = Mock()

        self.vm = Mock()
        self.vm.config.hardware = Mock()
        self.vnic = Mock(spec=vim.vm.device.VirtualEthernetCard)
        self.vnic.macAddress = True
        self.vnic.deviceInfo = Mock()
        self.vm.config.hardware.device = [self.vnic]
        self.py_vmomi_service.find_by_uuid = lambda a, b, c: self.vm
        self.py_vmomi_service.find_network_by_name = Mock(return_value=self.network)

        self.synchronous_task_waiter = Mock()
        self.synchronous_task_waiter.wait_for_task = Mock(return_value="TASK OK")
        self.si = Mock()

        mapping = {'vnic 1': (Mock(spec=vim.Network), None)}
        self.vnic_service = Mock()
        self.vnic_to_network_mapper = Mock()
        self.vnic_to_network_mapper.map_request_to_vnics = Mock(return_value=mapping)
        self.vnics = {'vnic 1': self.vnic}

        self.vnic_service.map_vnics = Mock(return_value=self.vnics)
        self.configurer = VirtualMachinePortGroupConfigurer(self.py_vmomi_service,
                                                            self.synchronous_task_waiter,
                                                            self.vnic_to_network_mapper,
                                                            self.vnic_service,
                                                            Mock())
コード例 #5
0
class TestDvPortGroupConfigurer(TestCase):
    def setUp(self):
        self._si = None
        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'JustTestNeedToBeRemoved'
        self.vm_uuid = "422254d5-5226-946e-26fb-60c21898b731"

        self.vcenter_name = "QualiSB"
        self.port_group_path = 'QualiSB'
        self.dv_switch_path = 'QualiSB'
        self.network_path = 'QualiSB'

        self.dv_switch_name = 'dvSwitch-SergiiT'
        self.dv_port_group_name = 'aa-dvPortGroup3B'

        self.network = Mock()
        self.network.key = "network-key"
        self.network.name = "QS_123"
        self.network.config.distributedVirtualSwitch.uuid = "422254d5-5226-946e-26fb-60c21898b73f"
        self.py_vmomi_service = Mock()

        self.vm = Mock()
        self.vm.config.hardware = Mock()
        self.vnic = Mock(spec=vim.vm.device.VirtualEthernetCard)
        self.vnic.macAddress = True
        self.vnic.deviceInfo = Mock()
        self.vm.config.hardware.device = [self.vnic]
        self.py_vmomi_service.find_by_uuid = lambda a, b, c: self.vm
        self.py_vmomi_service.find_network_by_name = Mock(return_value=self.network)

        self.synchronous_task_waiter = Mock()
        self.synchronous_task_waiter.wait_for_task = Mock(return_value="TASK OK")
        self.si = Mock()

        mapping = {'vnic 1': (Mock(spec=vim.Network), None)}
        self.vnic_service = Mock()
        self.vnic_to_network_mapper = Mock()
        self.vnic_to_network_mapper.map_request_to_vnics = Mock(return_value=mapping)
        self.vnics = {'vnic 1': self.vnic}

        self.vnic_service.map_vnics = Mock(return_value=self.vnics)
        self.configurer = VirtualMachinePortGroupConfigurer(self.py_vmomi_service,
                                                            self.synchronous_task_waiter,
                                                            self.vnic_to_network_mapper,
                                                            self.vnic_service,
                                                            Mock())

    def test_get_networks_on_vnics(self):
        res = self.configurer.get_networks_on_vnics(self.vm, [self.vnic], logger=Mock())
        self.assertIsNotNone(res)

    def test_erase_network_by_mapping(self):
        res = self.configurer.erase_network_by_mapping([self.network], [], logger=Mock())
        self.assertIsNone(res)

    def test_disconnect_all_networks(self):
        mapping = self.configurer.disconnect_all_networks(self.vm, Mock(spec=vim.Network), [], logger=Mock())
        self.assertFalse(mapping[0].connect)

    def test_disconnect_network(self):
        mapping = self.configurer.disconnect_network(self.vm, self.network, Mock(spec=vim.Network), '', logger=Mock())
        self.assertFalse(mapping[0].connect)

    def test_connect_vnic_to_networks(self):
        mapping = [ConnectRequest('vnic 1', (Mock(spec=vim.Network), None))]
        res = self.configurer.connect_vnic_to_networks(self.vm, mapping, Mock(spec=vim.Network), [], logger=Mock())
        self.assertIsNotNone(res[0].vnic)
コード例 #6
0
    def __init__(self):
        """
        Initialize the driver session, this function is called everytime a new instance of the driver is created
        in here the driver is going to be bootstrapped

        :param context: models.QualiDriverModels.InitCommandContext
        """
        self.cs_helper = CloudshellDriverHelper()
        synchronous_task_waiter = SynchronousTaskWaiter()
        pv_service = pyVmomiService(connect=SmartConnect,
                                    disconnect=Disconnect,
                                    task_waiter=synchronous_task_waiter)
        self.resource_model_parser = ResourceModelParser()
        port_group_name_generator = DvPortGroupNameGenerator()

        vnic_to_network_mapper = VnicToNetworkMapper(
            quali_name_generator=port_group_name_generator)
        resource_remover = CloudshellResourceRemover()
        ovf_service = OvfImageDeployerService(self.resource_model_parser)

        self.vm_loader = VMLoader(pv_service)

        vm_deployer = VirtualMachineDeployer(
            pv_service=pv_service,
            name_generator=generate_unique_name,
            ovf_service=ovf_service,
            cs_helper=self.cs_helper,
            resource_model_parser=ResourceModelParser())

        dv_port_group_creator = DvPortGroupCreator(
            pyvmomi_service=pv_service,
            synchronous_task_waiter=synchronous_task_waiter)
        virtual_machine_port_group_configurer = \
            VirtualMachinePortGroupConfigurer(pyvmomi_service=pv_service,
                                              synchronous_task_waiter=synchronous_task_waiter,
                                              vnic_to_network_mapper=vnic_to_network_mapper,
                                              vnic_service=VNicService(),
                                              name_gen=port_group_name_generator)
        virtual_switch_to_machine_connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)
        # Command Wrapper
        self.command_wrapper = CommandWrapper(
            pv_service=pv_service,
            cloud_shell_helper=self.cs_helper,
            resource_model_parser=self.resource_model_parser,
            context_based_logger_factory=ContextBasedLoggerFactory())
        # Deploy Command
        self.deploy_command = DeployCommand(deployer=vm_deployer)

        # Virtual Switch Revoke
        self.virtual_switch_disconnect_command = \
            VirtualSwitchToMachineDisconnectCommand(
                pyvmomi_service=pv_service,
                port_group_configurer=virtual_machine_port_group_configurer,
                resource_model_parser=self.resource_model_parser)

        # Virtual Switch Connect
        virtual_switch_connect_command = \
            VirtualSwitchConnectCommand(
                pv_service=pv_service,
                virtual_switch_to_machine_connector=virtual_switch_to_machine_connector,
                dv_port_group_name_generator=DvPortGroupNameGenerator(),
                vlan_spec_factory=VlanSpecFactory(),
                vlan_id_range_parser=VLanIdRangeParser())
        self.connection_orchestrator = ConnectionCommandOrchestrator(
            connector=virtual_switch_connect_command,
            disconnector=self.virtual_switch_disconnect_command,
            resource_model_parser=self.resource_model_parser)

        # Destroy VM Command
        self.destroy_virtual_machine_command = \
            DestroyVirtualMachineCommand(pv_service=pv_service,
                                         resource_remover=resource_remover,
                                         disconnector=self.virtual_switch_disconnect_command)
        # Power Command
        self.vm_power_management_command = \
            VirtualMachinePowerManagementCommand(pyvmomi_service=pv_service,
                                                 synchronous_task_waiter=synchronous_task_waiter)

        ip_manager = VMIPManager()

        # Refresh IP command
        self.refresh_ip_command = RefreshIpCommand(
            pyvmomi_service=pv_service,
            resource_model_parser=ResourceModelParser(),
            ip_manager=ip_manager)

        # Save Snapshot
        self.snapshot_saver = SaveSnapshotCommand(
            pyvmomi_service=pv_service, task_waiter=synchronous_task_waiter)

        # Snapshot Restorer
        self.snapshot_restorer = SnapshotRestoreCommand(
            pyvmomi_service=pv_service, task_waiter=synchronous_task_waiter)

        self.snapshots_retriever = RetrieveSnapshotsCommand(
            pyvmomi_service=pv_service)
コード例 #7
0
class TestDvPortGroupConfigurer(TestCase):
    def setUp(self):
        self._si = None
        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'JustTestNeedToBeRemoved'
        self.vm_uuid = "422254d5-5226-946e-26fb-60c21898b731"

        self.vcenter_name = "QualiSB"
        self.dv_switch_path = 'QualiSB'
        self.network_path = 'QualiSB'

        self.dv_switch_name = 'dvSwitch-SergiiT'
        self.dv_port_group_name = 'aa-dvPortGroup3B'

        self.network = Mock()
        self.network.key = "network-key"
        self.network.name = "QS_123"
        self.network.config.distributedVirtualSwitch.uuid = "422254d5-5226-946e-26fb-60c21898b73f"
        self.py_vmomi_service = Mock()

        self.network2 = Mock()
        self.network2.key = "network2-key"
        self.network2.name = "QS_network2"
        self.network3 = Mock()
        self.network3.key = "network3-key"
        self.network3.name = "QS_network3"

        self.vm = Mock()
        self.vm.config.hardware = Mock()
        self.vnic = Mock(spec=vim.vm.device.VirtualEthernetCard)
        self.vnic.macAddress = True
        self.vnic.deviceInfo = Mock()
        self.vm.config.hardware.device = [self.vnic]
        self.py_vmomi_service.find_by_uuid = lambda a, b, c: self.vm
        self.py_vmomi_service.find_network_by_name = Mock(
            return_value=self.network)

        self.synchronous_task_waiter = Mock()
        self.synchronous_task_waiter.wait_for_task = Mock(
            return_value="TASK OK")
        self.si = Mock()

        mapping = {'vnic 1': (Mock(spec=vim.Network), None)}
        self.vnic_service = Mock()
        self.vnic_to_network_mapper = Mock()
        self.vnic_to_network_mapper.map_request_to_vnics = Mock(
            return_value=mapping)
        self.vnics = {'vnic 1': self.vnic}

        self.port_group_name_generator = DvPortGroupNameGenerator()

        self.vnic_service.map_vnics = Mock(return_value=self.vnics)
        self.configurer = VirtualMachinePortGroupConfigurer(
            self.py_vmomi_service, self.synchronous_task_waiter,
            self.vnic_to_network_mapper, self.vnic_service,
            self.port_group_name_generator)

    def test_get_networks_on_vnics(self):
        res = self.configurer.get_networks_on_vnics(self.vm, [self.vnic],
                                                    logger=Mock())
        self.assertIsNotNone(res)

    def test_erase_network_by_mapping(self):
        res = self.configurer.erase_network_by_mapping([self.network], [],
                                                       logger=Mock())
        self.assertIsNone(res)

    def test_disconnect_all_networks(self):
        mapping = self.configurer.disconnect_all_networks(
            self.vm, Mock(spec=vim.Network), [], logger=Mock())
        self.assertFalse(mapping[0].connect)

    def test_disconnect_network(self):
        mapping = self.configurer.disconnect_network(self.vm,
                                                     self.network,
                                                     Mock(spec=vim.Network),
                                                     '',
                                                     logger=Mock())
        self.assertFalse(mapping[0].connect)

    def test_connect_vnic_to_networks(self):
        mapping = [ConnectRequest('vnic 1', (Mock(spec=vim.Network), None))]
        res = self.configurer.connect_vnic_to_networks(self.vm,
                                                       mapping,
                                                       Mock(spec=vim.Network),
                                                       [],
                                                       logger=Mock())
        self.assertIsNotNone(res[0].vnic)

    def test_disconnect_network_that_two_vms_have(self):
        def side_effect(*args, **keys):
            del self.network.name

        self.network.vm = None
        self.port_group_name_generator.is_generated_name = MagicMock(
            return_value=True)
        self.configurer.destroy_port_group_task = MagicMock(
            side_effect=side_effect)
        self.configurer.erase_network_by_mapping([self.network, self.network],
                                                 [],
                                                 logger=Mock())

    def test_disconnect_vm_with_three_networks(self):
        def side_effect(*args, **keys):
            del args[0].name

        self.network.vm = None
        self.network2.vm = None
        self.network3.vm = None
        self.port_group_name_generator.is_generated_name = MagicMock(
            return_value=True)
        self.configurer.destroy_port_group_task = MagicMock(
            side_effect=side_effect)
        self.configurer.erase_network_by_mapping(
            [self.network, self.network2, self.network3], [], logger=Mock())

        # Assert
        self.assertFalse(hasattr(self.network, 'name'))
        self.assertFalse(hasattr(self.network2, 'name'))
        self.assertFalse(hasattr(self.network3, 'name'))