def integrationtest_attach_vnic(self, network):
        nicspes = VNicService.vnic_new_attached_to_network(network)
        path = "{}/{}".format(self.vcenter_name, self.virtual_machine_path)
        vm = self.py_vmomi_service.find_vm_by_name(self.si, path, self.virtual_machine_name)
        if not vm:
            print "No VM named '{}/{}'".format(path, self.virtual_machine_name)
            return
        print "VM found. \n{}".format(vm)

        task = VNicService.vnic_add_to_vm_task(nicspes, vm)
        self.synchronous_task_waiter.wait_for_task(task)
Ejemplo n.º 2
0
    def integrationtest_attach_vnic(self, network):
        nicspes = VNicService.vnic_new_attached_to_network(network)
        path = "{}/{}".format(self.vcenter_name, self.virtual_machine_path)
        vm = self.py_vmomi_service.find_vm_by_name(self.si, path,
                                                   self.virtual_machine_name)
        if not vm:
            print "No VM named '{}/{}'".format(path, self.virtual_machine_name)
            return
        print "VM found. \n{}".format(vm)

        task = VNicService.vnic_add_to_vm_task(nicspes, vm)
        self.synchronous_task_waiter.wait_for_task(task)
Ejemplo n.º 3
0
    def __init__(self):
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cloudshell_data_retriever_service = CloudshellDataRetrieverService()
        resource_connection_details_retriever = ResourceConnectionDetailsRetriever(
            helpers, cloudshell_data_retriever_service)
        resource_remover = CloudshellResourceRemover(helpers)
        command_wrapper = CommandWrapper(getLogger, py_vmomi_service)
        template_deployer = VirtualMachineDeployer(py_vmomi_service,
                                                   generate_unique_name)

        deploy_from_template_command = DeployFromTemplateCommand(
            template_deployer)

        resource_model_parser = ResourceModelParser()
        vc_model_retriever = VCenterDataModelRetriever(helpers,
                                                       resource_model_parser)
        vc_data_model = vc_model_retriever.get_vcenter_data_model()

        #vnic_to_network_mapper = VnicToNetworkMapper(name_generator, vc_data_model.default_network)
        port_group_name_generator = DvPortGroupNameGenerator()
        vnic_to_network_mapper = VnicToNetworkMapper(port_group_name_generator)

        # Virtual Switch Connect
        synchronous_task_waiter = SynchronousTaskWaiter()
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service,
                                                   synchronous_task_waiter)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(
            py_vmomi_service, synchronous_task_waiter, vnic_to_network_mapper,
            VNicService())
        virtual_switch_to_machine_connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)

        virtual_switch_connect_command = VirtualSwitchConnectCommand(
            py_vmomi_service, virtual_switch_to_machine_connector,
            DvPortGroupNameGenerator(), VlanSpecFactory(), VLanIdRangeParser(),
            getLogger('VirtualSwitchConnectCommand'))

        # Virtual Switch Revoke
        virtual_switch_disconnect_command = \
            VirtualSwitchToMachineDisconnectCommand(py_vmomi_service,
                                                    virtual_machine_port_group_configurer,
                                                    vc_data_model.default_network)

        destroy_virtual_machine_command = DestroyVirtualMachineCommand(
            py_vmomi_service, resource_remover,
            virtual_switch_disconnect_command)
        # Power Command
        vm_power_management_command = VirtualMachinePowerManagementCommand(
            py_vmomi_service, synchronous_task_waiter)
        # Refresh IP command
        refresh_ip_command = RefreshIpCommand(
            py_vmomi_service, cloudshell_data_retriever_service, helpers,
            resource_model_parser)

        self.commandExecuterService = CommandExecuterService(
            jsonpickle, helpers, command_wrapper,
            resource_connection_details_retriever, vc_data_model,
            destroy_virtual_machine_command, deploy_from_template_command,
            virtual_switch_connect_command, virtual_switch_disconnect_command,
            vm_power_management_command, refresh_ip_command)
Ejemplo n.º 4
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)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(py_vmomi_service,
                                                                                  synchronous_task_waiter,
                                                                                  mapper,
                                                                                  VNicService())

        mapping = VmNetworkMapping()
        mapping.vlan_id = [vim.NumericRange(start=65, end=65)]
        mapping.dv_port_name = DvPortGroupNameGenerator().generate_port_group_name(65)
        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
Ejemplo n.º 5
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.port_group_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)

        vnic_updater = VnicUpdater(helpers)
        command = VirtualSwitchConnectCommand(py_vmomi_service, connector, name_gen, vlan_spec, range_fac, vnic_updater)

        command.connect_to_networks(si, vm_uuid, [mapping], 'QualiSB/anetwork')
