projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixes for landscape bundle.
[osm/N2VC.git]
/
juju
/
constraints.py
diff --git
a/juju/constraints.py
b/juju/constraints.py
index
d713774
..
97529e4
100644
(file)
--- a/
juju/constraints.py
+++ b/
juju/constraints.py
@@
-1,5
+1,5
@@
#
#
-#
Library to parse
constraints
+#
Module that parses
constraints
#
# The current version of juju core expects the client to take
# constraints given in the form "mem=10G foo=bar" and parse them into
#
# The current version of juju core expects the client to take
# constraints given in the form "mem=10G foo=bar" and parse them into
@@
-11,6
+11,9
@@
# constraints keys are valid, and that we can successfully dump the
# constraints dict to json.
#
# constraints keys are valid, and that we can successfully dump the
# constraints dict to json.
#
+# Once https://bugs.launchpad.net/juju/+bug/1645402 is addressed, this
+# module should be deprecated.
+#
import re
import re
@@
-25,6
+28,9
@@
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
def parse(constraints):
"""
Constraints must be expressed as a string containing only spaces
@@
-34,6
+40,13
@@
def parse(constraints):
if constraints is None:
return None
if constraints is None:
return None
+ if constraints == "":
+ return None
+
+ if type(constraints) is dict:
+ # Fowards compatibilty: already parsed
+ return constraints
+
constraints = {
normalize_key(k): normalize_value(v) for k, v in [
s.split("=") for s in constraints.split(" ")]}
constraints = {
normalize_key(k): normalize_value(v) for k, v in [
s.split("=") for s in constraints.split(" ")]}
@@
-45,6
+58,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
@@
-61,4
+79,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