c255a37f5cde40d1bd30fbe8f76a635217bb2585
[osm/N2VC.git] / docs / narrative / application.rst
1 Applications
2 ============
3
4
5 Deploying
6 ---------
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.
10
11 .. code:: python
12
13   from juju.model import Model
14
15   model = Model()
16   await model.connect_current()
17
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.
21       'cs:mysql-55',
22       application_name='mysql',
23       series='trusty',
24       channel='stable',
25       config={
26           'tuning-level': 'safest',
27       },
28       constraints={
29           'mem': 256 * MB,
30       },
31   )
32
33
34 Adding Units
35 ------------
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.
39
40 .. code:: python
41
42     ubuntu_app = await model.deploy(
43         'ubuntu',
44         application_name='ubuntu',
45         series='trusty',
46         channel='stable',
47     )
48
49     unit_a, unit_b = await ubuntu_app.add_units(count=2)
50
51
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`.
57
58 .. code:: python
59
60   MB = 1024 * 1024
61
62   # Update and check app config
63   await mysql_app.set_config({'tuning-level': 'fast'})
64   config = await mysql_app.get_config()
65
66   assert(config['tuning-level']['value'] == 'fast')
67
68   # update and check app constraints
69   await mysql_app.set_constraints({'mem': 512 * MB})
70   constraints = await mysql_app.get_constraints()
71
72   assert(constraints['mem'] == 512 * MB)