diff options
| author | Anthony Young <sleepsonthefloor@gmail.com> | 2011-08-22 20:05:08 -0700 |
|---|---|---|
| committer | Anthony Young <sleepsonthefloor@gmail.com> | 2011-08-22 20:05:08 -0700 |
| commit | 2f304ecb74cced6d57dc4590f5bf41b7df88a504 (patch) | |
| tree | b6a6adbbcdb6e342a21112e5521f708cd0e3d8c7 /nova/utils.py | |
| parent | af39051bd033e9e4017fec0fe1647aef582bc38e (diff) | |
| parent | c2fb9485f956482a5e6d628bb80e86d3e8d90d3a (diff) | |
| download | nova-2f304ecb74cced6d57dc4590f5bf41b7df88a504.tar.gz nova-2f304ecb74cced6d57dc4590f5bf41b7df88a504.tar.xz nova-2f304ecb74cced6d57dc4590f5bf41b7df88a504.zip | |
merge trunk, resolve conflicts, fix tests
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/nova/utils.py b/nova/utils.py index 54126f644..fc4bbd53b 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -295,7 +295,7 @@ EASIER_PASSWORD_SYMBOLS = ('23456789' # Removed: 0, 1 def usage_from_instance(instance_ref, **kw): usage_info = dict( - tenant_id=instance_ref['project_id'], + project_id=instance_ref['project_id'], user_id=instance_ref['user_id'], instance_id=instance_ref['id'], instance_type=instance_ref['instance_type']['name'], @@ -547,11 +547,17 @@ def to_primitive(value, convert_instances=False, level=0): Therefore, convert_instances=True is lossy ... be aware. """ - if inspect.isclass(value): - return unicode(value) + nasty = [inspect.ismodule, inspect.isclass, inspect.ismethod, + inspect.isfunction, inspect.isgeneratorfunction, + inspect.isgenerator, inspect.istraceback, inspect.isframe, + inspect.iscode, inspect.isbuiltin, inspect.isroutine, + inspect.isabstract] + for test in nasty: + if test(value): + return unicode(value) if level > 3: - return [] + return '?' # The try block may not be necessary after the class check above, # but just in case ... @@ -838,3 +844,19 @@ def bool_from_str(val): return True if int(val) else False except ValueError: return val.lower() == 'true' + + +def is_valid_ipv4(address): + """valid the address strictly as per format xxx.xxx.xxx.xxx. + where xxx is a value between 0 and 255. + """ + parts = address.split(".") + if len(parts) != 4: + return False + for item in parts: + try: + if not 0 <= int(item) <= 255: + return False + except ValueError: + return False + return True |
