3
# Copyright (c) 2012 Openstack, LLC
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
"""Handle the uploading and downloading of images via Glance."""
20
import cPickle as pickle
24
import simplejson as json
32
#FIXME(sirp): should this use pluginlib from 5.6?
33
from pluginlib_nova import *
34
configure_logging('hacks')
37
def _copy_vdis(sr_path, staging_path, vdi_uuids):
39
for vdi_uuid in vdi_uuids:
40
src = os.path.join(sr_path, "%s.vhd" % vdi_uuid)
41
dst = os.path.join(staging_path, "%d.vhd" % seq_num)
42
shutil.copyfile(src, dst)
46
def safe_copy_vdis(session, args):
47
params = pickle.loads(exists(args, 'params'))
48
sr_path = params["sr_path"]
49
vdi_uuids = params["vdi_uuids"]
50
uuid_stack = params["uuid_stack"]
52
staging_path = utils.make_staging_area(sr_path)
54
_copy_vdis(sr_path, staging_path, vdi_uuids)
55
imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack)
57
utils.cleanup_staging_area(staging_path)
59
# Right now, it's easier to return a single string via XenAPI,
60
# so we'll json encode the list of VHDs.
61
return json.dumps(imported_vhds)
64
if __name__ == '__main__':
65
XenAPIPlugin.dispatch({'safe_copy_vdis': safe_copy_vdis})