def test_deploy_clone_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)

        template_resource_model = vCenterVMFromTemplateResourceModel()

        deploy_params = DeployFromTemplateDetails(template_resource_model, 'VM Deployment')

        deploy_command = DeployCommand(deployer)

        resource_context = Mock()

        # act
        result = deploy_command.execute_deploy_clone_from_vm(
            si=si,
            logger=Mock(),
            vcenter_data_model=Mock(),
            deployment_params=deploy_params)

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

        cred = TestCredentials()
        pv_service = pyVmomiService(SmartConnect, Disconnect)
        si = pv_service.connect(cred.host, cred.username, cred.password)
        service = OvfImageDeployerService('C:\\Program Files\\VMware\\VMware OVF Tool\\ovftool.exe', Mock())
        deployer = VirtualMachineDeployer(pv_service, generate_unique_name, service)

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

        params = DeployDataHolder(
            {
                "image_url": "http://192.168.65.88/ovf/Debian%2064%20-%20Yoav.ovf",
                "cluster_name": "QualiSB Cluster",
                "resource_pool": "LiverPool",
                "datastore_name": "datastore1",
                "datacenter_name": "QualiSB",
                "power_on": True,
                "app_name": "appName 1",
                "vm_folder": "Raz 2"
            })

        deploy_command = DeployCommand(deployer)
        # act
        result = deploy_command.execute_deploy_from_image(si, params, cred)

        # assert
        self.assertIsNotNone(result)
示例#3
0
    def test_deploy_image_execute(self):
        deployer = Mock()
        si = Mock()
        deployment_params = Mock()
        connectivity = Mock()
        res = Mock()
        deployer.deploy_from_image = Mock(return_value=res)
        session = Mock()
        vcenter_data_model = Mock()

        deploy_command = DeployCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_image(
            si=si,
            logger=Mock(),
            session=session,
            vcenter_data_model=vcenter_data_model,
            deployment_params=deployment_params,
            resource_context=connectivity)

        # assert
        self.assertTrue(result)
        self.assertTrue(
            deployer.deploy_from_image.called_with(si, deployment_params,
                                                   connectivity))
    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 = DeployCommand(deployer)

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

        # assert
        self.assertIsNotNone(result)
    def test_deploy_image(self):
        # arrange

        cred = TestCredentials()
        pv_service = pyVmomiService(SmartConnect, Disconnect)
        si = pv_service.connect(cred.host, cred.username, cred.password)
        service = OvfImageDeployerService(
            'C:\\Program Files\\VMware\\VMware OVF Tool\\ovftool.exe', Mock())
        deployer = VirtualMachineDeployer(pv_service, generate_unique_name,
                                          service)

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

        params = DeployDataHolder({
            "image_url": "http://192.168.65.88/ovf/Debian%2064%20-%20Yoav.ovf",
            "cluster_name": "QualiSB Cluster",
            "resource_pool": "LiverPool",
            "datastore_name": "datastore1",
            "datacenter_name": "QualiSB",
            "power_on": True,
            "app_name": "appName 1",
            "vm_folder": "Raz 2"
        })

        deploy_command = DeployCommand(deployer)
        # act
        result = deploy_command.execute_deploy_from_image(si, params, cred)

        # assert
        self.assertIsNotNone(result)
    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 = DeployCommand(deployer)

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

        # assert
        self.assertIsNotNone(result)
示例#7
0
    def test_deploy_clone_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)

        reservation_id = Mock()
        logger = Mock()

        vcenter_data_model = Mock()
        vcenter_data_model.default_datacenter = 'QualiSB'
        vcenter_data_model.vm_location = 'TargetFolder'

        template_resource_model = vCenterVMFromTemplateResourceModel()

        deploy_params = DeployFromTemplateDetails(template_resource_model,
                                                  'VM Deployment')

        deploy_command = DeployCommand(deployer)

        resource_context = Mock()
        cancellation_context = object()

        # act
        result = deploy_command.execute_deploy_clone_from_vm(
            si=si,
            logger=logger,
            vcenter_data_model=vcenter_data_model,
            deployment_params=deploy_params,
            reservation_id=reservation_id,
            cancellation_context=cancellation_context,
            folder_manager=Mock())

        # assert
        self.assertTrue(result)
        deployer.deploy_clone_from_vm.assert_called_once_with(
            si, logger, deploy_params, vcenter_data_model, reservation_id,
            cancellation_context)
示例#8
0
    def test_deploy_image_execute(self):
        deployer = Mock()
        si = Mock()
        deployment_params = Mock()
        deployment_params.template_resource_model.vm_location = 'SomeFolder'

        connectivity = Mock()
        res = Mock()
        deployer.deploy_from_image = Mock(return_value=res)
        session = Mock()
        vcenter_data_model = Mock()
        vcenter_data_model.default_datacenter = 'QualiSB'
        logger = Mock()
        reservation_id = Mock()

        deploy_command = DeployCommand(deployer)
        cancellation_context = object()

        # act
        folder_manager = Mock()
        result = deploy_command.execute_deploy_from_image(
            si=si,
            logger=logger,
            session=session,
            vcenter_data_model=vcenter_data_model,
            deployment_params=deployment_params,
            resource_context=connectivity,
            reservation_id=reservation_id,
            cancellation_context=cancellation_context,
            folder_manager=folder_manager)

        # assert
        self.assertTrue(result)
        deployer.deploy_from_image.assert_called_once_with(
            si=si,
            logger=logger,
            session=session,
            vcenter_data_model=vcenter_data_model,
            data_holder=deployment_params,
            resource_context=connectivity,
            reservation_id=reservation_id,
            cancellation_context=cancellation_context)
    def test_deploy_image_execute(self):
        deployer = Mock()
        si = Mock()
        deployment_params = Mock()
        connectivity = Mock()
        res = Mock()
        deployer.deploy_from_image = Mock(return_value=res)
        session = Mock()
        vcenter_data_model = Mock()

        deploy_command = DeployCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_image(si=si,
                                                          logger=Mock(),
                                                          session=session,
                                                          vcenter_data_model=vcenter_data_model,
                                                          deployment_params=deployment_params,
                                                          resource_context=connectivity)

        # assert
        self.assertTrue(result)
        self.assertTrue(deployer.deploy_from_image.called_with(si, deployment_params, connectivity))
示例#10
0
    def test_deploy_clone_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)

        template_resource_model = vCenterVMFromTemplateResourceModel()

        deploy_params = DeployFromTemplateDetails(template_resource_model,
                                                  'VM Deployment')

        deploy_command = DeployCommand(deployer)

        resource_context = Mock()

        # act
        result = deploy_command.execute_deploy_clone_from_vm(
            si=si,
            logger=Mock(),
            vcenter_data_model=Mock(),
            deployment_params=deploy_params)

        # assert
        self.assertTrue(result)
        self.assertTrue(
            deployer.deploy_from_template.called_with(si, deploy_params,
                                                      resource_context))
示例#11
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)