Ejemplo n.º 1
0
    def test_deploy_execute(self):
        # arrange
        deployer = Mock()
        si = Mock()
        template_model = Mock()

        deploy_res = dict()
        deploy_res['vm_path'] = 'path'
        deploy_res['vm_name'] = 'name'
        deploy_res['uuid'] = 'uuid'

        template_model.template_name = 'temp name'
        template_model.vm_folder = 'temp folder'
        deployer.deploy_from_template = Mock(return_value=deploy_res)

        deploy_params = DeployDataHolder.create_from_params(template_model,
                                                            'datastore_name',
                                                            'vm_cluster_model',
                                                            'power_on')

        deploy_command = DeployFromTemplateCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_template(si, deploy_params)

        # assert
        self.assertTrue(result)
        self.assertTrue(deployer.deploy_from_template.called_with(si, deploy_params))
    def test_deploy_template(self):
        # arrange

        cred = TestCredentials()
        pv_service = pyVmomiService(SmartConnect, Disconnect)
        si = pv_service.connect(cred.host, cred.username, cred.password)
        deployer = VirtualMachineDeployer(pv_service, generate_unique_name)

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

        deploy_params = DeployDataHolder(
            {
                "template_model": {
                    "vCenter_resource_name": "QualiSB",
                    "vm_folder": "QualiSB/Raz",
                    "template_name": "2",
                },
                "vm_cluster_model": {"cluster_name": "QualiSB Cluster", "resource_pool": "IT"},
                "datastore_name": "eric ds cluster",
                "power_on": False,
            }
        )

        deploy_command = DeployFromTemplateCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_template(si, deploy_params)

        # assert
        self.assertIsNotNone(result)
Ejemplo n.º 3
0
    def test_deploy_execute(self):
        # arrange
        deployer = Mock()
        si = Mock()
        template_model = Mock()

        deploy_res = dict()
        deploy_res['vm_path'] = 'path'
        deploy_res['vm_name'] = 'name'
        deploy_res['uuid'] = 'uuid'

        template_model.template_name = 'temp name'
        template_model.vm_folder = 'temp folder'
        deployer.deploy_from_template = Mock(return_value=deploy_res)

        deploy_params = DeployDataHolder.create_from_params(
            template_model, 'datastore_name', 'vm_cluster_model', 'power_on')

        deploy_command = DeployFromTemplateCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_template(si, deploy_params)

        # assert
        self.assertTrue(result)
        self.assertTrue(
            deployer.deploy_from_template.called_with(si, deploy_params))
    def test_deploy_template(self):
        # arrange

        cred = TestCredentials()
        pv_service = pyVmomiService(SmartConnect, Disconnect)
        si = pv_service.connect(cred.host, cred.username, cred.password)
        deployer = VirtualMachineDeployer(pv_service, generate_unique_name)

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

        deploy_params = DeployDataHolder({
            "template_model": {
                "vCenter_resource_name": "QualiSB",
                "vm_folder": "QualiSB/Raz",
                "template_name": "2"
            },
            "vm_cluster_model": {
                "cluster_name": "QualiSB Cluster",
                "resource_pool": "IT"
            },
            "datastore_name": "eric ds cluster",
            "power_on": False
        })

        deploy_command = DeployFromTemplateCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_template(si, deploy_params)

        # assert
        self.assertIsNotNone(result)
Ejemplo n.º 5
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)