Skip to content

Commit a58645e

Browse files
authored
Merge pull request #1244 from tmihoc/add-discourse-docs
#1244 As part of a broader move where juju.is docs go federated and RTD, this PR adds all the python-libjuju material we previously had under juju.is/docs/juju (in how-to guide tabs) to the python-libjuju RTD (under a new section called "How-to guides"). This RTD project could use a lot of further improvements (e.g., for all of the other projects -- juju, terraform-provider-juju, charmcraft, ops -- I made sure to update the homepage according to the standard template and to have the full Diataxis tree and integrate the new content nicely with the old, removing duplication, etc.). However, given that we are slowly phasing python-libjuju out, I believe leaving things as is is probably fine. There is one fix that it is worth making, namely, the links to Juju docs. I followed the instructions in https://canonical-documentation-with-sphinx-and-readthedocscom.readthedocs-hosted.com/style-guide/#internal-references for "targets in other doc sets", but the links don't seem to be working. It could be because the Juju RTD project needs some fixing (we're working on it). I should know soon enough what needs to be done and then I'll come back and fix all the links in a follow-up PR. #### QA Steps From the root of the repo: ``` # Build the docs: tox -e docs #Preview the docs: open docs/_build/index.html ```
2 parents 619bb9f + ccfff3a commit a58645e

24 files changed

+1685
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ pytestdebug.log
1616
deb_dist
1717
*.tar.gz
1818
.idea/
19+
build/

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"sphinx.ext.viewcode",
4949
"sphinxcontrib.asyncio",
5050
"automembersummary",
51+
# 'sphinx_tabs.tabs',
5152
]
5253

5354
# Add any paths that contain templates here, relative to this directory.

docs/howto/index.rst

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
How-to guides
2+
#############
3+
4+
.. toctree::
5+
:glob:
6+
:maxdepth: 2
7+
8+
Manage python-libjuju <manage-python-libjuju>
9+
Manage clouds <manage-clouds>
10+
Manage credentials <manage-credentials>
11+
Manage controllers <manage-controllers>
12+
Manage users <manage-users>
13+
Manage SSH keys <manage-ssh-keys>
14+
Manage models <manage-models>
15+
Manage charms <manage-charms>
16+
Manage applications <manage-applications>
17+
Manage resources (charms) <manage-charm-resources>
18+
Manage actions <manage-actions>
19+
Manage relations <manage-relations>
20+
Manage offers <manage-offers>
21+
Manage units <manage-units>
22+
Manage secrets <manage-secrets>
23+
Manage secret backends <manage-secret-backends>
24+
Manage machines <manage-machines>
25+
Manage storage <manage-storage>
26+
Manage storage pools <manage-storage-pools>
27+
Manage spaces <manage-spaces>

docs/howto/manage-actions.rst

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _manage-actions:
2+
3+
How to manage actions
4+
=====================
5+
6+
7+
> See also: :ref:`juju:action`
8+
9+
10+
11+
List all actions
12+
----------------
13+
14+
15+
To list the actions defined for a deployed application, use the `get_actions()` method on the `Application` object to get all the actions defined for this application.
16+
17+
.. code:: python
18+
19+
await my_app.get_actions()
20+
21+
22+
> See more: `Application (object) <https://pythonlibjuju.readthedocs.io/en/latest/narrative/application.html>`_, `get_actions (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_actions>`_
23+
24+
25+
Run an action
26+
27+
To run an action on a unit, use the `run_action()` method on a Unit object of a deployed application.
28+
29+
Note that "running" an action on a unit, enqueues an action to be performed. The result will be an Action object to interact with. You will need to call `action.wait()` on that object to wait for the action to complete and retrieve the results.
30+
31+
.. code:: python
32+
33+
# Assume we deployed a git application
34+
my_app = await model.deploy('git', application_name='git', channel='stable')
35+
my_unit = my_app.units[0]
36+
37+
action = await my_unit.run_action('add-repo', repo='myrepo')
38+
await action.wait() # will return the result for the action
39+
40+
> See more: `Unit (object) <https://pythonlibjuju.readthedocs.io/en/latest/narrative/unit.html>`_, `Action (object) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.action.html#juju.action.Action>`_, `Unit.run_action (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.unit.html#juju.unit.Unit.run_action>`_, `Action.wait() (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.action.html#juju.action.Action.wait>`_

