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, first upload it to the model, then
38 deploy it using the returned charm url.
42 from juju.model import Model
45 await model.connect_current()
47 # Upload local charm to the model.
48 # The returned 'local:' url can be used to deploy the charm.
49 charm_url = await model.add_local_charm_dir(
50 '/home/tvansteenburgh/src/charms/ubuntu', 'trusty')
52 # Deploy the charm using the 'local:' charm.
55 application_name='ubuntu',
61 To add units to a deployed application, use the
62 :meth:`juju.application.Application.add_units` method. A list of the newly
63 added units (:class:`~juju.unit.Unit` objects) is returned.
67 ubuntu_app = await model.deploy(
69 application_name='ubuntu',
74 unit_a, unit_b = await ubuntu_app.add_units(count=2)
77 Updating Config and Constraints
78 -------------------------------
79 Example showing how to update configuration and constraints on a deployed
80 application. The `mysql_app` object is an instance of
81 :class:`juju.application.Application`.
87 # Update and check app config
88 await mysql_app.set_config({'tuning-level': 'fast'})
89 config = await mysql_app.get_config()
91 assert(config['tuning-level']['value'] == 'fast')
93 # update and check app constraints
94 await mysql_app.set_constraints({'mem': 512 * MB})
95 constraints = await mysql_app.get_constraints()
97 assert(constraints['mem'] == 512 * MB)
100 Adding and Removing Relations
101 -----------------------------
102 The :meth:`juju.application.Application.add_relation` method returns a
103 :class:`juju.relation.Relation` instance.
107 from juju.model import Model
110 await model.connect_current()
112 # Deploy mysql-master application
113 mysql_master = await model.deploy(
115 application_name='mysql-master',
120 # Deploy mysql-slave application
121 mysql_slave = await model.deploy(
123 application_name='mysql-slave',
128 # Add the master-slave relation
129 relation = await mysql_master.add_relation(
130 # Name of the relation on the local (mysql-master) side
132 # Name of the app:relation on the remote side
136 # Remove the relation
137 await mysql_master.remove_relation(