From b65e994d9597f0a989b30eafc7a51bc34c4c361f Mon Sep 17 00:00:00 2001 From: Cerberus Date: Fri, 4 Feb 2011 15:13:18 -0600 Subject: Added a bunch of stubbed out functionality --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index aadacce57..3b7ceacc9 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -54,6 +54,10 @@ def copy_kernel_vdi(session,args): _copy_kernel_vdi('/dev/%s' % dev,copy_args)) return filename +def transfer_disk(dest, args): + vdi = exists(args, 'vdi-ref') + + def _copy_kernel_vdi(dest,copy_args): vdi_uuid=copy_args['vdi_uuid'] vdi_size=copy_args['vdi_size'] -- cgit From 855b9443cf109302e9882d527f237049b9624a05 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Fri, 4 Feb 2011 15:43:41 -0600 Subject: Didn't mean to actually make changes to the glance plugin --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 4 ---- 1 file changed, 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 3b7ceacc9..aadacce57 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -54,10 +54,6 @@ def copy_kernel_vdi(session,args): _copy_kernel_vdi('/dev/%s' % dev,copy_args)) return filename -def transfer_disk(dest, args): - vdi = exists(args, 'vdi-ref') - - def _copy_kernel_vdi(dest,copy_args): vdi_uuid=copy_args['vdi_uuid'] vdi_size=copy_args['vdi_size'] -- cgit From e59c62efe5492e59fcc26b7b74f6ac2daa0caabe Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 7 Feb 2011 16:57:02 -0600 Subject: Added data_transfer xapi plugin --- .../xenapi/etc/xapi.d/plugins/data_transfer | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer new file mode 100644 index 000000000..d310a65d9 --- /dev/null +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +XenAPI Plugin for transfering data between host nodes +""" + +import os.path +import subprocess + +import XenAPIPlugin + +SSH_HOSTS = '/root/.ssh/known_hosts' +DEVNULL = '/dev/null' +KEYSCAN = '/usr/bin/ssh-keyscan' + +def _key_scan_and_add(host): + """SSH scans a remote host and writes the SSH key out to known_hosts""" + open(SSH_HOSTS, 'a').close() + null = open(DEVNULL, 'w') + known_hosts = open(SSH_HOSTS, 'a') + key = subprocess.Popen(['/usr/bin/ssh-keyscan', '-t', 'rsa', host], + stdout=subprocess.PIPE, stderr=null).communicate()[0].strip() + grep = subprocess.call(['/bin/grep', '-o', '%s' % key, SSH_HOSTS], + stdout=null, stderr=null) + if grep == 1: + known_hosts.write(key) + null.close() + known_hosts.close() -- cgit From a40f6041556ec09a1cb79c2b8abcec7fa70e72bf Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 7 Feb 2011 17:12:15 -0600 Subject: Some stuff --- plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer index d310a65d9..cde7bb823 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer @@ -28,10 +28,13 @@ import XenAPIPlugin SSH_HOSTS = '/root/.ssh/known_hosts' DEVNULL = '/dev/null' KEYSCAN = '/usr/bin/ssh-keyscan' +RSYNC = '/usr/bin/rsync' def _key_scan_and_add(host): """SSH scans a remote host and writes the SSH key out to known_hosts""" + # Touch the file if it doesn't yet exist open(SSH_HOSTS, 'a').close() + null = open(DEVNULL, 'w') known_hosts = open(SSH_HOSTS, 'a') key = subprocess.Popen(['/usr/bin/ssh-keyscan', '-t', 'rsa', host], @@ -42,3 +45,12 @@ def _key_scan_and_add(host): known_hosts.write(key) null.close() known_hosts.close() + +def transfer_vhd(host, vhd_path): + """Rsyncs a VHD to an adjacent host""" + _key_scan_and_add(host) + if subprocess.call([RSYNC, vhd_path, "%s:/root/" % host]) != 0: + raise Exception("Unexpected VHD transfer failure") + +if __name__ == '__main__': + XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) -- cgit From 203c94c89caabc1d4ece4c462819a90c05cde163 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 7 Feb 2011 17:39:53 -0600 Subject: blargh --- plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer index cde7bb823..2af4a758b 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer @@ -46,11 +46,11 @@ def _key_scan_and_add(host): null.close() known_hosts.close() -def transfer_vhd(host, vhd_path): +def transfer_file(host, file_path): """Rsyncs a VHD to an adjacent host""" _key_scan_and_add(host) - if subprocess.call([RSYNC, vhd_path, "%s:/root/" % host]) != 0: + if subprocess.call([RSYNC, file_path, "%s:/root/" % host]) != 0: raise Exception("Unexpected VHD transfer failure") if __name__ == '__main__': - XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) + XenAPIPlugin.dispatch({'transfer_file': transfer_file}) -- cgit From ce5e3bdd30712aa6704926e6cdeb5ae73ae8200b Mon Sep 17 00:00:00 2001 From: Cerberus Date: Wed, 9 Feb 2011 15:26:37 -0600 Subject: A lot of stuff --- .../xenapi/etc/xapi.d/plugins/data_transfer | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer index 2af4a758b..bd46e1c0b 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer @@ -21,6 +21,7 @@ XenAPI Plugin for transfering data between host nodes """ import os.path +import pickle import subprocess import XenAPIPlugin @@ -30,27 +31,23 @@ DEVNULL = '/dev/null' KEYSCAN = '/usr/bin/ssh-keyscan' RSYNC = '/usr/bin/rsync' -def _key_scan_and_add(host): - """SSH scans a remote host and writes the SSH key out to known_hosts""" - # Touch the file if it doesn't yet exist - open(SSH_HOSTS, 'a').close() - - null = open(DEVNULL, 'w') - known_hosts = open(SSH_HOSTS, 'a') - key = subprocess.Popen(['/usr/bin/ssh-keyscan', '-t', 'rsa', host], - stdout=subprocess.PIPE, stderr=null).communicate()[0].strip() - grep = subprocess.call(['/bin/grep', '-o', '%s' % key, SSH_HOSTS], - stdout=null, stderr=null) - if grep == 1: - known_hosts.write(key) - null.close() - known_hosts.close() - -def transfer_file(host, file_path): + +def transfer_vhd(session, args): """Rsyncs a VHD to an adjacent host""" - _key_scan_and_add(host) - if subprocess.call([RSYNC, file_path, "%s:/root/" % host]) != 0: + params = pickle.dumps(args) + instance_id = params['instance_id'] + host = params['host'] + vdi_uuid = params['vdi_uuid'] + sr_path = get_sr_path(session) + vhd_path = "%s.vhd" % vdi_uuid + + source_path = "%s/%s" % (sr_path, vhd_path) + dest_path = '%s:/images/instance%d/' % (host, instance_id) + rsync_args = [['nohup', RSYNC, '-av', '--progress', + '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] + + if subprocess.call(rsync_args) != 0: raise Exception("Unexpected VHD transfer failure") if __name__ == '__main__': - XenAPIPlugin.dispatch({'transfer_file': transfer_file}) + XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) -- cgit From 482c7b57a3d0ac8bf6df98539bf8a1220470e0f7 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Wed, 9 Feb 2011 15:27:23 -0600 Subject: Renamed migration plugin --- .../xenapi/etc/xapi.d/plugins/data_transfer | 53 ---------------------- .../xenserver/xenapi/etc/xapi.d/plugins/migration | 53 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer create mode 100644 plugins/xenserver/xenapi/etc/xapi.d/plugins/migration (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer b/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer deleted file mode 100644 index bd46e1c0b..000000000 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/data_transfer +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -XenAPI Plugin for transfering data between host nodes -""" - -import os.path -import pickle -import subprocess - -import XenAPIPlugin - -SSH_HOSTS = '/root/.ssh/known_hosts' -DEVNULL = '/dev/null' -KEYSCAN = '/usr/bin/ssh-keyscan' -RSYNC = '/usr/bin/rsync' - - -def transfer_vhd(session, args): - """Rsyncs a VHD to an adjacent host""" - params = pickle.dumps(args) - instance_id = params['instance_id'] - host = params['host'] - vdi_uuid = params['vdi_uuid'] - sr_path = get_sr_path(session) - vhd_path = "%s.vhd" % vdi_uuid - - source_path = "%s/%s" % (sr_path, vhd_path) - dest_path = '%s:/images/instance%d/' % (host, instance_id) - rsync_args = [['nohup', RSYNC, '-av', '--progress', - '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] - - if subprocess.call(rsync_args) != 0: - raise Exception("Unexpected VHD transfer failure") - -if __name__ == '__main__': - XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration new file mode 100644 index 000000000..bd46e1c0b --- /dev/null +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +XenAPI Plugin for transfering data between host nodes +""" + +import os.path +import pickle +import subprocess + +import XenAPIPlugin + +SSH_HOSTS = '/root/.ssh/known_hosts' +DEVNULL = '/dev/null' +KEYSCAN = '/usr/bin/ssh-keyscan' +RSYNC = '/usr/bin/rsync' + + +def transfer_vhd(session, args): + """Rsyncs a VHD to an adjacent host""" + params = pickle.dumps(args) + instance_id = params['instance_id'] + host = params['host'] + vdi_uuid = params['vdi_uuid'] + sr_path = get_sr_path(session) + vhd_path = "%s.vhd" % vdi_uuid + + source_path = "%s/%s" % (sr_path, vhd_path) + dest_path = '%s:/images/instance%d/' % (host, instance_id) + rsync_args = [['nohup', RSYNC, '-av', '--progress', + '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] + + if subprocess.call(rsync_args) != 0: + raise Exception("Unexpected VHD transfer failure") + +if __name__ == '__main__': + XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) -- cgit From ac33f61c5c382fc7c8e8ab872192858860672d70 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Wed, 9 Feb 2011 16:38:27 -0600 Subject: Plugin tidying and more migration implementation --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 4 +- .../xenserver/xenapi/etc/xapi.d/plugins/migration | 67 +++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index aadacce57..817269769 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -138,8 +138,8 @@ def get_sr_path(session): return sr_path -#TODO(sirp): both objectstore and glance need this, should this be refactored -#into common lib +#TODO(sirp): objectstore, migration and glance need this, should this be +# refactored into common lib def find_sr(session): host = get_this_host(session) srs = session.xenapi.SR.get_all() diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index bd46e1c0b..e81b18a5e 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -20,16 +20,79 @@ XenAPI Plugin for transfering data between host nodes """ +import os import os.path import pickle +import shutil import subprocess +import uuid import XenAPIPlugin +from pluginlib_nova import * + SSH_HOSTS = '/root/.ssh/known_hosts' DEVNULL = '/dev/null' KEYSCAN = '/usr/bin/ssh-keyscan' RSYNC = '/usr/bin/rsync' +FILE_SR_PATH = '/var/run/sr-mount' +IMAGE_PATH = '/images/' +VHD_UTIL = '/usr/sbin/vhd-util' + +def get_sr_path(session): + sr_ref = find_sr(session) + + if sr_ref is None: + raise Exception('Cannot find SR to read VDI from') + + sr_rec = session.xenapi.SR.get_record(sr_ref) + sr_uuid = sr_rec["uuid"] + sr_path = os.path.join(FILE_SR_PATH, sr_uuid) + return sr_path + +def find_sr(session): + host = get_this_host(session) + srs = session.xenapi.SR.get_all() + for sr in srs: + sr_rec = session.xenapi.SR.get_record(sr) + if not ('i18n-key' in sr_rec['other_config'] and + sr_rec['other_config']['i18n-key'] == 'local-storage'): + continue + for pbd in sr_rec['PBDs']: + pbd_rec = session.xenapi.PBD.get_record(pbd) + if pbd_rec['host'] == host: + return sr + return None + +def move_vhds_into_sr(session, args): + """Moves the VHDs from their copied location to the SR""" + params = pickle.dumps(args) + instance_id = params['instance_id'] + + sr_path = get_sr_path(session) + + # Discover the copied VHDs locally, and then set up paths to copy + # them to under the SR + source_image_path = "%s/instance%d" % (IMAGE_PATH, instance_id) + source_base_copy_path = "%s/base_copy.vhd" % source_image_path + source_cow_path = "%s/cow.vhd" % source_image_path + + temp_vhd_path = "%s/instance%d/" % (sr_path, instance_id) + new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) + new_cow_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) + + os.mkdir(temp_vhd_path) + shutil.move(source_base_copy_path, new_base_copy_path) + shutil.move(source_cow_path, new_cow_path) + + os.rmdir(source_image_path) + + # Link the COW to the base copy + subprocess.call([VHD_UTIL, 'modify', '-n', new_cow_path, '-p', + new_base_copy_path]) + + shutil.move("%s/*.vhd" % temp_vhd_path, sr_path) + os.rmdir(temp_vhd_path) def transfer_vhd(session, args): @@ -38,11 +101,13 @@ def transfer_vhd(session, args): instance_id = params['instance_id'] host = params['host'] vdi_uuid = params['vdi_uuid'] + dest_name = params['dest_name'] sr_path = get_sr_path(session) vhd_path = "%s.vhd" % vdi_uuid source_path = "%s/%s" % (sr_path, vhd_path) - dest_path = '%s:/images/instance%d/' % (host, instance_id) + dest_path = '%s:%sinstance%d/%s' % (host, IMAGE_PATH, instance_id, + dest_name) rsync_args = [['nohup', RSYNC, '-av', '--progress', '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] -- cgit From d8a7a76cd4fd22a6ad9fc1a7b879a8dbffcede5f Mon Sep 17 00:00:00 2001 From: Cerberus Date: Thu, 10 Feb 2011 13:42:57 -0600 Subject: Some more cleanup --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index e81b18a5e..0fb7b5806 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -70,6 +70,7 @@ def move_vhds_into_sr(session, args): instance_id = params['instance_id'] sr_path = get_sr_path(session) + sr_temp_path = "%s/images/" % sr_path # Discover the copied VHDs locally, and then set up paths to copy # them to under the SR @@ -77,7 +78,7 @@ def move_vhds_into_sr(session, args): source_base_copy_path = "%s/base_copy.vhd" % source_image_path source_cow_path = "%s/cow.vhd" % source_image_path - temp_vhd_path = "%s/instance%d/" % (sr_path, instance_id) + temp_vhd_path = "%s/instance%d/" % (sr_temp_path, instance_id) new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) new_cow_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) -- cgit From 7bb6122549ad5ac549465f0012020f8e5dc9d506 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 15:26:08 -0600 Subject: Some refactoring --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 0fb7b5806..71d4473c5 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -78,9 +78,12 @@ def move_vhds_into_sr(session, args): source_base_copy_path = "%s/base_copy.vhd" % source_image_path source_cow_path = "%s/cow.vhd" % source_image_path + new_base_copy_uuid = str(uuid.uuid4()) + new_cow_uuid = str(uuid.uuid4()) + temp_vhd_path = "%s/instance%d/" % (sr_temp_path, instance_id) - new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) - new_cow_path = "%s/%s.vhd" % (temp_vhd_path, str(uuid.uuid4())) + new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid) + new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid) os.mkdir(temp_vhd_path) shutil.move(source_base_copy_path, new_base_copy_path) @@ -94,6 +97,7 @@ def move_vhds_into_sr(session, args): shutil.move("%s/*.vhd" % temp_vhd_path, sr_path) os.rmdir(temp_vhd_path) + return (new_base_copy_uuid, new_cow_uuid) def transfer_vhd(session, args): -- cgit From fad5baf307b74a92fd5b9d8e2d1479f558e180aa Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 15:55:52 -0600 Subject: hurr --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 71d4473c5..e73480445 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -69,6 +69,9 @@ def move_vhds_into_sr(session, args): params = pickle.dumps(args) instance_id = params['instance_id'] + new_base_copy_uuid = params['new_base_copy_uuid'] + new_cow_uuid = params['new_cow_uuid'] + sr_path = get_sr_path(session) sr_temp_path = "%s/images/" % sr_path @@ -78,8 +81,6 @@ def move_vhds_into_sr(session, args): source_base_copy_path = "%s/base_copy.vhd" % source_image_path source_cow_path = "%s/cow.vhd" % source_image_path - new_base_copy_uuid = str(uuid.uuid4()) - new_cow_uuid = str(uuid.uuid4()) temp_vhd_path = "%s/instance%d/" % (sr_temp_path, instance_id) new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid) @@ -97,7 +98,7 @@ def move_vhds_into_sr(session, args): shutil.move("%s/*.vhd" % temp_vhd_path, sr_path) os.rmdir(temp_vhd_path) - return (new_base_copy_uuid, new_cow_uuid) + return None def transfer_vhd(session, args): -- cgit From 9a71c79dc3beb554c86a1b1b5d03ab66c6e96edc Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 16:24:51 -0600 Subject: Typo fixes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index e73480445..cf7f378fa 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -25,7 +25,6 @@ import os.path import pickle import shutil import subprocess -import uuid import XenAPIPlugin @@ -114,7 +113,7 @@ def transfer_vhd(session, args): source_path = "%s/%s" % (sr_path, vhd_path) dest_path = '%s:%sinstance%d/%s' % (host, IMAGE_PATH, instance_id, dest_name) - rsync_args = [['nohup', RSYNC, '-av', '--progress', + rsync_args = ['nohup', RSYNC, '-av', '--progress', '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] if subprocess.call(rsync_args) != 0: -- cgit From 41e4e18a0324593c0076c3936d63bb6dcca487cb Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Mon, 14 Feb 2011 23:12:34 +0000 Subject: First cut on XenServer unified-images --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 204 +++++++++++++++++---- 1 file changed, 169 insertions(+), 35 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index aadacce57..8352d7ee6 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -29,7 +29,10 @@ import os import os.path import pickle import sha +import shlex +import shutil import subprocess +import tempfile import time import urlparse @@ -66,65 +69,190 @@ def _copy_kernel_vdi(dest,copy_args): data=f.read(vdi_size) of.write(data) f.close() - of.close() + of.close() logging.debug("Done. Filename: %s",filename) - return filename + return filename + + +def execute(cmd): + args = shlex.split(cmd) + proc = subprocess.Popen( + args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) + return proc + + +def get_vdi(session, args): + """ + """ + params = pickle.loads(exists(args, 'params')) + image_id = params["image_id"] + glance_host = params["glance_host"] + glance_port = params["glance_port"] + + def unbundle_xfer(sr_path, staging_path): + """ + + """ + conn = httplib.HTTPConnection(glance_host, glance_port) + conn.request('GET', '/images/%s' % image_id) + resp = conn.getresponse() + if resp.status == httplib.NOT_FOUND: + raise Exception("Image '%s' not found in Glance" % image_id) + elif resp.status != httplib.OK: + raise Exception("Unexpected response from Glance %i" % res.status) + + tar_proc = execute("tar -zx --directory=%(staging_path)s" % locals()) + 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)) + conn.close() + + def fixup_vhds(sr_path, staging_path): + """ + """ + 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() + new_path = os.path.join(orig_dirname, "%s.vhd" % uuid) + os.rename(orig_path, new_path) + return new_path, uuid + + def move_into_sr(orig_path): + """Move a file into the SR""" + filename = os.path.basename(orig_path) + new_path = os.path.join(sr_path, filename) + #os.rename(orig_path, new_path) + # FIXME(sirp) : testing + shutil.copyfile(orig_path, new_path) + 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) + + image_path = os.path.join(staging_path, 'image') + + orig_base_copy_path = os.path.join(image_path, 'image.vhd') + if not os.path.exists(orig_base_copy_path): + raise Exception("Invalid image: image.vhd not present") + + base_copy_path, base_copy_uuid = rename_with_uuid(orig_base_copy_path) + + vdi_uuid = base_copy_uuid + orig_snap_path = os.path.join(image_path, 'snap.vhd') + if os.path.exists(orig_snap_path): + snap_path, snap_uuid = rename_with_uuid(orig_snap_path) + vdi_uuid = snap_uuid + # NOTE(sirp): this step is necessary so that an SR scan won't + # delete the base_copy out from under us (since it would be + # orphaned) + link_vhds(snap_path, base_copy_path) + move_into_sr(snap_path) + else: + raise Exception("path '%s' not found!!!" % orig_snap_path) + move_into_sr(base_copy_path) + return vdi_uuid + + sr_path = get_sr_path(session) + staging_path = make_staging_area(sr_path) + try: + unbundle_xfer(sr_path, staging_path) + vdi_uuid = fixup_vhds(sr_path, staging_path) + return vdi_uuid + finally: + # FIXME(sirp) : testing + pass + #cleanup_staging_area(staging_path) + def put_vdis(session, args): + """ + """ params = pickle.loads(exists(args, 'params')) vdi_uuids = params["vdi_uuids"] image_id = params["image_id"] glance_host = params["glance_host"] glance_port = params["glance_port"] - - sr_path = get_sr_path(session) - #FIXME(sirp): writing to a temp file until Glance supports chunked-PUTs - tmp_file = "%s.tar.gz" % os.path.join('/tmp', str(image_id)) - tar_cmd = ['tar', '-zcf', tmp_file, '--directory=%s' % sr_path] - paths = [ "%s.vhd" % vdi_uuid for vdi_uuid in vdi_uuids ] - tar_cmd.extend(paths) - logging.debug("Bundling image with cmd: %s", tar_cmd) - subprocess.call(tar_cmd) - logging.debug("Writing to test file %s", tmp_file) - put_bundle_in_glance(tmp_file, image_id, glance_host, glance_port) - return "" # FIXME(sirp): return anything useful here? + def prepare_staging_area(sr_path, staging_path): + """ + Explain preparing staging area here... + """ + image_path = os.path.join(staging_path, 'image') + os.mkdir(image_path) + for name, uuid in vdi_uuids.items(): + source = os.path.join(sr_path, "%s.vhd" % uuid) + link_name = os.path.join(image_path, "%s.vhd" % name) + os.link(source, link_name) -def put_bundle_in_glance(tmp_file, image_id, glance_host, glance_port): - size = os.path.getsize(tmp_file) - basename = os.path.basename(tmp_file) + def bundle_xfer(staging_path): + conn = httplib.HTTPConnection(glance_host, glance_port) + #NOTE(sirp): httplib under python2.4 won't accept a file-like object + # to request + conn.putrequest('PUT', '/images/%s' % image_id) - bundle = open(tmp_file, 'r') - try: headers = { 'x-image-meta-store': 'file', 'x-image-meta-is_public': 'True', 'x-image-meta-type': 'raw', - 'x-image-meta-size': size, - 'content-length': size, + 'x-image-meta-property-disk-format': 'vhd', + 'x-image-meta-property-container-format': 'tarball', + 'transfer-encoding': "chunked", 'content-type': 'application/octet-stream', } - conn = httplib.HTTPConnection(glance_host, glance_port) - #NOTE(sirp): httplib under python2.4 won't accept a file-like object - # to request - conn.putrequest('PUT', '/images/%s' % image_id) - for header, value in headers.iteritems(): conn.putheader(header, value) conn.endheaders() - - chunk = bundle.read(CHUNK_SIZE) + + tar_proc = execute("tar -zc --directory=%(staging_path)s ." % locals()) + + chunk = tar_proc.stdout.read(CHUNK_SIZE) while chunk: - conn.send(chunk) - chunk = bundle.read(CHUNK_SIZE) - + conn.send("%x\r\n%s\r\n" % (len(chunk), chunk)) + chunk = tar_proc.stdout.read(CHUNK_SIZE) + conn.send("0\r\n\r\n") - res = conn.getresponse() + resp = conn.getresponse() #FIXME(sirp): should this be 201 Created? - if res.status != httplib.OK: + if resp.status != httplib.OK: raise Exception("Unexpected response from Glance %i" % res.status) + + conn.close() + + sr_path = get_sr_path(session) + staging_path = make_staging_area(sr_path) + try: + prepare_staging_area(sr_path, staging_path) + bundle_xfer(staging_path) finally: - bundle.close() + cleanup_staging_area(staging_path) + + return "" # FIXME(sirp): return anything useful here? + + +def make_staging_area(sr_path): + """ + Explain staging area here... + """ + # NOTE(sirp): staging area is created in SR to allow hard-linking + staging_path = tempfile.mkdtemp(dir=sr_path) + return staging_path + + +def cleanup_staging_area(staging_path): + shutil.rmtree(staging_path) + def get_sr_path(session): sr_ref = find_sr(session) @@ -154,7 +282,13 @@ 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, + XenAPIPlugin.dispatch({'put_vdis': put_vdis, + 'get_vdi': get_vdi, 'copy_kernel_vdi': copy_kernel_vdi}) -- cgit From 0bd48e3d53c6fce04b0c5e483537b3fd31c7364a Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 17:24:33 -0600 Subject: bad plugin --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index cf7f378fa..c68fc93c5 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -120,4 +120,5 @@ def transfer_vhd(session, args): raise Exception("Unexpected VHD transfer failure") if __name__ == '__main__': - XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd}) + XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd, + 'move_vhd_into_sr':move_vhd_into_sr, }) -- cgit From e44a91ced3d19a3bca10457239592307bf6f829b Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 17:31:20 -0600 Subject: bad plugin --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index c68fc93c5..c1f5b7528 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -65,7 +65,7 @@ def find_sr(session): def move_vhds_into_sr(session, args): """Moves the VHDs from their copied location to the SR""" - params = pickle.dumps(args) + params = pickle.loads(exists(args, 'params')) instance_id = params['instance_id'] new_base_copy_uuid = params['new_base_copy_uuid'] @@ -102,7 +102,7 @@ def move_vhds_into_sr(session, args): def transfer_vhd(session, args): """Rsyncs a VHD to an adjacent host""" - params = pickle.dumps(args) + params = pickle.loads(exists(args, 'params')) instance_id = params['instance_id'] host = params['host'] vdi_uuid = params['vdi_uuid'] @@ -121,4 +121,4 @@ def transfer_vhd(session, args): if __name__ == '__main__': XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd, - 'move_vhd_into_sr':move_vhd_into_sr, }) + 'move_vhds_into_sr':move_vhds_into_sr, }) -- cgit From 238ae2b5a8c559acc362a3b44160404771f1259f Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 00:00:56 +0000 Subject: Removing testing statements --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 8352d7ee6..0cb3b52db 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -129,9 +129,7 @@ def get_vdi(session, args): """Move a file into the SR""" filename = os.path.basename(orig_path) new_path = os.path.join(sr_path, filename) - #os.rename(orig_path, new_path) - # FIXME(sirp) : testing - shutil.copyfile(orig_path, new_path) + os.rename(orig_path, new_path) return new_path def link_vhds(child_path, parent_path): @@ -159,8 +157,7 @@ def get_vdi(session, args): # orphaned) link_vhds(snap_path, base_copy_path) move_into_sr(snap_path) - else: - raise Exception("path '%s' not found!!!" % orig_snap_path) + move_into_sr(base_copy_path) return vdi_uuid @@ -171,9 +168,7 @@ def get_vdi(session, args): vdi_uuid = fixup_vhds(sr_path, staging_path) return vdi_uuid finally: - # FIXME(sirp) : testing - pass - #cleanup_staging_area(staging_path) + cleanup_staging_area(staging_path) def put_vdis(session, args): -- cgit From 3014c0896202b592858fc1a7fc9c29b92a6f5d1b Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 18:04:07 -0600 Subject: plugin --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index c1f5b7528..9c56cb379 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -111,14 +111,18 @@ def transfer_vhd(session, args): vhd_path = "%s.vhd" % vdi_uuid source_path = "%s/%s" % (sr_path, vhd_path) - dest_path = '%s:%sinstance%d/%s' % (host, IMAGE_PATH, instance_id, - dest_name) - rsync_args = ['nohup', RSYNC, '-av', '--progress', - '-e "ssh -o StrictHostKeyChecking=no"', source_path, dest_path] + dest_path = '%sinstance%d/' % (IMAGE_PATH, instance_id) + + dest_path_with_vhd="$s:%s/%s" % (host, dest_path, dest_name) + ssh_cmd = '-e "ssh -o StrictHostKeyChecking=no \'mkdir -p %s\' " ' % dest_path + + rsync_args = ['nohup', RSYNC, '-av', '--progress', ssh_cmd, source_path, + dest_path_with_vhd] if subprocess.call(rsync_args) != 0: raise Exception("Unexpected VHD transfer failure") + if __name__ == '__main__': XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd, 'move_vhds_into_sr':move_vhds_into_sr, }) -- cgit From e7fe96453760320ef897b9edfc39e057d565e6c0 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 23:22:37 -0600 Subject: Refactored --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 9c56cb379..3d3ad4e67 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -68,6 +68,9 @@ def move_vhds_into_sr(session, args): params = pickle.loads(exists(args, 'params')) instance_id = params['instance_id'] + old_base_copy_uuid = params['old_base_copy_uuid'] + old_cow_uuid = params['old_cow_uuid'] + new_base_copy_uuid = params['new_base_copy_uuid'] new_cow_uuid = params['new_cow_uuid'] @@ -77,9 +80,9 @@ def move_vhds_into_sr(session, args): # Discover the copied VHDs locally, and then set up paths to copy # them to under the SR source_image_path = "%s/instance%d" % (IMAGE_PATH, instance_id) - source_base_copy_path = "%s/base_copy.vhd" % source_image_path - source_cow_path = "%s/cow.vhd" % source_image_path - + source_base_copy_path = "%s/%s.vhd" % (source_image_path, + old_base_copy_uuid) + source_cow_path = "%s/%s.vhd" % (source_image_path, old_cow_uuid) temp_vhd_path = "%s/instance%d/" % (sr_temp_path, instance_id) new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid) @@ -106,18 +109,16 @@ def transfer_vhd(session, args): instance_id = params['instance_id'] host = params['host'] vdi_uuid = params['vdi_uuid'] - dest_name = params['dest_name'] sr_path = get_sr_path(session) vhd_path = "%s.vhd" % vdi_uuid source_path = "%s/%s" % (sr_path, vhd_path) - dest_path = '%sinstance%d/' % (IMAGE_PATH, instance_id) + dest_path = '%s:%sinstance%d/' % (host, IMAGE_PATH, instance_id) - dest_path_with_vhd="$s:%s/%s" % (host, dest_path, dest_name) - ssh_cmd = '-e "ssh -o StrictHostKeyChecking=no \'mkdir -p %s\' " ' % dest_path + ssh_cmd = '-e "ssh -o StrictHostKeyChecking=no " ' rsync_args = ['nohup', RSYNC, '-av', '--progress', ssh_cmd, source_path, - dest_path_with_vhd] + dest_path] if subprocess.call(rsync_args) != 0: raise Exception("Unexpected VHD transfer failure") -- cgit From 4574bcdfe303a76a46eb7579a5a70de4e54cc926 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 14 Feb 2011 23:58:21 -0600 Subject: Tons o loggin --- .../xenserver/xenapi/etc/xapi.d/plugins/migration | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 3d3ad4e67..63de5bfba 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -29,6 +29,7 @@ import subprocess import XenAPIPlugin from pluginlib_nova import * +configure_logging('migration') SSH_HOSTS = '/root/.ssh/known_hosts' DEVNULL = '/dev/null' @@ -88,17 +89,27 @@ def move_vhds_into_sr(session, args): new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid) new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid) + logging.debug('Creating temporary SR path' % temp_vhd_path) os.mkdir(temp_vhd_path) + + logging.debug('Moving %s into %s' % (source_base_copy_path, temp_vhd_path)) shutil.move(source_base_copy_path, new_base_copy_path) + + logging.debug('Moving %s into %s' % (source_cow_path, temp_vhd_path)) shutil.move(source_cow_path, new_cow_path) + logging.debug('Cleaning up %s' % source_image_path) os.rmdir(source_image_path) # Link the COW to the base copy + logging.debug('Attaching COW to the base copy...') subprocess.call([VHD_UTIL, 'modify', '-n', new_cow_path, '-p', new_base_copy_path]) + logging.debug('Moving VHDs into SR %s' % sr_path) shutil.move("%s/*.vhd" % temp_vhd_path, sr_path) + + loggin.debug('Cleaning up temporary SR path %s' % temp_vhd_path) os.rmdir(temp_vhd_path) return None @@ -115,12 +126,19 @@ def transfer_vhd(session, args): source_path = "%s/%s" % (sr_path, vhd_path) dest_path = '%s:%sinstance%d/' % (host, IMAGE_PATH, instance_id) + logging.debug("Preparing to transmit %s to %s" % (source_path, + dest_path)) + ssh_cmd = '-e "ssh -o StrictHostKeyChecking=no " ' rsync_args = ['nohup', RSYNC, '-av', '--progress', ssh_cmd, source_path, dest_path] - if subprocess.call(rsync_args) != 0: + logging.debug('rsync %s' % (' '.join(rsync_args, ))) + + rsync_proc = subprocess.POpen(rsync_args) + logging.debug('Rsync output: \n %s' % rsync_proc.communicate()[0]) + if rsync_proc.returncode != 0 raise Exception("Unexpected VHD transfer failure") -- cgit From bf82637cad867b0e8fb6ad868f60c6dcd66d7f97 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 11:05:20 -0600 Subject: Better host acquisition --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 63de5bfba..97c970da5 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -136,7 +136,7 @@ def transfer_vhd(session, args): logging.debug('rsync %s' % (' '.join(rsync_args, ))) - rsync_proc = subprocess.POpen(rsync_args) + rsync_proc = subprocess.Popen(rsync_args) logging.debug('Rsync output: \n %s' % rsync_proc.communicate()[0]) if rsync_proc.returncode != 0 raise Exception("Unexpected VHD transfer failure") -- cgit From 15cdeef7820aacd0b1ff95da48816cba9f2544ba Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 18:01:13 +0000 Subject: Adding more documentation, code-cleanup --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'plugins') 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, -- cgit From 0fc3a184230c479254b9f713ea61de2f24f680ab Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 18:23:14 +0000 Subject: Moving SR path code outside of glance plugin --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 34 ++-------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 2018dca5f..0b270f5f9 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -38,7 +38,6 @@ configure_logging('glance') CHUNK_SIZE = 8192 KERNEL_DIR = '/boot/guest' -FILE_SR_PATH = '/var/run/sr-mount' def copy_kernel_vdi(session,args): vdi = exists(args, 'vdi-ref') @@ -86,6 +85,7 @@ def get_vdi(session, args): glance_host = params["glance_host"] glance_port = params["glance_port"] uuid_stack = params["uuid_stack"] + sr_path = params["sr_path"] def unbundle_xfer(sr_path, staging_path): """ @@ -161,7 +161,6 @@ def get_vdi(session, args): move_into_sr(base_copy_path) return vdi_uuid - sr_path = get_sr_path(session) staging_path = make_staging_area(sr_path) try: unbundle_xfer(sr_path, staging_path) @@ -179,6 +178,7 @@ def put_vdis(session, args): image_id = params["image_id"] glance_host = params["glance_host"] glance_port = params["glance_port"] + sr_path = params["sr_path"] def prepare_staging_area(sr_path, staging_path): """ @@ -230,7 +230,6 @@ def put_vdis(session, args): conn.close() - sr_path = get_sr_path(session) staging_path = make_staging_area(sr_path) try: prepare_staging_area(sr_path, staging_path) @@ -254,35 +253,6 @@ def cleanup_staging_area(staging_path): shutil.rmtree(staging_path) -def get_sr_path(session): - sr_ref = find_sr(session) - - if sr_ref is None: - raise Exception('Cannot find SR to read VDI from') - - sr_rec = session.xenapi.SR.get_record(sr_ref) - sr_uuid = sr_rec["uuid"] - sr_path = os.path.join(FILE_SR_PATH, sr_uuid) - return sr_path - - -#TODO(sirp): both objectstore and glance need this, should this be refactored -#into common lib -def find_sr(session): - host = get_this_host(session) - srs = session.xenapi.SR.get_all() - for sr in srs: - sr_rec = session.xenapi.SR.get_record(sr) - if not ('i18n-key' in sr_rec['other_config'] and - sr_rec['other_config']['i18n-key'] == 'local-storage'): - continue - for pbd in sr_rec['PBDs']: - pbd_rec = session.xenapi.PBD.get_record(pbd) - if pbd_rec['host'] == host: - return sr - return None - - if __name__ == '__main__': XenAPIPlugin.dispatch({'put_vdis': put_vdis, 'get_vdi': get_vdi, -- cgit From eb603b5ec3d54b2b6c893f8d41e7d12bbaa49e57 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 18:50:40 +0000 Subject: Refactoring put_vdis --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 136 +++++++++++---------- 1 file changed, 69 insertions(+), 67 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 0b270f5f9..3fe2d4059 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -67,16 +67,6 @@ def _copy_kernel_vdi(dest,copy_args): return filename -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): """ """ @@ -109,7 +99,7 @@ def get_vdi(session, args): tar_proc.stdin.write(chunk) chunk = resp.read(CHUNK_SIZE) - assert_process_success(tar_proc, "tar") + _assert_process_success(tar_proc, "tar") conn.close() def fixup_vhds(sr_path, staging_path): @@ -136,7 +126,7 @@ def get_vdi(session, args): % locals()) modify_proc = subprocess.Popen( modify_args, stderr=subprocess.PIPE) - assert_process_success(modify_proc, "vhd-util") + _assert_process_success(modify_proc, "vhd-util") image_path = os.path.join(staging_path, 'image') @@ -161,13 +151,13 @@ def get_vdi(session, args): move_into_sr(base_copy_path) return vdi_uuid - staging_path = make_staging_area(sr_path) + staging_path = _make_staging_area(sr_path) try: unbundle_xfer(sr_path, staging_path) vdi_uuid = fixup_vhds(sr_path, staging_path) return vdi_uuid finally: - cleanup_staging_area(staging_path) + _cleanup_staging_area(staging_path) def put_vdis(session, args): @@ -180,67 +170,69 @@ def put_vdis(session, args): glance_port = params["glance_port"] sr_path = params["sr_path"] - def prepare_staging_area(sr_path, staging_path): - """ - Explain preparing staging area here... - """ - image_path = os.path.join(staging_path, 'image') - os.mkdir(image_path) - for name, uuid in vdi_uuids.items(): - source = os.path.join(sr_path, "%s.vhd" % uuid) - link_name = os.path.join(image_path, "%s.vhd" % name) - os.link(source, link_name) - - def bundle_xfer(staging_path): - conn = httplib.HTTPConnection(glance_host, glance_port) - #NOTE(sirp): httplib under python2.4 won't accept a file-like object - # to request - conn.putrequest('PUT', '/images/%s' % image_id) - - headers = { - 'x-image-meta-store': 'file', - 'x-image-meta-is_public': 'True', - 'x-image-meta-type': 'raw', - 'x-image-meta-property-disk-format': 'vhd', - 'x-image-meta-property-container-format': 'tarball', - 'transfer-encoding': "chunked", - 'content-type': 'application/octet-stream', - } - for header, value in headers.iteritems(): - conn.putheader(header, value) - conn.endheaders() + staging_path = _make_staging_area(sr_path) + try: + _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids) + _bundle_xfer(staging_path, image_id, glance_host, glance_port) + finally: + _cleanup_staging_area(staging_path) - tar_args = shlex.split( - "tar -zc --directory=%(staging_path)s ." % locals()) - tar_proc = subprocess.Popen( - tar_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return "" - chunk = tar_proc.stdout.read(CHUNK_SIZE) - while chunk: - conn.send("%x\r\n%s\r\n" % (len(chunk), chunk)) - chunk = tar_proc.stdout.read(CHUNK_SIZE) - conn.send("0\r\n\r\n") - assert_process_success(tar_proc, "tar") +def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): + """ + Explain preparing staging area here... + """ + image_path = os.path.join(staging_path, 'image') + os.mkdir(image_path) + for name, uuid in vdi_uuids.items(): + source = os.path.join(sr_path, "%s.vhd" % uuid) + link_name = os.path.join(image_path, "%s.vhd" % name) + os.link(source, link_name) - resp = conn.getresponse() - #FIXME(sirp): should this be 201 Created? - if resp.status != httplib.OK: - raise Exception("Unexpected response from Glance %i" % res.status) - conn.close() +def _bundle_xfer(staging_path, image_id, glance_host, glance_port): + """ + """ + conn = httplib.HTTPConnection(glance_host, glance_port) + #NOTE(sirp): httplib under python2.4 won't accept a file-like object + # to request + conn.putrequest('PUT', '/images/%s' % image_id) + + headers = { + 'x-image-meta-store': 'file', + 'x-image-meta-is_public': 'True', + 'x-image-meta-type': 'raw', + 'x-image-meta-property-disk-format': 'vhd', + 'x-image-meta-property-container-format': 'tarball', + 'transfer-encoding': "chunked", + 'content-type': 'application/octet-stream', + } + for header, value in headers.iteritems(): + conn.putheader(header, value) + conn.endheaders() + + 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: + conn.send("%x\r\n%s\r\n" % (len(chunk), chunk)) + chunk = tar_proc.stdout.read(CHUNK_SIZE) + conn.send("0\r\n\r\n") - staging_path = make_staging_area(sr_path) - try: - prepare_staging_area(sr_path, staging_path) - bundle_xfer(staging_path) - finally: - cleanup_staging_area(staging_path) + _assert_process_success(tar_proc, "tar") - return "" # FIXME(sirp): return anything useful here? + resp = conn.getresponse() + if resp.status != httplib.OK: + raise Exception("Unexpected response from Glance %i" % res.status) + conn.close() -def make_staging_area(sr_path): +def _make_staging_area(sr_path): """ Explain staging area here... """ @@ -249,10 +241,20 @@ def make_staging_area(sr_path): return staging_path -def cleanup_staging_area(staging_path): +def _cleanup_staging_area(staging_path): shutil.rmtree(staging_path) +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) + + if __name__ == '__main__': XenAPIPlugin.dispatch({'put_vdis': put_vdis, 'get_vdi': get_vdi, -- cgit From acf95a640cfeb0812a55577b6a08bff972ad523b Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 19:17:27 +0000 Subject: Regrouping methods so they make sense --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 233 +++++++++++---------- 1 file changed, 120 insertions(+), 113 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 3fe2d4059..7bbab4f52 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -39,17 +39,6 @@ configure_logging('glance') CHUNK_SIZE = 8192 KERNEL_DIR = '/boot/guest' -def copy_kernel_vdi(session,args): - vdi = exists(args, 'vdi-ref') - size = exists(args,'image-size') - #Use the uuid as a filename - vdi_uuid=session.xenapi.VDI.get_uuid(vdi) - copy_args={'vdi_uuid':vdi_uuid,'vdi_size':int(size)} - filename=with_vdi_in_dom0(session, vdi, False, - lambda dev: - _copy_kernel_vdi('/dev/%s' % dev,copy_args)) - return filename - def _copy_kernel_vdi(dest,copy_args): vdi_uuid=copy_args['vdi_uuid'] vdi_size=copy_args['vdi_size'] @@ -67,117 +56,83 @@ def _copy_kernel_vdi(dest,copy_args): return filename -def get_vdi(session, args): - """ +def _download_tarball(sr_path, staging_path, image_id, glance_host, + glance_port): """ - params = pickle.loads(exists(args, 'params')) - image_id = params["image_id"] - glance_host = params["glance_host"] - glance_port = params["glance_port"] - uuid_stack = params["uuid_stack"] - sr_path = params["sr_path"] - - def unbundle_xfer(sr_path, staging_path): - """ - """ - conn = httplib.HTTPConnection(glance_host, glance_port) - conn.request('GET', '/images/%s' % image_id) - resp = conn.getresponse() - if resp.status == httplib.NOT_FOUND: - raise Exception("Image '%s' not found in Glance" % image_id) - elif resp.status != httplib.OK: - raise Exception("Unexpected response from Glance %i" % res.status) + """ + conn = httplib.HTTPConnection(glance_host, glance_port) + conn.request('GET', '/images/%s' % image_id) + resp = conn.getresponse() + if resp.status == httplib.NOT_FOUND: + raise Exception("Image '%s' not found in Glance" % image_id) + elif resp.status != httplib.OK: + raise Exception("Unexpected response from Glance %i" % res.status) - tar_args = shlex.split( - "tar -zx --directory=%(staging_path)s" % locals()) - tar_proc = subprocess.Popen( - tar_args, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + 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) - while chunk: - tar_proc.stdin.write(chunk) - chunk = resp.read(CHUNK_SIZE) - - _assert_process_success(tar_proc, "tar") - conn.close() - - def fixup_vhds(sr_path, staging_path): - """ - """ - def rename_with_uuid(orig_path): - """Generate a uuid and rename the file with the uuid""" - orig_dirname = os.path.dirname(orig_path) - uuid = uuid_stack.pop() - new_path = os.path.join(orig_dirname, "%s.vhd" % uuid) - os.rename(orig_path, new_path) - return new_path, uuid - - def move_into_sr(orig_path): - """Move a file into the SR""" - filename = os.path.basename(orig_path) - new_path = os.path.join(sr_path, filename) - os.rename(orig_path, new_path) - return new_path - - def link_vhds(child_path, parent_path): - 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') - - orig_base_copy_path = os.path.join(image_path, 'image.vhd') - if not os.path.exists(orig_base_copy_path): - raise Exception("Invalid image: image.vhd not present") - - base_copy_path, base_copy_uuid = rename_with_uuid(orig_base_copy_path) - - vdi_uuid = base_copy_uuid - orig_snap_path = os.path.join(image_path, 'snap.vhd') - if os.path.exists(orig_snap_path): - snap_path, snap_uuid = rename_with_uuid(orig_snap_path) - vdi_uuid = snap_uuid - # NOTE(sirp): this step is necessary so that an SR scan won't - # delete the base_copy out from under us (since it would be - # orphaned) - link_vhds(snap_path, base_copy_path) - move_into_sr(snap_path) - - move_into_sr(base_copy_path) - return vdi_uuid - staging_path = _make_staging_area(sr_path) - try: - unbundle_xfer(sr_path, staging_path) - vdi_uuid = fixup_vhds(sr_path, staging_path) - return vdi_uuid - finally: - _cleanup_staging_area(staging_path) + _assert_process_success(tar_proc, "tar") + conn.close() -def put_vdis(session, args): +def fixup_vhds(sr_path, staging_path, uuid_stack): """ """ - params = pickle.loads(exists(args, 'params')) - vdi_uuids = params["vdi_uuids"] - image_id = params["image_id"] - glance_host = params["glance_host"] - glance_port = params["glance_port"] - sr_path = params["sr_path"] + def rename_with_uuid(orig_path): + """Generate a uuid and rename the file with the uuid""" + orig_dirname = os.path.dirname(orig_path) + uuid = uuid_stack.pop() + new_path = os.path.join(orig_dirname, "%s.vhd" % uuid) + os.rename(orig_path, new_path) + return new_path, uuid - staging_path = _make_staging_area(sr_path) - try: - _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids) - _bundle_xfer(staging_path, image_id, glance_host, glance_port) - finally: - _cleanup_staging_area(staging_path) - return "" + def link_vhds(child_path, parent_path): + 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") + + + def move_into_sr(orig_path): + """Move a file into the SR""" + filename = os.path.basename(orig_path) + new_path = os.path.join(sr_path, filename) + os.rename(orig_path, new_path) + return new_path + + + image_path = os.path.join(staging_path, 'image') + + orig_base_copy_path = os.path.join(image_path, 'image.vhd') + if not os.path.exists(orig_base_copy_path): + raise Exception("Invalid image: image.vhd not present") + + base_copy_path, base_copy_uuid = rename_with_uuid(orig_base_copy_path) + + vdi_uuid = base_copy_uuid + orig_snap_path = os.path.join(image_path, 'snap.vhd') + if os.path.exists(orig_snap_path): + snap_path, snap_uuid = rename_with_uuid(orig_snap_path) + vdi_uuid = snap_uuid + # NOTE(sirp): this step is necessary so that an SR scan won't + # delete the base_copy out from under us (since it would be + # orphaned) + link_vhds(snap_path, base_copy_path) + move_into_sr(snap_path) + + move_into_sr(base_copy_path) + return vdi_uuid def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): @@ -192,7 +147,7 @@ def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): os.link(source, link_name) -def _bundle_xfer(staging_path, image_id, glance_host, glance_port): +def _upload_tarball(staging_path, image_id, glance_host, glance_port): """ """ conn = httplib.HTTPConnection(glance_host, glance_port) @@ -255,7 +210,59 @@ def _assert_process_success(proc, cmd): raise Exception(msg) +def download_image(session, args): + """ + """ + params = pickle.loads(exists(args, 'params')) + image_id = params["image_id"] + glance_host = params["glance_host"] + glance_port = params["glance_port"] + uuid_stack = params["uuid_stack"] + sr_path = params["sr_path"] + + staging_path = _make_staging_area(sr_path) + try: + _download_tarball(sr_path, staging_path, image_id, glance_host, + glance_port) + vdi_uuid = fixup_vhds(sr_path, staging_path, uuid_stack) + return vdi_uuid + finally: + _cleanup_staging_area(staging_path) + + +def upload_image(session, args): + """ + """ + params = pickle.loads(exists(args, 'params')) + vdi_uuids = params["vdi_uuids"] + image_id = params["image_id"] + glance_host = params["glance_host"] + glance_port = params["glance_port"] + sr_path = params["sr_path"] + + staging_path = _make_staging_area(sr_path) + try: + _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids) + _upload_tarball(staging_path, image_id, glance_host, glance_port) + finally: + _cleanup_staging_area(staging_path) + + return "" + + +def copy_kernel_vdi(session,args): + vdi = exists(args, 'vdi-ref') + size = exists(args,'image-size') + #Use the uuid as a filename + vdi_uuid=session.xenapi.VDI.get_uuid(vdi) + copy_args={'vdi_uuid':vdi_uuid,'vdi_size':int(size)} + filename=with_vdi_in_dom0(session, vdi, False, + lambda dev: + _copy_kernel_vdi('/dev/%s' % dev,copy_args)) + return filename + + if __name__ == '__main__': - XenAPIPlugin.dispatch({'put_vdis': put_vdis, - 'get_vdi': get_vdi, + XenAPIPlugin.dispatch({'upload_image': upload_image, + 'download_image': download_image, 'copy_kernel_vdi': copy_kernel_vdi}) -- cgit From 300657f298fbecf9a08792b6d15e462560a6cdf5 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 19:51:23 +0000 Subject: Adding documentation --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 85 +++++++++++++++++++--- 1 file changed, 76 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 7bbab4f52..dac773ff1 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -58,8 +58,8 @@ def _copy_kernel_vdi(dest,copy_args): def _download_tarball(sr_path, staging_path, image_id, glance_host, glance_port): - """ - + """Download the tarball image from Glance and extract it into the staging + area. """ conn = httplib.HTTPConnection(glance_host, glance_port) conn.request('GET', '/images/%s' % image_id) @@ -84,10 +84,34 @@ def _download_tarball(sr_path, staging_path, image_id, glance_host, def fixup_vhds(sr_path, staging_path, uuid_stack): - """ + """Fixup the downloaded VHDs before we move them into the SR. + + We cannot extract VHDs directly into the SR since they don't yet have + UUIDs, aren't properly associated with each other, and would be subject to + a race-condition of one-file being present and the other not being + downloaded yet. + + To avoid these we problems, we use a staging area to fixup the VHDs before + moving them into the SR. The steps involved are: + + 1. Extracting tarball into staging area + + 2. Renaming VHDs to use UUIDs ('snap.vhd' -> 'ffff-aaaa-...vhd') + + 3. Linking the two VHDs together + + 4. Pseudo-atomically moving the images into the SR. (It's not really + atomic because it takes place as two os.rename operations; however, the + chances of an SR.scan occuring between the two rename() invocations is so + small that we can safely ignore it) """ def rename_with_uuid(orig_path): - """Generate a uuid and rename the file with the uuid""" + """Rename VHD using UUID so that it will be recognized by SR on a + subsequent scan. + + Since Python2.4 doesn't have the `uuid` module, we pass a stack of + pre-computed UUIDs from the compute worker. + """ orig_dirname = os.path.dirname(orig_path) uuid = uuid_stack.pop() new_path = os.path.join(orig_dirname, "%s.vhd" % uuid) @@ -96,6 +120,11 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): def link_vhds(child_path, parent_path): + """Use vhd-util to associate the snapshot VHD with its base_copy. + + This needs to be done before we move both VHDs into the SR to prevent + the base_copy from being DOA (deleted-on-arrival). + """ modify_args = shlex.split( "vhd-util modify -n %(child_path)s -p %(parent_path)s" % locals()) @@ -136,8 +165,8 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): - """ - Explain preparing staging area here... + """Hard-link VHDs into staging area with appropriate filename + ('snap' or 'image.vhd') """ image_path = os.path.join(staging_path, 'image') os.mkdir(image_path) @@ -149,6 +178,8 @@ def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): def _upload_tarball(staging_path, image_id, glance_host, glance_port): """ + Create a tarball of the image and then stream that into Glance + using chunked-transfer-encoded HTTP. """ conn = httplib.HTTPConnection(glance_host, glance_port) #NOTE(sirp): httplib under python2.4 won't accept a file-like object @@ -189,7 +220,36 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): def _make_staging_area(sr_path): """ - Explain staging area here... + The staging area is a place where we can temporarily store and + manipulate VHDs. The use of the staging area is different for upload and + download: + + Download + ======== + + When we download the tarball, the VHDs contained within will have names + like "snap.vhd" and "image.vhd". We need to assign UUIDs to them before + moving them into the SR. However, since 'image.vhd' may be a base_copy, we + need to link it to 'snap.vhd' (using vhd-util modify) before moving both + into the SR (otherwise the SR.scan will cause 'image.vhd' to be deleted). + The staging area gives us a place to perform these operations before they + are moved to the SR, scanned, and then registered with XenServer. + + Upload + ====== + + On upload, we want to rename the VHDs to reflect what they are, 'snap.vhd' + in the case of the snapshot VHD, and 'image.vhd' in the case of the + base_copy. The staging area provides a directory in which we can create + hard-links to rename the VHDs without affecting what's in the SR. + + + NOTE + ==== + + The staging area is created as a subdirectory within the SR in order to + guarantee that it resides within the same filesystem and therefore permit + hard-linking and cheap file moves. """ # NOTE(sirp): staging area is created in SR to allow hard-linking staging_path = tempfile.mkdtemp(dir=sr_path) @@ -197,6 +257,12 @@ def _make_staging_area(sr_path): def _cleanup_staging_area(staging_path): + """Remove staging area directory + + On upload, the staging area contains hard-links to the VHDs in the SR; + it's safe to remove the staging-area because the SR will keep the link + count > 0 (so the VHDs in the SR will not be deleted). + """ shutil.rmtree(staging_path) @@ -211,7 +277,8 @@ def _assert_process_success(proc, cmd): def download_image(session, args): - """ + """Download an image from Glance, unbundle it, and then deposit the VHDs + into the storage repository """ params = pickle.loads(exists(args, 'params')) image_id = params["image_id"] @@ -231,7 +298,7 @@ def download_image(session, args): def upload_image(session, args): - """ + """Bundle the VHDs comprising an image and then stream them into Glance. """ params = pickle.loads(exists(args, 'params')) vdi_uuids = params["vdi_uuids"] -- cgit From c97d408842a4a5a8e9d379acc13c9c1f5871827f Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 14:10:43 -0600 Subject: Plugin changes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 97c970da5..4a4ed0e73 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -129,17 +129,19 @@ def transfer_vhd(session, args): logging.debug("Preparing to transmit %s to %s" % (source_path, dest_path)) - ssh_cmd = '-e "ssh -o StrictHostKeyChecking=no " ' + ssh_cmd = '-e \'ssh -o StrictHostKeyChecking=no\' ' - rsync_args = ['nohup', RSYNC, '-av', '--progress', ssh_cmd, source_path, - dest_path] + rsync_args = ['nohup > /root/instance%d_progress' % instance_id, RSYNC, + '-av', '--progress', ssh_cmd, source_path, dest_path] logging.debug('rsync %s' % (' '.join(rsync_args, ))) - rsync_proc = subprocess.Popen(rsync_args) + rsync_proc = subprocess.Popen(rsync_args, stdout=subprocess.PIPE) logging.debug('Rsync output: \n %s' % rsync_proc.communicate()[0]) - if rsync_proc.returncode != 0 + logging.debug('Rsync return: %d' % rsync_proc.returncode) + if rsync_proc.returncode != 0: raise Exception("Unexpected VHD transfer failure") + return "" if __name__ == '__main__': -- cgit From 00f2905a5debc5835b742dab8dce003f53e33fc2 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 14:29:31 -0600 Subject: plugin lol --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 4a4ed0e73..bfc2a2ed4 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -89,7 +89,7 @@ def move_vhds_into_sr(session, args): new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid) new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid) - logging.debug('Creating temporary SR path' % temp_vhd_path) + logging.debug('Creating temporary SR path %s' % temp_vhd_path) os.mkdir(temp_vhd_path) logging.debug('Moving %s into %s' % (source_base_copy_path, temp_vhd_path)) @@ -129,10 +129,10 @@ def transfer_vhd(session, args): logging.debug("Preparing to transmit %s to %s" % (source_path, dest_path)) - ssh_cmd = '-e \'ssh -o StrictHostKeyChecking=no\' ' + ssh_cmd = 'ssh -o StrictHostKeyChecking=no' - rsync_args = ['nohup > /root/instance%d_progress' % instance_id, RSYNC, - '-av', '--progress', ssh_cmd, source_path, dest_path] + rsync_args = ['nohup', RSYNC, '-av', '--progress', '-e', ssh_cmd, + source_path, dest_path] logging.debug('rsync %s' % (' '.join(rsync_args, ))) -- cgit From 9f77e0a46cac2ebaf9a18c4a175099b208db1adb Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 15:27:23 -0600 Subject: More plugin lol --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index bfc2a2ed4..cc72b5d26 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -90,7 +90,7 @@ def move_vhds_into_sr(session, args): new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid) logging.debug('Creating temporary SR path %s' % temp_vhd_path) - os.mkdir(temp_vhd_path) + os.makedirs(temp_vhd_path) logging.debug('Moving %s into %s' % (source_base_copy_path, temp_vhd_path)) shutil.move(source_base_copy_path, new_base_copy_path) @@ -107,11 +107,12 @@ def move_vhds_into_sr(session, args): new_base_copy_path]) logging.debug('Moving VHDs into SR %s' % sr_path) - shutil.move("%s/*.vhd" % temp_vhd_path, sr_path) + shutil.move("%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid), sr_path) + shutil.move("%s/%s.vhd" % (temp_vhd_path, new_cow_uuid), sr_path) - loggin.debug('Cleaning up temporary SR path %s' % temp_vhd_path) + logginig.debug('Cleaning up temporary SR path %s' % temp_vhd_path) os.rmdir(temp_vhd_path) - return None + return "" def transfer_vhd(session, args): -- cgit From 1d72b9d3ddc835d788ba1fec1a937c2788e94b38 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 21:36:13 +0000 Subject: Using Nova style nokernel --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index dac773ff1..75bdda2c6 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -182,15 +182,19 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): using chunked-transfer-encoded HTTP. """ conn = httplib.HTTPConnection(glance_host, glance_port) - #NOTE(sirp): httplib under python2.4 won't accept a file-like object + # NOTE(sirp): httplib under python2.4 won't accept a file-like object # to request conn.putrequest('PUT', '/images/%s' % image_id) + # FIXME(sirp): nokernel signals Nova to use a raw image. This is defined by + # FLAGS.null_kernel. Is there a way to get rid of this? headers = { 'x-image-meta-store': 'file', 'x-image-meta-is_public': 'True', 'x-image-meta-type': 'raw', 'x-image-meta-property-disk-format': 'vhd', + 'x-image-meta-property-kernel-id': 'nokernel', + 'x-image-meta-property-ramdisk-id': 'noramdisk', 'x-image-meta-property-container-format': 'tarball', 'transfer-encoding': "chunked", 'content-type': 'application/octet-stream', @@ -251,7 +255,6 @@ def _make_staging_area(sr_path): guarantee that it resides within the same filesystem and therefore permit hard-linking and cheap file moves. """ - # NOTE(sirp): staging area is created in SR to allow hard-linking staging_path = tempfile.mkdtemp(dir=sr_path) return staging_path @@ -314,7 +317,7 @@ def upload_image(session, args): finally: _cleanup_staging_area(staging_path) - return "" + return "" # Nothing useful to return on an upload def copy_kernel_vdi(session,args): -- cgit From c7cd7b755c86bd15e2b19f70a09f88f62361596c Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 22:31:51 +0000 Subject: More pep8 fixes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 51 +++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 75bdda2c6..43c58dcff 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -39,20 +39,22 @@ configure_logging('glance') CHUNK_SIZE = 8192 KERNEL_DIR = '/boot/guest' -def _copy_kernel_vdi(dest,copy_args): - vdi_uuid=copy_args['vdi_uuid'] - vdi_size=copy_args['vdi_size'] - logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s",dest,vdi_uuid) - filename=KERNEL_DIR + '/' + vdi_uuid + +def _copy_kernel_vdi(dest, copy_args): + vdi_uuid = copy_args['vdi_uuid'] + vdi_size = copy_args['vdi_size'] + logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s", + dest, vdi_uuid) + filename = KERNEL_DIR + '/' + vdi_uuid #read data from /dev/ and write into a file on /boot/guest - of=open(filename,'wb') - f=open(dest,'rb') + of = open(filename, 'wb') + f = open(dest, 'rb') #copy only vdi_size bytes - data=f.read(vdi_size) + data = f.read(vdi_size) of.write(data) f.close() of.close() - logging.debug("Done. Filename: %s",filename) + logging.debug("Done. Filename: %s", filename) return filename @@ -101,9 +103,9 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): 3. Linking the two VHDs together 4. Pseudo-atomically moving the images into the SR. (It's not really - atomic because it takes place as two os.rename operations; however, the - chances of an SR.scan occuring between the two rename() invocations is so - small that we can safely ignore it) + atomic because it takes place as two os.rename operations; however, + the chances of an SR.scan occuring between the two rename() + invocations is so small that we can safely ignore it) """ def rename_with_uuid(orig_path): """Rename VHD using UUID so that it will be recognized by SR on a @@ -118,7 +120,6 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): os.rename(orig_path, new_path) return new_path, uuid - def link_vhds(child_path, parent_path): """Use vhd-util to associate the snapshot VHD with its base_copy. @@ -132,7 +133,6 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): modify_args, stderr=subprocess.PIPE) _assert_process_success(modify_proc, "vhd-util") - def move_into_sr(orig_path): """Move a file into the SR""" filename = os.path.basename(orig_path) @@ -140,7 +140,6 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): os.rename(orig_path, new_path) return new_path - image_path = os.path.join(staging_path, 'image') orig_base_copy_path = os.path.join(image_path, 'image.vhd') @@ -157,7 +156,7 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): # NOTE(sirp): this step is necessary so that an SR scan won't # delete the base_copy out from under us (since it would be # orphaned) - link_vhds(snap_path, base_copy_path) + link_vhds(snap_path, base_copy_path) move_into_sr(snap_path) move_into_sr(base_copy_path) @@ -227,7 +226,7 @@ def _make_staging_area(sr_path): The staging area is a place where we can temporarily store and manipulate VHDs. The use of the staging area is different for upload and download: - + Download ======== @@ -241,7 +240,7 @@ def _make_staging_area(sr_path): Upload ====== - + On upload, we want to rename the VHDs to reflect what they are, 'snap.vhd' in the case of the snapshot VHD, and 'image.vhd' in the case of the base_copy. The staging area provides a directory in which we can create @@ -264,7 +263,7 @@ def _cleanup_staging_area(staging_path): On upload, the staging area contains hard-links to the VHDs in the SR; it's safe to remove the staging-area because the SR will keep the link - count > 0 (so the VHDs in the SR will not be deleted). + count > 0 (so the VHDs in the SR will not be deleted). """ shutil.rmtree(staging_path) @@ -320,15 +319,15 @@ def upload_image(session, args): return "" # Nothing useful to return on an upload -def copy_kernel_vdi(session,args): +def copy_kernel_vdi(session, args): vdi = exists(args, 'vdi-ref') - size = exists(args,'image-size') + size = exists(args, 'image-size') #Use the uuid as a filename - vdi_uuid=session.xenapi.VDI.get_uuid(vdi) - copy_args={'vdi_uuid':vdi_uuid,'vdi_size':int(size)} - filename=with_vdi_in_dom0(session, vdi, False, - lambda dev: - _copy_kernel_vdi('/dev/%s' % dev,copy_args)) + vdi_uuid = session.xenapi.VDI.get_uuid(vdi) + copy_args = {'vdi_uuid': vdi_uuid, 'vdi_size': int(size)} + filename = with_vdi_in_dom0(session, vdi, False, + lambda dev: + _copy_kernel_vdi('/dev/%s' % dev, copy_args)) return filename -- cgit From af920572f42b07c3ea491015d30eb5001d1f735d Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 15 Feb 2011 23:36:23 +0000 Subject: Adding vhd hidden sanity check --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 43c58dcff..ceb9a2185 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -140,6 +140,25 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): os.rename(orig_path, new_path) return new_path + def assert_vhd_not_hidden(path): + """ + This is a sanity check on the image; if a snap.vhd isn't + present, then the image.vhd better not be marked 'hidden' or it will + be deleted when moved into the SR. + """ + vhd_query_args = shlex.split( + "vhd-util query -n %(path)s -f" % locals()) + vhd_query_proc = subprocess.Popen( + vhd_query_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = _assert_process_success(vhd_query_proc, "vhd-util") + for line in out.splitlines(): + if line.startswith('hidden'): + value = line.split(':')[1].strip() + if value == "1": + raise Exception( + "VHD %(path)s is marked as hidden without child" % + locals()) + image_path = os.path.join(staging_path, 'image') orig_base_copy_path = os.path.join(image_path, 'image.vhd') @@ -158,6 +177,8 @@ def fixup_vhds(sr_path, staging_path, uuid_stack): # orphaned) link_vhds(snap_path, base_copy_path) move_into_sr(snap_path) + else: + assert_vhd_not_hidden(base_copy_path) move_into_sr(base_copy_path) return vdi_uuid @@ -276,7 +297,7 @@ def _assert_process_success(proc, cmd): if ret != 0: msg = "%(cmd)s returned non-zero exit code (%i): '%s'" % (ret, err) raise Exception(msg) - + return out, err def download_image(session, args): """Download an image from Glance, unbundle it, and then deposit the VHDs -- cgit From cd5aba9d1d00d9daad87efd89f78e49079bee2c7 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 18:02:57 -0600 Subject: foo --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index cc72b5d26..5bf0fe994 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -110,7 +110,7 @@ def move_vhds_into_sr(session, args): shutil.move("%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid), sr_path) shutil.move("%s/%s.vhd" % (temp_vhd_path, new_cow_uuid), sr_path) - logginig.debug('Cleaning up temporary SR path %s' % temp_vhd_path) + logging.debug('Cleaning up temporary SR path %s' % temp_vhd_path) os.rmdir(temp_vhd_path) return "" -- cgit From bb98e2055002ff3ed2099f60bbe4058d5f5c7b35 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Tue, 15 Feb 2011 23:10:29 -0600 Subject: hurr durr --- plugins/xenserver/xenapi/etc/xapi.d/plugins/migration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 5bf0fe994..7a6eefda2 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -102,7 +102,8 @@ def move_vhds_into_sr(session, args): os.rmdir(source_image_path) # Link the COW to the base copy - logging.debug('Attaching COW to the base copy...') + logging.debug('Attaching COW to the base copy %s -> %s' % + (new_cow_path, new_base_copy_path)) subprocess.call([VHD_UTIL, 'modify', '-n', new_cow_path, '-p', new_base_copy_path]) -- cgit From 585ba4d6cf25eabf83b1b33a6de794ce671c0c98 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 16 Feb 2011 18:43:55 +0000 Subject: Putting glance plugin under pep8 control --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 47e094f02..f737c6c41 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -299,6 +299,7 @@ def _assert_process_success(proc, cmd): raise Exception(msg) return out, err + def download_image(session, args): """Download an image from Glance, unbundle it, and then deposit the VHDs into the storage repository -- cgit From c56b1814cfae7a9c814b2d37388aff5e772771b6 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 16 Feb 2011 23:39:12 +0000 Subject: Pep8 fixes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index f737c6c41..c3f793ddd 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -300,7 +300,7 @@ def _assert_process_success(proc, cmd): return out, err -def download_image(session, args): +def download_vhd(session, args): """Download an image from Glance, unbundle it, and then deposit the VHDs into the storage repository """ @@ -321,7 +321,7 @@ def download_image(session, args): _cleanup_staging_area(staging_path) -def upload_image(session, args): +def upload_vhd(session, args): """Bundle the VHDs comprising an image and then stream them into Glance. """ params = pickle.loads(exists(args, 'params')) @@ -365,7 +365,7 @@ def remove_kernel_ramdisk(session, args): if __name__ == '__main__': - XenAPIPlugin.dispatch({'upload_image': upload_image, - 'download_image': download_image, + XenAPIPlugin.dispatch({'upload_vhd': upload_vhd, + 'download_vhd': download_vhd, 'copy_kernel_vdi': copy_kernel_vdi, 'remove_kernel_ramdisk': remove_kernel_ramdisk}) -- cgit From 04e29f6dc4b13b6fd0cbe5013cf241a727eb56ac Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 17 Feb 2011 01:24:31 +0000 Subject: Use glance image type to determine disk type --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index c3f793ddd..a91f8a7c1 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -211,8 +211,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): headers = { 'x-image-meta-store': 'file', 'x-image-meta-is_public': 'True', - 'x-image-meta-type': 'raw', - 'x-image-meta-property-disk-format': 'vhd', + 'x-image-meta-type': 'vhd', 'x-image-meta-property-kernel-id': 'nokernel', 'x-image-meta-property-ramdisk-id': 'noramdisk', 'x-image-meta-property-container-format': 'tarball', -- cgit From 8dceaccb81e95b55fac2156df4f04ef0a7469112 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 17 Feb 2011 07:58:42 +0000 Subject: Typo fixes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index a91f8a7c1..3b5cedda7 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -85,7 +85,7 @@ def _download_tarball(sr_path, staging_path, image_id, glance_host, conn.close() -def fixup_vhds(sr_path, staging_path, uuid_stack): +def _fixup_vhds(sr_path, staging_path, uuid_stack): """Fixup the downloaded VHDs before we move them into the SR. We cannot extract VHDs directly into the SR since they don't yet have @@ -314,7 +314,7 @@ def download_vhd(session, args): try: _download_tarball(sr_path, staging_path, image_id, glance_host, glance_port) - vdi_uuid = fixup_vhds(sr_path, staging_path, uuid_stack) + vdi_uuid = _fixup_vhds(sr_path, staging_path, uuid_stack) return vdi_uuid finally: _cleanup_staging_area(staging_path) -- cgit From 05d135be0c0d8a90a97d62005a101345964800cf Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 18 Feb 2011 22:50:13 +0000 Subject: Typo fix --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 3b5cedda7..097670b58 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -215,7 +215,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): 'x-image-meta-property-kernel-id': 'nokernel', 'x-image-meta-property-ramdisk-id': 'noramdisk', 'x-image-meta-property-container-format': 'tarball', - 'transfer-encoding': "chunked", + 'transfer-encoding': 'chunked', 'content-type': 'application/octet-stream', } for header, value in headers.iteritems(): -- cgit From 8cf6a0c01ee39066f17a11d5e9313c2828a59634 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 25 Feb 2011 01:50:18 +0000 Subject: No longer users image/ directory in tarball --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index e229a9358..bcdf34413 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -163,16 +163,14 @@ def _fixup_vhds(sr_path, staging_path, uuid_stack): "VHD %(path)s is marked as hidden without child" % locals()) - image_path = os.path.join(staging_path, 'image') - - orig_base_copy_path = os.path.join(image_path, 'image.vhd') + orig_base_copy_path = os.path.join(staging_path, 'image.vhd') if not os.path.exists(orig_base_copy_path): raise Exception("Invalid image: image.vhd not present") base_copy_path, base_copy_uuid = rename_with_uuid(orig_base_copy_path) vdi_uuid = base_copy_uuid - orig_snap_path = os.path.join(image_path, 'snap.vhd') + orig_snap_path = os.path.join(staging_path, 'snap.vhd') if os.path.exists(orig_snap_path): snap_path, snap_uuid = rename_with_uuid(orig_snap_path) vdi_uuid = snap_uuid @@ -192,11 +190,9 @@ def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids): """Hard-link VHDs into staging area with appropriate filename ('snap' or 'image.vhd') """ - image_path = os.path.join(staging_path, 'image') - os.mkdir(image_path) for name, uuid in vdi_uuids.items(): source = os.path.join(sr_path, "%s.vhd" % uuid) - link_name = os.path.join(image_path, "%s.vhd" % name) + link_name = os.path.join(staging_path, "%s.vhd" % name) os.link(source, link_name) -- cgit From ec9ede003c839248ca9593c03160a23ff8ec0db1 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 25 Feb 2011 02:26:46 +0000 Subject: Adding _make_subprocess function --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 57 ++++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index bcdf34413..869d46e70 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -75,17 +75,15 @@ def _download_tarball(sr_path, staging_path, image_id, glance_host, elif resp.status != httplib.OK: raise Exception("Unexpected response from Glance %i" % res.status) - tar_args = shlex.split( - "tar -zx --directory=%(staging_path)s" % locals()) - tar_proc = subprocess.Popen( - tar_args, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + tar_cmd = "tar -zx --directory=%(staging_path)s" % locals() + tar_proc = _make_subprocess(tar_cmd, stderr=True, stdin=True) chunk = resp.read(CHUNK_SIZE) while chunk: tar_proc.stdin.write(chunk) chunk = resp.read(CHUNK_SIZE) - _assert_process_success(tar_proc, "tar") + _finish_subprocess(tar_proc, "tar") conn.close() @@ -130,12 +128,10 @@ def _fixup_vhds(sr_path, staging_path, uuid_stack): This needs to be done before we move both VHDs into the SR to prevent the base_copy from being DOA (deleted-on-arrival). """ - 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") + modify_cmd = ("vhd-util modify -n %(child_path)s -p %(parent_path)s" + % locals()) + modify_proc = _make_subprocess(modify_cmd, stderr=True) + _finish_subprocess(modify_proc, "vhd-util") def move_into_sr(orig_path): """Move a file into the SR""" @@ -150,11 +146,9 @@ def _fixup_vhds(sr_path, staging_path, uuid_stack): present, then the image.vhd better not be marked 'hidden' or it will be deleted when moved into the SR. """ - vhd_query_args = shlex.split( - "vhd-util query -n %(path)s -f" % locals()) - vhd_query_proc = subprocess.Popen( - vhd_query_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = _assert_process_success(vhd_query_proc, "vhd-util") + query_cmd = "vhd-util query -n %(path)s -f" % locals() + query_proc = _make_subprocess(query_cmd, stdout=True, stderr=True) + out, err = _finish_subprocess(query_proc, "vhd-util") for line in out.splitlines(): if line.startswith('hidden'): value = line.split(':')[1].strip() @@ -208,25 +202,24 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): # FIXME(sirp): nokernel signals Nova to use a raw image. This is defined by # FLAGS.null_kernel. Is there a way to get rid of this? + # TODO(sirp): make `store` configurable headers = { - 'x-image-meta-store': 'file', + 'content-type': 'application/octet-stream', + 'transfer-encoding': 'chunked', 'x-image-meta-is_public': 'True', - 'x-image-meta-type': 'vhd', 'x-image-meta-status': 'queued', + 'x-image-meta-store': 'file', + 'x-image-meta-type': 'vhd', 'x-image-meta-property-kernel-id': 'nokernel', 'x-image-meta-property-ramdisk-id': 'noramdisk', 'x-image-meta-property-container-format': 'tarball', - 'transfer-encoding': 'chunked', - 'content-type': 'application/octet-stream', } for header, value in headers.iteritems(): conn.putheader(header, value) conn.endheaders() - tar_args = shlex.split( - "tar -zc --directory=%(staging_path)s ." % locals()) - tar_proc = subprocess.Popen( - tar_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + tar_cmd = "tar -zc --directory=%(staging_path)s ." % locals() + tar_proc = _make_subprocess(tar_cmd, stdout=True, stderr=True) chunk = tar_proc.stdout.read(CHUNK_SIZE) while chunk: @@ -234,7 +227,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): chunk = tar_proc.stdout.read(CHUNK_SIZE) conn.send("0\r\n\r\n") - _assert_process_success(tar_proc, "tar") + _finish_subprocess(tar_proc, "tar") resp = conn.getresponse() if resp.status != httplib.OK: @@ -289,7 +282,19 @@ def _cleanup_staging_area(staging_path): shutil.rmtree(staging_path) -def _assert_process_success(proc, cmd): +def _make_subprocess(cmdline, stdout=False, stderr=False, stdin=False): + """Make a subprocess according to the given command-line string + """ + kwargs = {} + kwargs['stdout'] = stdout and subprocess.PIPE or None + kwargs['stderr'] = stderr and subprocess.PIPE or None + kwargs['stdin'] = stdin and subprocess.PIPE or None + args = shlex.split(cmdline) + proc = subprocess.Popen(args, **kwargs) + return proc + + +def _finish_subprocess(proc, cmd): """Ensure that the process returned a zero exit code indicating success """ out, err = proc.communicate() -- cgit From e3d6dc70a6b77d80afcf87473bc79549540ac4ce Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 25 Feb 2011 02:51:14 +0000 Subject: Removing unecessary nokernel stuff --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 4 ---- 1 file changed, 4 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 869d46e70..18e4866f7 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -200,8 +200,6 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): # to request conn.putrequest('PUT', '/images/%s' % image_id) - # FIXME(sirp): nokernel signals Nova to use a raw image. This is defined by - # FLAGS.null_kernel. Is there a way to get rid of this? # TODO(sirp): make `store` configurable headers = { 'content-type': 'application/octet-stream', @@ -210,8 +208,6 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): 'x-image-meta-status': 'queued', 'x-image-meta-store': 'file', 'x-image-meta-type': 'vhd', - 'x-image-meta-property-kernel-id': 'nokernel', - 'x-image-meta-property-ramdisk-id': 'noramdisk', 'x-image-meta-property-container-format': 'tarball', } for header, value in headers.iteritems(): -- cgit From d27197ae53f3282280198d9bfe7f37a059fa8a35 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 25 Feb 2011 03:16:04 +0000 Subject: Removing unecessary headers --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 18e4866f7..7531af4ec 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -83,7 +83,7 @@ def _download_tarball(sr_path, staging_path, image_id, glance_host, tar_proc.stdin.write(chunk) chunk = resp.read(CHUNK_SIZE) - _finish_subprocess(tar_proc, "tar") + _finish_subprocess(tar_proc, tar_cmd) conn.close() @@ -131,7 +131,7 @@ def _fixup_vhds(sr_path, staging_path, uuid_stack): modify_cmd = ("vhd-util modify -n %(child_path)s -p %(parent_path)s" % locals()) modify_proc = _make_subprocess(modify_cmd, stderr=True) - _finish_subprocess(modify_proc, "vhd-util") + _finish_subprocess(modify_proc, modify_cmd) def move_into_sr(orig_path): """Move a file into the SR""" @@ -148,7 +148,8 @@ def _fixup_vhds(sr_path, staging_path, uuid_stack): """ query_cmd = "vhd-util query -n %(path)s -f" % locals() query_proc = _make_subprocess(query_cmd, stdout=True, stderr=True) - out, err = _finish_subprocess(query_proc, "vhd-util") + out, err = _finish_subprocess(query_proc, query_cmd) + for line in out.splitlines(): if line.startswith('hidden'): value = line.split(':')[1].strip() @@ -206,9 +207,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): 'transfer-encoding': 'chunked', 'x-image-meta-is_public': 'True', 'x-image-meta-status': 'queued', - 'x-image-meta-store': 'file', - 'x-image-meta-type': 'vhd', - 'x-image-meta-property-container-format': 'tarball', + 'x-image-meta-type': 'vhd' } for header, value in headers.iteritems(): conn.putheader(header, value) @@ -223,7 +222,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): chunk = tar_proc.stdout.read(CHUNK_SIZE) conn.send("0\r\n\r\n") - _finish_subprocess(tar_proc, "tar") + _finish_subprocess(tar_proc, tar_cmd) resp = conn.getresponse() if resp.status != httplib.OK: @@ -290,14 +289,14 @@ def _make_subprocess(cmdline, stdout=False, stderr=False, stdin=False): return proc -def _finish_subprocess(proc, cmd): +def _finish_subprocess(proc, cmdline): """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) + raise Exception("'%(cmdline)s' returned non-zero exit code: " + "retcode=%(ret)i, stderr='%(err)s'" % locals()) return out, err -- cgit From 8da6796789767b1341cb5a650066b67ad3191c74 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 28 Feb 2011 12:30:02 -0600 Subject: Merge review fixes --- .../xenserver/xenapi/etc/xapi.d/plugins/migration | 62 +++++----------------- 1 file changed, 14 insertions(+), 48 deletions(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index 7a6eefda2..4aa89863a 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -1,7 +1,6 @@ #!/usr/bin/env python -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. +# Copyright 2010 OpenStack LLC. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -31,38 +30,6 @@ import XenAPIPlugin from pluginlib_nova import * configure_logging('migration') -SSH_HOSTS = '/root/.ssh/known_hosts' -DEVNULL = '/dev/null' -KEYSCAN = '/usr/bin/ssh-keyscan' -RSYNC = '/usr/bin/rsync' -FILE_SR_PATH = '/var/run/sr-mount' -IMAGE_PATH = '/images/' -VHD_UTIL = '/usr/sbin/vhd-util' - -def get_sr_path(session): - sr_ref = find_sr(session) - - if sr_ref is None: - raise Exception('Cannot find SR to read VDI from') - - sr_rec = session.xenapi.SR.get_record(sr_ref) - sr_uuid = sr_rec["uuid"] - sr_path = os.path.join(FILE_SR_PATH, sr_uuid) - return sr_path - -def find_sr(session): - host = get_this_host(session) - srs = session.xenapi.SR.get_all() - for sr in srs: - sr_rec = session.xenapi.SR.get_record(sr) - if not ('i18n-key' in sr_rec['other_config'] and - sr_rec['other_config']['i18n-key'] == 'local-storage'): - continue - for pbd in sr_rec['PBDs']: - pbd_rec = session.xenapi.PBD.get_record(pbd) - if pbd_rec['host'] == host: - return sr - return None def move_vhds_into_sr(session, args): """Moves the VHDs from their copied location to the SR""" @@ -75,13 +42,13 @@ def move_vhds_into_sr(session, args): new_base_copy_uuid = params['new_base_copy_uuid'] new_cow_uuid = params['new_cow_uuid'] - sr_path = get_sr_path(session) + sr_path = params['sr_path'] sr_temp_path = "%s/images/" % sr_path - # Discover the copied VHDs locally, and then set up paths to copy + # Discover the copied VHDs locally, and then set up paths to copy # them to under the SR - source_image_path = "%s/instance%d" % (IMAGE_PATH, instance_id) - source_base_copy_path = "%s/%s.vhd" % (source_image_path, + source_image_path = "%s/instance%d" % ('/images/', instance_id) + source_base_copy_path = "%s/%s.vhd" % (source_image_path, old_base_copy_uuid) source_cow_path = "%s/%s.vhd" % (source_image_path, old_cow_uuid) @@ -102,11 +69,10 @@ def move_vhds_into_sr(session, args): os.rmdir(source_image_path) # Link the COW to the base copy - logging.debug('Attaching COW to the base copy %s -> %s' % + logging.debug('Attaching COW to the base copy %s -> %s' % (new_cow_path, new_base_copy_path)) - subprocess.call([VHD_UTIL, 'modify', '-n', new_cow_path, '-p', - new_base_copy_path]) - + subprocess.call(shlex.split('/usr/sbin/vhd-util modify -n %s -p %s' % + (new_cow_path, new_base_copy_path))) logging.debug('Moving VHDs into SR %s' % sr_path) shutil.move("%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid), sr_path) shutil.move("%s/%s.vhd" % (temp_vhd_path, new_cow_uuid), sr_path) @@ -122,19 +88,19 @@ def transfer_vhd(session, args): instance_id = params['instance_id'] host = params['host'] vdi_uuid = params['vdi_uuid'] - sr_path = get_sr_path(session) + sr_path = params['sr_path'] vhd_path = "%s.vhd" % vdi_uuid source_path = "%s/%s" % (sr_path, vhd_path) - dest_path = '%s:%sinstance%d/' % (host, IMAGE_PATH, instance_id) + dest_path = '%s:%sinstance%d/' % (host, '/images/', instance_id) - logging.debug("Preparing to transmit %s to %s" % (source_path, + logging.debug("Preparing to transmit %s to %s" % (source_path, dest_path)) ssh_cmd = 'ssh -o StrictHostKeyChecking=no' - rsync_args = ['nohup', RSYNC, '-av', '--progress', '-e', ssh_cmd, - source_path, dest_path] + rsync_args = shlex.split('nohup /usr/bin/rsync -av --progress -e %s %s %s' + % (ssh_cmd, source_path, dest_path)) logging.debug('rsync %s' % (' '.join(rsync_args, ))) @@ -148,4 +114,4 @@ def transfer_vhd(session, args): if __name__ == '__main__': XenAPIPlugin.dispatch({'transfer_vhd': transfer_vhd, - 'move_vhds_into_sr':move_vhds_into_sr, }) + 'move_vhds_into_sr': move_vhds_into_sr, }) -- cgit From 953fe68ce9b27322003200c464c121464761d1e2 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Wed, 2 Mar 2011 15:46:50 -0600 Subject: merge fixes --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index d08754c19..aa12d432a 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -207,7 +207,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port): 'transfer-encoding': 'chunked', 'x-image-meta-is_public': 'True', 'x-image-meta-status': 'queued', - 'x-image-meta-type': 'vhd', } + 'x-image-meta-type': 'vhd'} for header, value in headers.iteritems(): conn.putheader(header, value) conn.endheaders() -- cgit