30
30
from quickstart.models import charms
33
def get_api_url(api_address, juju_version, env_uuid, prefix='', charm=None):
34
"""Return the Juju WebSocket API endpoint.
36
Receives the Juju API server address, the Juju version and the unique
37
identifier of the current environment.
39
Optionally receive a prefix to be used in the path.
41
Optionally also receive the Juju GUI charm object as an instance of
42
"quickstart.models.charms.Charm". If provided, the function checks that
43
the specified Juju GUI charm supports the new Juju API endpoint.
44
If not supported, the old endpoint is returned.
46
The environment UUID can be None, in which case the old-style API URL
47
(not including the environment UUID) is returned.
49
base_url = 'wss://{}'.format(api_address)
50
prefix = prefix.strip('/')
52
base_url = '{}/{}'.format(base_url, prefix)
53
if (env_uuid is None) or (juju_version < (1, 22, 0)):
55
complete_url = '{}/environment/{}/api'.format(base_url, env_uuid)
58
# If a customized Juju GUI charm is in use, there is no way to check if the
59
# GUI server is recent enough to support the new Juju API endpoints.
60
# In these cases, assume the customized charm is recent enough.
62
charm.name != settings.JUJU_GUI_CHARM_NAME or
67
# This is the promulgated Juju GUI charm. Check if it supports new APIs.
68
revision, series = charm.revision, charm.series
69
if revision < settings.MINIMUM_REVISIONS_FOR_NEW_API_ENDPOINT[series]:
33
74
def get_service_info(status, service_name):
34
75
"""Retrieve information on the given service and on its first alive unit.
62
103
Print (to stdout or to logs) info and warnings about the charm URL.
64
105
Return the parsed charm object as an instance of
65
quickstart.models.charms.Charm.
106
"quickstart.models.charms.Charm".
67
108
print('charm URL: {}'.format(charm_url))
68
109
charm = charms.Charm.from_url(charm_url)