~james-page/ubuntu/raring/nova/myfixes

« back to all changes in this revision

Viewing changes to plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-09-20 07:45:50 UTC
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: package-import@ubuntu.com-20120920074550-ir9euteqh5gt4ja8
Tags: upstream-2012.2~rc1
ImportĀ upstreamĀ versionĀ 2012.2~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
"""Various utilities used by XenServer plugins."""
16
16
 
 
17
import cPickle as pickle
17
18
import logging
18
19
import os
19
20
import shlex
21
22
import subprocess
22
23
import tempfile
23
24
 
 
25
import XenAPIPlugin
24
26
 
25
27
CHUNK_SIZE = 8192
26
28
 
362
364
        tar_proc.stdin.write(chunk)
363
365
 
364
366
    finish_subprocess(tar_proc, tar_cmd)
 
367
 
 
368
 
 
369
def _handle_serialization(func):
 
370
    def wrapped(session, params):
 
371
        params = pickle.loads(params['params'])
 
372
        rv = func(session, *params['args'], **params['kwargs'])
 
373
        return pickle.dumps(rv)
 
374
    return wrapped
 
375
 
 
376
 
 
377
def register_plugin_calls(*funcs):
 
378
    """Wrapper around XenAPIPlugin.dispatch which handles pickle
 
379
    serialization.
 
380
    """
 
381
    wrapped_dict = {}
 
382
    for func in funcs:
 
383
        wrapped_dict[func.__name__] = _handle_serialization(func)
 
384
    XenAPIPlugin.dispatch(wrapped_dict)