3 A Juju controller provides websocket endpoints for itself and each of its
4 models. In order to do anything useful, the juju lib must connect to one of
7 Connecting to the controller endpoint is useful if you want to programmatically
8 create a new model. If the model you want to use already exists, you can
9 connect directly to it (see py:doc:`model`).
11 For API docs, see py:class:`juju.controller.Controller`.
14 Connecting to the Current Controller
15 ------------------------------------
16 Connect to the currently active Juju controller (the one returned by
17 `juju switch`). This only works if you have the Juju CLI client installed.
21 from juju.controller import Controller
23 controller = Controller()
24 await controller.connect()
27 Connecting to a Named Controller
28 --------------------------------
29 Connect to a controller by name.
33 from juju.controller import Controller
35 controller = Controller()
36 await controller.connect('mycontroller')
39 Connecting with Authentication
40 ------------------------------
41 You can control what user you are connecting with by specifying either a
42 username/password pair, or a macaroon or bakery client that can provide
48 controller = Controller()
49 await controller.connect(username='admin',
50 password='f53f08cfc32a2e257fe5393271d89d62')
53 await controller.connect(macaroons=[
55 "Name": "macaroon-218d87053ad19626bcd5a0eef0bc9ba8bd4fbd80a968f52a5fd430b2aa8660df",
56 "Value": "W3siY2F2ZWF0cyI6 ... jBkZiJ9XQ==",
57 "Domain": "10.130.48.27",
61 "Expires": "2018-03-07T22:07:23Z",
65 # or with a bakery client
66 from macaroonbakery.httpbakery import Client
67 from http.cookiejar import FileCookieJar
69 bakery_client=Client()
70 bakery_client.cookies = FileCookieJar('cookies.txt')
71 controller = Controller()
72 await controller.connect(bakery_client=bakery_client)
76 Connecting with an Explicit Endpoint
77 ------------------------------------
78 The most flexible, but also most verbose, way to connect is using the API
79 endpoint url and credentials directly. This method does NOT require the
80 Juju CLI client to be installed.
84 controller = Controller()
85 await controller.connect(
86 endpoint='10.0.4.171:17070',
88 password='f53f08cfc32a2e257fe5393271d89d62',
89 cacert=None, # Left out for brevity, but if you have a cert string you
90 # should pass it in. You can get the cert from the output
91 # of The `juju show-controller` command.