projects
/
osm
/
N2VC.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
096fdda
)
Fix the deploy example
author
Tim Van Steenburgh
<tvansteenburgh@gmail.com>
Fri, 7 Oct 2016 16:02:50 +0000
(12:02 -0400)
committer
Tim Van Steenburgh
<tvansteenburgh@gmail.com>
Fri, 7 Oct 2016 16:02:50 +0000
(12:02 -0400)
examples/deploy.py
patch
|
blob
|
history
diff --git
a/examples/deploy.py
b/examples/deploy.py
index
a1ae503
..
d7ca29a
100644
(file)
--- a/
examples/deploy.py
+++ b/
examples/deploy.py
@@
-1,20
+1,24
@@
"""
"""
-Deploy a charm, wait until it's idle, then destroy the unit and application.
+This example:
+
+1. Connects to the current model
+2. Resets it
+3. Deploy a charm and waits until it's idle
+4. Destroys the unit and application
"""
import asyncio
import logging
from juju.model import Model, ModelObserver
"""
import asyncio
import logging
from juju.model import Model, ModelObserver
-from juju.client.connection import Connection
class MyModelObserver(ModelObserver):
class MyModelObserver(ModelObserver):
- def on_unit_add(self, delta, old, new, model):
+
async
def on_unit_add(self, delta, old, new, model):
logging.info(
'New unit added: %s', new.name)
logging.info(
'New unit added: %s', new.name)
- def on_change(self, delta, old, new, model):
+
async
def on_change(self, delta, old, new, model):
for unit in model.units.values():
unit_status = unit.data['agent-status']['current']
logging.info(
for unit in model.units.values():
unit_status = unit.data['agent-status']['current']
logging.info(
@@
-24,28
+28,39
@@
class MyModelObserver(ModelObserver):
'Destroying unit %s', unit.name)
loop.create_task(unit.destroy())
'Destroying unit %s', unit.name)
loop.create_task(unit.destroy())
- def on_unit_remove(self, delta, old, new, model):
+
async
def on_unit_remove(self, delta, old, new, model):
app_name = old.application
app = model.applications[app_name]
if not app.units:
logging.info(
'Destroying application %s', app.name)
loop.create_task(app.destroy())
app_name = old.application
app = model.applications[app_name]
if not app.units:
logging.info(
'Destroying application %s', app.name)
loop.create_task(app.destroy())
+ await model.block_until(
+ lambda: len(model.applications) == 0
+ )
+ await model.disconnect()
+ model.loop.stop()
async def run():
async def run():
- conn = await Connection.connect_current()
- model = Model(conn)
+ model = Model()
+ await model.connect_current()
+
+ await model.reset(force=True)
model.add_observer(MyModelObserver())
model.add_observer(MyModelObserver())
+
await model.deploy(
'ubuntu-0',
service_name='ubuntu',
series='trusty',
channel='stable',
)
await model.deploy(
'ubuntu-0',
service_name='ubuntu',
series='trusty',
channel='stable',
)
- await model.watch()
-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(level=logging.DEBUG)
+ws_logger = logging.getLogger('websockets.protocol')
+ws_logger.setLevel(logging.INFO)
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop()
-loop.run_until_complete(run())
+loop.set_debug(False)
+loop.create_task(run())
+loop.run_forever()