Ejemplo n.º 1
0
 def _create_vm_mock(self, vnc_port):
     vm = MagicMock()
     vm.config.extraConfig = []
     vm.config.extraConfig.append(
         vim.OptionValue(key="RemoteDisplay.vnc.port", value=str(vnc_port)))
     vm.config.extraConfig.append(
         vim.OptionValue(key="RemoteDisplay.vnc.enabled", value="True"))
     return vm
Ejemplo n.º 2
0
    def set_vnc_port(self, spec, port):
        """
        :param spec: vim.vm.ConfigSpec, the virtual machine config spec
        :param port: int, the vnc port assigned to the vm
        """
        if spec.extraConfig is None:
            spec.extraConfig = []

        spec.extraConfig.append(
            vim.OptionValue(key=self.EXTRA_CONFIG_VNC_ENABLED, value="True"))
        spec.extraConfig.append(
            vim.OptionValue(key=self.EXTRA_CONFIG_VNC_PORT, value=port))

        return spec
Ejemplo n.º 3
0
def clone_template(template, vm_name, vm_folder, relocate_spec, user_id):
    """

    :param template: template VM managed object - can be a normal VM (vim.VirtualMachine)
    :param vm_name: name the new VM will have (str)
    :param vm_folder: VIM folder object where the new VM will be created
    :param relocate_spec: VIM object describing the location
    :param user_id: the ID of the user this VM is for (str(UUID))
    :return: the new VM object (vim.VirtualMachine)
    """
    ensure_template_snapshot(template)

    guestinfos = [vim.OptionValue(key=USER_IDENTITY_FIELD_NAME, value=user_id)]

    vm_spec = vim.vm.ConfigSpec(extraConfig=guestinfos)
    clone_spec = vim.vm.CloneSpec(
        powerOn=True,
        template=False,
        location=relocate_spec,
        snapshot=template.snapshot.rootSnapshotList[0].snapshot,
        config=vm_spec)

    task = template.Clone(name=vm_name, folder=vm_folder, spec=clone_spec)
    WaitForTask(task)
    logging.info(
        f'Successfully cloned template {template.name} into a new VM named {vm_name}.'
    )
    return task.info.result
Ejemplo n.º 4
0
    def test_get_vnc_port(self, get_vm):
        vm_mock = MagicMock()
        vm_mock.config.extraConfig = [
            vim.OptionValue(key="RemoteDisplay.vnc.port", value="5901")
        ]
        get_vm.return_value = vm_mock

        port = self.vm_manager.get_vnc_port("id")
        assert_that(port, equal_to(5901))
Ejemplo n.º 5
0
 def set_large_page_support(self, disable=False):
     """Disables large page support on the ESX hypervisor
        This is done when the host memory is overcommitted.
     """
     optionManager = self.host_system.configManager.advancedOption
     option = vim.OptionValue()
     option.key = self.ALLOC_LARGE_PAGES
     if disable:
         option.value = 0L
         self._logger.warning("Disabling large page support")
     else:
         option.value = 1L
         self._logger.warning("Enabling large page support")
     optionManager.UpdateOptions([option])