~citrix-openstack/nova/xenapi

« back to all changes in this revision

Viewing changes to nova/utils.py

  • Committer: Josh Kearney
  • Date: 2011-03-09 20:42:50 UTC
  • mfrom: (408.9.350 nova)
  • mto: (408.9.371 nova)
  • mto: This revision was merged to the branch mainline in revision 449.
  • Revision ID: josh@jk0.org-20110309204250-k522wtakilwk68zn
Merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import base64
25
25
import datetime
 
26
import functools
26
27
import inspect
27
28
import json
 
29
import lockfile
 
30
import netaddr
28
31
import os
29
32
import random
 
33
import re
30
34
import socket
31
35
import string
32
36
import struct
34
38
import time
35
39
import types
36
40
from xml.sax import saxutils
37
 
import re
38
 
import netaddr
39
41
 
40
42
from eventlet import event
41
43
from eventlet import greenthread
43
45
 
44
46
from nova import exception
45
47
from nova.exception import ProcessExecutionError
 
48
from nova import flags
46
49
from nova import log as logging
47
50
 
48
51
 
49
52
LOG = logging.getLogger("nova.utils")
50
53
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 
54
FLAGS = flags.FLAGS
51
55
 
52
56
 
53
57
def import_class(import_str):
491
495
    return json.loads(s)
492
496
 
493
497
 
 
498
def synchronized(name):
 
499
    def wrap(f):
 
500
        @functools.wraps(f)
 
501
        def inner(*args, **kwargs):
 
502
            lock = lockfile.FileLock(os.path.join(FLAGS.lock_path,
 
503
                                                  'nova-%s.lock' % name))
 
504
            with lock:
 
505
                return f(*args, **kwargs)
 
506
        return inner
 
507
    return wrap
 
508
 
 
509
 
494
510
def ensure_b64_encoding(val):
495
511
    """Safety method to ensure that values expected to be base64-encoded
496
512
    actually are. If they are, the value is returned unchanged. Otherwise,