projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add get_config() and get_constraints() for Application
[osm/N2VC.git]
/
examples
/
relate.py
diff --git
a/examples/relate.py
b/examples/relate.py
index
fa32900
..
8e42bab
100644
(file)
--- a/
examples/relate.py
+++ b/
examples/relate.py
@@
-30,7
+30,7
@@
class MyModelObserver(ModelObserver):
_shutting_down = False
async def on_change(self, delta, old, new, model):
_shutting_down = False
async def on_change(self, delta, old, new, model):
- if model.all_units_idle() and not self._shutting_down:
+ if model.
units and model.
all_units_idle() and not self._shutting_down:
self._shutting_down = True
logging.debug('All units idle, disconnecting')
await model.reset(force=True)
self._shutting_down = True
logging.debug('All units idle, disconnecting')
await model.reset(force=True)
@@
-47,7
+47,7
@@
async def run():
model.add_observer(MyModelObserver())
ubuntu_app = await model.deploy(
model.add_observer(MyModelObserver())
ubuntu_app = await model.deploy(
- 'ubuntu
-0
',
+ 'ubuntu',
service_name='ubuntu',
series='trusty',
channel='stable',
service_name='ubuntu',
series='trusty',
channel='stable',
@@
-68,22
+68,31
@@
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(
await model.deploy(
- 'nrpe
-11
',
+ 'nrpe',
service_name='nrpe',
series='trusty',
channel='stable',
service_name='nrpe',
series='trusty',
channel='stable',
- num_units=
0
,
+ num_units=
1
,
)
)
- await model.add_relation(
+
my_relation =
await model.add_relation(
'ubuntu',
'nrpe',
)
'ubuntu',
'nrpe',
)
+ my_relation.on_remove(asyncio.coroutine(
+ lambda delta, old_rel, new_rel, model:
+ 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()
logging.basicConfig(level=logging.DEBUG)
ws_logger = logging.getLogger('websockets.protocol')
ws_logger.setLevel(logging.INFO)
loop = asyncio.get_event_loop()
-loop.set_debug(
Fals
e)
+loop.set_debug(
Tru
e)
loop.create_task(run())
loop.run_forever()
loop.create_task(run())
loop.run_forever()