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
5 these endpoints. There are several ways to do this.
10 Connect to the currently active Juju model (the one returned by
11 `juju switch`). This only works if you have the Juju CLI client installed.
15 from juju.model import Model
18 await model.connect_current()
23 Connect to a model by name, using the same format as that returned from the
24 `juju switch` command. The accepted format is '[controller:][user/]model'.
25 This only works if you have the Juju CLI client installed.
30 # juju-2.0.1:admin/libjuju
32 from juju.model import Model
35 await model.connect_model('juju-2.0.1:admin/libjuju')
38 To an API Endpoint with Username/Password Authentication
39 --------------------------------------------------------
40 The most flexible, but also most verbose, way to connect is using the API
41 endpoint url and credentials directly. This method does NOT require the Juju
42 CLI client to be installed.
46 from juju.model import Model
50 controller_endpoint = '10.0.4.171:17070'
51 model_uuid = 'e8399ac7-078c-4817-8e5e-32316d55b083'
53 password = 'f53f08cfc32a2e257fe5393271d89d62'
55 # Left out for brevity, but if you have a cert string you should pass it in.
56 # You can copy the cert from the output of The `juju show-controller`
69 To an API Endpoint with Macaroon Authentication
70 -----------------------------------------------
71 To connect to a shared model, or a model an a shared controller, you'll need
72 to use macaroon authentication. The simplest example is shown below, and uses
73 already-discharged macaroons from the local filesystem. This will work if you
74 have the Juju CLI installed.
78 The library does not yet contain support for fetching and discharging
79 macaroons. Until it does, if you want to use macaroon auth, you'll need
80 to supply already-discharged macaroons yourself.
84 from juju.client.connection import get_macaroons()
85 from juju.model import Model
89 controller_endpoint = '10.0.4.171:17070'
90 model_uuid = 'e8399ac7-078c-4817-8e5e-32316d55b083'
94 macaroons = get_macaroons()