How to use the juju.model.Model function in juju

To help you get started, we’ve selected a few juju examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github juju-solutions / matrix / tests / chaos / test_main.py View on Github external
def make_test_model(foo_unit=True, foo_status='idle'):
    juju_model = Model()
    state = juju_model.state
    state.apply_delta(ApplicationDelta(
        ('application', 'type2', {'name': 'foo'})))
    if foo_unit:
        state.apply_delta(UnitDelta(('unit', 'type1', {
            'name': 'steve',
            'application': 'foo',
            # Add some status to fake out chaos's "wait 'til the
            # cloud is idle" check.
            'agent-status': {'current': foo_status}
            })))
    return juju_model
github juju-solutions / matrix / tests / glitch / test_main.py View on Github external
async def _set_model():
            model = Model()
            await model.connect_current()
            self.model = model
github openstack-charmers / zaza / zaza / model.py View on Github external
async def run_in_model(model_name):
    """Context manager for executing code inside a libjuju model.

       Example of using run_in_model:
           async with run_in_model(model_name) as model:
               model.do_something()

    :param model_name: Name of model to run function in
    :type model_name: str
    :returns: The juju Model object correcsponding to model_name
    :rtype: Iterator[:class:'juju.Model()']
    """
    model = Model()
    if not model_name:
        model_name = await async_get_juju_model()
    await model.connect_model(model_name)
    try:
        await yield_(model)
    finally:
        await model.disconnect()
github conjure-up / conjure-up / conjureup / juju.py View on Github external
async def connect_model():
    """ Connect to the selected model.
    """
    if app.provider.controller is None:
        raise Exception("No controller selected")

    if app.provider.model is None:
        raise Exception("No model selected.")

    app.juju.client = Model(app.loop)
    model_name = '{}:{}'.format(app.provider.controller,
                                app.provider.model)
    await app.juju.client.connect(model_name)
    events.ModelConnected.set()
github juju-solutions / matrix / matrix / rules.py View on Github external
async def add_model(self, context):
        if self.model:
            if context.juju_model:
                return
            log.info("Connecting to model %s", self.model)
            context.juju_model = juju.model.Model(loop=self.loop)
            await context.juju_model.connect_model(self.model)
        else:
            # work-around for: https://bugs.launchpad.net/juju/+bug/1652171
            credential = await self._get_credential(context)
            name = "{}-{}".format(
                context.config.model_prefix,
                petname.Generate(2, '-')
            )
            log.info("Creating model %s", name)
            context.juju_model = await context.juju_controller.add_model(
                name, credential_name=credential,
                cloud_name=context.config.cloud)
        self.bus.dispatch(
            origin="matrix",
            payload=context.juju_model,
            kind="model.new",
github openstack-charmers / zaza / zaza / model.py View on Github external
async def deployed():
    """List deployed applications."""
    # Create a Model instance. We need to connect our Model to a Juju api
    # server before we can use it.
    model = Model()
    # Connect to the currently active Juju model
    await model.connect_current()
    try:
        # list currently deploeyd services
        return list(model.applications.keys())
    finally:
        # Disconnect from the api server and cleanup.
        await model.disconnect()