3 For api docs, see :class:`juju.application.Application`.
8 To deploy a new application, connect a model and then call its
9 :meth:`~juju.model.Model.deploy` method. An
10 :class:`~juju.application.Application` instance is returned.
14 from juju.model import Model
17 await model.connect_current()
19 mysql_app = await model.deploy(
20 # If a revision number is not included in the charm url,
21 # the latest revision from the Charm Store will be used.
23 application_name='mysql',
27 'tuning-level': 'safest',
35 Deploying a Local Charm
36 -----------------------
37 To deploy a local charm, pass the charm directory path to
42 from juju.model import Model
45 await model.connect_current()
47 # Deploy a local charm using a path to the charm directory
49 '/home/tvansteenburgh/src/charms/ubuntu',
50 application_name='ubuntu',
57 To add units to a deployed application, use the
58 :meth:`juju.application.Application.add_units` method. A list of the newly
59 added units (:class:`~juju.unit.Unit` objects) is returned.
63 ubuntu_app = await model.deploy(
65 application_name='ubuntu',
70 unit_a, unit_b = await ubuntu_app.add_units(count=2)
73 Updating Config and Constraints
74 -------------------------------
75 Example showing how to update configuration and constraints on a deployed
76 application. The `mysql_app` object is an instance of
77 :class:`juju.application.Application`.
83 # Update and check app config
84 await mysql_app.set_config({'tuning-level': 'fast'})
85 config = await mysql_app.get_config()
87 assert(config['tuning-level']['value'] == 'fast')
89 # update and check app constraints
90 await mysql_app.set_constraints({'mem': 512 * MB})
91 constraints = await mysql_app.get_constraints()
93 assert(constraints['mem'] == 512 * MB)
96 Adding and Removing Relations
97 -----------------------------
98 The :meth:`juju.application.Application.add_relation` method returns a
99 :class:`juju.relation.Relation` instance.
103 from juju.model import Model
106 await model.connect_current()
108 # Deploy mysql-master application
109 mysql_master = await model.deploy(
111 application_name='mysql-master',
116 # Deploy mysql-slave application
117 mysql_slave = await model.deploy(
119 application_name='mysql-slave',
124 # Add the master-slave relation
125 relation = await mysql_master.add_relation(
126 # Name of the relation on the local (mysql-master) side
128 # Name of the app:relation on the remote side
132 # Remove the relation
133 await mysql_master.remove_relation(