docs/howto/manage-applications.rst

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
.. _manage-applications:
2+
3+
How to manage applications
4+
==========================
5+
6+
> See also: :ref:`juju:application`
7+
8+
Deploy an application
9+
---------------------
10+
11+
To deploy an application, find and deploy a charm / bundle that delivers it.
12+
13+
> See more: :ref:`deploy-a-charm`
14+
15+
View details about an application
16+
---------------------------------
17+
18+
To view details about an application on python-libjuju, you may use various `get_*` methods that are defined for applications.
19+
20+
For example, to get the config for an application, call `get_config()` method on an `Application` object:
21+
22+
.. code:: python
23+
24+
config = await my_app.get_config()
25+
26+
27+
> See more: `Application.get_config (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_config>`_, `Application (methods) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application>`_
28+
29+
30+
Trust an application with a credential
31+
--------------------------------------
32+
33+
Some applications may require access to the backing cloud in order to fulfil their purpose (e.g., storage-related tasks). In such cases, the remote credential associated with the current model would need to be shared with the application. When the Juju administrator allows this to occur the application is said to be *trusted*.
34+
35+
To trust an application during deployment in python-libjuju, you may call the `Model.deploy()` with the `trust` parameter:
36+
37+
.. code:: python
38+
39+
await my_model.deploy(..., trust=True, ...)
40+
41+
To trust an application after deployment, you may use the `Application.set_trusted()` method:
42+
43+
.. code:: python
44+
45+
await my_app.set_trusted(True)
46+
47+
48+
> See more: `Application.set_trusted (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.set_trusted>`_, `Application.get_trusted (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_trusted>`_
49+
50+
51+
Run an application action
52+
-------------------------
53+
54+
> See more: :ref:`manage-actions`
55+
56+
Configure an application
57+
------------------------
58+
59+
**Get values.** To view the existing configuration for an application on python-libjuju, you may use the `Application.get_config()` method:
60+
61+
.. code:: python
62+
63+
config = await my_app.get_config()
64+
65+
66+
**Set values.** To set configuration values for an application on python-libjuju:
67+
68+
* To configure an application at deployment, simply provide a `config` map during the `Model.deploy()` call:
69+
70+
.. code:: python
71+
72+
await my_model.deploy(..., config={'redirect-map':'https://demo'}, ...)
73+
74+
75+
* To configure an application post deployment, you may use the `Application.set_config()` method, similar to passing config in the deploy call above:
76+
77+
.. code:: python
78+
79+
await my_app.set_config(config={'redirect-map':'https://demo'})
80+
81+
82+
> See more: `Application.set_config (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.set_config>`_, `Application.get_config (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_config)>`_
83+
84+
85+
.. _scale-an-application:
86+
Scale an application
87+
--------------------
88+
89+
> See also: :ref:`juju:scaling`
90+
91+
Scale an application vertically
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
94+
To scale an application vertically, set constraints for the resources that the application's units will be deployed on.
95+
96+
> See more: :ref:`manage-constraints-for-an-application`
97+
98+
Scale an application horizontally
99+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
101+
To scale an application horizontally, control the number of units.
102+
103+
> See more: :ref:`control-the-number-of-units`
104+
105+
106+
Make an application highly available
107+
------------------------------------
108+
> See also: :ref:`juju:high-availability`
109+
110+
1. Find out if the charm delivering the application supports high availability natively or not. If the latter, find out what you need to do. This could mean integrating with a load balancing reverse proxy, configuring storage etc.
111+
112+
> See more: `Charmhub <https://charmhub.io/>`_
113+
114+
2. Scale up horizontally as usual.
115+
116+
> See more: {ref}`How to scale an application horizontally <5476md>`
117+
118+
Every time a unit is added to an application, Juju will spread out that application's units, distributing them evenly as supported by the provider (e.g., across multiple availability zones) to best ensure high availability. So long as a cloud's availability zones don't all fail at once, and the charm and the charm's application are well written (changing leaders, coordinating across units, etc.), you can rest assured that cloud downtime will not affect your application.
119+
120+
> See more: `Charmhub | wordpress <https://charmhub.io/wordpress>`_, `Charmhub | mediawiki <https://charmhub.io/mediawiki>`_, `Charmhub | haproxy <https://charmhub.io/haproxy>`_
121+
122+
Integrate an application with another application
123+
-------------------------------------------------
124+
125+
> See more: :ref:`manage-relations`
126+
127+
128+
Manage an application’s public availability over the network
129+
------------------------------------------------------------
130+
131+
To expose some or all endpoints of an application over a network, you may use the `Application.expose()` method, as follows:
132+
133+
.. code:: python
134+
135+
await my_app.expose(exposed_endpoints=None) # everything's reachable from 0.0.0.0/0.
136+
137+
138+
To expose to specific CIDRs or spaces, you may use an `ExposedEndpoint` object to describe that, as follows:
139+
140+
.. code:: python
141+
142+
# For spaces
143+
await my_app.expose(exposed_endpoints={"": ExposedEndpoint(to_spaces=["alpha"]) })
144+
145+
# For cidrs
146+
await my_app.expose(exposed_endpoints={"": ExposedEndpoint(to_cidrs=["10.0.0.0/24"])})
147+
148+
# You may use both at the same time too
149+
await my_app.expose(exposed_endpoints={
150+
"ubuntu": ExposedEndpoint(to_spaces=["alpha"], to_cidrs=["10.0.0.0/24"])
151+
})
152+
153+
154+
155+
To unexpose an application, use the `Application.unexpose()` method:
156+
157+
.. code:: python
158+
159+
await my_app.unexpose() # unexposes the entire application
160+
161+
await my_app.unexpose(exposed_endpoints=["ubuntu"]) # unexposes the endpoint named "ubuntu"
162+
163+
164+
> See more: `ExposedEndpoint (methods) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.ExposedEndpoint>`_, `Application.expose() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.expose>`_, `Application.unexpose() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.unexpose>`_
165+
166+
167+
.. _manage-constraints-for-an-application:
168+
Manage constraints for an application
169+
-------------------------------------
170+
171+
> See also: :ref:`juju:constraint`
172+
173+
**Set values.** To set constraints for application in python-libjuju:
174+
175+
* To set at deployment, simply provide a `constraints` map during the `Model.deploy()` call:
176+
177+
.. code:: python
178+
179+
await my_model.deploy(..., constraints={'arch': 'amd64', 'mem': 256}, ...)
180+
181+
182+
* To set constraints post deployment, you may use the `Application.set_contraints()` method, similar to passing constraints in the deploy call above:
183+
184+
.. code:: python
185+
186+
await my_app.set_constraints(constraints={'arch': 'amd64', 'mem': 256})
187+
188+
189+
**Get values.** To see what constraints are set on an application, use the `Application.get_constraints()` method:
190+
191+
.. code:: python
192+
193+
await my_app.get_constraints()
194+
195+
196+
> See more: `Application.set_contraints() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.set_constraints>`_, `Application.get_constraints (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_constraints>`_
197+
198+
199+
Change space bindings for an application
200+
----------------------------------------
201+
202+
To set bindings for an application on python-libjuju, simply pass the `bind` parameter at the `Model.deploy()` call:
203+
204+
.. code:: python
205+
206+
await my_model.deploy(..., bind="db=db db-client=db public admin-api=public", ...)
207+
208+
Python-libjuju currently doesn't support resetting space bindings post deployment, please use the `juju-cli` for that.
209+
210+
> See more: [`Model.deploy()` (method) <5476md>`
211+
212+
Upgrade an application
213+
----------------------
214+
215+
To upgrade an application, update its charm.
216+
217+
> See more: :ref:`update-a-charm`
218+
219+
.. _remove-an-application:
220+
221+
Remove an application
222+
---------------------
223+
224+
> See also: :ref:`juju:removing-things`
225+
226+
To remove an application from a model in python-libjuju, you have two choices:
227+
228+
(1) If you have a reference to a connected model object (connected to the model you're working on), then you may use the `Model.remove_application()` method:
229+
230+
.. code:: python
231+
232+
await my_model.remove_application(my_app.name)
233+
234+
235+
(2) If you have a reference to the application you want to remove, then you may use the `Application.destroy()` directly on the application object you want to remove:
236+
237+
.. code:: python
238+
239+
await my_app.destroy()
240+
241+
> See more: `Model.remove_application (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.model.html#juju.model.Model.remove_application>`_, `Application.destroy (method) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.destroy>`_

docs/howto/manage-charm-resources.rst

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. _manage-charm-resources:
2+
3+
How to manage charm resources
4+
=============================
5+
6+
> See also: :ref:`juju:resource-charm`
7+
8+
When you deploy / update an application from a charm, that automatically deploys / updates any charm resources, using the defaults specified by the charm author. However, you can also specify resources manually (e.g., to try a resource released only to `edge` or to specify a non-Charmhub resource). This document shows you how.
9+
10+
11+
Find out the resources available for a charm
12+
--------------------------------------------
13+
14+
To find out what resources are available for a charm on Charmhub, on a connected Model object, select the `charmhub` object associated with the model, and use the `list_resources()` method, passing the name of the charm as an argument. For example:
15+
16+
.. code:: python
17+
18+
await model.charmhub.list_resources('postgresql-k8s')
19+
20+
> See more: `charmhub (property) <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.model.html#juju.model.Model.charmhub>`_, `Model (module) <https://pythonlibjuju.readthedocs.io/en/latest/narrative/model.html>`_
21+
22+
Specify the resources to be deployed with a charm
23+
-------------------------------------------------
24+
25+
To specify a resource during deployment, on a connected Model object, use the `deploy` method, passing the resources as a parameter. For example:
26+
27+
.. code:: python
28+
29+
resources = {"file-res": "test.file"}
30+
app = await model.deploy(charm_path, resources=resources)
31+
32+
To update a resource after deployment by uploading file from local disk, on an Application object, use the `attach_resource()` method, passing resource name, file name and the file object as parameters.
33+
34+
.. code:: python
35+
36+
with open(str(charm_path / 'test.file')) as f:
37+
app.attach_resource('file-res', 'test.file', f)
38+
39+
40+
41+
> See more: `deploy() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.model.html#juju.model.Model.deploy>`_, `attach_resource() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.attach_resource>`_, `Model (module) <https://pythonlibjuju.readthedocs.io/en/latest/narrative/model.html>`_
42+
43+
View the resources deployed with a charm
44+
----------------------------------------
45+
46+
To view the resources that have been deployed with a charm, on an Application object, use the `get_resources()` method. For example:
47+
48+
.. code:: python
49+
50+
await my_app.get_resources()
51+
52+
> See more: `get_resources() <https://pythonlibjuju.readthedocs.io/en/latest/api/juju.application.html#juju.application.Application.get_resources>`_, `Model (module) <https://pythonlibjuju.readthedocs.io/en/latest/narrative/model.html>`_

0 commit comments

Comments
 (0)