projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bump version and changelog for release
[osm/N2VC.git]
/
juju
/
constraints.py
diff --git
a/juju/constraints.py
b/juju/constraints.py
index
43c048a
..
998862d
100644
(file)
--- a/
juju/constraints.py
+++ b/
juju/constraints.py
@@
-21,6
+21,7
@@
import re
MEM = re.compile('^[1-9][0-9]*[MGTP]$')
# Multiplication factors to get Megabytes
MEM = re.compile('^[1-9][0-9]*[MGTP]$')
# Multiplication factors to get Megabytes
+# https://github.com/juju/juju/blob/master/constraints/constraints.go#L666
FACTORS = {
"M": 1,
"G": 1024,
FACTORS = {
"M": 1,
"G": 1024,
@@
-28,13
+29,17
@@
FACTORS = {
"P": 1024 * 1024 * 1024
}
"P": 1024 * 1024 * 1024
}
+SNAKE1 = re.compile(r'(.)([A-Z][a-z]+)')
+SNAKE2 = re.compile('([a-z0-9])([A-Z])')
+
+
def parse(constraints):
"""
Constraints must be expressed as a string containing only spaces
and key value pairs joined by an '='.
"""
def parse(constraints):
"""
Constraints must be expressed as a string containing only spaces
and key value pairs joined by an '='.
"""
- if
constraints is None
:
+ if
not constraints
:
return None
if type(constraints) is dict:
return None
if type(constraints) is dict:
@@
-52,6
+57,11
@@
def normalize_key(key):
key = key.strip()
key = key.replace("-", "_") # Our _client lib wants "_" in place of "-"
key = key.strip()
key = key.replace("-", "_") # Our _client lib wants "_" in place of "-"
+
+ # Convert camelCase to snake_case
+ key = SNAKE1.sub(r'\1_\2', key)
+ key = SNAKE2.sub(r'\1_\2', key).lower()
+
return key
return key
@@
-68,4
+78,7
@@
def normalize_value(value):
values = [normalize_value(v) for v in values]
return values
values = [normalize_value(v) for v in values]
return values
+ if value.isdigit():
+ return int(value)
+
return value
return value