| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 1 | """ |
| 2 | This example doesn't work - it demonstrates features that don't exist yet. |
| 3 | |
| 4 | """ |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 5 | import logging |
| 6 | |
| 7 | from juju.model import Model |
| 8 | from juju import loop |
| 9 | |
| 10 | |
| 11 | async def main(): |
| 12 | model = Model() |
| Adam Israel | b094366 | 2018-08-02 15:32:00 -0400 | [diff] [blame] | 13 | # connect to current model with current user, per Juju CLI |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame] | 14 | await model.connect() |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 15 | |
| 16 | goal_state = Model.from_yaml('bundle-like-thing') |
| 17 | ubuntu_app = await model.deploy( |
| 18 | 'ubuntu-0', |
| 19 | application_name='ubuntu', |
| 20 | series='trusty', |
| 21 | channel='stable', |
| 22 | ) |
| 23 | ubuntu_app.on_unit_added(callback=lambda unit: True) |
| 24 | |
| 25 | await model.deploy( |
| 26 | 'nrpe-11', |
| 27 | application_name='nrpe', |
| 28 | series='trusty', |
| 29 | channel='stable', |
| 30 | num_units=0, |
| 31 | ) |
| 32 | await model.add_relation( |
| 33 | 'ubuntu', |
| 34 | 'nrpe', |
| 35 | ) |
| 36 | |
| 37 | result, ok = await model.block_until( |
| 38 | lambda: model.matches(goal_state), |
| 39 | timeout=600 |
| 40 | ) |
| 41 | |
| 42 | |
| 43 | if __name__ == '__main__': |
| 44 | logging.basicConfig(level=logging.DEBUG) |
| 45 | ws_logger = logging.getLogger('websockets.protocol') |
| 46 | ws_logger.setLevel(logging.INFO) |
| 47 | loop.run(main()) |