172
171
return json.loads(status)
175
_juju_version_expression = re.compile(r"""
176
^ # Beginning of line.
177
(?:juju\s+)? # Optional juju prefix.
178
(\d+)\.(\d+) # Major and minor versions.
179
(?:\.(\d+))? # Optional patch version.
180
.* # Optional suffix.
186
"""Return the currently used Juju version.
188
The version is returned as a named tuple (major, minor, patch).
189
If the patch number is missing, it is set to zero.
192
# In pyJuju, version info is printed to stderr.
193
output = subprocess.check_output(
194
['juju', '--version'], stderr=subprocess.STDOUT)
195
except subprocess.CalledProcessError:
196
# Current juju-core exposes a version subcommand.
197
output = subprocess.check_output(['juju', 'version'])
198
match = _juju_version_expression.match(output)
200
raise ValueError('invalid juju version: {!r}'.format(output))
201
to_int = lambda num: 0 if num is None else int(num)
202
return Version._make(map(to_int, match.groups()))
205
174
def make_service_name(prefix='service-'):
206
175
"""Generate a long, random service name."""
207
176
characters = string.ascii_lowercase