projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated examples to use juju.loop
[osm/N2VC.git]
/
examples
/
relate.py
diff --git
a/examples/relate.py
b/examples/relate.py
index
241d1a6
..
8f1e708
100644
(file)
--- a/
examples/relate.py
+++ b/
examples/relate.py
@@
-11,6
+11,7
@@
import asyncio
import logging
from juju.model import Model, ModelObserver
import logging
from juju.model import Model, ModelObserver
+from juju import loop
class MyRemoveObserver(ModelObserver):
class MyRemoveObserver(ModelObserver):
@@
-35,10
+36,9
@@
class MyModelObserver(ModelObserver):
logging.debug('All units idle, disconnecting')
await model.reset(force=True)
await model.disconnect()
logging.debug('All units idle, disconnecting')
await model.reset(force=True)
await model.disconnect()
- model.loop.stop()
-async def
ru
n():
+async def
mai
n():
model = Model()
await model.connect_current()
model = Model()
await model.connect_current()
@@
-48,7
+48,7
@@
async def run():
ubuntu_app = await model.deploy(
'ubuntu',
ubuntu_app = await model.deploy(
'ubuntu',
-
service
_name='ubuntu',
+
application
_name='ubuntu',
series='trusty',
channel='stable',
)
series='trusty',
channel='stable',
)
@@
-68,11
+68,17
@@
async def run():
lambda delta, old_unit, new_unit, model:
print('Unit removed: {}'.format(old_unit.entity_id))
))
lambda delta, old_unit, new_unit, model:
print('Unit removed: {}'.format(old_unit.entity_id))
))
+ unit_a, unit_b = await ubuntu_app.add_units(count=2)
+ unit_a.on_change(asyncio.coroutine(
+ lambda delta, old_unit, new_unit, model:
+ print('Unit changed: {}'.format(new_unit.entity_id))
+ ))
await model.deploy(
'nrpe',
await model.deploy(
'nrpe',
-
service
_name='nrpe',
+
application
_name='nrpe',
series='trusty',
channel='stable',
series='trusty',
channel='stable',
+ # subordinates must be deployed without units
num_units=0,
)
my_relation = await model.add_relation(
num_units=0,
)
my_relation = await model.add_relation(
@@
-84,10
+90,9
@@
async def run():
print('Relation removed: {}'.format(old_rel.endpoints))
))
print('Relation removed: {}'.format(old_rel.endpoints))
))
-logging.basicConfig(level=logging.DEBUG)
-ws_logger = logging.getLogger('websockets.protocol')
-ws_logger.setLevel(logging.INFO)
-loop = asyncio.get_event_loop()
-loop.set_debug(False)
-loop.create_task(run())
-loop.run_forever()
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG)
+ ws_logger = logging.getLogger('websockets.protocol')
+ ws_logger.setLevel(logging.INFO)
+ loop.run(main())