~frankban/juju-quickstart/deploy-changeset

« back to all changes in this revision

Viewing changes to quickstart/jujutools.py

  • Committer: Francesco Banconi
  • Date: 2015-02-10 15:19:24 UTC
  • mfrom: (119.2.9 new-auth-api-endpoint)
  • Revision ID: francesco.banconi@canonical.com-20150210151924-m6br1cg2m0gvmctq
Add support for new Juju WebSocket API endpoints.

Recent Juju versions introduced a new API endpoint
path. In essence, instead of the usual 
"wss://<address>:17070", the new 
"wss://<address>:17070/environment/<env-uuid>/api"
is used to connect to the API.
This allows for connecting to a specific environment
in a multi-environment state server scenario.

In this branch the new API endpoint is used if a recent 
Juju version is in use, and if it is possible to retrieve 
the  environment UUID from the jenv file.

Also, when connecting to the GUI server (for creating
the auth token or for deploying bundles), use the new
GUI server API endpoints when possible, i.e. when the
charm is recent enough to support redirecting requests 
to the new Juju endpoints.
Note that this feature is assumed to land in the next
juju-gui charm release (see settings.py). If that's
not the case, we'll need to increase the charm revisions
in settings.MINIMUM_REVISIONS_FOR_NEW_API_ENDPOINT
before releasing the new Quickstart.

Tests: `make check`

QA:
- bootstrap quickstart as usual: `devenv/bin/juju-quickstart`;
- check that, if you are using juju devel (1.22beta), quickstart
  properly connect to the new API endpoint;
- run quickstart again to deploy a bundle, e.g.:
  `devenv/bin/juju-quickstart bundle:mediawiki/single`;
- ensure that the deployment request succeeds;
- if possible, do the above with and older version of Juju, 
  to ensure backward compatibility.

Done, thank you!

R=martin.hilton, jeff.pihach
CC=
https://codereview.appspot.com/199490043

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from quickstart.models import charms
31
31
 
32
32
 
 
33
def get_api_url(api_address, juju_version, env_uuid, prefix='', charm=None):
 
34
    """Return the Juju WebSocket API endpoint.
 
35
 
 
36
    Receives the Juju API server address, the Juju version and the unique
 
37
    identifier of the current environment.
 
38
 
 
39
    Optionally receive a prefix to be used in the path.
 
40
 
 
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.
 
45
 
 
46
    The environment UUID can be None, in which case the old-style API URL
 
47
    (not including the environment UUID) is returned.
 
48
    """
 
49
    base_url = 'wss://{}'.format(api_address)
 
50
    prefix = prefix.strip('/')
 
51
    if prefix:
 
52
        base_url = '{}/{}'.format(base_url, prefix)
 
53
    if (env_uuid is None) or (juju_version < (1, 22, 0)):
 
54
        return base_url
 
55
    complete_url = '{}/environment/{}/api'.format(base_url, env_uuid)
 
56
    if charm is None:
 
57
        return complete_url
 
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.
 
61
    if (
 
62
        charm.name != settings.JUJU_GUI_CHARM_NAME or
 
63
        charm.user or
 
64
        charm.is_local()
 
65
    ):
 
66
        return complete_url
 
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]:
 
70
        return base_url
 
71
    return complete_url
 
72
 
 
73
 
33
74
def get_service_info(status, service_name):
34
75
    """Retrieve information on the given service and on its first alive unit.
35
76
 
62
103
    Print (to stdout or to logs) info and warnings about the charm URL.
63
104
 
64
105
    Return the parsed charm object as an instance of
65
 
    quickstart.models.charms.Charm.
 
106
    "quickstart.models.charms.Charm".
66
107
    """
67
108
    print('charm URL: {}'.format(charm_url))
68
109
    charm = charms.Charm.from_url(charm_url)