-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathmodel.py
More file actions
executable file
·36 lines (25 loc) · 841 Bytes
/
model.py
File metadata and controls
executable file
·36 lines (25 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
"""This example shows how to reconnect to a model if you encounter an error
1. Connects to current model.
2. Attempts to get an application that doesn't exist.
3. Disconnect then reconnect.
"""
import asyncio
from juju.errors import JujuEntityNotFoundError
from juju.model import Model
async def main():
model = Model()
retries = 3
for _ in range(0, retries):
await model.connect_current()
try:
print(model.applications["foo"].relations)
except JujuEntityNotFoundError as e:
print(e.entity_name)
finally:
await model.disconnect()
# Everything worked out, continue on wards.
if __name__ == "__main__":
asyncio.run(main())