Adds strict mode suppor for DockerOpts #18

Merged
merged 2 commits into from Apr 27, 2016
Jump to file or symbol
Failed to load files and symbols.
+24 −8
Split
@@ -28,33 +28,38 @@ def __init__(self, opts_path=None):
def __save(self):
self.db.set('docker_opts', self.data)
- def add(self, key, value):
+ def add(self, key, value, strict=False):
'''
Adds data to the map of values for the DockerOpts file.
Supports single values, or "multiopt variables". If you
have a flag only option, like --tlsverify, set the value
- to None.
+ to None. To preserve the exact value, pass strict
eg:
opts.add('label', 'foo')
opts.add('label', 'foo, bar, baz')
opts.add('flagonly', None)
+ opts.add('cluster-store', 'consul://a:4001,b:4001,c:4001/swarm', strict=True)
'''
- if value:
+ if strict:
+ self.data['{}-strict'.format(key)] = value
+ if value:
values = [x.strip() for x in value.split(',')]
- if key in self.data:
+ # handle updates
+ if key in self.data and self.data[key] is not None:
item_data = self.data[key]
for c in values:
c = c.strip()
if c not in item_data:
item_data.append(c)
self.data[key] = item_data
else:
+ # handle new
self.data[key] = values
else:
+ # handle flagonly
self.data[key] = None
-
self.__save()
def remove(self, key, value):
@@ -82,8 +87,14 @@ def to_s(self):
flags = []
for key in self.data:
if self.data[key] == None:
+ # handle flagonly
flags.append("--{}".format(key))
+ elif '-strict' in key:
+ # handle strict values
+ proper_key = key.rstrip('-strict')
+ flags.append("--{}={}".format(proper_key, self.data[key]))
else:
+ # handle multiopt and typical flags
for item in self.data[key]:
flags.append("--{}={}".format(key, item))
return ' '.join(flags)
View
@@ -63,9 +63,9 @@
# built documents.
#
# The short X.Y version.
-version = u'0.1.4'
+version = u'0.1.5'
# The full version, including alpha/beta/rc tags.
-release = u'0.1.4'
+release = u'0.1.5'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
@@ -2,7 +2,7 @@
setup(
name = "charms.docker",
- version = '0.1.4',
+ version = '0.1.5',
author = "Charles Butler",
author_email = "charles.butler@ubuntu.com",
url = "http://github.com/juju-solutions/charms.docker",
@@ -46,3 +46,8 @@ def test_render_flag_only(self):
d = DockerOpts()
d.add('flagonly', None)
assert "--flagonly" in d.to_s()
+
+ def test_strict_options(self):
+ d = DockerOpts()
+ d.add('strictmode', 'strict-formatting,enabled-because', strict=True)
+ assert "--strictmode=strict-formatting,enabled-because" in d.to_s()