summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-06 00:38:13 +0000
committerGerrit Code Review <review@openstack.org>2013-01-06 00:38:13 +0000
commit850e5d6bf989b15ca67396dc246e72f7de7524a8 (patch)
treef8b7bb1de0b1d78c23f216e941c101e6e3bf9394 /nova/virt
parentcd0f02113110bdc25eea4f57db640e906636c814 (diff)
parent0df60e98790c722aef59d0015c209ea0944e62c0 (diff)
Merge "Adding two snapshot related task states"
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/driver.py2
-rw-r--r--nova/virt/fake.py4
-rw-r--r--nova/virt/hyperv/driver.py4
-rw-r--r--nova/virt/hyperv/snapshotops.py7
-rw-r--r--nova/virt/libvirt/driver.py7
-rw-r--r--nova/virt/vmwareapi/driver.py4
-rw-r--r--nova/virt/vmwareapi/vmops.py6
-rw-r--r--nova/virt/xenapi/driver.py4
-rw-r--r--nova/virt/xenapi/vm_utils.py9
-rw-r--r--nova/virt/xenapi/vmops.py8
10 files changed, 41 insertions, 14 deletions
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index 9291ac6f8..7d627e80c 100644
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -280,7 +280,7 @@ class ComputeDriver(object):
"""
raise NotImplementedError()
- def snapshot(self, context, instance, image_id):
+ def snapshot(self, context, instance, image_id, update_task_state):
"""
Snapshots the specified instance.
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index c9cd41680..5d3b3c926 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -26,6 +26,7 @@ semantics of real hypervisor connections.
"""
from nova.compute import power_state
+from nova.compute import task_states
from nova import db
from nova import exception
from nova.openstack.common import log as logging
@@ -122,9 +123,10 @@ class FakeDriver(driver.ComputeDriver):
fake_instance = FakeInstance(name, state)
self.instances[name] = fake_instance
- def snapshot(self, context, instance, name):
+ def snapshot(self, context, instance, name, update_task_state):
if not instance['name'] in self.instances:
raise exception.InstanceNotRunning(instance_id=instance['uuid'])
+ update_task_state(task_state=task_states.IMAGE_UPLOADING)
def reboot(self, instance, network_info, reboot_type,
block_device_info=None):
diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py
index 4359b1007..2b57ba0b1 100644
--- a/nova/virt/hyperv/driver.py
+++ b/nova/virt/hyperv/driver.py
@@ -128,8 +128,8 @@ class HyperVDriver(driver.ComputeDriver):
def host_power_action(self, host, action):
return self._hostops.host_power_action(host, action)
- def snapshot(self, context, instance, name):
- self._snapshotops.snapshot(context, instance, name)
+ def snapshot(self, context, instance, name, update_task_state):
+ self._snapshotops.snapshot(context, instance, name, update_task_state)
def pause(self, instance):
self._vmops.pause(instance)
diff --git a/nova/virt/hyperv/snapshotops.py b/nova/virt/hyperv/snapshotops.py
index 5dc19ebb1..cdc6e45a4 100644
--- a/nova/virt/hyperv/snapshotops.py
+++ b/nova/virt/hyperv/snapshotops.py
@@ -22,6 +22,7 @@ import os
import shutil
import sys
+from nova.compute import task_states
from nova import exception
from nova.image import glance
from nova.openstack.common import cfg
@@ -45,7 +46,7 @@ class SnapshotOps(baseops.BaseOps):
super(SnapshotOps, self).__init__()
self._vmutils = vmutils.VMUtils()
- def snapshot(self, context, instance, name):
+ def snapshot(self, context, instance, name, update_task_state):
"""Create snapshot from a running VM instance."""
instance_name = instance["name"]
vm = self._vmutils.lookup(self._conn, instance_name)
@@ -70,6 +71,8 @@ class SnapshotOps(baseops.BaseOps):
raise vmutils.HyperVException(
_('Failed to create snapshot for VM %s') %
instance_name)
+ else:
+ update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD)
export_folder = None
f = None
@@ -164,6 +167,8 @@ class SnapshotOps(baseops.BaseOps):
_("Updating Glance image %(image_id)s with content from "
"merged disk %(image_vhd_path)s"),
locals())
+ update_task_state(task_state=task_states.IMAGE_UPLOADING,
+ expected_state=task_states.IMAGE_PENDING_UPLOAD)
glance_image_service.update(context, image_id, image_metadata, f)
LOG.debug(_("Snapshot image %(image_id)s updated for VM "
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 365e49a8e..6befe429e 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -57,6 +57,7 @@ from xml.dom import minidom
from nova.api.metadata import base as instance_metadata
from nova import block_device
from nova.compute import power_state
+from nova.compute import task_states
from nova.compute import vm_mode
from nova import context as nova_context
from nova import exception
@@ -736,7 +737,7 @@ class LibvirtDriver(driver.ComputeDriver):
mount_device)
@exception.wrap_exception()
- def snapshot(self, context, instance, image_href):
+ def snapshot(self, context, instance, image_href, update_task_state):
"""Create snapshot from a running VM instance.
This command only works with qemu 0.14+
@@ -804,6 +805,7 @@ class LibvirtDriver(driver.ComputeDriver):
image_type=source_format)
snapshot.create()
+ update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD)
# Export the snapshot to a raw image
snapshot_directory = CONF.libvirt_snapshots_directory
@@ -821,6 +823,9 @@ class LibvirtDriver(driver.ComputeDriver):
self._create_domain(domain=virt_dom)
# Upload that image to the image service
+
+ update_task_state(task_state=task_states.IMAGE_UPLOADING,
+ expected_state=task_states.IMAGE_PENDING_UPLOAD)
with libvirt_utils.file_open(out_path) as image_file:
image_service.update(context,
image_href,
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 51df7a38a..5261a4776 100644
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -127,9 +127,9 @@ class VMWareESXDriver(driver.ComputeDriver):
"""Create VM instance."""
self._vmops.spawn(context, instance, image_meta, network_info)
- def snapshot(self, context, instance, name):
+ def snapshot(self, context, instance, name, update_task_state):
"""Create snapshot from a running VM instance."""
- self._vmops.snapshot(context, instance, name)
+ self._vmops.snapshot(context, instance, name, update_task_state)
def reboot(self, instance, network_info, reboot_type,
block_device_info=None):
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index 5d2685b18..b5b5d1fff 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -27,6 +27,7 @@ import urllib2
import uuid
from nova.compute import power_state
+from nova.compute import task_states
from nova import exception
from nova.openstack.common import cfg
from nova.openstack.common import importutils
@@ -333,7 +334,7 @@ class VMWareVMOps(object):
LOG.debug(_("Powered on the VM instance"), instance=instance)
_power_on_vm()
- def snapshot(self, context, instance, snapshot_name):
+ def snapshot(self, context, instance, snapshot_name, update_task_state):
"""Create snapshot from a running VM instance.
Steps followed are:
@@ -390,6 +391,7 @@ class VMWareVMOps(object):
instance=instance)
_create_vm_snapshot()
+ update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD)
def _check_if_tmp_folder_exists():
# Copy the contents of the VM that were there just before the
@@ -468,6 +470,8 @@ class VMWareVMOps(object):
LOG.debug(_("Uploaded image %s") % snapshot_name,
instance=instance)
+ update_task_state(task_state=task_states.IMAGE_UPLOADING,
+ expected_state=task_states.IMAGE_PENDING_UPLOAD)
_upload_vmdk_to_image_repository()
def _clean_temp_data():
diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py
index 10bc99fef..d3047d364 100644
--- a/nova/virt/xenapi/driver.py
+++ b/nova/virt/xenapi/driver.py
@@ -188,9 +188,9 @@ class XenAPIDriver(driver.ComputeDriver):
network_info, image_meta, resize_instance,
block_device_info)
- def snapshot(self, context, instance, image_id):
+ def snapshot(self, context, instance, image_id, update_task_state):
""" Create snapshot from a running VM instance """
- self._vmops.snapshot(context, instance, image_id)
+ self._vmops.snapshot(context, instance, image_id, update_task_state)
def reboot(self, instance, network_info, reboot_type,
block_device_info=None):
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index ee36cea0b..adb43a743 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -36,6 +36,7 @@ from eventlet import greenthread
from nova import block_device
from nova.compute import power_state
+from nova.compute import task_states
from nova import exception
from nova.image import glance
from nova.openstack.common import cfg
@@ -604,7 +605,11 @@ def get_vdi_for_vm_safely(session, vm_ref):
@contextlib.contextmanager
-def snapshot_attached_here(session, instance, vm_ref, label):
+def snapshot_attached_here(session, instance, vm_ref, label, *args):
+ update_task_state = None
+ if len(args) == 1:
+ update_task_state = args[0]
+
"""Snapshot the root disk only. Return a list of uuids for the vhds
in the chain.
"""
@@ -616,6 +621,8 @@ def snapshot_attached_here(session, instance, vm_ref, label):
sr_ref = vm_vdi_rec["SR"]
snapshot_ref = session.call_xenapi("VDI.snapshot", vm_vdi_ref, {})
+ if update_task_state is not None:
+ update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD)
try:
snapshot_rec = session.call_xenapi("VDI.get_record", snapshot_ref)
_wait_for_vhd_coalesce(session, instance, sr_ref, vm_vdi_ref,
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index a96a90f0e..fbf3e0599 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -28,6 +28,7 @@ import netaddr
from nova.compute import api as compute
from nova.compute import power_state
+from nova.compute import task_states
from nova.compute import vm_mode
from nova.compute import vm_states
from nova import context as nova_context
@@ -626,7 +627,7 @@ class VMOps(object):
vm,
"start")
- def snapshot(self, context, instance, image_id):
+ def snapshot(self, context, instance, image_id, update_task_state):
"""Create snapshot from a running VM instance.
:param context: request context
@@ -654,7 +655,10 @@ class VMOps(object):
label = "%s-snapshot" % instance['name']
with vm_utils.snapshot_attached_here(
- self._session, instance, vm_ref, label) as vdi_uuids:
+ self._session, instance, vm_ref, label,
+ update_task_state) as vdi_uuids:
+ update_task_state(task_state=task_states.IMAGE_UPLOADING,
+ expected_state=task_states.IMAGE_PENDING_UPLOAD)
vm_utils.upload_image(
context, self._session, instance, vdi_uuids, image_id)