330
330
def get_juju_version():
331
"""Get the current version of the Juju client.
333
Return a string of the numeric portion of the Juju version.
331
"""Return the current juju-core version.
333
Return a (major:int, minor:int, patch:bytes) tuple, including
334
major, minor and patch version numbers.
336
Raise a ValueError if the "juju version" call exits with an error
337
or the returned version is not well formed.
335
retcode, version, error = call('juju', 'version')
339
retcode, output, error = call('juju', 'version')
338
return version.split('-')[0]
341
def bootstrap_requires_sudo(is_local, version):
342
"""After Juju version 1.17.0 sudo is no longer required for
343
bootstrapping local deployments.
341
raise ValueError(error)
342
version_string = output.split('-')[0]
344
major, minor, patch = version_string.split('.', 2)
345
return int(major), int(minor), int(patch)
347
msg = 'invalid version string: {}'.format(version_string)
348
raise ValueError(msg.encode('utf-8'))
351
def local_bootstrap_requires_sudo(major, minor, patch):
352
"""Parse Juju version to check if sudo is required for local deployment.
354
Before Juju version 1.17.2 sudo is required for bootstrapping
345
major, minor, _ = version.split('.')
346
return is_local and int(major) >= 1 and int(minor) < 17
359
patch_ok = patch <= 1
360
return major >= 1 and minor >= 17 and patch_ok
349
363
def run_once(function):