Ejemplo n.º 6
0
    def integrationtest(self):
        resource_connection_details_retriever = Mock()
        credentials = TestCredentials()
        resource_connection_details_retriever.connection_details = Mock(
                return_value=VCenterConnectionDetails(credentials.host, credentials.username, credentials.password))
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        synchronous_task_waiter = SynchronousTaskWaiter()
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service, synchronous_task_waiter)

        pg_name_generator = DvPortGroupNameGenerator
        vnic_to_network_mapper = VnicToNetworkMapper(pg_name_generator)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(py_vmomi_service,
                                                                                  synchronous_task_waiter,
                                                                                  vnic_to_network_mapper,
                                                                                  VNicService())

        virtual_switch_to_machine_connector = VirtualSwitchToMachineConnector(dv_port_group_creator,
                                                                              virtual_machine_port_group_configurer)

        si = py_vmomi_service.connect(credentials.host, credentials.username,
                                      credentials.password,
                                      credentials.port)



        virtual_machine_path = 'Boris'
        virtual_machine_name = 'boris1'
        vm = py_vmomi_service.get_obj(si.content, [vim.VirtualMachine], virtual_machine_name)
        vm_uuid = vm.config.uuid
        #vm_uuid = self.get_vm_uuid(py_vmomi_service, si, virtual_machine_name)
        port_group_path = 'QualiSB'
        dv_switch_path = 'QualiSB'
        dv_switch_name = 'dvSwitch'
        dv_port_name = 'boris_group59'
Ejemplo n.º 7
0
    def test_device_attahed_to_network_standard(self):

        self.assertFalse(VNicService.device_is_attached_to_network(None, None))

        network_name = "TEST"
        device = Mock()
        device.backing = Mock()
        device.backing.network = Mock()
        device.backing.network.name = network_name
        self.assertTrue(VNicService.device_is_attached_to_network(device, network_name))

        network = Mock(spec=vim.Network)
        network.name = "xnet"
        nicspec = Mock()

        nicspec.device = device
        res = VNicService.vnic_attach_to_network_standard(nicspec, network)
        self.assertEquals(res.device.backing.network.name, "xnet")
Ejemplo n.º 8
0
    def test_device_attahed_to_network_distributed(self):
        network_name = "PORT-GROUP"
        device = Mock()
        device.backing = MagicMock()
        device.backing.port = Mock()
        hasattr(device.backing, "network")
        del device.backing.network
        device.backing.port.portgroupKey = network_name
        self.assertTrue(VNicService.device_is_attached_to_network(device, network_name))

        port_group = Mock(spec=vim.dvs.DistributedVirtualPortgroup)
        port_group.key = "group_net"
        port_group.config.distributedVirtualSwitch.uuid = "6686"
        nicspec = Mock()

        nicspec.device = device
        res = VNicService.vnic_attach_to_network_distributed(nicspec, port_group)
        self.assertEquals(res.device.backing.port.portgroupKey, "group_net")
    def test_is_device_match_network_not_found(self):
        # arrange
        device = Mock()
        device.backing = Mock(spec=[])

        virtual_switch_to_machine_connector = VirtualSwitchToMachineDisconnectCommand(Mock(), Mock(), 'anetwork')

        # act
        # res = virtual_switch_to_machine_connector.is_device_match_network(device, 'Fake name')
        res = VNicService.device_is_attached_to_network(device, 'Fake name')

        # assert
        self.assertFalse(res)
Ejemplo n.º 10
0
    def test_is_device_match_network_not_found(self):
        # arrange
        device = Mock()
        device.backing = Mock(spec=[])

        virtual_switch_to_machine_connector = VirtualSwitchToMachineDisconnectCommand(
            Mock(), Mock(), 'anetwork')

        # act
        # res = virtual_switch_to_machine_connector.is_device_match_network(device, 'Fake name')
        res = VNicService.device_is_attached_to_network(device, 'Fake name')

        # assert
        self.assertFalse(res)
    def test_is_device_match_network_other_type(self):
        # arrange
        backing = Mock(spec=[])
        device = Mock()
        nerwork = Mock()

        device.backing = backing
        backing.network = nerwork
        nerwork.name = 'vln name or network name'

        # act
        res = VNicService.device_is_attached_to_network(device, nerwork.name)

        # assert
        self.assertTrue(res)
    def test_is_device_match_network_port_type(self):
        # arrange
        backing = Mock(spec=[])
        device = Mock()
        port = Mock()

        device.backing = backing
        backing.port = port
        port.portgroupKey = 'port key'

        # act
        res = VNicService.device_is_attached_to_network(device, port.portgroupKey)

        # assert
        self.assertTrue(res)
    def remove_vnic(self, si, vm_uuid, network_name=None):
        """
        disconnect all of the network adapter of the vm
        :param <str> si:
        :param <str> vm_uuid: the uuid of the vm
        :param <str> network_name: the name of the specific network to disconnect & vNic remove
        :return:
        """
        _logger.debug(u"Revoking ALL Interfaces from VM '{}'...".format(vm_uuid))
        vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid)

        condition = lambda device: \
            VNicService.device_is_attached_to_network(device, network_name) if network_name else lambda x: True

        return self.remove_interfaces_from_vm_task(vm, condition)
