summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorDonal Lafferty <donal.lafferty@citrix.com>2011-06-27 15:22:15 +0100
committerDonal Lafferty <donal.lafferty@citrix.com>2011-06-27 15:22:15 +0100
commitd7844ecbf5dff67d22beaaff90f0bfa3acb4362a (patch)
tree413dd7858fdfbd8e214378e3102273f74be7ea71 /nova/utils.py
parent81894967d8b6920f7cf1b64636a7c4f531e81bde (diff)
parent8a8c013cd4513b07e936125a23188e7608f40d58 (diff)
Pulled trunk, merged boot from ISO changes.
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py45
1 files changed, 36 insertions, 9 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 361fc9873..6d8324e5b 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -35,6 +35,7 @@ import struct
import sys
import time
import types
+import uuid
from xml.sax import saxutils
from eventlet import event
@@ -142,24 +143,26 @@ def execute(*cmd, **kwargs):
env = os.environ.copy()
if addl_env:
env.update(addl_env)
+ _PIPE = subprocess.PIPE # pylint: disable=E1101
obj = subprocess.Popen(cmd,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ stdin=_PIPE,
+ stdout=_PIPE,
+ stderr=_PIPE,
env=env)
result = None
if process_input is not None:
result = obj.communicate(process_input)
else:
result = obj.communicate()
- obj.stdin.close()
- if obj.returncode:
- LOG.debug(_('Result was %s') % obj.returncode)
+ obj.stdin.close() # pylint: disable=E1101
+ _returncode = obj.returncode # pylint: disable=E1101
+ if _returncode:
+ LOG.debug(_('Result was %s') % _returncode)
if type(check_exit_code) == types.IntType \
- and obj.returncode != check_exit_code:
+ and _returncode != check_exit_code:
(stdout, stderr) = result
raise exception.ProcessExecutionError(
- exit_code=obj.returncode,
+ exit_code=_returncode,
stdout=stdout,
stderr=stderr,
cmd=' '.join(cmd))
@@ -307,7 +310,7 @@ def get_my_linklocal(interface):
def utcnow():
- """Overridable version of datetime.datetime.utcnow."""
+ """Overridable version of utils.utcnow."""
if utcnow.override_time:
return utcnow.override_time
return datetime.datetime.utcnow()
@@ -523,6 +526,16 @@ def loads(s):
return json.loads(s)
+try:
+ import anyjson
+except ImportError:
+ pass
+else:
+ anyjson._modules.append(("nova.utils", "dumps", TypeError,
+ "loads", ValueError))
+ anyjson.force_implementation("nova.utils")
+
+
_semaphores = {}
@@ -724,3 +737,17 @@ def parse_server_string(server_str):
except:
LOG.debug(_('Invalid server_string: %s' % server_str))
return ('', '')
+
+
+def gen_uuid():
+ return uuid.uuid4()
+
+
+def is_uuid_like(val):
+ """For our purposes, a UUID is a string in canoical form:
+
+ aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
+ """
+ if not isinstance(val, basestring):
+ return False
+ return (len(val) == 36) and (val.count('-') == 4)