Python libjuju


When developing Juju we sometimes have to change various API server interfaces, most if not all of the time these are or should be compatible with previous versions of Juju clients. Pythonlibjuju (pylibjuju) can be considered one of these clients. Going forward the CI infrastructure will start to test if your Juju PR will cause any issues with the pylibjuju client, if changes have broken the client, additional work will be required to fix the python code before attempting to merge your changes. These could include new endpoints, changes to parameters or deprecation of old existing endpoints.

Syncing with Juju

If you’re going to introduce new methods that you want to expose in pylibjuju you’re going to have to update the schema file found within pylibjuju.

You’ll need two things before doing this, a commit hash of the Juju you’re syncing against and schemagen. Schemagen generates the schema directly from the AllFacades method in Juju at the hash you’re syncing against.

  1. Fork
  2. Checkout schemagen and update the Gopkg.toml where hash points to your hash.
  3. Run make rebuild-dependencies dep - this should ensure that everything is pulled down correctly.

Conflicts can occur if the upstream Juju has changed and we can no longer pull in If this is the case, you’ll need to go through and update the dependencies inside of schemagen Gopkg.toml to also match that of Juju Gopkg.toml.

  1. Run go install . - this should ensure all your deps are correct and that it can indeed run.

Next steps include going to pylibjuju and syncing with Juju.

  1. Fork
  2. Run schemagen > juju/client/schemas-juju-${VERSION}.json

If you’re performing a release you also need to do:

  1. Run rm juju/client/schemas-juju-latest.json
  2. cd juju/client and Run ln -s schemas-juju-${VERSION}.json schemas-juju-latest.json

Then move back to the root of pylibjuju

  1. Run make client - You should expect to see updates to the juju/client/ file, as well as one or more of the juju/client/ files, depending on which facades were touched.

Additional work

Once syncing with Juju is complete you may need to integrate any new or changed API calls into the object layer, to provide a clean, Pythonic way to interact with the model. This may be as simple as adding an optional parameter to an existing model method, tweaking what manipulations, if any the model method does to the data before it is sent to the API, or it may require adding an entirely new model method to capture the new functionality.

In general, the approach should be to make the interactions with the model layer use the same patterns as when you use the CLI, just with Python idioms and OO approaches.


The Juju Show #51 - Juju + Open Source Mano : June 18 13:00 UTC