~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to plugins/xenserver/xenapi/etc/xapi.d/plugins/workarounds

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2012 Openstack, LLC
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
"""Handle the uploading and downloading of images via Glance."""
 
19
 
 
20
import cPickle as pickle
 
21
try:
 
22
    import json
 
23
except ImportError:
 
24
    import simplejson as json
 
25
import os
 
26
import shutil
 
27
 
 
28
import XenAPIPlugin
 
29
 
 
30
import utils
 
31
 
 
32
#FIXME(sirp): should this use pluginlib from 5.6?
 
33
from pluginlib_nova import *
 
34
configure_logging('hacks')
 
35
 
 
36
 
 
37
def _copy_vdis(sr_path, staging_path, vdi_uuids):
 
38
    seq_num = 0
 
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)
 
43
        seq_num += 1
 
44
 
 
45
 
 
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"]
 
51
 
 
52
    staging_path = utils.make_staging_area(sr_path)
 
53
    try:
 
54
        _copy_vdis(sr_path, staging_path, vdi_uuids)
 
55
        imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack)
 
56
    finally:
 
57
        utils.cleanup_staging_area(staging_path)
 
58
 
 
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)
 
62
 
 
63
 
 
64
if __name__ == '__main__':
 
65
    XenAPIPlugin.dispatch({'safe_copy_vdis': safe_copy_vdis})