Пример #1
0
    def test_refresh_ip_choose_ipv4(self):
        nic1 = Mock()
        nic1.network = 'A Network'
        nic1.ipAddress = ['192.168.1.1']

        nic2 = Mock()
        nic2.network = 'A Network'
        nic2.ipAddress = ['2001:0db8:0a0b:12f0:0000:0000:0000:0001']

        guest = Mock()
        guest.toolsStatus = 'toolsOk'
        guest.net = [nic1, nic2]

        vm = Mock()
        vm.guest = guest

        pyvmomi_service = Mock()
        pyvmomi_service.find_by_uuid = Mock(return_value=vm)

        ip_regex = self._create_custom_param('ip_regex', '')
        refresh_ip_timeout = self._create_custom_param('refresh_ip_timeout',
                                                       '10')

        resource_instance = create_autospec(ResourceInfo)
        resource_instance.ResourceModelName = 'Generic Deployed App'
        resource_instance.ResourceAttributes = {
            'vm_uuis': '123',
            'cloud_provider': 'vCenter'
        }
        resource_instance.VmDetails = create_autospec(ResourceInfoVmDetails)
        resource_instance.VmDetails.VmCustomParams = [
            ip_regex, refresh_ip_timeout
        ]

        refresh_ip_command = RefreshIpCommand(pyvmomi_service,
                                              ResourceModelParser(), Mock())
        session = Mock()
        session.UpdateResourceAddress = Mock(return_value=True)
        session.GetResourceDetails = Mock(return_value=resource_instance)
        si = Mock()

        center_resource_model = VMwarevCenterResourceModel()
        center_resource_model.default_datacenter = 'QualiSB'
        center_resource_model.holding_network = 'anetwork'
        cancellation_context = Mock()

        # Act
        refresh_ip_command.refresh_ip(
            si=si,
            session=session,
            vcenter_data_model=center_resource_model,
            vm_uuid='machine1',
            resource_name='default_network',
            cancellation_context=cancellation_context,
            logger=Mock())

        # Assert
        self.assertTrue(
            session.UpdateResourceAddress.called_with('machine1',
                                                      '192.168.1.1'))
Пример #2
0
    def test_integrationtest_refresh_ip(self):
        resource_context = Mock()
        resource_context.attributes = {
            "vCenter Template": "vCenter/Boris/Boris2-win7"
        }
        qualipy_helpers = Mock()
        qualipy_helpers.get_resource_context_details = Mock(
            return_value=resource_context)

        credentials = TestCredentials()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        si = py_vmomi_service.connect(credentials.host, credentials.username,
                                      credentials.password)
        cloudshell_data_retriever_service = Mock()
        cloudshell_data_retriever_service.getVCenterConnectionDetails = Mock(
            return_value=VCenterConnectionDetails(
                credentials.host, credentials.username, credentials.password))

        vm_resource = Mock()
        vm_resource.default_network = 'default'

        resource_model_parser = Mock()
        resource_model_parser.convert_to_resource_model = Mock(
            return_value=vm_resource)

        refresh_ip_command = RefreshIpCommand(
            py_vmomi_service, cloudshell_data_retriever_service,
            qualipy_helpers, resource_model_parser)

        # uuid = helpers.get_uuid('VM Deployment_afee8038')
        ip = refresh_ip_command.refresh_ip(
            si, '4222f613-e714-6204-8095-e282796985fb',
            'VM Deployment_afee8038')
        print ip
        pass
Пример #3
0
    def integrationtest_refresh_ip(self):
        resource_context = Mock()
        resource_context.attributes = {"vCenter Template": "vCenter/Alex/test"}
        qualipy_helpers = Mock()
        qualipy_helpers.get_resource_context_details = Mock(
            return_value=resource_context)

        credentials = TestCredentials()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cloudshell_data_retriever_service = Mock()
        cloudshell_data_retriever_service.getVCenterConnectionDetails = Mock(
            return_value=VCenterConnectionDetails(
                credentials.host, credentials.username, credentials.password))

        vm_resource = Mock()
        vm_resource.default_network = 'default'

        resource_model_parser = Mock()
        resource_model_parser.convert_to_resource_model = Mock(
            return_value=vm_resource)

        refresh_ip_command = RefreshIpCommand(
            py_vmomi_service, cloudshell_data_retriever_service,
            qualipy_helpers, resource_model_parser)

        uuid = helpers.get_uuid('vCenter-Server-Appliance-yaniv')
        refresh_ip_command.refresh_ip(uuid, '')

        pass
