7 To deploy a new application, connect a model and then call its
8 :meth:`~juju.model.Model.deploy` method. An
9 :class:`~juju.application.Application` instance is returned.
13 from juju.model import Model
16 await model.connect_current()
18 mysql_app = await model.deploy(
19 # If a revision number is not included in the charm url,
20 # the latest revision from the Charm Store will be used.
22 application_name='mysql',
26 'tuning-level': 'safest',
36 To add units to a deployed application, use the
37 :meth:`juju.application.Application.add_units` method. A list of the newly
38 added units (:class:`~juju.unit.Unit` objects) is returned.
42 ubuntu_app = await model.deploy(
44 application_name='ubuntu',
49 unit_a, unit_b = await ubuntu_app.add_units(count=2)
52 Updating Config and Constraints
53 -------------------------------
54 Example showing how to update configuration and constraints on a deployed
55 application. The `mysql_app` object is an instance of
56 :class:`juju.application.Application`.
62 # Update and check app config
63 await mysql_app.set_config({'tuning-level': 'fast'})
64 config = await mysql_app.get_config()
66 assert(config['tuning-level']['value'] == 'fast')
68 # update and check app constraints
69 await mysql_app.set_constraints({'mem': 512 * MB})
70 constraints = await mysql_app.get_constraints()
72 assert(constraints['mem'] == 512 * MB)
75 Adding and Removing Relations
76 -----------------------------
77 The :meth:`juju.application.Application.add_relation` method returns a
78 :class:`juju.relation.Relation` instance.
82 from juju.model import Model
85 await model.connect_current()
87 # Deploy mysql-master application
88 mysql_master = await model.deploy(
90 application_name='mysql-master',
95 # Deploy mysql-slave application
96 mysql_slave = await model.deploy(
98 application_name='mysql-slave',
103 # Add the master-slave relation
104 relation = await mysql_master.add_relation(
105 # Name of the relation on the local (mysql-master) side
107 # Name of the app:relation on the remote side
111 # Remove the relation
112 await mysql_master.remove_relation(