charmhelpers.fetch package

charmhelpers.fetch.archiveurl module

class charmhelpers.fetch.archiveurl.ArchiveUrlFetchHandler

Bases: charmhelpers.fetch.BaseFetchHandler

Handler to download archive files from arbitrary URLs.

Can fetch from http, https, ftp, and file URLs.

Can install either tarballs (.tar, .tgz, .tbz2, etc) or zip files.

Installs the contents of the archive in $CHARM_DIR/fetched/.

can_handle(source)
download(source, dest)

Download an archive file.

Parameters:
  • source (str) – URL pointing to an archive file.
  • dest (str) – Local path location to download archive file to.
download_and_validate(url, hashsum, validate='sha1')
install(source, dest=None, checksum=None, hash_type='sha1')

Download and install an archive file, with optional checksum validation.

The checksum can also be given on the source URL’s fragment. For example:

handler.install('http://example.com/file.tgz#sha1=deadbeef')
Parameters:
  • source (str) – URL pointing to an archive file.
  • dest (str) – Local destination path to install to. If not given, installs to $CHARM_DIR/archives/archive_file_name.
  • checksum (str) – If given, validate the archive file after download.
  • hash_type (str) – Algorithm used to generate checksum. Can be any hash alrgorithm supported by hashlib, such as md5, sha1, sha256, sha512, etc.
charmhelpers.fetch.archiveurl.splitpasswd(user)

urllib.splitpasswd(), but six’s support of this is missing

charmhelpers.fetch.archiveurl.splituser(host)

urllib.splituser(), but six’s support of this seems broken

charmhelpers.fetch.bzrurl module

exception charmhelpers.fetch.AptLockError

Bases: exceptions.Exception

class charmhelpers.fetch.BaseFetchHandler

Bases: object

Base class for FetchHandler implementations in fetch plugins

base_url(url)

Return url without querystring or fragment

can_handle(source)

Returns True if the source can be handled. Otherwise returns a string explaining why it cannot

install(source)

Try to download and unpack the source. Return the path to the unpacked files or raise UnhandledSource.

parse_url(url)
exception charmhelpers.fetch.SourceConfigError

Bases: exceptions.Exception

exception charmhelpers.fetch.UnhandledSource

Bases: exceptions.Exception

charmhelpers.fetch.add_source(source, key=None)

Add a package source to this system.

@param source: a URL or sources.list entry, as supported by add-apt-repository(1). Examples:

ppa:charmers/example
deb https://stub:key@private.example.com/ubuntu trusty main
In addition:
‘proposed:’ may be used to enable the standard ‘proposed’ pocket for the release. ‘cloud:’ may be used to activate official cloud archive pockets, such as ‘cloud:icehouse’ ‘distro’ may be used as a noop

@param key: A key to be added to the system’s APT keyring and used to verify the signatures on packages. Ideally, this should be an ASCII format GPG public key including the block headers. A GPG key id may also be used, but be aware that only insecure protocols are available to retrieve the actual public key from a public keyserver placing your Juju environment at risk. ppa and cloud archive keys are securely added automtically, so sould not be provided.

charmhelpers.fetch.apt_cache(in_memory=True)

Build and return an apt cache

charmhelpers.fetch.apt_hold(packages, fatal=False)
charmhelpers.fetch.apt_install(packages, options=None, fatal=False)

Install one or more packages

charmhelpers.fetch.apt_mark(packages, mark, fatal=False)

Flag one or more packages using apt-mark

charmhelpers.fetch.apt_purge(packages, fatal=False)

Purge one or more packages

charmhelpers.fetch.apt_unhold(packages, fatal=False)
charmhelpers.fetch.apt_update(fatal=False)

Update local apt cache

charmhelpers.fetch.apt_upgrade(options=None, fatal=False, dist=False)

Upgrade all packages

charmhelpers.fetch.configure_sources(update=False, sources_var='install_sources', keys_var='install_keys')

Configure multiple sources from charm configuration.

The lists are encoded as yaml fragments in the configuration. The frament needs to be included as a string. Sources and their corresponding keys are of the types supported by add_source().

Example config:
install_sources: |
install_keys: |
  • null
  • “a1b2c3d4”

Note that ‘null’ (a.k.a. None) should not be quoted.

charmhelpers.fetch.filter_installed_packages(packages)

Returns a list of packages that require installation

charmhelpers.fetch.install_from_config(config_var_name)
charmhelpers.fetch.install_remote(source, *args, **kwargs)

Install a file tree from a remote source

The specified source should be a url of the form:
scheme://[host]/path[#[option=value][&...]]

Schemes supported are based on this modules submodules. Options supported are submodule-specific. Additional arguments are passed through to the submodule.

For example:

dest = install_remote('http://example.com/archive.tgz',
                      checksum='deadbeef',
                      hash_type='sha1')

This will download archive.tgz, validate it using SHA1 and, if the file is ok, extract it and return the directory in which it was extracted. If the checksum fails, it will raise charmhelpers.core.host.ChecksumError.

charmhelpers.fetch.plugins(fetch_handlers=None)