id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
12,700 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _write_apt_gpg_keyfile | def _write_apt_gpg_keyfile(key_name, key_material):
"""Writes GPG key material into a file at a provided path.
:param key_name: A key name to use for a key file (could be a fingerprint)
:type key_name: str
:param key_material: A GPG key material (binary)
:type key_material: (str, bytes)
"""
... | python | def _write_apt_gpg_keyfile(key_name, key_material):
"""Writes GPG key material into a file at a provided path.
:param key_name: A key name to use for a key file (could be a fingerprint)
:type key_name: str
:param key_material: A GPG key material (binary)
:type key_material: (str, bytes)
"""
... | [
"def",
"_write_apt_gpg_keyfile",
"(",
"key_name",
",",
"key_material",
")",
":",
"with",
"open",
"(",
"'/etc/apt/trusted.gpg.d/{}.gpg'",
".",
"format",
"(",
"key_name",
")",
",",
"'wb'",
")",
"as",
"keyf",
":",
"keyf",
".",
"write",
"(",
"key_material",
")"
] | Writes GPG key material into a file at a provided path.
:param key_name: A key name to use for a key file (could be a fingerprint)
:type key_name: str
:param key_material: A GPG key material (binary)
:type key_material: (str, bytes) | [
"Writes",
"GPG",
"key",
"material",
"into",
"a",
"file",
"at",
"a",
"provided",
"path",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L440-L450 |
12,701 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _add_apt_repository | def _add_apt_repository(spec):
"""Add the spec using add_apt_repository
:param spec: the parameter to pass to add_apt_repository
:type spec: str
"""
if '{series}' in spec:
series = get_distrib_codename()
spec = spec.replace('{series}', series)
# software-properties package for b... | python | def _add_apt_repository(spec):
"""Add the spec using add_apt_repository
:param spec: the parameter to pass to add_apt_repository
:type spec: str
"""
if '{series}' in spec:
series = get_distrib_codename()
spec = spec.replace('{series}', series)
# software-properties package for b... | [
"def",
"_add_apt_repository",
"(",
"spec",
")",
":",
"if",
"'{series}'",
"in",
"spec",
":",
"series",
"=",
"get_distrib_codename",
"(",
")",
"spec",
"=",
"spec",
".",
"replace",
"(",
"'{series}'",
",",
"series",
")",
"# software-properties package for bionic prope... | Add the spec using add_apt_repository
:param spec: the parameter to pass to add_apt_repository
:type spec: str | [
"Add",
"the",
"spec",
"using",
"add_apt_repository"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L560-L573 |
12,702 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _add_cloud_distro_check | def _add_cloud_distro_check(cloud_archive_release, openstack_release):
"""Add the cloud pocket, but also check the cloud_archive_release against
the current distro, and use the openstack_release as the full lookup.
This just calls _add_cloud_pocket() with the openstack_release as pocket
to get the corr... | python | def _add_cloud_distro_check(cloud_archive_release, openstack_release):
"""Add the cloud pocket, but also check the cloud_archive_release against
the current distro, and use the openstack_release as the full lookup.
This just calls _add_cloud_pocket() with the openstack_release as pocket
to get the corr... | [
"def",
"_add_cloud_distro_check",
"(",
"cloud_archive_release",
",",
"openstack_release",
")",
":",
"_verify_is_ubuntu_rel",
"(",
"cloud_archive_release",
",",
"openstack_release",
")",
"_add_cloud_pocket",
"(",
"\"{}-{}\"",
".",
"format",
"(",
"cloud_archive_release",
",",... | Add the cloud pocket, but also check the cloud_archive_release against
the current distro, and use the openstack_release as the full lookup.
This just calls _add_cloud_pocket() with the openstack_release as pocket
to get the correct cloud-archive.list for dpkg to work with.
:param cloud_archive_releas... | [
"Add",
"the",
"cloud",
"pocket",
"but",
"also",
"check",
"the",
"cloud_archive_release",
"against",
"the",
"current",
"distro",
"and",
"use",
"the",
"openstack_release",
"as",
"the",
"full",
"lookup",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L617-L631 |
12,703 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _verify_is_ubuntu_rel | def _verify_is_ubuntu_rel(release, os_release):
"""Verify that the release is in the same as the current ubuntu release.
:param release: String, lowercase for the release.
:param os_release: String, the os_release being asked for
:raises: SourceConfigError if the release is not the same as the ubuntu
... | python | def _verify_is_ubuntu_rel(release, os_release):
"""Verify that the release is in the same as the current ubuntu release.
:param release: String, lowercase for the release.
:param os_release: String, the os_release being asked for
:raises: SourceConfigError if the release is not the same as the ubuntu
... | [
"def",
"_verify_is_ubuntu_rel",
"(",
"release",
",",
"os_release",
")",
":",
"ubuntu_rel",
"=",
"get_distrib_codename",
"(",
")",
"if",
"release",
"!=",
"ubuntu_rel",
":",
"raise",
"SourceConfigError",
"(",
"'Invalid Cloud Archive release specified: {}-{} on this Ubuntu'",
... | Verify that the release is in the same as the current ubuntu release.
:param release: String, lowercase for the release.
:param os_release: String, the os_release being asked for
:raises: SourceConfigError if the release is not the same as the ubuntu
release. | [
"Verify",
"that",
"the",
"release",
"is",
"in",
"the",
"same",
"as",
"the",
"current",
"ubuntu",
"release",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L634-L646 |
12,704 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _run_with_retries | def _run_with_retries(cmd, max_retries=CMD_RETRY_COUNT, retry_exitcodes=(1,),
retry_message="", cmd_env=None):
"""Run a command and retry until success or max_retries is reached.
:param: cmd: str: The apt command to run.
:param: max_retries: int: The number of retries to attempt on a ... | python | def _run_with_retries(cmd, max_retries=CMD_RETRY_COUNT, retry_exitcodes=(1,),
retry_message="", cmd_env=None):
"""Run a command and retry until success or max_retries is reached.
:param: cmd: str: The apt command to run.
:param: max_retries: int: The number of retries to attempt on a ... | [
"def",
"_run_with_retries",
"(",
"cmd",
",",
"max_retries",
"=",
"CMD_RETRY_COUNT",
",",
"retry_exitcodes",
"=",
"(",
"1",
",",
")",
",",
"retry_message",
"=",
"\"\"",
",",
"cmd_env",
"=",
"None",
")",
":",
"env",
"=",
"None",
"kwargs",
"=",
"{",
"}",
... | Run a command and retry until success or max_retries is reached.
:param: cmd: str: The apt command to run.
:param: max_retries: int: The number of retries to attempt on a fatal
command. Defaults to CMD_RETRY_COUNT.
:param: retry_exitcodes: tuple: Optional additional exit codes to retry.
Def... | [
"Run",
"a",
"command",
"and",
"retry",
"until",
"success",
"or",
"max_retries",
"is",
"reached",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L649-L687 |
12,705 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | _run_apt_command | def _run_apt_command(cmd, fatal=False):
"""Run an apt command with optional retries.
:param: cmd: str: The apt command to run.
:param: fatal: bool: Whether the command's output should be checked and
retried.
"""
# Provide DEBIAN_FRONTEND=noninteractive if not present in the environment.
... | python | def _run_apt_command(cmd, fatal=False):
"""Run an apt command with optional retries.
:param: cmd: str: The apt command to run.
:param: fatal: bool: Whether the command's output should be checked and
retried.
"""
# Provide DEBIAN_FRONTEND=noninteractive if not present in the environment.
... | [
"def",
"_run_apt_command",
"(",
"cmd",
",",
"fatal",
"=",
"False",
")",
":",
"# Provide DEBIAN_FRONTEND=noninteractive if not present in the environment.",
"cmd_env",
"=",
"{",
"'DEBIAN_FRONTEND'",
":",
"os",
".",
"environ",
".",
"get",
"(",
"'DEBIAN_FRONTEND'",
",",
... | Run an apt command with optional retries.
:param: cmd: str: The apt command to run.
:param: fatal: bool: Whether the command's output should be checked and
retried. | [
"Run",
"an",
"apt",
"command",
"with",
"optional",
"retries",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L690-L708 |
12,706 | juju/charm-helpers | charmhelpers/fetch/ubuntu.py | get_upstream_version | def get_upstream_version(package):
"""Determine upstream version based on installed package
@returns None (if not installed) or the upstream version
"""
import apt_pkg
cache = apt_cache()
try:
pkg = cache[package]
except Exception:
# the package is unknown to the current apt... | python | def get_upstream_version(package):
"""Determine upstream version based on installed package
@returns None (if not installed) or the upstream version
"""
import apt_pkg
cache = apt_cache()
try:
pkg = cache[package]
except Exception:
# the package is unknown to the current apt... | [
"def",
"get_upstream_version",
"(",
"package",
")",
":",
"import",
"apt_pkg",
"cache",
"=",
"apt_cache",
"(",
")",
"try",
":",
"pkg",
"=",
"cache",
"[",
"package",
"]",
"except",
"Exception",
":",
"# the package is unknown to the current apt cache.",
"return",
"No... | Determine upstream version based on installed package
@returns None (if not installed) or the upstream version | [
"Determine",
"upstream",
"version",
"based",
"on",
"installed",
"package"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L711-L728 |
12,707 | juju/charm-helpers | charmhelpers/contrib/storage/linux/bcache.py | get_bcache_fs | def get_bcache_fs():
"""Return all cache sets
"""
cachesetroot = "{}/fs/bcache".format(SYSFS)
try:
dirs = os.listdir(cachesetroot)
except OSError:
log("No bcache fs found")
return []
cacheset = set([Bcache('{}/{}'.format(cachesetroot, d)) for d in dirs if not d.startswith... | python | def get_bcache_fs():
"""Return all cache sets
"""
cachesetroot = "{}/fs/bcache".format(SYSFS)
try:
dirs = os.listdir(cachesetroot)
except OSError:
log("No bcache fs found")
return []
cacheset = set([Bcache('{}/{}'.format(cachesetroot, d)) for d in dirs if not d.startswith... | [
"def",
"get_bcache_fs",
"(",
")",
":",
"cachesetroot",
"=",
"\"{}/fs/bcache\"",
".",
"format",
"(",
"SYSFS",
")",
"try",
":",
"dirs",
"=",
"os",
".",
"listdir",
"(",
"cachesetroot",
")",
"except",
"OSError",
":",
"log",
"(",
"\"No bcache fs found\"",
")",
... | Return all cache sets | [
"Return",
"all",
"cache",
"sets"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/bcache.py#L50-L60 |
12,708 | juju/charm-helpers | charmhelpers/contrib/storage/linux/bcache.py | get_stats_action | def get_stats_action(cachespec, interval):
"""Action for getting bcache statistics for a given cachespec.
Cachespec can either be a device name, eg. 'sdb', which will retrieve
cache stats for the given device, or 'global', which will retrieve stats
for all cachesets
"""
if cachespec == 'global':... | python | def get_stats_action(cachespec, interval):
"""Action for getting bcache statistics for a given cachespec.
Cachespec can either be a device name, eg. 'sdb', which will retrieve
cache stats for the given device, or 'global', which will retrieve stats
for all cachesets
"""
if cachespec == 'global':... | [
"def",
"get_stats_action",
"(",
"cachespec",
",",
"interval",
")",
":",
"if",
"cachespec",
"==",
"'global'",
":",
"caches",
"=",
"get_bcache_fs",
"(",
")",
"else",
":",
"caches",
"=",
"[",
"Bcache",
".",
"fromdevice",
"(",
"cachespec",
")",
"]",
"res",
"... | Action for getting bcache statistics for a given cachespec.
Cachespec can either be a device name, eg. 'sdb', which will retrieve
cache stats for the given device, or 'global', which will retrieve stats
for all cachesets | [
"Action",
"for",
"getting",
"bcache",
"statistics",
"for",
"a",
"given",
"cachespec",
".",
"Cachespec",
"can",
"either",
"be",
"a",
"device",
"name",
"eg",
".",
"sdb",
"which",
"will",
"retrieve",
"cache",
"stats",
"for",
"the",
"given",
"device",
"or",
"g... | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/bcache.py#L63-L74 |
12,709 | juju/charm-helpers | charmhelpers/contrib/storage/linux/bcache.py | Bcache.get_stats | def get_stats(self, interval):
"""Get cache stats
"""
intervaldir = 'stats_{}'.format(interval)
path = "{}/{}".format(self.cachepath, intervaldir)
out = dict()
for elem in os.listdir(path):
out[elem] = open('{}/{}'.format(path, elem)).read().strip()
re... | python | def get_stats(self, interval):
"""Get cache stats
"""
intervaldir = 'stats_{}'.format(interval)
path = "{}/{}".format(self.cachepath, intervaldir)
out = dict()
for elem in os.listdir(path):
out[elem] = open('{}/{}'.format(path, elem)).read().strip()
re... | [
"def",
"get_stats",
"(",
"self",
",",
"interval",
")",
":",
"intervaldir",
"=",
"'stats_{}'",
".",
"format",
"(",
"interval",
")",
"path",
"=",
"\"{}/{}\"",
".",
"format",
"(",
"self",
".",
"cachepath",
",",
"intervaldir",
")",
"out",
"=",
"dict",
"(",
... | Get cache stats | [
"Get",
"cache",
"stats"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/bcache.py#L39-L47 |
12,710 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | update_dns_ha_resource_params | def update_dns_ha_resource_params(resources, resource_params,
relation_id=None,
crm_ocf='ocf:maas:dns'):
""" Configure DNS-HA resources based on provided configuration and
update resource dictionaries for the HA relation.
@param resources:... | python | def update_dns_ha_resource_params(resources, resource_params,
relation_id=None,
crm_ocf='ocf:maas:dns'):
""" Configure DNS-HA resources based on provided configuration and
update resource dictionaries for the HA relation.
@param resources:... | [
"def",
"update_dns_ha_resource_params",
"(",
"resources",
",",
"resource_params",
",",
"relation_id",
"=",
"None",
",",
"crm_ocf",
"=",
"'ocf:maas:dns'",
")",
":",
"_relation_data",
"=",
"{",
"'resources'",
":",
"{",
"}",
",",
"'resource_params'",
":",
"{",
"}",... | Configure DNS-HA resources based on provided configuration and
update resource dictionaries for the HA relation.
@param resources: Pointer to dictionary of resources.
Usually instantiated in ha_joined().
@param resource_params: Pointer to dictionary of resource parameters.
... | [
"Configure",
"DNS",
"-",
"HA",
"resources",
"based",
"on",
"provided",
"configuration",
"and",
"update",
"resource",
"dictionaries",
"for",
"the",
"HA",
"relation",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L77-L97 |
12,711 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | expect_ha | def expect_ha():
""" Determine if the unit expects to be in HA
Check juju goal-state if ha relation is expected, check for VIP or dns-ha
settings which indicate the unit should expect to be related to hacluster.
@returns boolean
"""
ha_related_units = []
try:
ha_related_units = lis... | python | def expect_ha():
""" Determine if the unit expects to be in HA
Check juju goal-state if ha relation is expected, check for VIP or dns-ha
settings which indicate the unit should expect to be related to hacluster.
@returns boolean
"""
ha_related_units = []
try:
ha_related_units = lis... | [
"def",
"expect_ha",
"(",
")",
":",
"ha_related_units",
"=",
"[",
"]",
"try",
":",
"ha_related_units",
"=",
"list",
"(",
"expected_related_units",
"(",
"reltype",
"=",
"'ha'",
")",
")",
"except",
"(",
"NotImplementedError",
",",
"KeyError",
")",
":",
"pass",
... | Determine if the unit expects to be in HA
Check juju goal-state if ha relation is expected, check for VIP or dns-ha
settings which indicate the unit should expect to be related to hacluster.
@returns boolean | [
"Determine",
"if",
"the",
"unit",
"expects",
"to",
"be",
"in",
"HA"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L114-L127 |
12,712 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | generate_ha_relation_data | def generate_ha_relation_data(service, extra_settings=None):
""" Generate relation data for ha relation
Based on configuration options and unit interfaces, generate a json
encoded dict of relation data items for the hacluster relation,
providing configuration for DNS HA or VIP's + haproxy clone sets.
... | python | def generate_ha_relation_data(service, extra_settings=None):
""" Generate relation data for ha relation
Based on configuration options and unit interfaces, generate a json
encoded dict of relation data items for the hacluster relation,
providing configuration for DNS HA or VIP's + haproxy clone sets.
... | [
"def",
"generate_ha_relation_data",
"(",
"service",
",",
"extra_settings",
"=",
"None",
")",
":",
"_haproxy_res",
"=",
"'res_{}_haproxy'",
".",
"format",
"(",
"service",
")",
"_relation_data",
"=",
"{",
"'resources'",
":",
"{",
"_haproxy_res",
":",
"'lsb:haproxy'"... | Generate relation data for ha relation
Based on configuration options and unit interfaces, generate a json
encoded dict of relation data items for the hacluster relation,
providing configuration for DNS HA or VIP's + haproxy clone sets.
Example of supplying additional settings::
COLO_CONSOLEA... | [
"Generate",
"relation",
"data",
"for",
"ha",
"relation"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L130-L186 |
12,713 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | update_hacluster_dns_ha | def update_hacluster_dns_ha(service, relation_data,
crm_ocf='ocf:maas:dns'):
""" Configure DNS-HA resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data.
@param crm_ocf: Coro... | python | def update_hacluster_dns_ha(service, relation_data,
crm_ocf='ocf:maas:dns'):
""" Configure DNS-HA resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data.
@param crm_ocf: Coro... | [
"def",
"update_hacluster_dns_ha",
"(",
"service",
",",
"relation_data",
",",
"crm_ocf",
"=",
"'ocf:maas:dns'",
")",
":",
"# Validate the charm environment for DNS HA",
"assert_charm_supports_dns_ha",
"(",
")",
"settings",
"=",
"[",
"'os-admin-hostname'",
",",
"'os-internal-... | Configure DNS-HA resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data.
@param crm_ocf: Corosync Open Cluster Framework resource agent to use for
DNS HA | [
"Configure",
"DNS",
"-",
"HA",
"resources",
"based",
"on",
"provided",
"configuration"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L189-L250 |
12,714 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | get_vip_settings | def get_vip_settings(vip):
"""Calculate which nic is on the correct network for the given vip.
If nic or netmask discovery fail then fallback to using charm supplied
config. If fallback is used this is indicated via the fallback variable.
@param vip: VIP to lookup nic and cidr for.
@returns (str, ... | python | def get_vip_settings(vip):
"""Calculate which nic is on the correct network for the given vip.
If nic or netmask discovery fail then fallback to using charm supplied
config. If fallback is used this is indicated via the fallback variable.
@param vip: VIP to lookup nic and cidr for.
@returns (str, ... | [
"def",
"get_vip_settings",
"(",
"vip",
")",
":",
"iface",
"=",
"get_iface_for_address",
"(",
"vip",
")",
"netmask",
"=",
"get_netmask_for_address",
"(",
"vip",
")",
"fallback",
"=",
"False",
"if",
"iface",
"is",
"None",
":",
"iface",
"=",
"config",
"(",
"'... | Calculate which nic is on the correct network for the given vip.
If nic or netmask discovery fail then fallback to using charm supplied
config. If fallback is used this is indicated via the fallback variable.
@param vip: VIP to lookup nic and cidr for.
@returns (str, str, bool): eg (iface, netmask, fa... | [
"Calculate",
"which",
"nic",
"is",
"on",
"the",
"correct",
"network",
"for",
"the",
"given",
"vip",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L253-L271 |
12,715 | juju/charm-helpers | charmhelpers/contrib/openstack/ha/utils.py | update_hacluster_vip | def update_hacluster_vip(service, relation_data):
""" Configure VIP resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data.
"""
cluster_config = get_hacluster_config()
vip_group = []
vips_to... | python | def update_hacluster_vip(service, relation_data):
""" Configure VIP resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data.
"""
cluster_config = get_hacluster_config()
vip_group = []
vips_to... | [
"def",
"update_hacluster_vip",
"(",
"service",
",",
"relation_data",
")",
":",
"cluster_config",
"=",
"get_hacluster_config",
"(",
")",
"vip_group",
"=",
"[",
"]",
"vips_to_delete",
"=",
"[",
"]",
"for",
"vip",
"in",
"cluster_config",
"[",
"'vip'",
"]",
".",
... | Configure VIP resources based on provided configuration
@param service: Name of the service being configured
@param relation_data: Pointer to dictionary of relation data. | [
"Configure",
"VIP",
"resources",
"based",
"on",
"provided",
"configuration"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ha/utils.py#L274-L348 |
12,716 | juju/charm-helpers | charmhelpers/contrib/amulet/deployment.py | AmuletDeployment._add_services | def _add_services(self, this_service, other_services):
"""Add services.
Add services to the deployment where this_service is the local charm
that we're testing and other_services are the other services that
are being used in the local amulet tests.
"""
if thi... | python | def _add_services(self, this_service, other_services):
"""Add services.
Add services to the deployment where this_service is the local charm
that we're testing and other_services are the other services that
are being used in the local amulet tests.
"""
if thi... | [
"def",
"_add_services",
"(",
"self",
",",
"this_service",
",",
"other_services",
")",
":",
"if",
"this_service",
"[",
"'name'",
"]",
"!=",
"os",
".",
"path",
".",
"basename",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
":",
"s",
"=",
"this_service",
"[",
... | Add services.
Add services to the deployment where this_service is the local charm
that we're testing and other_services are the other services that
are being used in the local amulet tests. | [
"Add",
"services",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/deployment.py#L37-L69 |
12,717 | juju/charm-helpers | charmhelpers/contrib/amulet/deployment.py | AmuletDeployment._add_relations | def _add_relations(self, relations):
"""Add all of the relations for the services."""
for k, v in six.iteritems(relations):
self.d.relate(k, v) | python | def _add_relations(self, relations):
"""Add all of the relations for the services."""
for k, v in six.iteritems(relations):
self.d.relate(k, v) | [
"def",
"_add_relations",
"(",
"self",
",",
"relations",
")",
":",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"relations",
")",
":",
"self",
".",
"d",
".",
"relate",
"(",
"k",
",",
"v",
")"
] | Add all of the relations for the services. | [
"Add",
"all",
"of",
"the",
"relations",
"for",
"the",
"services",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/deployment.py#L71-L74 |
12,718 | juju/charm-helpers | charmhelpers/contrib/amulet/deployment.py | AmuletDeployment._configure_services | def _configure_services(self, configs):
"""Configure all of the services."""
for service, config in six.iteritems(configs):
self.d.configure(service, config) | python | def _configure_services(self, configs):
"""Configure all of the services."""
for service, config in six.iteritems(configs):
self.d.configure(service, config) | [
"def",
"_configure_services",
"(",
"self",
",",
"configs",
")",
":",
"for",
"service",
",",
"config",
"in",
"six",
".",
"iteritems",
"(",
"configs",
")",
":",
"self",
".",
"d",
".",
"configure",
"(",
"service",
",",
"config",
")"
] | Configure all of the services. | [
"Configure",
"all",
"of",
"the",
"services",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/deployment.py#L76-L79 |
12,719 | juju/charm-helpers | charmhelpers/contrib/amulet/deployment.py | AmuletDeployment._deploy | def _deploy(self):
"""Deploy environment and wait for all hooks to finish executing."""
timeout = int(os.environ.get('AMULET_SETUP_TIMEOUT', 900))
try:
self.d.setup(timeout=timeout)
self.d.sentry.wait(timeout=timeout)
except amulet.helpers.TimeoutError:
... | python | def _deploy(self):
"""Deploy environment and wait for all hooks to finish executing."""
timeout = int(os.environ.get('AMULET_SETUP_TIMEOUT', 900))
try:
self.d.setup(timeout=timeout)
self.d.sentry.wait(timeout=timeout)
except amulet.helpers.TimeoutError:
... | [
"def",
"_deploy",
"(",
"self",
")",
":",
"timeout",
"=",
"int",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'AMULET_SETUP_TIMEOUT'",
",",
"900",
")",
")",
"try",
":",
"self",
".",
"d",
".",
"setup",
"(",
"timeout",
"=",
"timeout",
")",
"self",
"."... | Deploy environment and wait for all hooks to finish executing. | [
"Deploy",
"environment",
"and",
"wait",
"for",
"all",
"hooks",
"to",
"finish",
"executing",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/amulet/deployment.py#L81-L93 |
12,720 | juju/charm-helpers | charmhelpers/contrib/ssl/service.py | ServiceCA._init_ca | def _init_ca(self):
"""Generate the root ca's cert and key.
"""
if not exists(path_join(self.ca_dir, 'ca.cnf')):
with open(path_join(self.ca_dir, 'ca.cnf'), 'w') as fh:
fh.write(
CA_CONF_TEMPLATE % (self.get_conf_variables()))
if not exist... | python | def _init_ca(self):
"""Generate the root ca's cert and key.
"""
if not exists(path_join(self.ca_dir, 'ca.cnf')):
with open(path_join(self.ca_dir, 'ca.cnf'), 'w') as fh:
fh.write(
CA_CONF_TEMPLATE % (self.get_conf_variables()))
if not exist... | [
"def",
"_init_ca",
"(",
"self",
")",
":",
"if",
"not",
"exists",
"(",
"path_join",
"(",
"self",
".",
"ca_dir",
",",
"'ca.cnf'",
")",
")",
":",
"with",
"open",
"(",
"path_join",
"(",
"self",
".",
"ca_dir",
",",
"'ca.cnf'",
")",
",",
"'w'",
")",
"as"... | Generate the root ca's cert and key. | [
"Generate",
"the",
"root",
"ca",
"s",
"cert",
"and",
"key",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/ssl/service.py#L95-L116 |
12,721 | juju/charm-helpers | charmhelpers/contrib/openstack/keystone.py | format_endpoint | def format_endpoint(schema, addr, port, api_version):
"""Return a formatted keystone endpoint
@param schema: http or https
@param addr: ipv4/ipv6 host of the keystone service
@param port: port of the keystone service
@param api_version: 2 or 3
@returns a fully formatted keystone endpoint
"""... | python | def format_endpoint(schema, addr, port, api_version):
"""Return a formatted keystone endpoint
@param schema: http or https
@param addr: ipv4/ipv6 host of the keystone service
@param port: port of the keystone service
@param api_version: 2 or 3
@returns a fully formatted keystone endpoint
"""... | [
"def",
"format_endpoint",
"(",
"schema",
",",
"addr",
",",
"port",
",",
"api_version",
")",
":",
"return",
"'{}://{}:{}/{}/'",
".",
"format",
"(",
"schema",
",",
"addr",
",",
"port",
",",
"get_api_suffix",
"(",
"api_version",
")",
")"
] | Return a formatted keystone endpoint
@param schema: http or https
@param addr: ipv4/ipv6 host of the keystone service
@param port: port of the keystone service
@param api_version: 2 or 3
@returns a fully formatted keystone endpoint | [
"Return",
"a",
"formatted",
"keystone",
"endpoint"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/keystone.py#L35-L44 |
12,722 | juju/charm-helpers | charmhelpers/contrib/openstack/keystone.py | get_keystone_manager | def get_keystone_manager(endpoint, api_version, **kwargs):
"""Return a keystonemanager for the correct API version
@param endpoint: the keystone endpoint to point client at
@param api_version: version of the keystone api the client should use
@param kwargs: token or username/tenant/password information... | python | def get_keystone_manager(endpoint, api_version, **kwargs):
"""Return a keystonemanager for the correct API version
@param endpoint: the keystone endpoint to point client at
@param api_version: version of the keystone api the client should use
@param kwargs: token or username/tenant/password information... | [
"def",
"get_keystone_manager",
"(",
"endpoint",
",",
"api_version",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"api_version",
"==",
"2",
":",
"return",
"KeystoneManager2",
"(",
"endpoint",
",",
"*",
"*",
"kwargs",
")",
"if",
"api_version",
"==",
"3",
":",
... | Return a keystonemanager for the correct API version
@param endpoint: the keystone endpoint to point client at
@param api_version: version of the keystone api the client should use
@param kwargs: token or username/tenant/password information
@returns keystonemanager class used for interrogating keyston... | [
"Return",
"a",
"keystonemanager",
"for",
"the",
"correct",
"API",
"version"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/keystone.py#L47-L59 |
12,723 | juju/charm-helpers | charmhelpers/contrib/openstack/keystone.py | get_keystone_manager_from_identity_service_context | def get_keystone_manager_from_identity_service_context():
"""Return a keystonmanager generated from a
instance of charmhelpers.contrib.openstack.context.IdentityServiceContext
@returns keystonamenager instance
"""
context = IdentityServiceContext()()
if not context:
msg = "Identity servic... | python | def get_keystone_manager_from_identity_service_context():
"""Return a keystonmanager generated from a
instance of charmhelpers.contrib.openstack.context.IdentityServiceContext
@returns keystonamenager instance
"""
context = IdentityServiceContext()()
if not context:
msg = "Identity servic... | [
"def",
"get_keystone_manager_from_identity_service_context",
"(",
")",
":",
"context",
"=",
"IdentityServiceContext",
"(",
")",
"(",
")",
"if",
"not",
"context",
":",
"msg",
"=",
"\"Identity service context cannot be generated\"",
"log",
"(",
"msg",
",",
"level",
"=",... | Return a keystonmanager generated from a
instance of charmhelpers.contrib.openstack.context.IdentityServiceContext
@returns keystonamenager instance | [
"Return",
"a",
"keystonmanager",
"generated",
"from",
"a",
"instance",
"of",
"charmhelpers",
".",
"contrib",
".",
"openstack",
".",
"context",
".",
"IdentityServiceContext"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/keystone.py#L62-L86 |
12,724 | juju/charm-helpers | charmhelpers/contrib/openstack/keystone.py | KeystoneManager.resolve_service_id | def resolve_service_id(self, service_name=None, service_type=None):
"""Find the service_id of a given service"""
services = [s._info for s in self.api.services.list()]
service_name = service_name.lower()
for s in services:
name = s['name'].lower()
if service_type... | python | def resolve_service_id(self, service_name=None, service_type=None):
"""Find the service_id of a given service"""
services = [s._info for s in self.api.services.list()]
service_name = service_name.lower()
for s in services:
name = s['name'].lower()
if service_type... | [
"def",
"resolve_service_id",
"(",
"self",
",",
"service_name",
"=",
"None",
",",
"service_type",
"=",
"None",
")",
":",
"services",
"=",
"[",
"s",
".",
"_info",
"for",
"s",
"in",
"self",
".",
"api",
".",
"services",
".",
"list",
"(",
")",
"]",
"servi... | Find the service_id of a given service | [
"Find",
"the",
"service_id",
"of",
"a",
"given",
"service"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/keystone.py#L91-L105 |
12,725 | juju/charm-helpers | charmhelpers/contrib/storage/linux/lvm.py | deactivate_lvm_volume_group | def deactivate_lvm_volume_group(block_device):
'''
Deactivate any volume gruop associated with an LVM physical volume.
:param block_device: str: Full path to LVM physical volume
'''
vg = list_lvm_volume_group(block_device)
if vg:
cmd = ['vgchange', '-an', vg]
check_call(cmd) | python | def deactivate_lvm_volume_group(block_device):
'''
Deactivate any volume gruop associated with an LVM physical volume.
:param block_device: str: Full path to LVM physical volume
'''
vg = list_lvm_volume_group(block_device)
if vg:
cmd = ['vgchange', '-an', vg]
check_call(cmd) | [
"def",
"deactivate_lvm_volume_group",
"(",
"block_device",
")",
":",
"vg",
"=",
"list_lvm_volume_group",
"(",
"block_device",
")",
"if",
"vg",
":",
"cmd",
"=",
"[",
"'vgchange'",
",",
"'-an'",
",",
"vg",
"]",
"check_call",
"(",
"cmd",
")"
] | Deactivate any volume gruop associated with an LVM physical volume.
:param block_device: str: Full path to LVM physical volume | [
"Deactivate",
"any",
"volume",
"gruop",
"associated",
"with",
"an",
"LVM",
"physical",
"volume",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/lvm.py#L28-L37 |
12,726 | juju/charm-helpers | charmhelpers/contrib/storage/linux/lvm.py | remove_lvm_physical_volume | def remove_lvm_physical_volume(block_device):
'''
Remove LVM PV signatures from a given block device.
:param block_device: str: Full path of block device to scrub.
'''
p = Popen(['pvremove', '-ff', block_device],
stdin=PIPE)
p.communicate(input='y\n') | python | def remove_lvm_physical_volume(block_device):
'''
Remove LVM PV signatures from a given block device.
:param block_device: str: Full path of block device to scrub.
'''
p = Popen(['pvremove', '-ff', block_device],
stdin=PIPE)
p.communicate(input='y\n') | [
"def",
"remove_lvm_physical_volume",
"(",
"block_device",
")",
":",
"p",
"=",
"Popen",
"(",
"[",
"'pvremove'",
",",
"'-ff'",
",",
"block_device",
"]",
",",
"stdin",
"=",
"PIPE",
")",
"p",
".",
"communicate",
"(",
"input",
"=",
"'y\\n'",
")"
] | Remove LVM PV signatures from a given block device.
:param block_device: str: Full path of block device to scrub. | [
"Remove",
"LVM",
"PV",
"signatures",
"from",
"a",
"given",
"block",
"device",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/lvm.py#L55-L63 |
12,727 | juju/charm-helpers | charmhelpers/contrib/storage/linux/lvm.py | list_lvm_volume_group | def list_lvm_volume_group(block_device):
'''
List LVM volume group associated with a given block device.
Assumes block device is a valid LVM PV.
:param block_device: str: Full path of block device to inspect.
:returns: str: Name of volume group associated with block device or None
'''
vg ... | python | def list_lvm_volume_group(block_device):
'''
List LVM volume group associated with a given block device.
Assumes block device is a valid LVM PV.
:param block_device: str: Full path of block device to inspect.
:returns: str: Name of volume group associated with block device or None
'''
vg ... | [
"def",
"list_lvm_volume_group",
"(",
"block_device",
")",
":",
"vg",
"=",
"None",
"pvd",
"=",
"check_output",
"(",
"[",
"'pvdisplay'",
",",
"block_device",
"]",
")",
".",
"splitlines",
"(",
")",
"for",
"lvm",
"in",
"pvd",
":",
"lvm",
"=",
"lvm",
".",
"... | List LVM volume group associated with a given block device.
Assumes block device is a valid LVM PV.
:param block_device: str: Full path of block device to inspect.
:returns: str: Name of volume group associated with block device or None | [
"List",
"LVM",
"volume",
"group",
"associated",
"with",
"a",
"given",
"block",
"device",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/lvm.py#L66-L82 |
12,728 | juju/charm-helpers | charmhelpers/contrib/storage/linux/lvm.py | list_logical_volumes | def list_logical_volumes(select_criteria=None, path_mode=False):
'''
List logical volumes
:param select_criteria: str: Limit list to those volumes matching this
criteria (see 'lvs -S help' for more details)
:param path_mode: bool: return logical volume name in 'vg/lv' f... | python | def list_logical_volumes(select_criteria=None, path_mode=False):
'''
List logical volumes
:param select_criteria: str: Limit list to those volumes matching this
criteria (see 'lvs -S help' for more details)
:param path_mode: bool: return logical volume name in 'vg/lv' f... | [
"def",
"list_logical_volumes",
"(",
"select_criteria",
"=",
"None",
",",
"path_mode",
"=",
"False",
")",
":",
"lv_diplay_attr",
"=",
"'lv_name'",
"if",
"path_mode",
":",
"# Parsing output logic relies on the column order",
"lv_diplay_attr",
"=",
"'vg_name,'",
"+",
"lv_d... | List logical volumes
:param select_criteria: str: Limit list to those volumes matching this
criteria (see 'lvs -S help' for more details)
:param path_mode: bool: return logical volume name in 'vg/lv' format, this
format is required for some commands ... | [
"List",
"logical",
"volumes"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/lvm.py#L107-L132 |
12,729 | juju/charm-helpers | charmhelpers/contrib/storage/linux/lvm.py | create_logical_volume | def create_logical_volume(lv_name, volume_group, size=None):
'''
Create a new logical volume in an existing volume group
:param lv_name: str: name of logical volume to be created.
:param volume_group: str: Name of volume group to use for the new volume.
:param size: str: Size of logical volume to c... | python | def create_logical_volume(lv_name, volume_group, size=None):
'''
Create a new logical volume in an existing volume group
:param lv_name: str: name of logical volume to be created.
:param volume_group: str: Name of volume group to use for the new volume.
:param size: str: Size of logical volume to c... | [
"def",
"create_logical_volume",
"(",
"lv_name",
",",
"volume_group",
",",
"size",
"=",
"None",
")",
":",
"if",
"size",
":",
"check_call",
"(",
"[",
"'lvcreate'",
",",
"'--yes'",
",",
"'-L'",
",",
"'{}'",
".",
"format",
"(",
"size",
")",
",",
"'-n'",
",... | Create a new logical volume in an existing volume group
:param lv_name: str: name of logical volume to be created.
:param volume_group: str: Name of volume group to use for the new volume.
:param size: str: Size of logical volume to create (100% if not supplied)
:raises subprocess.CalledProcessError: i... | [
"Create",
"a",
"new",
"logical",
"volume",
"in",
"an",
"existing",
"volume",
"group"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/storage/linux/lvm.py#L156-L182 |
12,730 | juju/charm-helpers | charmhelpers/core/templating.py | render | def render(source, target, context, owner='root', group='root',
perms=0o444, templates_dir=None, encoding='UTF-8',
template_loader=None, config_template=None):
"""
Render a template.
The `source` path, if not absolute, is relative to the `templates_dir`.
The `target` path should ... | python | def render(source, target, context, owner='root', group='root',
perms=0o444, templates_dir=None, encoding='UTF-8',
template_loader=None, config_template=None):
"""
Render a template.
The `source` path, if not absolute, is relative to the `templates_dir`.
The `target` path should ... | [
"def",
"render",
"(",
"source",
",",
"target",
",",
"context",
",",
"owner",
"=",
"'root'",
",",
"group",
"=",
"'root'",
",",
"perms",
"=",
"0o444",
",",
"templates_dir",
"=",
"None",
",",
"encoding",
"=",
"'UTF-8'",
",",
"template_loader",
"=",
"None",
... | Render a template.
The `source` path, if not absolute, is relative to the `templates_dir`.
The `target` path should be absolute. It can also be `None`, in which
case no file will be written.
The context should be a dict containing the values to be replaced in the
template.
config_template m... | [
"Render",
"a",
"template",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/templating.py#L22-L93 |
12,731 | juju/charm-helpers | charmhelpers/core/hookenv.py | cached | def cached(func):
"""Cache return values for multiple executions of func + args
For example::
@cached
def unit_get(attribute):
pass
unit_get('test')
will cache the result of unit_get + 'test' for future calls.
"""
@wraps(func)
def wrapper(*args, **kwargs):... | python | def cached(func):
"""Cache return values for multiple executions of func + args
For example::
@cached
def unit_get(attribute):
pass
unit_get('test')
will cache the result of unit_get + 'test' for future calls.
"""
@wraps(func)
def wrapper(*args, **kwargs):... | [
"def",
"cached",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"cache",
"key",
"=",
"json",
".",
"dumps",
"(",
"(",
"func",
",",
"args",
",",
"kwargs",
")... | Cache return values for multiple executions of func + args
For example::
@cached
def unit_get(attribute):
pass
unit_get('test')
will cache the result of unit_get + 'test' for future calls. | [
"Cache",
"return",
"values",
"for",
"multiple",
"executions",
"of",
"func",
"+",
"args"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L61-L86 |
12,732 | juju/charm-helpers | charmhelpers/core/hookenv.py | flush | def flush(key):
"""Flushes any entries from function cache where the
key is found in the function+args """
flush_list = []
for item in cache:
if key in item:
flush_list.append(item)
for item in flush_list:
del cache[item] | python | def flush(key):
"""Flushes any entries from function cache where the
key is found in the function+args """
flush_list = []
for item in cache:
if key in item:
flush_list.append(item)
for item in flush_list:
del cache[item] | [
"def",
"flush",
"(",
"key",
")",
":",
"flush_list",
"=",
"[",
"]",
"for",
"item",
"in",
"cache",
":",
"if",
"key",
"in",
"item",
":",
"flush_list",
".",
"append",
"(",
"item",
")",
"for",
"item",
"in",
"flush_list",
":",
"del",
"cache",
"[",
"item"... | Flushes any entries from function cache where the
key is found in the function+args | [
"Flushes",
"any",
"entries",
"from",
"function",
"cache",
"where",
"the",
"key",
"is",
"found",
"in",
"the",
"function",
"+",
"args"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L89-L97 |
12,733 | juju/charm-helpers | charmhelpers/core/hookenv.py | log | def log(message, level=None):
"""Write a message to the juju log"""
command = ['juju-log']
if level:
command += ['-l', level]
if not isinstance(message, six.string_types):
message = repr(message)
command += [message[:SH_MAX_ARG]]
# Missing juju-log should not cause failures in un... | python | def log(message, level=None):
"""Write a message to the juju log"""
command = ['juju-log']
if level:
command += ['-l', level]
if not isinstance(message, six.string_types):
message = repr(message)
command += [message[:SH_MAX_ARG]]
# Missing juju-log should not cause failures in un... | [
"def",
"log",
"(",
"message",
",",
"level",
"=",
"None",
")",
":",
"command",
"=",
"[",
"'juju-log'",
"]",
"if",
"level",
":",
"command",
"+=",
"[",
"'-l'",
",",
"level",
"]",
"if",
"not",
"isinstance",
"(",
"message",
",",
"six",
".",
"string_types"... | Write a message to the juju log | [
"Write",
"a",
"message",
"to",
"the",
"juju",
"log"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L100-L119 |
12,734 | juju/charm-helpers | charmhelpers/core/hookenv.py | execution_environment | def execution_environment():
"""A convenient bundling of the current execution context"""
context = {}
context['conf'] = config()
if relation_id():
context['reltype'] = relation_type()
context['relid'] = relation_id()
context['rel'] = relation_get()
context['unit'] = local_un... | python | def execution_environment():
"""A convenient bundling of the current execution context"""
context = {}
context['conf'] = config()
if relation_id():
context['reltype'] = relation_type()
context['relid'] = relation_id()
context['rel'] = relation_get()
context['unit'] = local_un... | [
"def",
"execution_environment",
"(",
")",
":",
"context",
"=",
"{",
"}",
"context",
"[",
"'conf'",
"]",
"=",
"config",
"(",
")",
"if",
"relation_id",
"(",
")",
":",
"context",
"[",
"'reltype'",
"]",
"=",
"relation_type",
"(",
")",
"context",
"[",
"'rel... | A convenient bundling of the current execution context | [
"A",
"convenient",
"bundling",
"of",
"the",
"current",
"execution",
"context"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L161-L172 |
12,735 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_id | def relation_id(relation_name=None, service_or_unit=None):
"""The relation ID for the current or a specified relation"""
if not relation_name and not service_or_unit:
return os.environ.get('JUJU_RELATION_ID', None)
elif relation_name and service_or_unit:
service_name = service_or_unit.split(... | python | def relation_id(relation_name=None, service_or_unit=None):
"""The relation ID for the current or a specified relation"""
if not relation_name and not service_or_unit:
return os.environ.get('JUJU_RELATION_ID', None)
elif relation_name and service_or_unit:
service_name = service_or_unit.split(... | [
"def",
"relation_id",
"(",
"relation_name",
"=",
"None",
",",
"service_or_unit",
"=",
"None",
")",
":",
"if",
"not",
"relation_name",
"and",
"not",
"service_or_unit",
":",
"return",
"os",
".",
"environ",
".",
"get",
"(",
"'JUJU_RELATION_ID'",
",",
"None",
")... | The relation ID for the current or a specified relation | [
"The",
"relation",
"ID",
"for",
"the",
"current",
"or",
"a",
"specified",
"relation"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L186-L197 |
12,736 | juju/charm-helpers | charmhelpers/core/hookenv.py | principal_unit | def principal_unit():
"""Returns the principal unit of this unit, otherwise None"""
# Juju 2.2 and above provides JUJU_PRINCIPAL_UNIT
principal_unit = os.environ.get('JUJU_PRINCIPAL_UNIT', None)
# If it's empty, then this unit is the principal
if principal_unit == '':
return os.environ['JUJU... | python | def principal_unit():
"""Returns the principal unit of this unit, otherwise None"""
# Juju 2.2 and above provides JUJU_PRINCIPAL_UNIT
principal_unit = os.environ.get('JUJU_PRINCIPAL_UNIT', None)
# If it's empty, then this unit is the principal
if principal_unit == '':
return os.environ['JUJU... | [
"def",
"principal_unit",
"(",
")",
":",
"# Juju 2.2 and above provides JUJU_PRINCIPAL_UNIT",
"principal_unit",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'JUJU_PRINCIPAL_UNIT'",
",",
"None",
")",
"# If it's empty, then this unit is the principal",
"if",
"principal_unit",
... | Returns the principal unit of this unit, otherwise None | [
"Returns",
"the",
"principal",
"unit",
"of",
"this",
"unit",
"otherwise",
"None"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L239-L259 |
12,737 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_get | def relation_get(attribute=None, unit=None, rid=None):
"""Get relation information"""
_args = ['relation-get', '--format=json']
if rid:
_args.append('-r')
_args.append(rid)
_args.append(attribute or '-')
if unit:
_args.append(unit)
try:
return json.loads(subproces... | python | def relation_get(attribute=None, unit=None, rid=None):
"""Get relation information"""
_args = ['relation-get', '--format=json']
if rid:
_args.append('-r')
_args.append(rid)
_args.append(attribute or '-')
if unit:
_args.append(unit)
try:
return json.loads(subproces... | [
"def",
"relation_get",
"(",
"attribute",
"=",
"None",
",",
"unit",
"=",
"None",
",",
"rid",
"=",
"None",
")",
":",
"_args",
"=",
"[",
"'relation-get'",
",",
"'--format=json'",
"]",
"if",
"rid",
":",
"_args",
".",
"append",
"(",
"'-r'",
")",
"_args",
... | Get relation information | [
"Get",
"relation",
"information"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L429-L445 |
12,738 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_set | def relation_set(relation_id=None, relation_settings=None, **kwargs):
"""Set relation information for the current unit"""
relation_settings = relation_settings if relation_settings else {}
relation_cmd_line = ['relation-set']
accepts_file = "--file" in subprocess.check_output(
relation_cmd_line ... | python | def relation_set(relation_id=None, relation_settings=None, **kwargs):
"""Set relation information for the current unit"""
relation_settings = relation_settings if relation_settings else {}
relation_cmd_line = ['relation-set']
accepts_file = "--file" in subprocess.check_output(
relation_cmd_line ... | [
"def",
"relation_set",
"(",
"relation_id",
"=",
"None",
",",
"relation_settings",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"relation_settings",
"=",
"relation_settings",
"if",
"relation_settings",
"else",
"{",
"}",
"relation_cmd_line",
"=",
"[",
"'relatio... | Set relation information for the current unit | [
"Set",
"relation",
"information",
"for",
"the",
"current",
"unit"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L448-L481 |
12,739 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_clear | def relation_clear(r_id=None):
''' Clears any relation data already set on relation r_id '''
settings = relation_get(rid=r_id,
unit=local_unit())
for setting in settings:
if setting not in ['public-address', 'private-address']:
settings[setting] = None
rel... | python | def relation_clear(r_id=None):
''' Clears any relation data already set on relation r_id '''
settings = relation_get(rid=r_id,
unit=local_unit())
for setting in settings:
if setting not in ['public-address', 'private-address']:
settings[setting] = None
rel... | [
"def",
"relation_clear",
"(",
"r_id",
"=",
"None",
")",
":",
"settings",
"=",
"relation_get",
"(",
"rid",
"=",
"r_id",
",",
"unit",
"=",
"local_unit",
"(",
")",
")",
"for",
"setting",
"in",
"settings",
":",
"if",
"setting",
"not",
"in",
"[",
"'public-a... | Clears any relation data already set on relation r_id | [
"Clears",
"any",
"relation",
"data",
"already",
"set",
"on",
"relation",
"r_id"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L484-L492 |
12,740 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_ids | def relation_ids(reltype=None):
"""A list of relation_ids"""
reltype = reltype or relation_type()
relid_cmd_line = ['relation-ids', '--format=json']
if reltype is not None:
relid_cmd_line.append(reltype)
return json.loads(
subprocess.check_output(relid_cmd_line).decode('UTF-8... | python | def relation_ids(reltype=None):
"""A list of relation_ids"""
reltype = reltype or relation_type()
relid_cmd_line = ['relation-ids', '--format=json']
if reltype is not None:
relid_cmd_line.append(reltype)
return json.loads(
subprocess.check_output(relid_cmd_line).decode('UTF-8... | [
"def",
"relation_ids",
"(",
"reltype",
"=",
"None",
")",
":",
"reltype",
"=",
"reltype",
"or",
"relation_type",
"(",
")",
"relid_cmd_line",
"=",
"[",
"'relation-ids'",
",",
"'--format=json'",
"]",
"if",
"reltype",
"is",
"not",
"None",
":",
"relid_cmd_line",
... | A list of relation_ids | [
"A",
"list",
"of",
"relation_ids"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L496-L504 |
12,741 | juju/charm-helpers | charmhelpers/core/hookenv.py | related_units | def related_units(relid=None):
"""A list of related units"""
relid = relid or relation_id()
units_cmd_line = ['relation-list', '--format=json']
if relid is not None:
units_cmd_line.extend(('-r', relid))
return json.loads(
subprocess.check_output(units_cmd_line).decode('UTF-8')) or [] | python | def related_units(relid=None):
"""A list of related units"""
relid = relid or relation_id()
units_cmd_line = ['relation-list', '--format=json']
if relid is not None:
units_cmd_line.extend(('-r', relid))
return json.loads(
subprocess.check_output(units_cmd_line).decode('UTF-8')) or [] | [
"def",
"related_units",
"(",
"relid",
"=",
"None",
")",
":",
"relid",
"=",
"relid",
"or",
"relation_id",
"(",
")",
"units_cmd_line",
"=",
"[",
"'relation-list'",
",",
"'--format=json'",
"]",
"if",
"relid",
"is",
"not",
"None",
":",
"units_cmd_line",
".",
"... | A list of related units | [
"A",
"list",
"of",
"related",
"units"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L508-L515 |
12,742 | juju/charm-helpers | charmhelpers/core/hookenv.py | expected_peer_units | def expected_peer_units():
"""Get a generator for units we expect to join peer relation based on
goal-state.
The local unit is excluded from the result to make it easy to gauge
completion of all peers joining the relation with existing hook tools.
Example usage:
log('peer {} of {} joined peer ... | python | def expected_peer_units():
"""Get a generator for units we expect to join peer relation based on
goal-state.
The local unit is excluded from the result to make it easy to gauge
completion of all peers joining the relation with existing hook tools.
Example usage:
log('peer {} of {} joined peer ... | [
"def",
"expected_peer_units",
"(",
")",
":",
"if",
"not",
"has_juju_version",
"(",
"\"2.4.0\"",
")",
":",
"# goal-state first appeared in 2.4.0.",
"raise",
"NotImplementedError",
"(",
"\"goal-state\"",
")",
"_goal_state",
"=",
"goal_state",
"(",
")",
"return",
"(",
... | Get a generator for units we expect to join peer relation based on
goal-state.
The local unit is excluded from the result to make it easy to gauge
completion of all peers joining the relation with existing hook tools.
Example usage:
log('peer {} of {} joined peer relation'
.format(len(rela... | [
"Get",
"a",
"generator",
"for",
"units",
"we",
"expect",
"to",
"join",
"peer",
"relation",
"based",
"on",
"goal",
"-",
"state",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L518-L542 |
12,743 | juju/charm-helpers | charmhelpers/core/hookenv.py | expected_related_units | def expected_related_units(reltype=None):
"""Get a generator for units we expect to join relation based on
goal-state.
Note that you can not use this function for the peer relation, take a look
at expected_peer_units() for that.
This function will raise KeyError if you request information for a
... | python | def expected_related_units(reltype=None):
"""Get a generator for units we expect to join relation based on
goal-state.
Note that you can not use this function for the peer relation, take a look
at expected_peer_units() for that.
This function will raise KeyError if you request information for a
... | [
"def",
"expected_related_units",
"(",
"reltype",
"=",
"None",
")",
":",
"if",
"not",
"has_juju_version",
"(",
"\"2.4.4\"",
")",
":",
"# goal-state existed in 2.4.0, but did not list individual units to",
"# join a relation in 2.4.1 through 2.4.3. (LP: #1794739)",
"raise",
"NotImp... | Get a generator for units we expect to join relation based on
goal-state.
Note that you can not use this function for the peer relation, take a look
at expected_peer_units() for that.
This function will raise KeyError if you request information for a
relation type for which juju goal-state does no... | [
"Get",
"a",
"generator",
"for",
"units",
"we",
"expect",
"to",
"join",
"relation",
"based",
"on",
"goal",
"-",
"state",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L545-L576 |
12,744 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_for_unit | def relation_for_unit(unit=None, rid=None):
"""Get the json represenation of a unit's relation"""
unit = unit or remote_unit()
relation = relation_get(unit=unit, rid=rid)
for key in relation:
if key.endswith('-list'):
relation[key] = relation[key].split()
relation['__unit__'] = u... | python | def relation_for_unit(unit=None, rid=None):
"""Get the json represenation of a unit's relation"""
unit = unit or remote_unit()
relation = relation_get(unit=unit, rid=rid)
for key in relation:
if key.endswith('-list'):
relation[key] = relation[key].split()
relation['__unit__'] = u... | [
"def",
"relation_for_unit",
"(",
"unit",
"=",
"None",
",",
"rid",
"=",
"None",
")",
":",
"unit",
"=",
"unit",
"or",
"remote_unit",
"(",
")",
"relation",
"=",
"relation_get",
"(",
"unit",
"=",
"unit",
",",
"rid",
"=",
"rid",
")",
"for",
"key",
"in",
... | Get the json represenation of a unit's relation | [
"Get",
"the",
"json",
"represenation",
"of",
"a",
"unit",
"s",
"relation"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L580-L588 |
12,745 | juju/charm-helpers | charmhelpers/core/hookenv.py | relations_for_id | def relations_for_id(relid=None):
"""Get relations of a specific relation ID"""
relation_data = []
relid = relid or relation_ids()
for unit in related_units(relid):
unit_data = relation_for_unit(unit, relid)
unit_data['__relid__'] = relid
relation_data.append(unit_data)
retur... | python | def relations_for_id(relid=None):
"""Get relations of a specific relation ID"""
relation_data = []
relid = relid or relation_ids()
for unit in related_units(relid):
unit_data = relation_for_unit(unit, relid)
unit_data['__relid__'] = relid
relation_data.append(unit_data)
retur... | [
"def",
"relations_for_id",
"(",
"relid",
"=",
"None",
")",
":",
"relation_data",
"=",
"[",
"]",
"relid",
"=",
"relid",
"or",
"relation_ids",
"(",
")",
"for",
"unit",
"in",
"related_units",
"(",
"relid",
")",
":",
"unit_data",
"=",
"relation_for_unit",
"(",... | Get relations of a specific relation ID | [
"Get",
"relations",
"of",
"a",
"specific",
"relation",
"ID"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L592-L600 |
12,746 | juju/charm-helpers | charmhelpers/core/hookenv.py | relations_of_type | def relations_of_type(reltype=None):
"""Get relations of a specific type"""
relation_data = []
reltype = reltype or relation_type()
for relid in relation_ids(reltype):
for relation in relations_for_id(relid):
relation['__relid__'] = relid
relation_data.append(relation)
... | python | def relations_of_type(reltype=None):
"""Get relations of a specific type"""
relation_data = []
reltype = reltype or relation_type()
for relid in relation_ids(reltype):
for relation in relations_for_id(relid):
relation['__relid__'] = relid
relation_data.append(relation)
... | [
"def",
"relations_of_type",
"(",
"reltype",
"=",
"None",
")",
":",
"relation_data",
"=",
"[",
"]",
"reltype",
"=",
"reltype",
"or",
"relation_type",
"(",
")",
"for",
"relid",
"in",
"relation_ids",
"(",
"reltype",
")",
":",
"for",
"relation",
"in",
"relatio... | Get relations of a specific type | [
"Get",
"relations",
"of",
"a",
"specific",
"type"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L604-L612 |
12,747 | juju/charm-helpers | charmhelpers/core/hookenv.py | metadata | def metadata():
"""Get the current charm metadata.yaml contents as a python object"""
with open(os.path.join(charm_dir(), 'metadata.yaml')) as md:
return yaml.safe_load(md) | python | def metadata():
"""Get the current charm metadata.yaml contents as a python object"""
with open(os.path.join(charm_dir(), 'metadata.yaml')) as md:
return yaml.safe_load(md) | [
"def",
"metadata",
"(",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"charm_dir",
"(",
")",
",",
"'metadata.yaml'",
")",
")",
"as",
"md",
":",
"return",
"yaml",
".",
"safe_load",
"(",
"md",
")"
] | Get the current charm metadata.yaml contents as a python object | [
"Get",
"the",
"current",
"charm",
"metadata",
".",
"yaml",
"contents",
"as",
"a",
"python",
"object"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L616-L619 |
12,748 | juju/charm-helpers | charmhelpers/core/hookenv.py | relation_types | def relation_types():
"""Get a list of relation types supported by this charm"""
rel_types = []
md = metadata()
for key in ('provides', 'requires', 'peers'):
section = md.get(key)
if section:
rel_types.extend(section.keys())
return rel_types | python | def relation_types():
"""Get a list of relation types supported by this charm"""
rel_types = []
md = metadata()
for key in ('provides', 'requires', 'peers'):
section = md.get(key)
if section:
rel_types.extend(section.keys())
return rel_types | [
"def",
"relation_types",
"(",
")",
":",
"rel_types",
"=",
"[",
"]",
"md",
"=",
"metadata",
"(",
")",
"for",
"key",
"in",
"(",
"'provides'",
",",
"'requires'",
",",
"'peers'",
")",
":",
"section",
"=",
"md",
".",
"get",
"(",
"key",
")",
"if",
"secti... | Get a list of relation types supported by this charm | [
"Get",
"a",
"list",
"of",
"relation",
"types",
"supported",
"by",
"this",
"charm"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L641-L649 |
12,749 | juju/charm-helpers | charmhelpers/core/hookenv.py | peer_relation_id | def peer_relation_id():
'''Get the peers relation id if a peers relation has been joined, else None.'''
md = metadata()
section = md.get('peers')
if section:
for key in section:
relids = relation_ids(key)
if relids:
return relids[0]
return None | python | def peer_relation_id():
'''Get the peers relation id if a peers relation has been joined, else None.'''
md = metadata()
section = md.get('peers')
if section:
for key in section:
relids = relation_ids(key)
if relids:
return relids[0]
return None | [
"def",
"peer_relation_id",
"(",
")",
":",
"md",
"=",
"metadata",
"(",
")",
"section",
"=",
"md",
".",
"get",
"(",
"'peers'",
")",
"if",
"section",
":",
"for",
"key",
"in",
"section",
":",
"relids",
"=",
"relation_ids",
"(",
"key",
")",
"if",
"relids"... | Get the peers relation id if a peers relation has been joined, else None. | [
"Get",
"the",
"peers",
"relation",
"id",
"if",
"a",
"peers",
"relation",
"has",
"been",
"joined",
"else",
"None",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L653-L662 |
12,750 | juju/charm-helpers | charmhelpers/core/hookenv.py | interface_to_relations | def interface_to_relations(interface_name):
"""
Given an interface, return a list of relation names for the current
charm that use that interface.
:returns: A list of relation names.
"""
results = []
for role in ('provides', 'requires', 'peers'):
results.extend(role_and_interface_to... | python | def interface_to_relations(interface_name):
"""
Given an interface, return a list of relation names for the current
charm that use that interface.
:returns: A list of relation names.
"""
results = []
for role in ('provides', 'requires', 'peers'):
results.extend(role_and_interface_to... | [
"def",
"interface_to_relations",
"(",
"interface_name",
")",
":",
"results",
"=",
"[",
"]",
"for",
"role",
"in",
"(",
"'provides'",
",",
"'requires'",
",",
"'peers'",
")",
":",
"results",
".",
"extend",
"(",
"role_and_interface_to_relations",
"(",
"role",
",",... | Given an interface, return a list of relation names for the current
charm that use that interface.
:returns: A list of relation names. | [
"Given",
"an",
"interface",
"return",
"a",
"list",
"of",
"relation",
"names",
"for",
"the",
"current",
"charm",
"that",
"use",
"that",
"interface",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L709-L719 |
12,751 | juju/charm-helpers | charmhelpers/core/hookenv.py | relations | def relations():
"""Get a nested dictionary of relation data for all related units"""
rels = {}
for reltype in relation_types():
relids = {}
for relid in relation_ids(reltype):
units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
for unit in related_unit... | python | def relations():
"""Get a nested dictionary of relation data for all related units"""
rels = {}
for reltype in relation_types():
relids = {}
for relid in relation_ids(reltype):
units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
for unit in related_unit... | [
"def",
"relations",
"(",
")",
":",
"rels",
"=",
"{",
"}",
"for",
"reltype",
"in",
"relation_types",
"(",
")",
":",
"relids",
"=",
"{",
"}",
"for",
"relid",
"in",
"relation_ids",
"(",
"reltype",
")",
":",
"units",
"=",
"{",
"local_unit",
"(",
")",
"... | Get a nested dictionary of relation data for all related units | [
"Get",
"a",
"nested",
"dictionary",
"of",
"relation",
"data",
"for",
"all",
"related",
"units"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L729-L741 |
12,752 | juju/charm-helpers | charmhelpers/core/hookenv.py | _port_op | def _port_op(op_name, port, protocol="TCP"):
"""Open or close a service network port"""
_args = [op_name]
icmp = protocol.upper() == "ICMP"
if icmp:
_args.append(protocol)
else:
_args.append('{}/{}'.format(port, protocol))
try:
subprocess.check_call(_args)
except subp... | python | def _port_op(op_name, port, protocol="TCP"):
"""Open or close a service network port"""
_args = [op_name]
icmp = protocol.upper() == "ICMP"
if icmp:
_args.append(protocol)
else:
_args.append('{}/{}'.format(port, protocol))
try:
subprocess.check_call(_args)
except subp... | [
"def",
"_port_op",
"(",
"op_name",
",",
"port",
",",
"protocol",
"=",
"\"TCP\"",
")",
":",
"_args",
"=",
"[",
"op_name",
"]",
"icmp",
"=",
"protocol",
".",
"upper",
"(",
")",
"==",
"\"ICMP\"",
"if",
"icmp",
":",
"_args",
".",
"append",
"(",
"protocol... | Open or close a service network port | [
"Open",
"or",
"close",
"a",
"service",
"network",
"port"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L764-L778 |
12,753 | juju/charm-helpers | charmhelpers/core/hookenv.py | open_ports | def open_ports(start, end, protocol="TCP"):
"""Opens a range of service network ports"""
_args = ['open-port']
_args.append('{}-{}/{}'.format(start, end, protocol))
subprocess.check_call(_args) | python | def open_ports(start, end, protocol="TCP"):
"""Opens a range of service network ports"""
_args = ['open-port']
_args.append('{}-{}/{}'.format(start, end, protocol))
subprocess.check_call(_args) | [
"def",
"open_ports",
"(",
"start",
",",
"end",
",",
"protocol",
"=",
"\"TCP\"",
")",
":",
"_args",
"=",
"[",
"'open-port'",
"]",
"_args",
".",
"append",
"(",
"'{}-{}/{}'",
".",
"format",
"(",
"start",
",",
"end",
",",
"protocol",
")",
")",
"subprocess"... | Opens a range of service network ports | [
"Opens",
"a",
"range",
"of",
"service",
"network",
"ports"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L791-L795 |
12,754 | juju/charm-helpers | charmhelpers/core/hookenv.py | unit_get | def unit_get(attribute):
"""Get the unit ID for the remote unit"""
_args = ['unit-get', '--format=json', attribute]
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
except ValueError:
return None | python | def unit_get(attribute):
"""Get the unit ID for the remote unit"""
_args = ['unit-get', '--format=json', attribute]
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
except ValueError:
return None | [
"def",
"unit_get",
"(",
"attribute",
")",
":",
"_args",
"=",
"[",
"'unit-get'",
",",
"'--format=json'",
",",
"attribute",
"]",
"try",
":",
"return",
"json",
".",
"loads",
"(",
"subprocess",
".",
"check_output",
"(",
"_args",
")",
".",
"decode",
"(",
"'UT... | Get the unit ID for the remote unit | [
"Get",
"the",
"unit",
"ID",
"for",
"the",
"remote",
"unit"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L817-L823 |
12,755 | juju/charm-helpers | charmhelpers/core/hookenv.py | storage_get | def storage_get(attribute=None, storage_id=None):
"""Get storage attributes"""
_args = ['storage-get', '--format=json']
if storage_id:
_args.extend(('-s', storage_id))
if attribute:
_args.append(attribute)
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))... | python | def storage_get(attribute=None, storage_id=None):
"""Get storage attributes"""
_args = ['storage-get', '--format=json']
if storage_id:
_args.extend(('-s', storage_id))
if attribute:
_args.append(attribute)
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))... | [
"def",
"storage_get",
"(",
"attribute",
"=",
"None",
",",
"storage_id",
"=",
"None",
")",
":",
"_args",
"=",
"[",
"'storage-get'",
",",
"'--format=json'",
"]",
"if",
"storage_id",
":",
"_args",
".",
"extend",
"(",
"(",
"'-s'",
",",
"storage_id",
")",
")"... | Get storage attributes | [
"Get",
"storage",
"attributes"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L837-L847 |
12,756 | juju/charm-helpers | charmhelpers/core/hookenv.py | storage_list | def storage_list(storage_name=None):
"""List the storage IDs for the unit"""
_args = ['storage-list', '--format=json']
if storage_name:
_args.append(storage_name)
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
except ValueError:
return None
except ... | python | def storage_list(storage_name=None):
"""List the storage IDs for the unit"""
_args = ['storage-list', '--format=json']
if storage_name:
_args.append(storage_name)
try:
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
except ValueError:
return None
except ... | [
"def",
"storage_list",
"(",
"storage_name",
"=",
"None",
")",
":",
"_args",
"=",
"[",
"'storage-list'",
",",
"'--format=json'",
"]",
"if",
"storage_name",
":",
"_args",
".",
"append",
"(",
"storage_name",
")",
"try",
":",
"return",
"json",
".",
"loads",
"(... | List the storage IDs for the unit | [
"List",
"the",
"storage",
"IDs",
"for",
"the",
"unit"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L851-L865 |
12,757 | juju/charm-helpers | charmhelpers/core/hookenv.py | charm_dir | def charm_dir():
"""Return the root directory of the current charm"""
d = os.environ.get('JUJU_CHARM_DIR')
if d is not None:
return d
return os.environ.get('CHARM_DIR') | python | def charm_dir():
"""Return the root directory of the current charm"""
d = os.environ.get('JUJU_CHARM_DIR')
if d is not None:
return d
return os.environ.get('CHARM_DIR') | [
"def",
"charm_dir",
"(",
")",
":",
"d",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'JUJU_CHARM_DIR'",
")",
"if",
"d",
"is",
"not",
"None",
":",
"return",
"d",
"return",
"os",
".",
"environ",
".",
"get",
"(",
"'CHARM_DIR'",
")"
] | Return the root directory of the current charm | [
"Return",
"the",
"root",
"directory",
"of",
"the",
"current",
"charm"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L941-L946 |
12,758 | juju/charm-helpers | charmhelpers/core/hookenv.py | action_set | def action_set(values):
"""Sets the values to be returned after the action finishes"""
cmd = ['action-set']
for k, v in list(values.items()):
cmd.append('{}={}'.format(k, v))
subprocess.check_call(cmd) | python | def action_set(values):
"""Sets the values to be returned after the action finishes"""
cmd = ['action-set']
for k, v in list(values.items()):
cmd.append('{}={}'.format(k, v))
subprocess.check_call(cmd) | [
"def",
"action_set",
"(",
"values",
")",
":",
"cmd",
"=",
"[",
"'action-set'",
"]",
"for",
"k",
",",
"v",
"in",
"list",
"(",
"values",
".",
"items",
"(",
")",
")",
":",
"cmd",
".",
"append",
"(",
"'{}={}'",
".",
"format",
"(",
"k",
",",
"v",
")... | Sets the values to be returned after the action finishes | [
"Sets",
"the",
"values",
"to",
"be",
"returned",
"after",
"the",
"action",
"finishes"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L960-L965 |
12,759 | juju/charm-helpers | charmhelpers/core/hookenv.py | status_set | def status_set(workload_state, message):
"""Set the workload state with a message
Use status-set to set the workload state with a message which is visible
to the user via juju status. If the status-set command is not found then
assume this is juju < 1.23 and juju-log the message unstead.
workload_... | python | def status_set(workload_state, message):
"""Set the workload state with a message
Use status-set to set the workload state with a message which is visible
to the user via juju status. If the status-set command is not found then
assume this is juju < 1.23 and juju-log the message unstead.
workload_... | [
"def",
"status_set",
"(",
"workload_state",
",",
"message",
")",
":",
"valid_states",
"=",
"[",
"'maintenance'",
",",
"'blocked'",
",",
"'waiting'",
",",
"'active'",
"]",
"if",
"workload_state",
"not",
"in",
"valid_states",
":",
"raise",
"ValueError",
"(",
"'{... | Set the workload state with a message
Use status-set to set the workload state with a message which is visible
to the user via juju status. If the status-set command is not found then
assume this is juju < 1.23 and juju-log the message unstead.
workload_state -- valid juju workload state.
message ... | [
"Set",
"the",
"workload",
"state",
"with",
"a",
"message"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L990-L1015 |
12,760 | juju/charm-helpers | charmhelpers/core/hookenv.py | status_get | def status_get():
"""Retrieve the previously set juju workload state and message
If the status-get command is not found then assume this is juju < 1.23 and
return 'unknown', ""
"""
cmd = ['status-get', "--format=json", "--include-data"]
try:
raw_status = subprocess.check_output(cmd)
... | python | def status_get():
"""Retrieve the previously set juju workload state and message
If the status-get command is not found then assume this is juju < 1.23 and
return 'unknown', ""
"""
cmd = ['status-get', "--format=json", "--include-data"]
try:
raw_status = subprocess.check_output(cmd)
... | [
"def",
"status_get",
"(",
")",
":",
"cmd",
"=",
"[",
"'status-get'",
",",
"\"--format=json\"",
",",
"\"--include-data\"",
"]",
"try",
":",
"raw_status",
"=",
"subprocess",
".",
"check_output",
"(",
"cmd",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e"... | Retrieve the previously set juju workload state and message
If the status-get command is not found then assume this is juju < 1.23 and
return 'unknown', "" | [
"Retrieve",
"the",
"previously",
"set",
"juju",
"workload",
"state",
"and",
"message"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1018-L1035 |
12,761 | juju/charm-helpers | charmhelpers/core/hookenv.py | application_version_set | def application_version_set(version):
"""Charm authors may trigger this command from any hook to output what
version of the application is running. This could be a package version,
for instance postgres version 9.5. It could also be a build number or
version control revision identifier, for instance git... | python | def application_version_set(version):
"""Charm authors may trigger this command from any hook to output what
version of the application is running. This could be a package version,
for instance postgres version 9.5. It could also be a build number or
version control revision identifier, for instance git... | [
"def",
"application_version_set",
"(",
"version",
")",
":",
"cmd",
"=",
"[",
"'application-version-set'",
"]",
"cmd",
".",
"append",
"(",
"version",
")",
"try",
":",
"subprocess",
".",
"check_call",
"(",
"cmd",
")",
"except",
"OSError",
":",
"log",
"(",
"\... | Charm authors may trigger this command from any hook to output what
version of the application is running. This could be a package version,
for instance postgres version 9.5. It could also be a build number or
version control revision identifier, for instance git sha 6fb7ba68. | [
"Charm",
"authors",
"may",
"trigger",
"this",
"command",
"from",
"any",
"hook",
"to",
"output",
"what",
"version",
"of",
"the",
"application",
"is",
"running",
".",
"This",
"could",
"be",
"a",
"package",
"version",
"for",
"instance",
"postgres",
"version",
"... | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1052-L1063 |
12,762 | juju/charm-helpers | charmhelpers/core/hookenv.py | payload_register | def payload_register(ptype, klass, pid):
""" is used while a hook is running to let Juju know that a
payload has been started."""
cmd = ['payload-register']
for x in [ptype, klass, pid]:
cmd.append(x)
subprocess.check_call(cmd) | python | def payload_register(ptype, klass, pid):
""" is used while a hook is running to let Juju know that a
payload has been started."""
cmd = ['payload-register']
for x in [ptype, klass, pid]:
cmd.append(x)
subprocess.check_call(cmd) | [
"def",
"payload_register",
"(",
"ptype",
",",
"klass",
",",
"pid",
")",
":",
"cmd",
"=",
"[",
"'payload-register'",
"]",
"for",
"x",
"in",
"[",
"ptype",
",",
"klass",
",",
"pid",
"]",
":",
"cmd",
".",
"append",
"(",
"x",
")",
"subprocess",
".",
"ch... | is used while a hook is running to let Juju know that a
payload has been started. | [
"is",
"used",
"while",
"a",
"hook",
"is",
"running",
"to",
"let",
"Juju",
"know",
"that",
"a",
"payload",
"has",
"been",
"started",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1108-L1114 |
12,763 | juju/charm-helpers | charmhelpers/core/hookenv.py | resource_get | def resource_get(name):
"""used to fetch the resource path of the given name.
<name> must match a name of defined resource in metadata.yaml
returns either a path or False if resource not available
"""
if not name:
return False
cmd = ['resource-get', name]
try:
return subpr... | python | def resource_get(name):
"""used to fetch the resource path of the given name.
<name> must match a name of defined resource in metadata.yaml
returns either a path or False if resource not available
"""
if not name:
return False
cmd = ['resource-get', name]
try:
return subpr... | [
"def",
"resource_get",
"(",
"name",
")",
":",
"if",
"not",
"name",
":",
"return",
"False",
"cmd",
"=",
"[",
"'resource-get'",
",",
"name",
"]",
"try",
":",
"return",
"subprocess",
".",
"check_output",
"(",
"cmd",
")",
".",
"decode",
"(",
"'UTF-8'",
")"... | used to fetch the resource path of the given name.
<name> must match a name of defined resource in metadata.yaml
returns either a path or False if resource not available | [
"used",
"to",
"fetch",
"the",
"resource",
"path",
"of",
"the",
"given",
"name",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1142-L1156 |
12,764 | juju/charm-helpers | charmhelpers/core/hookenv.py | atstart | def atstart(callback, *args, **kwargs):
'''Schedule a callback to run before the main hook.
Callbacks are run in the order they were added.
This is useful for modules and classes to perform initialization
and inject behavior. In particular:
- Run common code before all of your hooks, such as ... | python | def atstart(callback, *args, **kwargs):
'''Schedule a callback to run before the main hook.
Callbacks are run in the order they were added.
This is useful for modules and classes to perform initialization
and inject behavior. In particular:
- Run common code before all of your hooks, such as ... | [
"def",
"atstart",
"(",
"callback",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"_atstart",
"_atstart",
".",
"append",
"(",
"(",
"callback",
",",
"args",
",",
"kwargs",
")",
")"
] | Schedule a callback to run before the main hook.
Callbacks are run in the order they were added.
This is useful for modules and classes to perform initialization
and inject behavior. In particular:
- Run common code before all of your hooks, such as logging
the hook name or interesting ... | [
"Schedule",
"a",
"callback",
"to",
"run",
"before",
"the",
"main",
"hook",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1177-L1197 |
12,765 | juju/charm-helpers | charmhelpers/core/hookenv.py | _run_atstart | def _run_atstart():
'''Hook frameworks must invoke this before running the main hook body.'''
global _atstart
for callback, args, kwargs in _atstart:
callback(*args, **kwargs)
del _atstart[:] | python | def _run_atstart():
'''Hook frameworks must invoke this before running the main hook body.'''
global _atstart
for callback, args, kwargs in _atstart:
callback(*args, **kwargs)
del _atstart[:] | [
"def",
"_run_atstart",
"(",
")",
":",
"global",
"_atstart",
"for",
"callback",
",",
"args",
",",
"kwargs",
"in",
"_atstart",
":",
"callback",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"del",
"_atstart",
"[",
":",
"]"
] | Hook frameworks must invoke this before running the main hook body. | [
"Hook",
"frameworks",
"must",
"invoke",
"this",
"before",
"running",
"the",
"main",
"hook",
"body",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1207-L1212 |
12,766 | juju/charm-helpers | charmhelpers/core/hookenv.py | _run_atexit | def _run_atexit():
'''Hook frameworks must invoke this after the main hook body has
successfully completed. Do not invoke it if the hook fails.'''
global _atexit
for callback, args, kwargs in reversed(_atexit):
callback(*args, **kwargs)
del _atexit[:] | python | def _run_atexit():
'''Hook frameworks must invoke this after the main hook body has
successfully completed. Do not invoke it if the hook fails.'''
global _atexit
for callback, args, kwargs in reversed(_atexit):
callback(*args, **kwargs)
del _atexit[:] | [
"def",
"_run_atexit",
"(",
")",
":",
"global",
"_atexit",
"for",
"callback",
",",
"args",
",",
"kwargs",
"in",
"reversed",
"(",
"_atexit",
")",
":",
"callback",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"del",
"_atexit",
"[",
":",
"]"
] | Hook frameworks must invoke this after the main hook body has
successfully completed. Do not invoke it if the hook fails. | [
"Hook",
"frameworks",
"must",
"invoke",
"this",
"after",
"the",
"main",
"hook",
"body",
"has",
"successfully",
"completed",
".",
"Do",
"not",
"invoke",
"it",
"if",
"the",
"hook",
"fails",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1215-L1221 |
12,767 | juju/charm-helpers | charmhelpers/core/hookenv.py | network_get | def network_get(endpoint, relation_id=None):
"""
Retrieve the network details for a relation endpoint
:param endpoint: string. The name of a relation endpoint
:param relation_id: int. The ID of the relation for the current context.
:return: dict. The loaded YAML output of the network-get query.
... | python | def network_get(endpoint, relation_id=None):
"""
Retrieve the network details for a relation endpoint
:param endpoint: string. The name of a relation endpoint
:param relation_id: int. The ID of the relation for the current context.
:return: dict. The loaded YAML output of the network-get query.
... | [
"def",
"network_get",
"(",
"endpoint",
",",
"relation_id",
"=",
"None",
")",
":",
"if",
"not",
"has_juju_version",
"(",
"'2.2'",
")",
":",
"raise",
"NotImplementedError",
"(",
"juju_version",
"(",
")",
")",
"# earlier versions require --primary-address",
"if",
"re... | Retrieve the network details for a relation endpoint
:param endpoint: string. The name of a relation endpoint
:param relation_id: int. The ID of the relation for the current context.
:return: dict. The loaded YAML output of the network-get query.
:raise: NotImplementedError if request not supported by ... | [
"Retrieve",
"the",
"network",
"details",
"for",
"a",
"relation",
"endpoint"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1249-L1270 |
12,768 | juju/charm-helpers | charmhelpers/core/hookenv.py | add_metric | def add_metric(*args, **kwargs):
"""Add metric values. Values may be expressed with keyword arguments. For
metric names containing dashes, these may be expressed as one or more
'key=value' positional arguments. May only be called from the collect-metrics
hook."""
_args = ['add-metric']
_kvpairs ... | python | def add_metric(*args, **kwargs):
"""Add metric values. Values may be expressed with keyword arguments. For
metric names containing dashes, these may be expressed as one or more
'key=value' positional arguments. May only be called from the collect-metrics
hook."""
_args = ['add-metric']
_kvpairs ... | [
"def",
"add_metric",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"_args",
"=",
"[",
"'add-metric'",
"]",
"_kvpairs",
"=",
"[",
"]",
"_kvpairs",
".",
"extend",
"(",
"args",
")",
"_kvpairs",
".",
"extend",
"(",
"[",
"'{}={}'",
".",
"format",
... | Add metric values. Values may be expressed with keyword arguments. For
metric names containing dashes, these may be expressed as one or more
'key=value' positional arguments. May only be called from the collect-metrics
hook. | [
"Add",
"metric",
"values",
".",
"Values",
"may",
"be",
"expressed",
"with",
"keyword",
"arguments",
".",
"For",
"metric",
"names",
"containing",
"dashes",
"these",
"may",
"be",
"expressed",
"as",
"one",
"or",
"more",
"key",
"=",
"value",
"positional",
"argum... | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1273-L1290 |
12,769 | juju/charm-helpers | charmhelpers/core/hookenv.py | iter_units_for_relation_name | def iter_units_for_relation_name(relation_name):
"""Iterate through all units in a relation
Generator that iterates through all the units in a relation and yields
a named tuple with rid and unit field names.
Usage:
data = [(u.rid, u.unit)
for u in iter_units_for_relation_name(relation_... | python | def iter_units_for_relation_name(relation_name):
"""Iterate through all units in a relation
Generator that iterates through all the units in a relation and yields
a named tuple with rid and unit field names.
Usage:
data = [(u.rid, u.unit)
for u in iter_units_for_relation_name(relation_... | [
"def",
"iter_units_for_relation_name",
"(",
"relation_name",
")",
":",
"RelatedUnit",
"=",
"namedtuple",
"(",
"'RelatedUnit'",
",",
"'rid, unit'",
")",
"for",
"rid",
"in",
"relation_ids",
"(",
"relation_name",
")",
":",
"for",
"unit",
"in",
"related_units",
"(",
... | Iterate through all units in a relation
Generator that iterates through all the units in a relation and yields
a named tuple with rid and unit field names.
Usage:
data = [(u.rid, u.unit)
for u in iter_units_for_relation_name(relation_name)]
:param relation_name: string relation name
... | [
"Iterate",
"through",
"all",
"units",
"in",
"a",
"relation"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1304-L1320 |
12,770 | juju/charm-helpers | charmhelpers/core/hookenv.py | ingress_address | def ingress_address(rid=None, unit=None):
"""
Retrieve the ingress-address from a relation when available.
Otherwise, return the private-address.
When used on the consuming side of the relation (unit is a remote
unit), the ingress-address is the IP address that this unit needs
to use to reach t... | python | def ingress_address(rid=None, unit=None):
"""
Retrieve the ingress-address from a relation when available.
Otherwise, return the private-address.
When used on the consuming side of the relation (unit is a remote
unit), the ingress-address is the IP address that this unit needs
to use to reach t... | [
"def",
"ingress_address",
"(",
"rid",
"=",
"None",
",",
"unit",
"=",
"None",
")",
":",
"settings",
"=",
"relation_get",
"(",
"rid",
"=",
"rid",
",",
"unit",
"=",
"unit",
")",
"return",
"(",
"settings",
".",
"get",
"(",
"'ingress-address'",
")",
"or",
... | Retrieve the ingress-address from a relation when available.
Otherwise, return the private-address.
When used on the consuming side of the relation (unit is a remote
unit), the ingress-address is the IP address that this unit needs
to use to reach the provided service on the remote unit.
When used... | [
"Retrieve",
"the",
"ingress",
"-",
"address",
"from",
"a",
"relation",
"when",
"available",
".",
"Otherwise",
"return",
"the",
"private",
"-",
"address",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1323-L1354 |
12,771 | juju/charm-helpers | charmhelpers/core/hookenv.py | egress_subnets | def egress_subnets(rid=None, unit=None):
"""
Retrieve the egress-subnets from a relation.
This function is to be used on the providing side of the
relation, and provides the ranges of addresses that client
connections may come from. The result is uninteresting on
the consuming side of a relatio... | python | def egress_subnets(rid=None, unit=None):
"""
Retrieve the egress-subnets from a relation.
This function is to be used on the providing side of the
relation, and provides the ranges of addresses that client
connections may come from. The result is uninteresting on
the consuming side of a relatio... | [
"def",
"egress_subnets",
"(",
"rid",
"=",
"None",
",",
"unit",
"=",
"None",
")",
":",
"def",
"_to_range",
"(",
"addr",
")",
":",
"if",
"re",
".",
"search",
"(",
"r'^(?:\\d{1,3}\\.){3}\\d{1,3}$'",
",",
"addr",
")",
"is",
"not",
"None",
":",
"addr",
"+="... | Retrieve the egress-subnets from a relation.
This function is to be used on the providing side of the
relation, and provides the ranges of addresses that client
connections may come from. The result is uninteresting on
the consuming side of a relation (unit == local_unit()).
Returns a stable list ... | [
"Retrieve",
"the",
"egress",
"-",
"subnets",
"from",
"a",
"relation",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1357-L1391 |
12,772 | juju/charm-helpers | charmhelpers/core/hookenv.py | unit_doomed | def unit_doomed(unit=None):
"""Determines if the unit is being removed from the model
Requires Juju 2.4.1.
:param unit: string unit name, defaults to local_unit
:side effect: calls goal_state
:side effect: calls local_unit
:side effect: calls has_juju_version
:return: True if the unit is b... | python | def unit_doomed(unit=None):
"""Determines if the unit is being removed from the model
Requires Juju 2.4.1.
:param unit: string unit name, defaults to local_unit
:side effect: calls goal_state
:side effect: calls local_unit
:side effect: calls has_juju_version
:return: True if the unit is b... | [
"def",
"unit_doomed",
"(",
"unit",
"=",
"None",
")",
":",
"if",
"not",
"has_juju_version",
"(",
"\"2.4.1\"",
")",
":",
"# We cannot risk blindly returning False for 'we don't know',",
"# because that could cause data loss; if call sites don't",
"# need an accurate answer, they like... | Determines if the unit is being removed from the model
Requires Juju 2.4.1.
:param unit: string unit name, defaults to local_unit
:side effect: calls goal_state
:side effect: calls local_unit
:side effect: calls has_juju_version
:return: True if the unit is being removed, already gone, or neve... | [
"Determines",
"if",
"the",
"unit",
"is",
"being",
"removed",
"from",
"the",
"model"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1394-L1421 |
12,773 | juju/charm-helpers | charmhelpers/core/hookenv.py | env_proxy_settings | def env_proxy_settings(selected_settings=None):
"""Get proxy settings from process environment variables.
Get charm proxy settings from environment variables that correspond to
juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2,
see lp:1782236) in a format suitable for passing t... | python | def env_proxy_settings(selected_settings=None):
"""Get proxy settings from process environment variables.
Get charm proxy settings from environment variables that correspond to
juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2,
see lp:1782236) in a format suitable for passing t... | [
"def",
"env_proxy_settings",
"(",
"selected_settings",
"=",
"None",
")",
":",
"SUPPORTED_SETTINGS",
"=",
"{",
"'http'",
":",
"'HTTP_PROXY'",
",",
"'https'",
":",
"'HTTPS_PROXY'",
",",
"'no_proxy'",
":",
"'NO_PROXY'",
",",
"'ftp'",
":",
"'FTP_PROXY'",
"}",
"if",
... | Get proxy settings from process environment variables.
Get charm proxy settings from environment variables that correspond to
juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2,
see lp:1782236) in a format suitable for passing to an application that
reacts to proxy settings pass... | [
"Get",
"proxy",
"settings",
"from",
"process",
"environment",
"variables",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1424-L1470 |
12,774 | juju/charm-helpers | charmhelpers/core/hookenv.py | Config.load_previous | def load_previous(self, path=None):
"""Load previous copy of config from disk.
In normal usage you don't need to call this method directly - it
is called automatically at object initialization.
:param path:
File path from which to load the previous config. If `None`,
... | python | def load_previous(self, path=None):
"""Load previous copy of config from disk.
In normal usage you don't need to call this method directly - it
is called automatically at object initialization.
:param path:
File path from which to load the previous config. If `None`,
... | [
"def",
"load_previous",
"(",
"self",
",",
"path",
"=",
"None",
")",
":",
"self",
".",
"path",
"=",
"path",
"or",
"self",
".",
"path",
"with",
"open",
"(",
"self",
".",
"path",
")",
"as",
"f",
":",
"try",
":",
"self",
".",
"_prev_dict",
"=",
"json... | Load previous copy of config from disk.
In normal usage you don't need to call this method directly - it
is called automatically at object initialization.
:param path:
File path from which to load the previous config. If `None`,
config is loaded from the default locati... | [
"Load",
"previous",
"copy",
"of",
"config",
"from",
"disk",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L327-L350 |
12,775 | juju/charm-helpers | charmhelpers/core/hookenv.py | Config.changed | def changed(self, key):
"""Return True if the current value for this key is different from
the previous value.
"""
if self._prev_dict is None:
return True
return self.previous(key) != self.get(key) | python | def changed(self, key):
"""Return True if the current value for this key is different from
the previous value.
"""
if self._prev_dict is None:
return True
return self.previous(key) != self.get(key) | [
"def",
"changed",
"(",
"self",
",",
"key",
")",
":",
"if",
"self",
".",
"_prev_dict",
"is",
"None",
":",
"return",
"True",
"return",
"self",
".",
"previous",
"(",
"key",
")",
"!=",
"self",
".",
"get",
"(",
"key",
")"
] | Return True if the current value for this key is different from
the previous value. | [
"Return",
"True",
"if",
"the",
"current",
"value",
"for",
"this",
"key",
"is",
"different",
"from",
"the",
"previous",
"value",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L352-L359 |
12,776 | juju/charm-helpers | charmhelpers/core/hookenv.py | Config.save | def save(self):
"""Save this config to disk.
If the charm is using the :mod:`Services Framework <services.base>`
or :meth:'@hook <Hooks.hook>' decorator, this
is called automatically at the end of successful hook execution.
Otherwise, it should be called directly by user code.
... | python | def save(self):
"""Save this config to disk.
If the charm is using the :mod:`Services Framework <services.base>`
or :meth:'@hook <Hooks.hook>' decorator, this
is called automatically at the end of successful hook execution.
Otherwise, it should be called directly by user code.
... | [
"def",
"save",
"(",
"self",
")",
":",
"with",
"open",
"(",
"self",
".",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"os",
".",
"fchmod",
"(",
"f",
".",
"fileno",
"(",
")",
",",
"0o600",
")",
"json",
".",
"dump",
"(",
"self",
",",
"f",
")"
] | Save this config to disk.
If the charm is using the :mod:`Services Framework <services.base>`
or :meth:'@hook <Hooks.hook>' decorator, this
is called automatically at the end of successful hook execution.
Otherwise, it should be called directly by user code.
To disable automati... | [
"Save",
"this",
"config",
"to",
"disk",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L370-L384 |
12,777 | juju/charm-helpers | charmhelpers/core/hookenv.py | Hooks.hook | def hook(self, *hook_names):
"""Decorator, registering them as hooks"""
def wrapper(decorated):
for hook_name in hook_names:
self.register(hook_name, decorated)
else:
self.register(decorated.__name__, decorated)
if '_' in decorated.... | python | def hook(self, *hook_names):
"""Decorator, registering them as hooks"""
def wrapper(decorated):
for hook_name in hook_names:
self.register(hook_name, decorated)
else:
self.register(decorated.__name__, decorated)
if '_' in decorated.... | [
"def",
"hook",
"(",
"self",
",",
"*",
"hook_names",
")",
":",
"def",
"wrapper",
"(",
"decorated",
")",
":",
"for",
"hook_name",
"in",
"hook_names",
":",
"self",
".",
"register",
"(",
"hook_name",
",",
"decorated",
")",
"else",
":",
"self",
".",
"regist... | Decorator, registering them as hooks | [
"Decorator",
"registering",
"them",
"as",
"hooks"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L923-L934 |
12,778 | juju/charm-helpers | charmhelpers/fetch/python/rpdb.py | Rpdb.shutdown | def shutdown(self):
"""Revert stdin and stdout, close the socket."""
sys.stdout = self.old_stdout
sys.stdin = self.old_stdin
self.skt.close()
self.set_continue() | python | def shutdown(self):
"""Revert stdin and stdout, close the socket."""
sys.stdout = self.old_stdout
sys.stdin = self.old_stdin
self.skt.close()
self.set_continue() | [
"def",
"shutdown",
"(",
"self",
")",
":",
"sys",
".",
"stdout",
"=",
"self",
".",
"old_stdout",
"sys",
".",
"stdin",
"=",
"self",
".",
"old_stdin",
"self",
".",
"skt",
".",
"close",
"(",
")",
"self",
".",
"set_continue",
"(",
")"
] | Revert stdin and stdout, close the socket. | [
"Revert",
"stdin",
"and",
"stdout",
"close",
"the",
"socket",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/python/rpdb.py#L44-L49 |
12,779 | juju/charm-helpers | charmhelpers/contrib/benchmark/__init__.py | Benchmark.start | def start():
action_set('meta.start', time.strftime('%Y-%m-%dT%H:%M:%SZ'))
"""
If the collectd charm is also installed, tell it to send a snapshot
of the current profile data.
"""
COLLECT_PROFILE_DATA = '/usr/local/bin/collect-profile-data'
if os.path.exists(COLL... | python | def start():
action_set('meta.start', time.strftime('%Y-%m-%dT%H:%M:%SZ'))
"""
If the collectd charm is also installed, tell it to send a snapshot
of the current profile data.
"""
COLLECT_PROFILE_DATA = '/usr/local/bin/collect-profile-data'
if os.path.exists(COLL... | [
"def",
"start",
"(",
")",
":",
"action_set",
"(",
"'meta.start'",
",",
"time",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:%SZ'",
")",
")",
"COLLECT_PROFILE_DATA",
"=",
"'/usr/local/bin/collect-profile-data'",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"COLLECT_PROFI... | If the collectd charm is also installed, tell it to send a snapshot
of the current profile data. | [
"If",
"the",
"collectd",
"charm",
"is",
"also",
"installed",
"tell",
"it",
"to",
"send",
"a",
"snapshot",
"of",
"the",
"current",
"profile",
"data",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/benchmark/__init__.py#L99-L108 |
12,780 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_os_codename_install_source | def get_os_codename_install_source(src):
'''Derive OpenStack release codename from a given installation source.'''
ubuntu_rel = lsb_release()['DISTRIB_CODENAME']
rel = ''
if src is None:
return rel
if src in ['distro', 'distro-proposed', 'proposed']:
try:
rel = UBUNTU_OPE... | python | def get_os_codename_install_source(src):
'''Derive OpenStack release codename from a given installation source.'''
ubuntu_rel = lsb_release()['DISTRIB_CODENAME']
rel = ''
if src is None:
return rel
if src in ['distro', 'distro-proposed', 'proposed']:
try:
rel = UBUNTU_OPE... | [
"def",
"get_os_codename_install_source",
"(",
"src",
")",
":",
"ubuntu_rel",
"=",
"lsb_release",
"(",
")",
"[",
"'DISTRIB_CODENAME'",
"]",
"rel",
"=",
"''",
"if",
"src",
"is",
"None",
":",
"return",
"rel",
"if",
"src",
"in",
"[",
"'distro'",
",",
"'distro-... | Derive OpenStack release codename from a given installation source. | [
"Derive",
"OpenStack",
"release",
"codename",
"from",
"a",
"given",
"installation",
"source",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L322-L348 |
12,781 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_os_version_codename | def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES):
'''Determine OpenStack version number from codename.'''
for k, v in six.iteritems(version_map):
if v == codename:
return k
e = 'Could not derive OpenStack version for '\
'codename: %s' % codename
error_ou... | python | def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES):
'''Determine OpenStack version number from codename.'''
for k, v in six.iteritems(version_map):
if v == codename:
return k
e = 'Could not derive OpenStack version for '\
'codename: %s' % codename
error_ou... | [
"def",
"get_os_version_codename",
"(",
"codename",
",",
"version_map",
"=",
"OPENSTACK_CODENAMES",
")",
":",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"version_map",
")",
":",
"if",
"v",
"==",
"codename",
":",
"return",
"k",
"e",
"=",
"'C... | Determine OpenStack version number from codename. | [
"Determine",
"OpenStack",
"version",
"number",
"from",
"codename",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L365-L372 |
12,782 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_os_version_codename_swift | def get_os_version_codename_swift(codename):
'''Determine OpenStack version number of swift from codename.'''
for k, v in six.iteritems(SWIFT_CODENAMES):
if k == codename:
return v[-1]
e = 'Could not derive swift version for '\
'codename: %s' % codename
error_out(e) | python | def get_os_version_codename_swift(codename):
'''Determine OpenStack version number of swift from codename.'''
for k, v in six.iteritems(SWIFT_CODENAMES):
if k == codename:
return v[-1]
e = 'Could not derive swift version for '\
'codename: %s' % codename
error_out(e) | [
"def",
"get_os_version_codename_swift",
"(",
"codename",
")",
":",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"SWIFT_CODENAMES",
")",
":",
"if",
"k",
"==",
"codename",
":",
"return",
"v",
"[",
"-",
"1",
"]",
"e",
"=",
"'Could not derive sw... | Determine OpenStack version number of swift from codename. | [
"Determine",
"OpenStack",
"version",
"number",
"of",
"swift",
"from",
"codename",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L375-L382 |
12,783 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_swift_codename | def get_swift_codename(version):
'''Determine OpenStack codename that corresponds to swift version.'''
codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v]
if len(codenames) > 1:
# If more than one release codename contains this version we determine
# the actual codena... | python | def get_swift_codename(version):
'''Determine OpenStack codename that corresponds to swift version.'''
codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v]
if len(codenames) > 1:
# If more than one release codename contains this version we determine
# the actual codena... | [
"def",
"get_swift_codename",
"(",
"version",
")",
":",
"codenames",
"=",
"[",
"k",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"SWIFT_CODENAMES",
")",
"if",
"version",
"in",
"v",
"]",
"if",
"len",
"(",
"codenames",
")",
">",
"1",
":",
... | Determine OpenStack codename that corresponds to swift version. | [
"Determine",
"OpenStack",
"codename",
"that",
"corresponds",
"to",
"swift",
"version",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L385-L412 |
12,784 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_os_codename_package | def get_os_codename_package(package, fatal=True):
'''Derive OpenStack release codename from an installed package.'''
if snap_install_requested():
cmd = ['snap', 'list', package]
try:
out = subprocess.check_output(cmd)
if six.PY3:
out = out.decode('UTF-8')... | python | def get_os_codename_package(package, fatal=True):
'''Derive OpenStack release codename from an installed package.'''
if snap_install_requested():
cmd = ['snap', 'list', package]
try:
out = subprocess.check_output(cmd)
if six.PY3:
out = out.decode('UTF-8')... | [
"def",
"get_os_codename_package",
"(",
"package",
",",
"fatal",
"=",
"True",
")",
":",
"if",
"snap_install_requested",
"(",
")",
":",
"cmd",
"=",
"[",
"'snap'",
",",
"'list'",
",",
"package",
"]",
"try",
":",
"out",
"=",
"subprocess",
".",
"check_output",
... | Derive OpenStack release codename from an installed package. | [
"Derive",
"OpenStack",
"release",
"codename",
"from",
"an",
"installed",
"package",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L415-L483 |
12,785 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_os_version_package | def get_os_version_package(pkg, fatal=True):
'''Derive OpenStack version number from an installed package.'''
codename = get_os_codename_package(pkg, fatal=fatal)
if not codename:
return None
if 'swift' in pkg:
vers_map = SWIFT_CODENAMES
for cname, version in six.iteritems(vers... | python | def get_os_version_package(pkg, fatal=True):
'''Derive OpenStack version number from an installed package.'''
codename = get_os_codename_package(pkg, fatal=fatal)
if not codename:
return None
if 'swift' in pkg:
vers_map = SWIFT_CODENAMES
for cname, version in six.iteritems(vers... | [
"def",
"get_os_version_package",
"(",
"pkg",
",",
"fatal",
"=",
"True",
")",
":",
"codename",
"=",
"get_os_codename_package",
"(",
"pkg",
",",
"fatal",
"=",
"fatal",
")",
"if",
"not",
"codename",
":",
"return",
"None",
"if",
"'swift'",
"in",
"pkg",
":",
... | Derive OpenStack version number from an installed package. | [
"Derive",
"OpenStack",
"version",
"number",
"from",
"an",
"installed",
"package",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L486-L502 |
12,786 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | os_release | def os_release(package, base='essex', reset_cache=False):
'''
Returns OpenStack release codename from a cached global.
If reset_cache then unset the cached os_release version and return the
freshly determined version.
If the codename can not be determined from either an installed package or
th... | python | def os_release(package, base='essex', reset_cache=False):
'''
Returns OpenStack release codename from a cached global.
If reset_cache then unset the cached os_release version and return the
freshly determined version.
If the codename can not be determined from either an installed package or
th... | [
"def",
"os_release",
"(",
"package",
",",
"base",
"=",
"'essex'",
",",
"reset_cache",
"=",
"False",
")",
":",
"global",
"_os_rel",
"if",
"reset_cache",
":",
"reset_os_release",
"(",
")",
"if",
"_os_rel",
":",
"return",
"_os_rel",
"_os_rel",
"=",
"(",
"get_... | Returns OpenStack release codename from a cached global.
If reset_cache then unset the cached os_release version and return the
freshly determined version.
If the codename can not be determined from either an installed package or
the installation source, the earliest release supported by the charm sho... | [
"Returns",
"OpenStack",
"release",
"codename",
"from",
"a",
"cached",
"global",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L517-L537 |
12,787 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | import_key | def import_key(keyid):
"""Import a key, either ASCII armored, or a GPG key id.
@param keyid: the key in ASCII armor format, or a GPG key id.
@raises SystemExit() via sys.exit() on failure.
"""
try:
return fetch_import_key(keyid)
except GPGKeyError as e:
error_out("Could not impo... | python | def import_key(keyid):
"""Import a key, either ASCII armored, or a GPG key id.
@param keyid: the key in ASCII armor format, or a GPG key id.
@raises SystemExit() via sys.exit() on failure.
"""
try:
return fetch_import_key(keyid)
except GPGKeyError as e:
error_out("Could not impo... | [
"def",
"import_key",
"(",
"keyid",
")",
":",
"try",
":",
"return",
"fetch_import_key",
"(",
"keyid",
")",
"except",
"GPGKeyError",
"as",
"e",
":",
"error_out",
"(",
"\"Could not import key: {}\"",
".",
"format",
"(",
"str",
"(",
"e",
")",
")",
")"
] | Import a key, either ASCII armored, or a GPG key id.
@param keyid: the key in ASCII armor format, or a GPG key id.
@raises SystemExit() via sys.exit() on failure. | [
"Import",
"a",
"key",
"either",
"ASCII",
"armored",
"or",
"a",
"GPG",
"key",
"id",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L541-L550 |
12,788 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_source_and_pgp_key | def get_source_and_pgp_key(source_and_key):
"""Look for a pgp key ID or ascii-armor key in the given input.
:param source_and_key: Sting, "source_spec|keyid" where '|keyid' is
optional.
:returns (source_spec, key_id OR None) as a tuple. Returns None for key_id
if there was no '|' in the so... | python | def get_source_and_pgp_key(source_and_key):
"""Look for a pgp key ID or ascii-armor key in the given input.
:param source_and_key: Sting, "source_spec|keyid" where '|keyid' is
optional.
:returns (source_spec, key_id OR None) as a tuple. Returns None for key_id
if there was no '|' in the so... | [
"def",
"get_source_and_pgp_key",
"(",
"source_and_key",
")",
":",
"try",
":",
"source",
",",
"key",
"=",
"source_and_key",
".",
"split",
"(",
"'|'",
",",
"2",
")",
"return",
"source",
",",
"key",
"or",
"None",
"except",
"ValueError",
":",
"return",
"source... | Look for a pgp key ID or ascii-armor key in the given input.
:param source_and_key: Sting, "source_spec|keyid" where '|keyid' is
optional.
:returns (source_spec, key_id OR None) as a tuple. Returns None for key_id
if there was no '|' in the source_and_key string. | [
"Look",
"for",
"a",
"pgp",
"key",
"ID",
"or",
"ascii",
"-",
"armor",
"key",
"in",
"the",
"given",
"input",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L553-L565 |
12,789 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | configure_installation_source | def configure_installation_source(source_plus_key):
"""Configure an installation source.
The functionality is provided by charmhelpers.fetch.add_source()
The difference between the two functions is that add_source() signature
requires the key to be passed directly, whereas this function passes an
o... | python | def configure_installation_source(source_plus_key):
"""Configure an installation source.
The functionality is provided by charmhelpers.fetch.add_source()
The difference between the two functions is that add_source() signature
requires the key to be passed directly, whereas this function passes an
o... | [
"def",
"configure_installation_source",
"(",
"source_plus_key",
")",
":",
"if",
"source_plus_key",
".",
"startswith",
"(",
"'snap'",
")",
":",
"# Do nothing for snap installs",
"return",
"# extract the key if there is one, denoted by a '|' in the rel",
"source",
",",
"key",
"... | Configure an installation source.
The functionality is provided by charmhelpers.fetch.add_source()
The difference between the two functions is that add_source() signature
requires the key to be passed directly, whereas this function passes an
optional key by appending '|<key>' to the end of the source ... | [
"Configure",
"an",
"installation",
"source",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L570-L600 |
12,790 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | config_value_changed | def config_value_changed(option):
"""
Determine if config value changed since last call to this function.
"""
hook_data = unitdata.HookData()
with hook_data():
db = unitdata.kv()
current = config(option)
saved = db.get(option)
db.set(option, current)
if saved ... | python | def config_value_changed(option):
"""
Determine if config value changed since last call to this function.
"""
hook_data = unitdata.HookData()
with hook_data():
db = unitdata.kv()
current = config(option)
saved = db.get(option)
db.set(option, current)
if saved ... | [
"def",
"config_value_changed",
"(",
"option",
")",
":",
"hook_data",
"=",
"unitdata",
".",
"HookData",
"(",
")",
"with",
"hook_data",
"(",
")",
":",
"db",
"=",
"unitdata",
".",
"kv",
"(",
")",
"current",
"=",
"config",
"(",
"option",
")",
"saved",
"=",... | Determine if config value changed since last call to this function. | [
"Determine",
"if",
"config",
"value",
"changed",
"since",
"last",
"call",
"to",
"this",
"function",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L603-L615 |
12,791 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | save_script_rc | def save_script_rc(script_path="scripts/scriptrc", **env_vars):
"""
Write an rc file in the charm-delivered directory containing
exported environment variables provided by env_vars. Any charm scripts run
outside the juju hook environment can source this scriptrc to obtain
updated config information ... | python | def save_script_rc(script_path="scripts/scriptrc", **env_vars):
"""
Write an rc file in the charm-delivered directory containing
exported environment variables provided by env_vars. Any charm scripts run
outside the juju hook environment can source this scriptrc to obtain
updated config information ... | [
"def",
"save_script_rc",
"(",
"script_path",
"=",
"\"scripts/scriptrc\"",
",",
"*",
"*",
"env_vars",
")",
":",
"juju_rc_path",
"=",
"\"%s/%s\"",
"%",
"(",
"charm_dir",
"(",
")",
",",
"script_path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
... | Write an rc file in the charm-delivered directory containing
exported environment variables provided by env_vars. Any charm scripts run
outside the juju hook environment can source this scriptrc to obtain
updated config information necessary to perform health checks or
service changes. | [
"Write",
"an",
"rc",
"file",
"in",
"the",
"charm",
"-",
"delivered",
"directory",
"containing",
"exported",
"environment",
"variables",
"provided",
"by",
"env_vars",
".",
"Any",
"charm",
"scripts",
"run",
"outside",
"the",
"juju",
"hook",
"environment",
"can",
... | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L618-L633 |
12,792 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | openstack_upgrade_available | def openstack_upgrade_available(package):
"""
Determines if an OpenStack upgrade is available from installation
source, based on version of installed package.
:param package: str: Name of installed package.
:returns: bool: : Returns True if configured installation source offers
... | python | def openstack_upgrade_available(package):
"""
Determines if an OpenStack upgrade is available from installation
source, based on version of installed package.
:param package: str: Name of installed package.
:returns: bool: : Returns True if configured installation source offers
... | [
"def",
"openstack_upgrade_available",
"(",
"package",
")",
":",
"import",
"apt_pkg",
"as",
"apt",
"src",
"=",
"config",
"(",
"'openstack-origin'",
")",
"cur_vers",
"=",
"get_os_version_package",
"(",
"package",
")",
"if",
"not",
"cur_vers",
":",
"# The package has... | Determines if an OpenStack upgrade is available from installation
source, based on version of installed package.
:param package: str: Name of installed package.
:returns: bool: : Returns True if configured installation source offers
a newer version of package. | [
"Determines",
"if",
"an",
"OpenStack",
"upgrade",
"is",
"available",
"from",
"installation",
"source",
"based",
"on",
"version",
"of",
"installed",
"package",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L636-L659 |
12,793 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | ensure_block_device | def ensure_block_device(block_device):
'''
Confirm block_device, create as loopback if necessary.
:param block_device: str: Full path of block device to ensure.
:returns: str: Full path of ensured block device.
'''
_none = ['None', 'none', None]
if (block_device in _none):
error_ou... | python | def ensure_block_device(block_device):
'''
Confirm block_device, create as loopback if necessary.
:param block_device: str: Full path of block device to ensure.
:returns: str: Full path of ensured block device.
'''
_none = ['None', 'none', None]
if (block_device in _none):
error_ou... | [
"def",
"ensure_block_device",
"(",
"block_device",
")",
":",
"_none",
"=",
"[",
"'None'",
",",
"'none'",
",",
"None",
"]",
"if",
"(",
"block_device",
"in",
"_none",
")",
":",
"error_out",
"(",
"'prepare_storage(): Missing required input: block_device=%s.'",
"%",
"... | Confirm block_device, create as loopback if necessary.
:param block_device: str: Full path of block device to ensure.
:returns: str: Full path of ensured block device. | [
"Confirm",
"block_device",
"create",
"as",
"loopback",
"if",
"necessary",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L662-L691 |
12,794 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | os_requires_version | def os_requires_version(ostack_release, pkg):
"""
Decorator for hook to specify minimum supported release
"""
def wrap(f):
@wraps(f)
def wrapped_f(*args):
if os_release(pkg) < ostack_release:
raise Exception("This hook is not supported on releases"
... | python | def os_requires_version(ostack_release, pkg):
"""
Decorator for hook to specify minimum supported release
"""
def wrap(f):
@wraps(f)
def wrapped_f(*args):
if os_release(pkg) < ostack_release:
raise Exception("This hook is not supported on releases"
... | [
"def",
"os_requires_version",
"(",
"ostack_release",
",",
"pkg",
")",
":",
"def",
"wrap",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapped_f",
"(",
"*",
"args",
")",
":",
"if",
"os_release",
"(",
"pkg",
")",
"<",
"ostack_release",
":"... | Decorator for hook to specify minimum supported release | [
"Decorator",
"for",
"hook",
"to",
"specify",
"minimum",
"supported",
"release"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L754-L766 |
12,795 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | os_workload_status | def os_workload_status(configs, required_interfaces, charm_func=None):
"""
Decorator to set workload status based on complete contexts
"""
def wrap(f):
@wraps(f)
def wrapped_f(*args, **kwargs):
# Run the original function first
f(*args, **kwargs)
# Set... | python | def os_workload_status(configs, required_interfaces, charm_func=None):
"""
Decorator to set workload status based on complete contexts
"""
def wrap(f):
@wraps(f)
def wrapped_f(*args, **kwargs):
# Run the original function first
f(*args, **kwargs)
# Set... | [
"def",
"os_workload_status",
"(",
"configs",
",",
"required_interfaces",
",",
"charm_func",
"=",
"None",
")",
":",
"def",
"wrap",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapped_f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":"... | Decorator to set workload status based on complete contexts | [
"Decorator",
"to",
"set",
"workload",
"status",
"based",
"on",
"complete",
"contexts"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L769-L782 |
12,796 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | set_os_workload_status | def set_os_workload_status(configs, required_interfaces, charm_func=None,
services=None, ports=None):
"""Set the state of the workload status for the charm.
This calls _determine_os_workload_status() to get the new state, message
and sets the status using status_set()
@param... | python | def set_os_workload_status(configs, required_interfaces, charm_func=None,
services=None, ports=None):
"""Set the state of the workload status for the charm.
This calls _determine_os_workload_status() to get the new state, message
and sets the status using status_set()
@param... | [
"def",
"set_os_workload_status",
"(",
"configs",
",",
"required_interfaces",
",",
"charm_func",
"=",
"None",
",",
"services",
"=",
"None",
",",
"ports",
"=",
"None",
")",
":",
"state",
",",
"message",
"=",
"_determine_os_workload_status",
"(",
"configs",
",",
... | Set the state of the workload status for the charm.
This calls _determine_os_workload_status() to get the new state, message
and sets the status using status_set()
@param configs: a templating.OSConfigRenderer() object
@param required_interfaces: {generic: [specific, specific2, ...]}
@param charm_... | [
"Set",
"the",
"state",
"of",
"the",
"workload",
"status",
"for",
"the",
"charm",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L785-L802 |
12,797 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | _determine_os_workload_status | def _determine_os_workload_status(
configs, required_interfaces, charm_func=None,
services=None, ports=None):
"""Determine the state of the workload status for the charm.
This function returns the new workload status for the charm based
on the state of the interfaces, the paused state and w... | python | def _determine_os_workload_status(
configs, required_interfaces, charm_func=None,
services=None, ports=None):
"""Determine the state of the workload status for the charm.
This function returns the new workload status for the charm based
on the state of the interfaces, the paused state and w... | [
"def",
"_determine_os_workload_status",
"(",
"configs",
",",
"required_interfaces",
",",
"charm_func",
"=",
"None",
",",
"services",
"=",
"None",
",",
"ports",
"=",
"None",
")",
":",
"state",
",",
"message",
"=",
"_ows_check_if_paused",
"(",
"services",
",",
"... | Determine the state of the workload status for the charm.
This function returns the new workload status for the charm based
on the state of the interfaces, the paused state and whether the
services are actually running and any specified ports are open.
This checks:
1. if the unit should be pause... | [
"Determine",
"the",
"state",
"of",
"the",
"workload",
"status",
"for",
"the",
"charm",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L805-L853 |
12,798 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | _ows_check_generic_interfaces | def _ows_check_generic_interfaces(configs, required_interfaces):
"""Check the complete contexts to determine the workload status.
- Checks for missing or incomplete contexts
- juju log details of missing required data.
- determines the correct workload status
- creates an appropriate message fo... | python | def _ows_check_generic_interfaces(configs, required_interfaces):
"""Check the complete contexts to determine the workload status.
- Checks for missing or incomplete contexts
- juju log details of missing required data.
- determines the correct workload status
- creates an appropriate message fo... | [
"def",
"_ows_check_generic_interfaces",
"(",
"configs",
",",
"required_interfaces",
")",
":",
"incomplete_rel_data",
"=",
"incomplete_relation_data",
"(",
"configs",
",",
"required_interfaces",
")",
"state",
"=",
"None",
"message",
"=",
"None",
"missing_relations",
"=",... | Check the complete contexts to determine the workload status.
- Checks for missing or incomplete contexts
- juju log details of missing required data.
- determines the correct workload status
- creates an appropriate message for status_set(...)
if there are no problems then the function return... | [
"Check",
"the",
"complete",
"contexts",
"to",
"determine",
"the",
"workload",
"status",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L890-L969 |
12,799 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | _ows_check_services_running | def _ows_check_services_running(services, ports):
"""Check that the services that should be running are actually running
and that any ports specified are being listened to.
@param services: list of strings OR dictionary specifying services/ports
@param ports: list of ports
@returns state, message: ... | python | def _ows_check_services_running(services, ports):
"""Check that the services that should be running are actually running
and that any ports specified are being listened to.
@param services: list of strings OR dictionary specifying services/ports
@param ports: list of ports
@returns state, message: ... | [
"def",
"_ows_check_services_running",
"(",
"services",
",",
"ports",
")",
":",
"messages",
"=",
"[",
"]",
"state",
"=",
"None",
"if",
"services",
"is",
"not",
"None",
":",
"services",
"=",
"_extract_services_list_helper",
"(",
"services",
")",
"services_running"... | Check that the services that should be running are actually running
and that any ports specified are being listened to.
@param services: list of strings OR dictionary specifying services/ports
@param ports: list of ports
@returns state, message: strings or None, None | [
"Check",
"that",
"the",
"services",
"that",
"should",
"be",
"running",
"are",
"actually",
"running",
"and",
"that",
"any",
"ports",
"specified",
"are",
"being",
"listened",
"to",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L998-L1046 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.