## Simple bootstrap/deploy
```python
+"""
+This doesn't work yet! It's an example of what usage might
+look like in the future.
+
+"""
from juju import Juju
juju = Juju()
# We might want an async and blocking version of deploy()?
model.deploy('mediawiki-single')
-mediawiki = model.get_service('mediawiki')
+mediawiki = model.get_application('mediawiki')
mediawiki.expose()
```
--- /dev/null
+TODO
+====
+
+Model as state history of immutable objects
+-------------------------------------------
+
+1. Model gets delta from AllWatcher
+2. Entity type+id in the delta uniquely identifies an entity in the model
+3. The model keeps a history deque for each of these entities
+4. The new delta is appended to the deque for this entity
+5. When a new python object is created for this entitiy, it:
+ a. Registers an observer with the model so it'll get change callbacks
+ b. Gets its state from a pointer back to the last item in the model's
+ history deque for this entity
+ c. Has a previous() method that returns a copy of the object at its previous
+ frame of history (or None if no previous history exists). This object
+ would be disconnected (would not receive live updates from the model).
+
+
+Make model-changing methods (like deploy()) return the appropriate object
+-------------------------------------------------------------------------
+For objects being added (newly created), this will require that the method
+doesn't return until the AllWatcher returns a delta containing an id for
+the newly created thing.
+
+
+Add a LogWatcher coroutine that yields from debug-log api
+---------------------------------------------------------
+"""
+This example:
+
+1. Connects to the current model
+2. Starts an AllWatcher
+3. Prints all changes received from the AllWatcher
+4. Runs forever (kill with Ctrl-C)
+
+"""
import asyncio
import logging
-logging.basicConfig(level=logging.DEBUG)
from juju.client.connection import Connection
from juju.client import watcher
-loop = asyncio.get_event_loop()
-conn = loop.run_until_complete(Connection.connect_current())
-
-
async def watch():
allwatcher = watcher.AllWatcher()
allwatcher.connect(conn)
for delta in change.deltas:
print(delta.deltas)
+
+logging.basicConfig(level=logging.DEBUG)
+loop = asyncio.get_event_loop()
+conn = loop.run_until_complete(Connection.connect_current())
loop.run_until_complete(watch())
--- /dev/null
+"""
+This example doesn't work - it demonstrates features that don't exist yet.
+
+"""
+import asyncio
+import logging
+
+from juju.model import Model
+
+
+async def run():
+ model = Model()
+ await model.connect_current()
+ await model.reset(force=True)
+
+ goal_state = Model.from_yaml('bundle-like-thing')
+ ubuntu_app = await model.deploy(
+ 'ubuntu-0',
+ service_name='ubuntu',
+ series='trusty',
+ channel='stable',
+ )
+ ubuntu_app.on_unit_added(callback=lambda unit: True)
+
+ await model.deploy(
+ 'nrpe-11',
+ service_name='nrpe',
+ series='trusty',
+ channel='stable',
+ num_units=0,
+ )
+ await model.add_relation(
+ 'ubuntu',
+ 'nrpe',
+ )
+
+ result, ok = await model.block_until(
+ lambda: model.matches(goal_state),
+ timeout=600
+ )
+
+
+logging.basicConfig(level=logging.DEBUG)
+ws_logger = logging.getLogger('websockets.protocol')
+ws_logger.setLevel(logging.INFO)
+loop = asyncio.get_event_loop()
+loop.create_task(run())
+loop.run_forever()
"""
-Deploy two charms and relate them.
+This example:
+
+1. Connects to the current model
+2. Resets it
+3. Deploys two charms and relates them
+4. Waits for units to be idle, then exits
"""
import asyncio