Ejemplo n.º 14
0
    def test_is_device_match_network_other_type(self):
        # arrange
        backing = Mock(spec=[])
        device = Mock()
        nerwork = Mock()

        device.backing = backing
        backing.network = nerwork
        nerwork.name = 'vln name or network name'

        # act
        res = VNicService.device_is_attached_to_network(device, nerwork.name)

        # assert
        self.assertTrue(res)
    def remove_vnic(self, si, vm_uuid, network_name=None):
        """
        disconnect all of the network adapter of the vm
        :param <str> si:
        :param <str> vm_uuid: the uuid of the vm
        :param <str> network_name: the name of the specific network to disconnect & vNic remove
        :return:
        """
        _logger.debug(
            u"Revoking ALL Interfaces from VM '{}'...".format(vm_uuid))
        vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid)

        condition = lambda device: \
            VNicService.device_is_attached_to_network(device, network_name) if network_name else lambda x: True

        return self.remove_interfaces_from_vm_task(vm, condition)
Ejemplo n.º 16
0
    def test_is_device_match_network_port_type(self):
        # arrange
        backing = Mock(spec=[])
        device = Mock()
        port = Mock()

        device.backing = backing
        backing.port = port
        port.portgroupKey = 'port key'

        # act
        res = VNicService.device_is_attached_to_network(
            device, port.portgroupKey)

        # assert
        self.assertTrue(res)
Ejemplo n.º 17
0
    def setUp(self):
        self._si = None

        self.vm = None

        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'TestVM'
        self.vm_uuid = None

        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_switch_name = 'dvSwitch'
        #self.dv_port_group_name = 'aa-dvPortGroup3B'
        self.dv_port_group_name = 'dvPortGroup'
        self.standard_network_name = "Anetwork"

        try:
            self.py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
            self.credentials = TestCredentials()
            self.resource_connection_details_retriever = Mock()
            self.resource_connection_details_retriever.connection_details = Mock(
                return_value=VCenterConnectionDetails(
                    self.credentials.host, self.credentials.username,
                    self.credentials.password))

            self.synchronous_task_waiter = SynchronousTaskWaiter()
            self.pg_name_generator = DvPortGroupNameGenerator
            self.vnic_to_network_mapper = VnicToNetworkMapper(
                self.pg_name_generator)

            self.configurer = VirtualMachinePortGroupConfigurer(
                self.py_vmomi_service, self.synchronous_task_waiter,
                self.vnic_to_network_mapper, VNicService())
        except:
            print "Infrastructure not available - pretty OK or UnitTesting environment"
Ejemplo n.º 18
0
 def test_set_connectiv(self):
     nicspec = Mock()
     nicspec.device = Mock()
     connect_status = True
     nicspec = VNicService.vnic_set_connectivity_status(nicspec, connect_status)
     self.assertEquals(nicspec.device.connectable.connected, connect_status)
Ejemplo n.º 19
0
 def test_vnic_is_attachet_to_network(self):
     nicspec = Mock()
     nicspec.device = Mock()
     res = VNicService.vnic_is_attachet_to_network(nicspec, Mock())
     self.assertFalse(res)
Ejemplo n.º 20
0
 def test_compose_empty(self):
     nicspec = VNicService.vnic_compose_empty()
     self.assertTrue(isinstance(nicspec, vim.vm.device.VirtualDeviceSpec))
     self.assertTrue(isinstance(nicspec.device, vim.vm.device.VirtualVmxnet3))
     self.assertTrue(isinstance(nicspec.device.connectable, vim.vm.device.VirtualDevice.ConnectInfo))
Ejemplo n.º 21
0
 def test_xx(self):
     vm = Mock()
     vm.ReconfigVM_Task = lambda x: isinstance(x,  vim.vm.ConfigSpec)
     nicspec = Mock()
     res = VNicService.vnic_add_to_vm_task(nicspec, vm)
     self.assertIsNone(res)