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://pythonlibjuju.readthedocs.io/en/latest/

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:

#!/usr/bin/python3

import logging
import sys

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()

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

        if '--wait' in sys.argv:
            # optionally block until the application is ready
            await model.block_until(lambda: ubuntu_app.status == 'active')
    finally:
        # Disconnect from the api server and cleanup.
        await model.disconnect()


def main():
    logging.basicConfig(level=logging.INFO)

    # 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()

More examples can be found in the docs, as well as in the examples/ directory of the source tree which can be run using tox. For example, to run examples/connect_current_model.py, use:

tox -e example -- examples/connect_current_model.py

Versioning

Pylibjuju releases now track the Juju release cadence. New generated schemas will be updated per Juju releases.

Changelog

2.9.5

Friday December 3 2021

## What’s Changed

2.9.4

Tuesday October 12 2021

2.9.3

Monday August 12 2021

  • Bug fix - Fix ‘Default to bundle series if the charm has no series field’ #514

2.9.2

Monday June 28 2021

  • Bug fix - Fix ‘metadata referenced before assignment’ error #509

2.9.1

Wednesday June 16 2021

  • Bug fix - Bundle Exposed endpoints missing #502

  • Bug fix - Fix series requirement for local charms #504

  • Add local charm update support #507

2.9.0

