| Adam Israel | b094366 | 2018-08-02 15:32:00 -0400 | [diff] [blame] | 1 | """ |
| 2 | This is a very basic example that connects to the currently selected model |
| 3 | and prints the number of applications deployed to it. |
| 4 | """ |
| 5 | import logging |
| 6 | |
| 7 | from juju import loop |
| 8 | from juju.model import Model |
| 9 | |
| 10 | log = logging.getLogger(__name__) |
| 11 | |
| 12 | |
| 13 | async def main(): |
| 14 | model = Model() |
| 15 | try: |
| 16 | # connect to the current model with the current user, per the Juju CLI |
| 17 | await model.connect() |
| 18 | print('There are {} applications'.format(len(model.applications))) |
| 19 | finally: |
| 20 | if model.is_connected(): |
| 21 | print('Disconnecting from model') |
| 22 | await model.disconnect() |
| 23 | |
| 24 | |
| 25 | if __name__ == '__main__': |
| 26 | logging.basicConfig(level=logging.INFO) |
| 27 | loop.run(main()) |