Skip to main content

Python library for Juju

Project description

Source code: https://github.com/juju/python-libjuju

Bug reports: https://github.com/juju/python-libjuju/issues

Documentation: https://pythonhosted.org/juju/

Requirements

  • Python 3.5+

  • Juju 2.0+

Design Notes

  • Asynchronous - uses asyncio and async/await features of python 3.5

  • Websocket-level bindings are programmatically generated (indirectly) from the Juju golang code, ensuring full api coverage

  • Provides an OO layer which encapsulates much of the websocket api and provides familiar nouns and verbs (e.g. Model.deploy(), Application.add_unit(), etc.)

Installation

pip3 install juju

Quickstart

Here’s a simple example that shows basic usage of the library. The example connects to the currently active Juju model, deploys a single unit of the ubuntu charm, then exits.

More examples can be found in the examples/ directory of the source tree, and in the documentation.

#!/usr/bin/python3.5

import asyncio
import logging

from juju import loop
from juju.model import Model


async def deploy():
    # 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()

    # Deploy a single unit of the ubuntu charm, using revision 0 from the
    # stable channel of the Charm Store.
    ubuntu_app = await model.deploy(
        'ubuntu-0',
        application_name='ubuntu',
        series='xenial',
        channel='stable',
    )

    # Disconnect from the api server and cleanup.
    model.disconnect()


def main():
    # Set logging level to debug so we can see verbose output from the
    # juju library.
    logging.basicConfig(level=logging.DEBUG)

    # Quiet logging from the websocket library. If you want to see
    # everything sent over the wire, set this to DEBUG.
    ws_logger = logging.getLogger('websockets.protocol')
    ws_logger.setLevel(logging.INFO)

    # Run the deploy coroutine in an asyncio event loop, using a helper
    # that abstracts loop creation and teardown.
    loop.run(deploy())


if __name__ == '__main__':
    main()

Change Log

0.4.3

Thu June 1 2017 * Accept new / unknown API fields gracefully (#131) * Add support for new agent-version field in ModelInfo (#131) * Replace pip with pip3 in install instructions (#129) * Strip local:-prefix from local charm urls (#121)

0.4.2

Wed May 10 2017

  • Support (and prefer) per-controller macaroon files (#125)

0.4.1

Wed Apr 27 2017

  • Remove VERSION_MAP and rely on facade list from controller (#118)

  • Refactor connection task management to avoid cancels (#117)

  • Refactored login code to better handle redirects (#116)

0.4.0

Wed Apr 19 2017

  • Feature/api version support (#109)

  • Expanding controller.py with basic user functions, get_models and destroy (#89)

  • Added Monitor class to Connection. (#105)

  • Support placement lists (#103)

  • Include resources from store when deploying (#102)

  • Allow underscore to dash translation when accessing model attributes (#101)

  • Added controller to ssh fix. (#100)

  • Regen schema to pick up missing APIs

  • Improve error handling

  • Fix issue where we do not check to make sure that we are receiving the correct response.

  • Retry calls to charmstore and increase timeout to 5s

  • Make connect_model and deploy a bit more friendly

  • Fix model name not including user

  • Implement Model.get_status

  • Add integration tests.

0.3.0

Mon Feb 27 2017

  • Fix docstrings for placement directives.

  • Implement Model.add_machine()

  • Bug fix - “to” parameter to Model.deploy() was broken

  • Add docs and examples for adding machines and containers and deploying charms to them.

  • Make Machine.destroy() block the current coroutine, returning only after the machine is actually removed from the remote model. This is more consistent with the way the other apis work (e.g. Model.deploy(), Application.add_unit(), etc).

  • Raise NotImplementedError in all unimplemented method stubs instead of silently passing.

0.2.0

Thu Feb 16 2017

  • Add default ssh key to newly created model.

  • Add loop helpers and simplify examples/deploy.py

  • Add support for deploying local charms, and bundles containing local charm paths.

  • Add ability to get cloud name for controller.

  • Bug fix - fix wrong api used in Model.destroy_unit()

  • Add error detection in bundle deploy.

0.1.2

Thu Dec 22 2016

  • Bug fix - Include docs in package

0.1.1

Thu Dec 22 2016

  • Bug fix - Include VERSION file in package

0.1.0

Wed Dec 21 2016

  • Initial Release

Project details


Release history Release notifications | RSS feed

This version

0.4.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

juju-0.4.3.tar.gz (170.5 kB view details)

Uploaded Source

File details

Details for the file juju-0.4.3.tar.gz.

File metadata

  • Download URL: juju-0.4.3.tar.gz
  • Upload date:
  • Size: 170.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for juju-0.4.3.tar.gz
Algorithm Hash digest
SHA256 9c6d842925ca3661c09d947f34eb995f1f8649999a2baa6f7e196deefbf513eb
MD5 996ac3aace17df7bf7a27e2c7e0dc7c7
BLAKE2b-256 3d26543538bd9d8cadf5aa513277e83dec6fd8add81f9611c01b400a12821a2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page