Пример #4
0
    def test_refresh_ip_choose_ip_by_regex(self):
        nic1 = Mock()
        nic1.network = 'A Network'
        nic1.ipAddress = ['192.168.1.1']

        nic2 = Mock()
        nic2.network = 'A Network'
        nic2.ipAddress = ['111.111.111.111']

        guest = Mock()
        guest.toolsStatus = 'toolsOk'
        guest.net = [nic1, nic2]

        vm = Mock()
        vm.guest = guest

        pyvmomi_service = Mock()
        pyvmomi_service.find_by_uuid = Mock(return_value=vm)

        ip_regex = self._create_custom_param('ip_regex', '192\.168\..*')
        refresh_ip_timeout = self._create_custom_param('refresh_ip_timeout',
                                                       '10')

        resource_model = create_autospec(GenericDeployedAppResourceModel)
        resource_model.fullname = 'Generic Deployed App'
        resource_model.vm_uuid = '123',
        resource_model.cloud_provider = 'vCenter'
        resource_model.vm_custom_params = [ip_regex, refresh_ip_timeout]

        refresh_ip_command = RefreshIpCommand(pyvmomi_service,
                                              ResourceModelParser(), Mock())
        session = Mock()
        session.UpdateResourceAddress = Mock(return_value=True)
        session.GetResourceDetails = Mock(return_value=resource_model)
        si = Mock()

        center_resource_model = VMwarevCenterResourceModel()
        center_resource_model.default_datacenter = 'QualiSB'
        center_resource_model.holding_network = 'anetwork'
        cancellation_context = Mock()

        # Act
        refresh_ip_command.refresh_ip(
            si=si,
            session=session,
            vcenter_data_model=center_resource_model,
            resource_model=resource_model,
            cancellation_context=cancellation_context,
            logger=Mock(),
            app_request_json=Mock())

        # Assert
        self.assertTrue(
            session.UpdateResourceAddress.called_with('machine1',
                                                      '192.168.1.1'))
Пример #5
0
    def test_refresh_ip_choose_ipv4(self):
        nic1 = Mock()
        nic1.network = 'A Network'
        nic1.ipAddress = ['192.168.1.1']

        nic2 = Mock()
        nic2.network = 'A Network'
        nic2.ipAddress = ['2001:0db8:0a0b:12f0:0000:0000:0000:0001']

        guest = Mock()
        guest.toolsStatus = 'toolsOk'
        guest.net = [nic1, nic2]

        vm = Mock()
        vm.guest = guest

        pyvmomi_service = Mock()
        pyvmomi_service.find_by_uuid = Mock(return_value=vm)

        ip_regex = self._create_custom_param('ip_regex', '')
        refresh_ip_timeout = self._create_custom_param('refresh_ip_timeout', '10')

        resource_instance = create_autospec(ResourceInfo)
        resource_instance.ResourceModelName = 'Generic Deployed App'
        resource_instance.ResourceAttributes = {'vm_uuis': '123',
                                                'cloud_provider': 'vCenter'
                                                }
        resource_instance.VmDetails = create_autospec(ResourceInfoVmDetails)
        resource_instance.VmDetails.VmCustomParams = [ip_regex, refresh_ip_timeout]

        refresh_ip_command = RefreshIpCommand(pyvmomi_service, ResourceModelParser(), Mock())
        session = Mock()
        session.UpdateResourceAddress = Mock(return_value=True)
        session.GetResourceDetails = Mock(return_value=resource_instance)
        si = Mock()

        center_resource_model = VMwarevCenterResourceModel()
        center_resource_model.default_datacenter = 'QualiSB'
        center_resource_model.holding_network = 'anetwork'
        cancellation_context = Mock()

        # Act
        refresh_ip_command.refresh_ip(
            si=si,
            session=session,
            vcenter_data_model=center_resource_model,
            vm_uuid='machine1',
            resource_name='default_network',
            cancellation_context=cancellation_context,
            logger=Mock(),
            app_request_json=Mock())

        # Assert
        self.assertTrue(session.UpdateResourceAddress.called_with('machine1', '192.168.1.1'))
Пример #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
 def test_refresh_ip_should_fail_static_vm(self):
     # Act
     refresh_ip_command = RefreshIpCommand(Mock(), Mock(), Mock())
     # assert
     self.assertRaises(ValueError, refresh_ip_command.refresh_ip, Mock(),
                       Mock(), Mock(), Mock(), Mock(), Mock(), None)