API Documentation

jujuresources.fetch(which=None, mirror_url=None, resources_yaml='resources.yaml', force=False, reporthook=None)

Attempt to fetch all resources for a charm.

Parameters:
  • which (list) – A name, or a list of one or more resource names, to fetch. If ommitted, all non-optional resources are fetched. You can also pass jujuresources.ALL to fetch all optional and required resources.
  • mirror_url (str) – Fetch resources from the given mirror.
  • resources_yaml (str) – Location of the yaml file containing the resource descriptions (default: ./resources.yaml). Can be a local file name or a remote URL.
  • bool (force) – Force re-downloading of valid resources.
  • reporthook (func) – Callback for reporting download progress. Will be called once for each resource, just prior to fetching, and will be passed the resource name.
Returns:

True or False indicating whether the resources were successfully downloaded.

jujuresources.verify(which=None, resources_yaml='resources.yaml')

Verify if some or all resources previously fetched with fetch_resources(), including validating their cryptographic hash.

Parameters:
  • which (list) – A list of one or more resource names to check. If ommitted, all non-optional resources are verified. You can also pass jujuresources.ALL to fetch all optional and required resources.
  • resources_yaml (str) – Location of the yaml file containing the resource descriptions (default: resources.yaml). Can be a local file name or a remote URL.
  • output_dir (str) – Override output_dir option from resources_yaml (this is intended for mirroring via the CLI and it is not recommended to be used otherwise)
Returns:

True if all of the resources are available and valid, otherwise False.

jujuresources.install(which=None, mirror_url=None, destination=None, skip_top_level=False, resources_yaml='resources.yaml')

Install one or more resources.

The resource(s) will be fetched, if necessary, and different resource types are handled appropriately (e.g., PyPI resources are installed with pip, archive file resources are extracted, non-archive file resources are copied, etc).

For PyPI resources, this is roughly equivalent to the following:

pip install `juju-resources resource_spec $resource` -i $mirror_url
Parameters:
  • which (list) – A name, or a list of one or more resource names, to fetch. If ommitted, all non-optional resources are installed.
  • mirror_url (str) – Fetch resources from the given mirror.
  • destination (str) – Destination to which to extract or copy file resources.
  • skip_top_level (bool) – When extracting archive file resources, skip all members that are at the top level of the archive and instead extract all nested members directly into destination. E.g., an archive containing foo/bar.txt and foo/qux/baz.txt will be extracted as destination/bar.txt and destination/qux/baz.txt.
  • resources_yaml (str) – Location of the yaml file containing the resource descriptions (default: resources.yaml). Can be a local file name or a remote URL.
Returns:

True if all resources were successfully installed.

jujuresources.resource_path(resource_name, resources_yaml='resources.yaml')

Get the local path for a named resource that has been fetched.

This may return None if the local path cannot be determined (for example, if the resource has not been fetched yet and needs to be resolved). Even if it returns a path, that path is not guaranteed to exist or be valid; you should always confirm that a resource is available using verify() or fetch() before using it.

Parameters:
  • resource_name (str) – The name of a resource to resolve.
  • resources_yaml (str) – Location of the yaml file containing the resource descriptions (default: ./resources.yaml). Can be a local file name or a remote URL.
jujuresources.resource_spec(resource_name, resources_yaml='resources.yaml')

Get the spec for a named resource. This would be the URL for URL resources, the Python package spec for PyPI resources, the full path for local file resources, etc.

Parameters:
  • resource_name (str) – The name of a resource to resolve.
  • resources_yaml (str) – Location of the yaml file containing the resource descriptions (default: ./resources.yaml). Can be a local file name or a remote URL.
class jujuresources.ALL

Placeholder to select all resources, optional as well as required.

jujuresources.config_get(option_name)

Helper to access a Juju config option when charmhelpers is not available.

Parameters:option_name (str) – Name of the config option to get the value of
jujuresources.juju_log(message, level='DEBUG')

Helper to send Juju log messages when charmhelpers is not available.

Parameters:
  • message (str) – Message to log
  • level (str) – Log level (DEBUG, INFO, ERROR, WARNING, CRITICAL; default: DEBUG)