Thursday May 27 2021

  • Update facade methods for Juju 2.9.0

  • Update facade methods for Juju 2.9.1

  • Bug fix - Support for Juju client proxies (LP#1926595)

  • Bug fix - Honor charm channel in bundles #496

  • Remove machine workaround for Juju 2.2.3

2.8.6

Tuesday March 23 2021

  • Update facade methods for Juju 2.8.10

  • Bug fix - Fix typo in param name for ScaleApplications

  • Introduction of hostname property for Machines

2.8.5

Monday February 8 2021

  • Implement add_space and get_spaces.

  • Update facade controllers.

  • Support already archived (.charm or .zip) local charms.

  • Introduction of wait_for_bundle method.

  • Bug fix - Handle None in list_offers results

  • Bug fix - Update libraries to support Python 3.9+

2.8.4

Thursday October 1 2020

  • Update facade methods for Juju 2.8.3

  • Bug fix - Add force and max wait for destroying a model

  • Bug fix - Fix derivation of the application status

2.8.3

Friday August 28 2020

  • Bug fix - Export the CAAS model operator facade (#434)

  • Bug fix - Allow passing controllers to prevent consume reading local filesystem (#436)

2.8.2

Tuesday July 14 2020

  • Update facade methods for Juju 2.8.1

  • Add documentation to the client API methods (using the 2.8.1 changes)

  • Bug fix -Fixes application status being reported as unset (#430)

  • Bug fix - Handle Network Unreachable OSErrors (#426)

2.8.1

Monday May 18 2020

  • Fix positional argument usage in facade calls.

  • Add get shim to facade types.

  • Fix SSH await on unit

  • Fix integration tests

  • Fix tox.ini to use supported python versions.

  • Fix constraints regex using subscript on matches (py36).

  • Fix facade return type documentation.

  • Fix schema objects with array values.

  • Fix subscript lookups by using JSON keys.

  • Add definition test.

2.8.0

Wednesday May 13 2020

  • Update facade methods for Juju 2.8.0

  • Fixes codegen for Python 3.7+

  • Nested facade definitions are now deserialised properly (e.g. storage on ApplicationDeploy)

  • Missing client facades are now ignored and a warning is printed (#382)

  • Add SCP example (#383)

  • Add watch_model_summaries method to Controller (#390)

  • Bug fix - make_archive on Model handles symlinks (#391 #392)

  • Add SSH support for units and machines (#393)

  • Add connection HA support (#402)

  • Bug fix - resolve api_endpoints from controller (#406 #407)

2.7.1

Thursday January 9 2020

  • Added the missing facade type, when attempting to connect to a model.

2.7.0

Tuesday January 7 2020

  • Update facade methods for Juju 2.7.0

  • Fix an issue when querying CMR relations (#366)

  • Fix storage support in bundles (#361)

  • Fix reporting of unit leaders (#374)

  • AddCloud API support (#370)

2.6.3

  • Refactor bundle handler code so that it can be more resilient against changes to the bundle changes API.

  • Updated the dependencies to the latest version (pyyaml)

2.6.2

Wednesday August 27 2019

  • Fixes validation issue with a go interface{} type (Any type) being returned from the Juju API server (#344)

2.6.1

Wednesday August 21 2019

  • Pylibjuju now validates arguments correctly, instead of relying on default positional argument values.

2.6.0

Wednesday August 14 2019

  • Update facade methods for Juju 2.6.6

  • Pylibjuju release now follows the cadence of Juju releases, which also includes bumping the version number to follow suit.

  • Pinned API facades. All facades in Pylibjuju are now pinned to a set of facade versions that is more conservative to prevent breakages against new features. The ability to override the pinned facades and specify your own facade versions is possible upon connection to a controller or model.

  • Cross model relations (CMR) when deploying and adding relations. Additionally getting information about the CMR offers are available on the model.

  • Cross model relations (CMR) in bundles.

  • Ability to export bundle including overlays.

  • Manual provisioning without a ubuntu user (#335)

  • Addition of remote applications when adding relations via SAAS blocks

  • Applying topological sorting to bundle changes API response, allows deployment of complex bundles possible.

  • Updated definitions types to include the latest information from Juju.

  • Keyword arguments (unknown_field in code) are now available on Juju responses.

0.11.7

Wednesday April 19 2019

  • Update facade methods for Juju 2.6.4

  • Support for trusted bundles and charms (See: Trust documentation)

0.11.6

Wednesday May 22 2019

  • Disable hostname checking on controller connection (#305)

  • Handle RedirectError payloads returned by Login RPCs (#303)

0.11.5

Monday April 1 2019

  • Handle deltas of unknown types (fixes connecting to Juju 2.6 controllers) (#299)

  • Test fixes (#298)

0.11.4

Monday April 1 2019

  • Additional work with annotations. (#290)

  • Check server cert. (#296)

0.11.3

Wednesday March 13 2019

  • k8s bundles no longer have application placement (#293)

  • Add retry for connection if all endpoints fail (#288)

  • Support generation of registration string for model sharing. (#279)

  • Add Twine for dist upload on release (#284)

0.11.2

Wednesday January 16 2019

  • update facade methods for Juju 2.5-rc2 (#281)

  • Add test case for redirect during connect (#275)

  • Implement App.get_resources and pinned resources in bundles (#278)

0.11.1

Thursday December 13 2018

  • Fix bundles with subordinates for Juju <2.5 (#277)

0.11.0

Tuesday December 11 2018

  • Updates for new Juju version (#274)

  • Fix wrong variable name in revoke_model function (#271)

0.10.2

Tuesday September 18 2018

  • set include_stats to false to reduce request time (#266)

0.10.1

Monday September 17 2018

  • Retry ssh in manual provision test (#265)

  • Clean up lint and add lint coverage to travis config (#263)

  • Increase the timeout for charmstore connections (#262)

  • Fix log level of Driver connected to juju message (#258)

0.10.0

Thursday August 16 2018

  • Fix error due to scp extra opts order (#260)

  • Implement set/get model constraints (#253)

0.9.1

Monday July 16 2018

  • Update websockets to 6.0 to fix OS X support due to Brew update to Py3.7 (#254)

0.9.0

Friday June 29 2018

  • python3.7 compatibility updates (#251)

  • Handle juju not installed in is_bootstrapped for tests (#250)

  • Add app.reset_config(list). (#249)

  • Implement model.get_action_status (#248)

  • Fix make client in Python 3.6 (#247)

0.8.0

Thursday June 14 2018

  • Add support for adding a manual (ssh) machine (#240)

  • Backwards compatibility fixes (#213)

  • Implement model.get_action_output (#242)

  • Fix JSON serialization error for bundle with lxd to unit placement (#243)

  • Fix reference in docs to connect_current (#239)

  • Wrap machine agent status workaround in version check (#238)

  • Convert seconds to nanoseconds for juju.unit.run (#237)

  • Fix spurious intermittent failure in test_machines.py::test_status (#236)

  • Define an unused juju-zfs lxd storage pool for Travis (#235)

  • Add support for Application get_actions (#234)

0.7.5

Friday May 18 2018

  • Surface errors from bundle plan (#233)

  • Always send auth-tag even with macaroon auth (#217)

  • Inline jsonfile credential when sending to controller (#231)

0.7.4

Tuesday Apr 24 2018

  • Always parse tags and spaces constraints to lists (#228)

  • Doc index improvements (#211)

  • Add doc req to force newer pymacaroons to fix RTD builds

  • Fix dependency conflict for building docs

0.7.3

Tuesday Feb 20 2018

  • Full macaroon bakery support (#206)

  • Fix regression with deploying local charm, add test case (#209)

  • Expose a machines series (#208)

  • Automated test runner fixes (#205)

0.7.2

Friday Feb 9 2018

  • Support deploying bundle YAML file directly (rather than just directory) (#202)

0.7.1

Monday Dec 18 2017

  • Fix missed renames of model_uuids (#197)

0.7.0

Fri Dec 15 2017

  • Fix race condition in adding relations (#192)

  • Fix race condition in connection monitor test (#183)

  • Fix example in README (#178)

  • Fix rare hang during Unit.run (#177)

  • Fix licensing quirks (#176)

  • Refactor model handling (#171)

  • Refactor users handling, add get_users (#170)

  • Upload credential to controller when adding model (#168)

  • Support ‘applications’ key in bundles (#165)

  • Improve handling of thread error handling for loop.run() (#169)

  • Fix encoding when using to_json() (#166)

  • Fix intermittent test failures (#167)

0.6.1

Fri Sept 29 2017

  • Fix failure when controller supports newer facade version (#145)

  • Fix test failures (#163)

  • Fix SSH key handling when adding a new model (#161)

  • Make Application.upgrade_charm upgrade resources (#158)

  • Expand integration tests to use stable/edge versions of juju (#155)

  • Move docs to ReadTheDocs (https://pythonlibjuju.readthedocs.io/en/latest/)

0.6.0

Thu June 29 2017

  • Implement scp functionality (#149)

  • Add Unit.public_address property (#153)

  • Adds support for getting/setting config on a model (#152)

0.5.3

Thu June 22 2017

  • Improve handling of closed connections (#148)

  • Configurable and larger max message size (#146)

0.5.2

Wed June 14 2017

  • Fix deploying non-stable channels and explicit revs (#144)

0.5.1

Tue June 13 2017

  • Update schema for Juju 2.3 alpha1 (#142)

  • Improve API doc navigation and coverage (#141)

  • Add type info to Model.add_machine docs (#138)

0.5.0

Thu June 8 2017

  • Add machine status properties (#133)

  • Add model context manager (#128)

  • Implement Application.upgrade_charm method (#132)

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

2.9.5

Download files

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

Source Distribution

juju-2.9.5.tar.gz (744.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: juju-2.9.5.tar.gz
  • Upload date:
  • Size: 744.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for juju-2.9.5.tar.gz
Algorithm Hash digest
SHA256 c1a62d31afef1f890580d775d1e8fb51f9bff43275c2450f9df89719d97b364f
MD5 a728f46ced687ee12b31a34d7db3fda8
BLAKE2b-256 e8b25b87d093a73ea1318d14febf61ccfc5d602609e0e3f90d7a9733c49cb2be

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