Exemplo n.º 1
0
    def snapshot(self, context, instance, name, update_task_state):
        if (vixutils.get_vix_host_type() == vixutils.VIX_VMWARE_PLAYER):
            raise NotImplementedError(_("VMware Player does not support "
                                        "snapshots"))

        # TODO(alexpilotti): Consider raising an exception when a snapshot
        # of a CoW instance is attemped

        instance_name = instance['name']
        vmx_path = self._pathutils.get_vmx_path(instance_name)

        update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD)

        with self._conn.open_vm(vmx_path) as vm:
            with vm.create_snapshot(name="Nova snapshot") as snapshot:
                try:
                    root_vmdk_path = self._pathutils.get_root_vmdk_path(
                        instance_name)

                    update_task_state(
                        task_state=task_states.IMAGE_UPLOADING,
                        expected_state=task_states.IMAGE_PENDING_UPLOAD)

                    self._image_cache.save_glance_image(context, name,
                                                        root_vmdk_path)
                finally:
                    vm.remove_snapshot(snapshot)
Exemplo n.º 2
0
 def _check_player_compatibility(self, cow):
     if vixutils.get_vix_host_type() == vixutils.VIX_VMWARE_PLAYER:
         if cow:
             raise NotImplementedError(_("CoW images are not supported on "
                                         "VMware Player. \"use_cow_images\""
                                         " must be set to false"))
         if CONF.vnc_enabled:
             raise NotImplementedError(_("VNC connections are not supported"
                                         " on VMWare Player"))
Exemplo n.º 3
0
    def _test_get_vix_host_type(self,
                                mock_get_vmx_value,
                                platform,
                                path_exists=False,
                                fake_key=None,
                                product_name=None):
        fake_value = mock.MagicMock()
        sys.platform = platform

        os.path.exists = mock.MagicMock()
        os.path.exists.return_value = path_exists

        _winreg.EnumValue = mock.MagicMock()
        _winreg.EnumValue.return_value = fake_value
        _winreg.QueryValueEx = mock.MagicMock()
        _winreg.QueryValueEx.return_value = product_name

        if platform == 'darwin' and path_exists:
            vixutils._host_type = None
            response = vixutils.get_vix_host_type()
            os.path.exists.assert_called_with(
                "/Applications/VMware Fusion.app")
            self.assertEqual(response,
                             vixlib.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION)

        elif platform == 'win32' and fake_key is not None:
            vixutils._host_type = None
            response = vixutils.get_vix_host_type()
            _winreg.OpenKey = mock.MagicMock(return_value=fake_key)
            print response
            self.assertEqual(_winreg.OpenKey.call_count, 2)
            _winreg.EnumValue.assert_called_with(fake_key, 0)
            _winreg.QueryValueEx.assert_called_with(fake_key, "ProductName")
            self.assertEqual(response, product_name)

        elif platform == 'linux' and product_name == "VMware Player":
            vixutils._host_type = None
            mock_get_vmx_value.return_value = product_name
            response = vixutils.get_vix_host_type()
            print response
            self.assertEqual(response, 3)
Exemplo n.º 4
0
    def _test_get_vix_host_type(self, mock_get_vmx_value,
                                platform,
                                path_exists=False,
                                fake_key=None, product_name=None):
        fake_value = mock.MagicMock()
        sys.platform = platform

        os.path.exists = mock.MagicMock()
        os.path.exists.return_value = path_exists

        _winreg.EnumValue = mock.MagicMock()
        _winreg.EnumValue.return_value = fake_value
        _winreg.QueryValueEx = mock.MagicMock()
        _winreg.QueryValueEx.return_value = product_name

        if platform == 'darwin' and path_exists:
            vixutils._host_type = None
            response = vixutils.get_vix_host_type()
            os.path.exists.assert_called_with(
                "/Applications/VMware Fusion.app")
            self.assertEqual(response,
                             vixlib.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION)

        elif platform == 'win32' and fake_key is not None:
            vixutils._host_type = None
            response = vixutils.get_vix_host_type()
            _winreg.OpenKey = mock.MagicMock(return_value=fake_key)
            print response
            self.assertEqual(_winreg.OpenKey.call_count, 2)
            _winreg.EnumValue.assert_called_with(fake_key, 0)
            _winreg.QueryValueEx.assert_called_with(fake_key, "ProductName")
            self.assertEqual(response, product_name)

        elif platform == 'linux' and product_name == "VMware Player":
            vixutils._host_type = None
            mock_get_vmx_value.return_value = product_name
            response = vixutils.get_vix_host_type()
            print response
            self.assertEqual(response, 3)