X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=docs%2Fnarrative%2Fmodel.rst;h=74f7e844143c9420f76f69f77506239455c0de69;hp=79df011bfe15fe144916ce3637b1f80aa0ba937d;hb=5fef7503b13f145adc7cd4ee31c2d684e09a6a85;hpb=616e1bab41a3a450919966018c3a2fa572989797 diff --git a/docs/narrative/model.rst b/docs/narrative/model.rst index 79df011..74f7e84 100644 --- a/docs/narrative/model.rst +++ b/docs/narrative/model.rst @@ -131,6 +131,50 @@ Example of creating a new model and then destroying it. See model = None +Adding Machines and Containers +------------------------------ +To add a machine or container, connect to a model and then call its +:meth:`~juju.model.Model.add_machine` method. A +:class:`~juju.machine.Machine` instance is returned. The machine id +can be used to deploy a charm to a specific machine or container. + +.. code:: python + + from juju.model import Model + + model = Model() + await model.connect_current() + + # add a new default machine + machine1 = await model.add_machine() + + # add a machine with constraints, disks, and series specified + machine2 = await model.add_machine( + constraints={ + 'mem': 256 * MB, + }, + disks=[{ + 'pool': 'rootfs', + 'size': 10 * GB, + 'count': 1, + }], + series='xenial', + ) + + # add a lxd container to machine2 + machine3 = await model.add_machine( + 'lxd:{}'.format(machine2.id)) + + # deploy charm to the lxd container + application = await model.deploy( + 'ubuntu-10', + application_name='ubuntu', + series='xenial', + channel='stable', + to=machine3.id + ) + + Reacting to Changes in a Model ------------------------------ To watch for and respond to changes in a model, register an observer with the