2 Deploy a charm, wait until it's idle, then destroy the unit and application.
8 from juju
.model
import Model
, ModelObserver
9 from juju
.client
.connection
import Connection
12 class MyModelObserver(ModelObserver
):
13 def on_unit_add(self
, delta
, old
, new
, model
):
15 'New unit added: %s', new
.name
)
17 def on_change(self
, delta
, old
, new
, model
):
18 for unit
in model
.units
.values():
19 unit_status
= unit
.data
['agent-status']['current']
21 'Unit %s status: %s', unit
.name
, unit_status
)
22 if unit_status
== 'idle':
24 'Destroying unit %s', unit
.name
)
25 loop
.create_task(unit
.destroy())
27 def on_unit_remove(self
, delta
, old
, new
, model
):
28 app_name
= old
.application
29 app
= model
.applications
[app_name
]
32 'Destroying application %s', app
.name
)
33 loop
.create_task(app
.destroy())
37 conn
= await Connection
.connect_current()
39 model
.add_observer(MyModelObserver())
42 service_name
='ubuntu',
49 logging
.basicConfig(level
=logging
.INFO
)
50 loop
= asyncio
.get_event_loop()
51 loop
.run_until_complete(run())