summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-02-15 18:01:13 +0000
committerRick Harris <rick.harris@rackspace.com>2011-02-15 18:01:13 +0000
commit15cdeef7820aacd0b1ff95da48816cba9f2544ba (patch)
tree8673902a4676f0cdf6b562be96ec2dfdeb43fc9b /plugins
parentfe6efb38ee30c5a3e532cd19faef0fec063b7446 (diff)
downloadnova-15cdeef7820aacd0b1ff95da48816cba9f2544ba.tar.gz
nova-15cdeef7820aacd0b1ff95da48816cba9f2544ba.tar.xz
nova-15cdeef7820aacd0b1ff95da48816cba9f2544ba.zip
Adding more documentation, code-cleanup
Diffstat (limited to 'plugins')
-rw-r--r--plugins/xenserver/xenapi/etc/xapi.d/plugins/glance60
1 files changed, 30 insertions, 30 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
index 0cb3b52db..2018dca5f 100644
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
@@ -21,20 +21,14 @@
# XenAPI plugin for managing glance images
#
-import base64
-import errno
-import hmac
import httplib
import os
import os.path
import pickle
-import sha
import shlex
import shutil
import subprocess
import tempfile
-import time
-import urlparse
import XenAPIPlugin
@@ -74,11 +68,14 @@ def _copy_kernel_vdi(dest,copy_args):
return filename
-def execute(cmd):
- args = shlex.split(cmd)
- proc = subprocess.Popen(
- args, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
- return proc
+def assert_process_success(proc, cmd):
+ """Ensure that the process returned a zero exit code indicating success
+ """
+ out, err = proc.communicate()
+ ret = proc.returncode
+ if ret != 0:
+ msg = "%(cmd)s returned non-zero exit code (%i): '%s'" % (ret, err)
+ raise Exception(msg)
def get_vdi(session, args):
@@ -88,6 +85,7 @@ def get_vdi(session, args):
image_id = params["image_id"]
glance_host = params["glance_host"]
glance_port = params["glance_port"]
+ uuid_stack = params["uuid_stack"]
def unbundle_xfer(sr_path, staging_path):
"""
@@ -101,17 +99,17 @@ def get_vdi(session, args):
elif resp.status != httplib.OK:
raise Exception("Unexpected response from Glance %i" % res.status)
- tar_proc = execute("tar -zx --directory=%(staging_path)s" % locals())
+ tar_args = shlex.split(
+ "tar -zx --directory=%(staging_path)s" % locals())
+ tar_proc = subprocess.Popen(
+ tar_args, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+
chunk = resp.read(CHUNK_SIZE)
while chunk:
tar_proc.stdin.write(chunk)
chunk = resp.read(CHUNK_SIZE)
- out, err = tar_proc.communicate()
- # TODO(sirp): write assert_process_success
- ret = tar_proc.returncode
- if ret != 0:
- raise Exception(
- "tar returned non-zero exit code (%i): '%s'" % (ret, err))
+
+ assert_process_success(tar_proc, "tar")
conn.close()
def fixup_vhds(sr_path, staging_path):
@@ -120,7 +118,7 @@ def get_vdi(session, args):
def rename_with_uuid(orig_path):
"""Generate a uuid and rename the file with the uuid"""
orig_dirname = os.path.dirname(orig_path)
- uuid = generate_uuid()
+ uuid = uuid_stack.pop()
new_path = os.path.join(orig_dirname, "%s.vhd" % uuid)
os.rename(orig_path, new_path)
return new_path, uuid
@@ -133,11 +131,13 @@ def get_vdi(session, args):
return new_path
def link_vhds(child_path, parent_path):
- proc = execute("vhd-util modify -n %(child_path)s -p %(parent_path)s"
- % locals())
- out, err = proc.communicate()
- if proc.returncode != 0:
- raise Exception("Failed to link vhds: '%s'" % err)
+ modify_args = shlex.split(
+ "vhd-util modify -n %(child_path)s -p %(parent_path)s"
+ % locals())
+ modify_proc = subprocess.Popen(
+ modify_args, stderr=subprocess.PIPE)
+ assert_process_success(modify_proc, "vhd-util")
+
image_path = os.path.join(staging_path, 'image')
@@ -210,7 +210,10 @@ def put_vdis(session, args):
conn.putheader(header, value)
conn.endheaders()
- tar_proc = execute("tar -zc --directory=%(staging_path)s ." % locals())
+ tar_args = shlex.split(
+ "tar -zc --directory=%(staging_path)s ." % locals())
+ tar_proc = subprocess.Popen(
+ tar_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
chunk = tar_proc.stdout.read(CHUNK_SIZE)
while chunk:
@@ -218,6 +221,8 @@ def put_vdis(session, args):
chunk = tar_proc.stdout.read(CHUNK_SIZE)
conn.send("0\r\n\r\n")
+ assert_process_success(tar_proc, "tar")
+
resp = conn.getresponse()
#FIXME(sirp): should this be 201 Created?
if resp.status != httplib.OK:
@@ -277,11 +282,6 @@ def find_sr(session):
return sr
return None
-def generate_uuid():
- # NOTE(sirp): Python2.4 does not include the uuid module
- proc = execute("uuidgen")
- uuid = proc.stdout.read().strip()
- return uuid
if __name__ == '__main__':
XenAPIPlugin.dispatch({'put_vdis': put_vdis,