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,800 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | _check_listening_on_ports_list | def _check_listening_on_ports_list(ports):
"""Check that the ports list given are being listened to
Returns a list of ports being listened to and a list of the
booleans.
@param ports: LIST or port numbers.
@returns [(port_num, boolean), ...], [boolean]
"""
ports_open = [port_has_listener('... | python | def _check_listening_on_ports_list(ports):
"""Check that the ports list given are being listened to
Returns a list of ports being listened to and a list of the
booleans.
@param ports: LIST or port numbers.
@returns [(port_num, boolean), ...], [boolean]
"""
ports_open = [port_has_listener('... | [
"def",
"_check_listening_on_ports_list",
"(",
"ports",
")",
":",
"ports_open",
"=",
"[",
"port_has_listener",
"(",
"'0.0.0.0'",
",",
"p",
")",
"for",
"p",
"in",
"ports",
"]",
"return",
"zip",
"(",
"ports",
",",
"ports_open",
")",
",",
"ports_open"
] | Check that the ports list given are being listened to
Returns a list of ports being listened to and a list of the
booleans.
@param ports: LIST or port numbers.
@returns [(port_num, boolean), ...], [boolean] | [
"Check",
"that",
"the",
"ports",
"list",
"given",
"are",
"being",
"listened",
"to"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1118-L1128 |
12,801 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | workload_state_compare | def workload_state_compare(current_workload_state, workload_state):
""" Return highest priority of two states"""
hierarchy = {'unknown': -1,
'active': 0,
'maintenance': 1,
'waiting': 2,
'blocked': 3,
}
if hierarchy.get(wor... | python | def workload_state_compare(current_workload_state, workload_state):
""" Return highest priority of two states"""
hierarchy = {'unknown': -1,
'active': 0,
'maintenance': 1,
'waiting': 2,
'blocked': 3,
}
if hierarchy.get(wor... | [
"def",
"workload_state_compare",
"(",
"current_workload_state",
",",
"workload_state",
")",
":",
"hierarchy",
"=",
"{",
"'unknown'",
":",
"-",
"1",
",",
"'active'",
":",
"0",
",",
"'maintenance'",
":",
"1",
",",
"'waiting'",
":",
"2",
",",
"'blocked'",
":",
... | Return highest priority of two states | [
"Return",
"highest",
"priority",
"of",
"two",
"states"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1142-L1160 |
12,802 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | incomplete_relation_data | def incomplete_relation_data(configs, required_interfaces):
"""Check complete contexts against required_interfaces
Return dictionary of incomplete relation data.
configs is an OSConfigRenderer object with configs registered
required_interfaces is a dictionary of required general interfaces
with di... | python | def incomplete_relation_data(configs, required_interfaces):
"""Check complete contexts against required_interfaces
Return dictionary of incomplete relation data.
configs is an OSConfigRenderer object with configs registered
required_interfaces is a dictionary of required general interfaces
with di... | [
"def",
"incomplete_relation_data",
"(",
"configs",
",",
"required_interfaces",
")",
":",
"complete_ctxts",
"=",
"configs",
".",
"complete_contexts",
"(",
")",
"incomplete_relations",
"=",
"[",
"svc_type",
"for",
"svc_type",
",",
"interfaces",
"in",
"required_interface... | Check complete contexts against required_interfaces
Return dictionary of incomplete relation data.
configs is an OSConfigRenderer object with configs registered
required_interfaces is a dictionary of required general interfaces
with dictionary values of possible specific interfaces.
Example:
r... | [
"Check",
"complete",
"contexts",
"against",
"required_interfaces",
"Return",
"dictionary",
"of",
"incomplete",
"relation",
"data",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1163-L1195 |
12,803 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | do_action_openstack_upgrade | def do_action_openstack_upgrade(package, upgrade_callback, configs):
"""Perform action-managed OpenStack upgrade.
Upgrades packages to the configured openstack-origin version and sets
the corresponding action status as a result.
If the charm was installed from source we cannot upgrade it.
For back... | python | def do_action_openstack_upgrade(package, upgrade_callback, configs):
"""Perform action-managed OpenStack upgrade.
Upgrades packages to the configured openstack-origin version and sets
the corresponding action status as a result.
If the charm was installed from source we cannot upgrade it.
For back... | [
"def",
"do_action_openstack_upgrade",
"(",
"package",
",",
"upgrade_callback",
",",
"configs",
")",
":",
"ret",
"=",
"False",
"if",
"openstack_upgrade_available",
"(",
"package",
")",
":",
"if",
"config",
"(",
"'action-managed-upgrade'",
")",
":",
"juju_log",
"(",... | Perform action-managed OpenStack upgrade.
Upgrades packages to the configured openstack-origin version and sets
the corresponding action status as a result.
If the charm was installed from source we cannot upgrade it.
For backwards compatibility a config flag (action-managed-upgrade) must
be set f... | [
"Perform",
"action",
"-",
"managed",
"OpenStack",
"upgrade",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1198-L1236 |
12,804 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | manage_payload_services | def manage_payload_services(action, services=None, charm_func=None):
"""Run an action against all services.
An optional charm_func() can be called. It should raise an Exception to
indicate that the function failed. If it was succesfull it should return
None or an optional message.
The signature fo... | python | def manage_payload_services(action, services=None, charm_func=None):
"""Run an action against all services.
An optional charm_func() can be called. It should raise an Exception to
indicate that the function failed. If it was succesfull it should return
None or an optional message.
The signature fo... | [
"def",
"manage_payload_services",
"(",
"action",
",",
"services",
"=",
"None",
",",
"charm_func",
"=",
"None",
")",
":",
"actions",
"=",
"{",
"'pause'",
":",
"service_pause",
",",
"'resume'",
":",
"service_resume",
",",
"'start'",
":",
"service_start",
",",
... | Run an action against all services.
An optional charm_func() can be called. It should raise an Exception to
indicate that the function failed. If it was succesfull it should return
None or an optional message.
The signature for charm_func is:
charm_func() -> message: str
charm_func() is execu... | [
"Run",
"an",
"action",
"against",
"all",
"services",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1334-L1390 |
12,805 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | pausable_restart_on_change | def pausable_restart_on_change(restart_map, stopstart=False,
restart_functions=None):
"""A restart_on_change decorator that checks to see if the unit is
paused. If it is paused then the decorated function doesn't fire.
This is provided as a helper, as the @restart_on_change(.... | python | def pausable_restart_on_change(restart_map, stopstart=False,
restart_functions=None):
"""A restart_on_change decorator that checks to see if the unit is
paused. If it is paused then the decorated function doesn't fire.
This is provided as a helper, as the @restart_on_change(.... | [
"def",
"pausable_restart_on_change",
"(",
"restart_map",
",",
"stopstart",
"=",
"False",
",",
"restart_functions",
"=",
"None",
")",
":",
"def",
"wrap",
"(",
"f",
")",
":",
"# py27 compatible nonlocal variable. When py3 only, replace with",
"# nonlocal keyword",
"__resta... | A restart_on_change decorator that checks to see if the unit is
paused. If it is paused then the decorated function doesn't fire.
This is provided as a helper, as the @restart_on_change(...) decorator
is in core.host, yet the openstack specific helpers are in this file
(contrib.openstack.utils). Thus,... | [
"A",
"restart_on_change",
"decorator",
"that",
"checks",
"to",
"see",
"if",
"the",
"unit",
"is",
"paused",
".",
"If",
"it",
"is",
"paused",
"then",
"the",
"decorated",
"function",
"doesn",
"t",
"fire",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1498-L1548 |
12,806 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | ordered | def ordered(orderme):
"""Converts the provided dictionary into a collections.OrderedDict.
The items in the returned OrderedDict will be inserted based on the
natural sort order of the keys. Nested dictionaries will also be sorted
in order to ensure fully predictable ordering.
:param orderme: the d... | python | def ordered(orderme):
"""Converts the provided dictionary into a collections.OrderedDict.
The items in the returned OrderedDict will be inserted based on the
natural sort order of the keys. Nested dictionaries will also be sorted
in order to ensure fully predictable ordering.
:param orderme: the d... | [
"def",
"ordered",
"(",
"orderme",
")",
":",
"if",
"not",
"isinstance",
"(",
"orderme",
",",
"dict",
")",
":",
"raise",
"ValueError",
"(",
"'argument must be a dict type'",
")",
"result",
"=",
"OrderedDict",
"(",
")",
"for",
"k",
",",
"v",
"in",
"sorted",
... | Converts the provided dictionary into a collections.OrderedDict.
The items in the returned OrderedDict will be inserted based on the
natural sort order of the keys. Nested dictionaries will also be sorted
in order to ensure fully predictable ordering.
:param orderme: the dict to order
:return: col... | [
"Converts",
"the",
"provided",
"dictionary",
"into",
"a",
"collections",
".",
"OrderedDict",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1551-L1572 |
12,807 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | config_flags_parser | def config_flags_parser(config_flags):
"""Parses config flags string into dict.
This parsing method supports a few different formats for the config
flag values to be parsed:
1. A string in the simple format of key=value pairs, with the possibility
of specifying multiple key value pairs with... | python | def config_flags_parser(config_flags):
"""Parses config flags string into dict.
This parsing method supports a few different formats for the config
flag values to be parsed:
1. A string in the simple format of key=value pairs, with the possibility
of specifying multiple key value pairs with... | [
"def",
"config_flags_parser",
"(",
"config_flags",
")",
":",
"# If we find a colon before an equals sign then treat it as yaml.",
"# Note: limit it to finding the colon first since this indicates assignment",
"# for inline yaml.",
"colon",
"=",
"config_flags",
".",
"find",
"(",
"':'",
... | Parses config flags string into dict.
This parsing method supports a few different formats for the config
flag values to be parsed:
1. A string in the simple format of key=value pairs, with the possibility
of specifying multiple key value pairs within the same string. For
example, a st... | [
"Parses",
"config",
"flags",
"string",
"into",
"dict",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1575-L1649 |
12,808 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | os_application_version_set | def os_application_version_set(package):
'''Set version of application for Juju 2.0 and later'''
application_version = get_upstream_version(package)
# NOTE(jamespage) if not able to figure out package version, fallback to
# openstack codename version detection.
if not application_ver... | python | def os_application_version_set(package):
'''Set version of application for Juju 2.0 and later'''
application_version = get_upstream_version(package)
# NOTE(jamespage) if not able to figure out package version, fallback to
# openstack codename version detection.
if not application_ver... | [
"def",
"os_application_version_set",
"(",
"package",
")",
":",
"application_version",
"=",
"get_upstream_version",
"(",
"package",
")",
"# NOTE(jamespage) if not able to figure out package version, fallback to",
"# openstack codename version detection.",
"if",
"not",
... | Set version of application for Juju 2.0 and later | [
"Set",
"version",
"of",
"application",
"for",
"Juju",
"2",
".",
"0",
"and",
"later"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1652-L1660 |
12,809 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | enable_memcache | def enable_memcache(source=None, release=None, package=None):
"""Determine if memcache should be enabled on the local unit
@param release: release of OpenStack currently deployed
@param package: package to derive OpenStack version deployed
@returns boolean Whether memcache should be enabled
"""
... | python | def enable_memcache(source=None, release=None, package=None):
"""Determine if memcache should be enabled on the local unit
@param release: release of OpenStack currently deployed
@param package: package to derive OpenStack version deployed
@returns boolean Whether memcache should be enabled
"""
... | [
"def",
"enable_memcache",
"(",
"source",
"=",
"None",
",",
"release",
"=",
"None",
",",
"package",
"=",
"None",
")",
":",
"_release",
"=",
"None",
"if",
"release",
":",
"_release",
"=",
"release",
"else",
":",
"_release",
"=",
"os_release",
"(",
"package... | Determine if memcache should be enabled on the local unit
@param release: release of OpenStack currently deployed
@param package: package to derive OpenStack version deployed
@returns boolean Whether memcache should be enabled | [
"Determine",
"if",
"memcache",
"should",
"be",
"enabled",
"on",
"the",
"local",
"unit"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1663-L1678 |
12,810 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | token_cache_pkgs | def token_cache_pkgs(source=None, release=None):
"""Determine additional packages needed for token caching
@param source: source string for charm
@param release: release of OpenStack currently deployed
@returns List of package to enable token caching
"""
packages = []
if enable_memcache(sou... | python | def token_cache_pkgs(source=None, release=None):
"""Determine additional packages needed for token caching
@param source: source string for charm
@param release: release of OpenStack currently deployed
@returns List of package to enable token caching
"""
packages = []
if enable_memcache(sou... | [
"def",
"token_cache_pkgs",
"(",
"source",
"=",
"None",
",",
"release",
"=",
"None",
")",
":",
"packages",
"=",
"[",
"]",
"if",
"enable_memcache",
"(",
"source",
"=",
"source",
",",
"release",
"=",
"release",
")",
":",
"packages",
".",
"extend",
"(",
"[... | Determine additional packages needed for token caching
@param source: source string for charm
@param release: release of OpenStack currently deployed
@returns List of package to enable token caching | [
"Determine",
"additional",
"packages",
"needed",
"for",
"token",
"caching"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1681-L1691 |
12,811 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | snap_install_requested | def snap_install_requested():
""" Determine if installing from snaps
If openstack-origin is of the form snap:track/channel[/branch]
and channel is in SNAPS_CHANNELS return True.
"""
origin = config('openstack-origin') or ""
if not origin.startswith('snap:'):
return False
_src = ori... | python | def snap_install_requested():
""" Determine if installing from snaps
If openstack-origin is of the form snap:track/channel[/branch]
and channel is in SNAPS_CHANNELS return True.
"""
origin = config('openstack-origin') or ""
if not origin.startswith('snap:'):
return False
_src = ori... | [
"def",
"snap_install_requested",
"(",
")",
":",
"origin",
"=",
"config",
"(",
"'openstack-origin'",
")",
"or",
"\"\"",
"if",
"not",
"origin",
".",
"startswith",
"(",
"'snap:'",
")",
":",
"return",
"False",
"_src",
"=",
"origin",
"[",
"5",
":",
"]",
"if",... | Determine if installing from snaps
If openstack-origin is of the form snap:track/channel[/branch]
and channel is in SNAPS_CHANNELS return True. | [
"Determine",
"if",
"installing",
"from",
"snaps"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1718-L1734 |
12,812 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | get_snaps_install_info_from_origin | def get_snaps_install_info_from_origin(snaps, src, mode='classic'):
"""Generate a dictionary of snap install information from origin
@param snaps: List of snaps
@param src: String of openstack-origin or source of the form
snap:track/channel
@param mode: String classic, devmode or jailmode
@... | python | def get_snaps_install_info_from_origin(snaps, src, mode='classic'):
"""Generate a dictionary of snap install information from origin
@param snaps: List of snaps
@param src: String of openstack-origin or source of the form
snap:track/channel
@param mode: String classic, devmode or jailmode
@... | [
"def",
"get_snaps_install_info_from_origin",
"(",
"snaps",
",",
"src",
",",
"mode",
"=",
"'classic'",
")",
":",
"if",
"not",
"src",
".",
"startswith",
"(",
"'snap:'",
")",
":",
"juju_log",
"(",
"\"Snap source is not a snap origin\"",
",",
"'WARN'",
")",
"return"... | Generate a dictionary of snap install information from origin
@param snaps: List of snaps
@param src: String of openstack-origin or source of the form
snap:track/channel
@param mode: String classic, devmode or jailmode
@returns: Dictionary of snaps with channels and modes | [
"Generate",
"a",
"dictionary",
"of",
"snap",
"install",
"information",
"from",
"origin"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1737-L1755 |
12,813 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | install_os_snaps | def install_os_snaps(snaps, refresh=False):
"""Install OpenStack snaps from channel and with mode
@param snaps: Dictionary of snaps with channels and modes of the form:
{'snap_name': {'channel': 'snap_channel',
'mode': 'snap_mode'}}
Where channel is a snapstore channel an... | python | def install_os_snaps(snaps, refresh=False):
"""Install OpenStack snaps from channel and with mode
@param snaps: Dictionary of snaps with channels and modes of the form:
{'snap_name': {'channel': 'snap_channel',
'mode': 'snap_mode'}}
Where channel is a snapstore channel an... | [
"def",
"install_os_snaps",
"(",
"snaps",
",",
"refresh",
"=",
"False",
")",
":",
"def",
"_ensure_flag",
"(",
"flag",
")",
":",
"if",
"flag",
".",
"startswith",
"(",
"'--'",
")",
":",
"return",
"flag",
"return",
"'--{}'",
".",
"format",
"(",
"flag",
")"... | Install OpenStack snaps from channel and with mode
@param snaps: Dictionary of snaps with channels and modes of the form:
{'snap_name': {'channel': 'snap_channel',
'mode': 'snap_mode'}}
Where channel is a snapstore channel and mode is --classic, --devmode
or --jailmod... | [
"Install",
"OpenStack",
"snaps",
"from",
"channel",
"and",
"with",
"mode"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1758-L1784 |
12,814 | juju/charm-helpers | charmhelpers/contrib/openstack/utils.py | series_upgrade_complete | def series_upgrade_complete(resume_unit_helper=None, configs=None):
""" Run common series upgrade complete tasks.
:param resume_unit_helper: function: Function to resume unit
:param configs: OSConfigRenderer object: Configurations
:returns None:
"""
clear_unit_paused()
clear_unit_upgrading(... | python | def series_upgrade_complete(resume_unit_helper=None, configs=None):
""" Run common series upgrade complete tasks.
:param resume_unit_helper: function: Function to resume unit
:param configs: OSConfigRenderer object: Configurations
:returns None:
"""
clear_unit_paused()
clear_unit_upgrading(... | [
"def",
"series_upgrade_complete",
"(",
"resume_unit_helper",
"=",
"None",
",",
"configs",
"=",
"None",
")",
":",
"clear_unit_paused",
"(",
")",
"clear_unit_upgrading",
"(",
")",
"if",
"configs",
":",
"configs",
".",
"write_all",
"(",
")",
"if",
"resume_unit_help... | Run common series upgrade complete tasks.
:param resume_unit_helper: function: Function to resume unit
:param configs: OSConfigRenderer object: Configurations
:returns None: | [
"Run",
"common",
"series",
"upgrade",
"complete",
"tasks",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L1831-L1843 |
12,815 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | get_certificate_request | def get_certificate_request(json_encode=True):
"""Generate a certificatee requests based on the network confioguration
"""
req = CertRequest(json_encode=json_encode)
req.add_hostname_cn()
# Add os-hostname entries
for net_type in [INTERNAL, ADMIN, PUBLIC]:
net_config = config(ADDRESS_MA... | python | def get_certificate_request(json_encode=True):
"""Generate a certificatee requests based on the network confioguration
"""
req = CertRequest(json_encode=json_encode)
req.add_hostname_cn()
# Add os-hostname entries
for net_type in [INTERNAL, ADMIN, PUBLIC]:
net_config = config(ADDRESS_MA... | [
"def",
"get_certificate_request",
"(",
"json_encode",
"=",
"True",
")",
":",
"req",
"=",
"CertRequest",
"(",
"json_encode",
"=",
"json_encode",
")",
"req",
".",
"add_hostname_cn",
"(",
")",
"# Add os-hostname entries",
"for",
"net_type",
"in",
"[",
"INTERNAL",
"... | Generate a certificatee requests based on the network confioguration | [
"Generate",
"a",
"certificatee",
"requests",
"based",
"on",
"the",
"network",
"confioguration"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L114-L143 |
12,816 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | create_ip_cert_links | def create_ip_cert_links(ssl_dir, custom_hostname_link=None):
"""Create symlinks for SAN records
:param ssl_dir: str Directory to create symlinks in
:param custom_hostname_link: str Additional link to be created
"""
hostname = get_hostname(unit_get('private-address'))
hostname_cert = os.path.jo... | python | def create_ip_cert_links(ssl_dir, custom_hostname_link=None):
"""Create symlinks for SAN records
:param ssl_dir: str Directory to create symlinks in
:param custom_hostname_link: str Additional link to be created
"""
hostname = get_hostname(unit_get('private-address'))
hostname_cert = os.path.jo... | [
"def",
"create_ip_cert_links",
"(",
"ssl_dir",
",",
"custom_hostname_link",
"=",
"None",
")",
":",
"hostname",
"=",
"get_hostname",
"(",
"unit_get",
"(",
"'private-address'",
")",
")",
"hostname_cert",
"=",
"os",
".",
"path",
".",
"join",
"(",
"ssl_dir",
",",
... | Create symlinks for SAN records
:param ssl_dir: str Directory to create symlinks in
:param custom_hostname_link: str Additional link to be created | [
"Create",
"symlinks",
"for",
"SAN",
"records"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L146-L180 |
12,817 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | install_certs | def install_certs(ssl_dir, certs, chain=None, user='root', group='root'):
"""Install the certs passed into the ssl dir and append the chain if
provided.
:param ssl_dir: str Directory to create symlinks in
:param certs: {} {'cn': {'cert': 'CERT', 'key': 'KEY'}}
:param chain: str Chain to be appen... | python | def install_certs(ssl_dir, certs, chain=None, user='root', group='root'):
"""Install the certs passed into the ssl dir and append the chain if
provided.
:param ssl_dir: str Directory to create symlinks in
:param certs: {} {'cn': {'cert': 'CERT', 'key': 'KEY'}}
:param chain: str Chain to be appen... | [
"def",
"install_certs",
"(",
"ssl_dir",
",",
"certs",
",",
"chain",
"=",
"None",
",",
"user",
"=",
"'root'",
",",
"group",
"=",
"'root'",
")",
":",
"for",
"cn",
",",
"bundle",
"in",
"certs",
".",
"items",
"(",
")",
":",
"cert_filename",
"=",
"'cert_{... | Install the certs passed into the ssl dir and append the chain if
provided.
:param ssl_dir: str Directory to create symlinks in
:param certs: {} {'cn': {'cert': 'CERT', 'key': 'KEY'}}
:param chain: str Chain to be appended to certs
:param user: (Optional) Owner of certificate files. Defaults to ... | [
"Install",
"the",
"certs",
"passed",
"into",
"the",
"ssl",
"dir",
"and",
"append",
"the",
"chain",
"if",
"provided",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L183-L208 |
12,818 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | process_certificates | def process_certificates(service_name, relation_id, unit,
custom_hostname_link=None, user='root', group='root'):
"""Process the certificates supplied down the relation
:param service_name: str Name of service the certifcates are for.
:param relation_id: str Relation id providing th... | python | def process_certificates(service_name, relation_id, unit,
custom_hostname_link=None, user='root', group='root'):
"""Process the certificates supplied down the relation
:param service_name: str Name of service the certifcates are for.
:param relation_id: str Relation id providing th... | [
"def",
"process_certificates",
"(",
"service_name",
",",
"relation_id",
",",
"unit",
",",
"custom_hostname_link",
"=",
"None",
",",
"user",
"=",
"'root'",
",",
"group",
"=",
"'root'",
")",
":",
"data",
"=",
"relation_get",
"(",
"rid",
"=",
"relation_id",
","... | Process the certificates supplied down the relation
:param service_name: str Name of service the certifcates are for.
:param relation_id: str Relation id providing the certs
:param unit: str Unit providing the certs
:param custom_hostname_link: str Name of custom link to create
:param user: (Option... | [
"Process",
"the",
"certificates",
"supplied",
"down",
"the",
"relation"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L211-L241 |
12,819 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | get_requests_for_local_unit | def get_requests_for_local_unit(relation_name=None):
"""Extract any certificates data targeted at this unit down relation_name.
:param relation_name: str Name of relation to check for data.
:returns: List of bundles of certificates.
:rtype: List of dicts
"""
local_name = local_unit().replace('/... | python | def get_requests_for_local_unit(relation_name=None):
"""Extract any certificates data targeted at this unit down relation_name.
:param relation_name: str Name of relation to check for data.
:returns: List of bundles of certificates.
:rtype: List of dicts
"""
local_name = local_unit().replace('/... | [
"def",
"get_requests_for_local_unit",
"(",
"relation_name",
"=",
"None",
")",
":",
"local_name",
"=",
"local_unit",
"(",
")",
".",
"replace",
"(",
"'/'",
",",
"'_'",
")",
"raw_certs_key",
"=",
"'{}.processed_requests'",
".",
"format",
"(",
"local_name",
")",
"... | Extract any certificates data targeted at this unit down relation_name.
:param relation_name: str Name of relation to check for data.
:returns: List of bundles of certificates.
:rtype: List of dicts | [
"Extract",
"any",
"certificates",
"data",
"targeted",
"at",
"this",
"unit",
"down",
"relation_name",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L244-L263 |
12,820 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | get_bundle_for_cn | def get_bundle_for_cn(cn, relation_name=None):
"""Extract certificates for the given cn.
:param cn: str Canonical Name on certificate.
:param relation_name: str Relation to check for certificates down.
:returns: Dictionary of certificate data,
:rtype: dict.
"""
entries = get_requests_for_lo... | python | def get_bundle_for_cn(cn, relation_name=None):
"""Extract certificates for the given cn.
:param cn: str Canonical Name on certificate.
:param relation_name: str Relation to check for certificates down.
:returns: Dictionary of certificate data,
:rtype: dict.
"""
entries = get_requests_for_lo... | [
"def",
"get_bundle_for_cn",
"(",
"cn",
",",
"relation_name",
"=",
"None",
")",
":",
"entries",
"=",
"get_requests_for_local_unit",
"(",
"relation_name",
")",
"cert_bundle",
"=",
"{",
"}",
"for",
"entry",
"in",
"entries",
":",
"for",
"_cn",
",",
"bundle",
"in... | Extract certificates for the given cn.
:param cn: str Canonical Name on certificate.
:param relation_name: str Relation to check for certificates down.
:returns: Dictionary of certificate data,
:rtype: dict. | [
"Extract",
"certificates",
"for",
"the",
"given",
"cn",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L266-L287 |
12,821 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | CertRequest.add_entry | def add_entry(self, net_type, cn, addresses):
"""Add a request to the batch
:param net_type: str netwrok space name request is for
:param cn: str Canonical Name for certificate
:param addresses: [] List of addresses to be used as SANs
"""
self.entries.append({
... | python | def add_entry(self, net_type, cn, addresses):
"""Add a request to the batch
:param net_type: str netwrok space name request is for
:param cn: str Canonical Name for certificate
:param addresses: [] List of addresses to be used as SANs
"""
self.entries.append({
... | [
"def",
"add_entry",
"(",
"self",
",",
"net_type",
",",
"cn",
",",
"addresses",
")",
":",
"self",
".",
"entries",
".",
"append",
"(",
"{",
"'cn'",
":",
"cn",
",",
"'addresses'",
":",
"addresses",
"}",
")"
] | Add a request to the batch
:param net_type: str netwrok space name request is for
:param cn: str Canonical Name for certificate
:param addresses: [] List of addresses to be used as SANs | [
"Add",
"a",
"request",
"to",
"the",
"batch"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L64-L73 |
12,822 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | CertRequest.add_hostname_cn | def add_hostname_cn(self):
"""Add a request for the hostname of the machine"""
ip = unit_get('private-address')
addresses = [ip]
# If a vip is being used without os-hostname config or
# network spaces then we need to ensure the local units
# cert has the approriate vip in... | python | def add_hostname_cn(self):
"""Add a request for the hostname of the machine"""
ip = unit_get('private-address')
addresses = [ip]
# If a vip is being used without os-hostname config or
# network spaces then we need to ensure the local units
# cert has the approriate vip in... | [
"def",
"add_hostname_cn",
"(",
"self",
")",
":",
"ip",
"=",
"unit_get",
"(",
"'private-address'",
")",
"addresses",
"=",
"[",
"ip",
"]",
"# If a vip is being used without os-hostname config or",
"# network spaces then we need to ensure the local units",
"# cert has the approria... | Add a request for the hostname of the machine | [
"Add",
"a",
"request",
"for",
"the",
"hostname",
"of",
"the",
"machine"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L75-L87 |
12,823 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | CertRequest.add_hostname_cn_ip | def add_hostname_cn_ip(self, addresses):
"""Add an address to the SAN list for the hostname request
:param addr: [] List of address to be added
"""
for addr in addresses:
if addr not in self.hostname_entry['addresses']:
self.hostname_entry['addresses'].append... | python | def add_hostname_cn_ip(self, addresses):
"""Add an address to the SAN list for the hostname request
:param addr: [] List of address to be added
"""
for addr in addresses:
if addr not in self.hostname_entry['addresses']:
self.hostname_entry['addresses'].append... | [
"def",
"add_hostname_cn_ip",
"(",
"self",
",",
"addresses",
")",
":",
"for",
"addr",
"in",
"addresses",
":",
"if",
"addr",
"not",
"in",
"self",
".",
"hostname_entry",
"[",
"'addresses'",
"]",
":",
"self",
".",
"hostname_entry",
"[",
"'addresses'",
"]",
"."... | Add an address to the SAN list for the hostname request
:param addr: [] List of address to be added | [
"Add",
"an",
"address",
"to",
"the",
"SAN",
"list",
"for",
"the",
"hostname",
"request"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L89-L96 |
12,824 | juju/charm-helpers | charmhelpers/contrib/openstack/cert_utils.py | CertRequest.get_request | def get_request(self):
"""Generate request from the batched up entries
"""
if self.hostname_entry:
self.entries.append(self.hostname_entry)
request = {}
for entry in self.entries:
sans = sorted(list(set(entry['addresses'])))
request[entry['cn'... | python | def get_request(self):
"""Generate request from the batched up entries
"""
if self.hostname_entry:
self.entries.append(self.hostname_entry)
request = {}
for entry in self.entries:
sans = sorted(list(set(entry['addresses'])))
request[entry['cn'... | [
"def",
"get_request",
"(",
"self",
")",
":",
"if",
"self",
".",
"hostname_entry",
":",
"self",
".",
"entries",
".",
"append",
"(",
"self",
".",
"hostname_entry",
")",
"request",
"=",
"{",
"}",
"for",
"entry",
"in",
"self",
".",
"entries",
":",
"sans",
... | Generate request from the batched up entries | [
"Generate",
"request",
"from",
"the",
"batched",
"up",
"entries"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/cert_utils.py#L98-L111 |
12,825 | juju/charm-helpers | charmhelpers/contrib/hardening/host/checks/sysctl.py | get_audits | def get_audits():
"""Get OS hardening sysctl audits.
:returns: dictionary of audits
"""
audits = []
settings = utils.get_settings('os')
# Apply the sysctl settings which are configured to be applied.
audits.append(SysctlConf())
# Make sure that only root has access to the sysctl.conf ... | python | def get_audits():
"""Get OS hardening sysctl audits.
:returns: dictionary of audits
"""
audits = []
settings = utils.get_settings('os')
# Apply the sysctl settings which are configured to be applied.
audits.append(SysctlConf())
# Make sure that only root has access to the sysctl.conf ... | [
"def",
"get_audits",
"(",
")",
":",
"audits",
"=",
"[",
"]",
"settings",
"=",
"utils",
".",
"get_settings",
"(",
"'os'",
")",
"# Apply the sysctl settings which are configured to be applied.",
"audits",
".",
"append",
"(",
"SysctlConf",
"(",
")",
")",
"# Make sure... | Get OS hardening sysctl audits.
:returns: dictionary of audits | [
"Get",
"OS",
"hardening",
"sysctl",
"audits",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/host/checks/sysctl.py#L77-L97 |
12,826 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | _stat | def _stat(file):
"""
Get the Ownership information from a file.
:param file: The path to a file to stat
:type file: str
:returns: owner, group, and mode of the specified file
:rtype: Ownership
:raises subprocess.CalledProcessError: If the underlying stat fails
"""
out = subprocess.c... | python | def _stat(file):
"""
Get the Ownership information from a file.
:param file: The path to a file to stat
:type file: str
:returns: owner, group, and mode of the specified file
:rtype: Ownership
:raises subprocess.CalledProcessError: If the underlying stat fails
"""
out = subprocess.c... | [
"def",
"_stat",
"(",
"file",
")",
":",
"out",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"'stat'",
",",
"'-c'",
",",
"'%U %G %a'",
",",
"file",
"]",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"return",
"Ownership",
"(",
"*",
"out",
".",
"strip",... | Get the Ownership information from a file.
:param file: The path to a file to stat
:type file: str
:returns: owner, group, and mode of the specified file
:rtype: Ownership
:raises subprocess.CalledProcessError: If the underlying stat fails | [
"Get",
"the",
"Ownership",
"information",
"from",
"a",
"file",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L104-L116 |
12,827 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | _config_ini | def _config_ini(path):
"""
Parse an ini file
:param path: The path to a file to parse
:type file: str
:returns: Configuration contained in path
:rtype: Dict
"""
conf = configparser.ConfigParser()
conf.read(path)
return dict(conf) | python | def _config_ini(path):
"""
Parse an ini file
:param path: The path to a file to parse
:type file: str
:returns: Configuration contained in path
:rtype: Dict
"""
conf = configparser.ConfigParser()
conf.read(path)
return dict(conf) | [
"def",
"_config_ini",
"(",
"path",
")",
":",
"conf",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"conf",
".",
"read",
"(",
"path",
")",
"return",
"dict",
"(",
"conf",
")"
] | Parse an ini file
:param path: The path to a file to parse
:type file: str
:returns: Configuration contained in path
:rtype: Dict | [
"Parse",
"an",
"ini",
"file"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L120-L131 |
12,828 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | _validate_file_mode | def _validate_file_mode(mode, file_name, optional=False):
"""
Validate that a specified file has the specified permissions.
:param mode: file mode that is desires
:type owner: str
:param file_name: Path to the file to verify
:type file_name: str
:param optional: Is this file optional,
... | python | def _validate_file_mode(mode, file_name, optional=False):
"""
Validate that a specified file has the specified permissions.
:param mode: file mode that is desires
:type owner: str
:param file_name: Path to the file to verify
:type file_name: str
:param optional: Is this file optional,
... | [
"def",
"_validate_file_mode",
"(",
"mode",
",",
"file_name",
",",
"optional",
"=",
"False",
")",
":",
"try",
":",
"ownership",
"=",
"_stat",
"(",
"file_name",
")",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"e",
":",
"print",
"(",
"\"Error read... | Validate that a specified file has the specified permissions.
:param mode: file mode that is desires
:type owner: str
:param file_name: Path to the file to verify
:type file_name: str
:param optional: Is this file optional,
ie: Should this test fail when it's missing
:type ... | [
"Validate",
"that",
"a",
"specified",
"file",
"has",
"the",
"specified",
"permissions",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L163-L184 |
12,829 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | _config_section | def _config_section(config, section):
"""Read the configuration file and return a section."""
path = os.path.join(config.get('config_path'), config.get('config_file'))
conf = _config_ini(path)
return conf.get(section) | python | def _config_section(config, section):
"""Read the configuration file and return a section."""
path = os.path.join(config.get('config_path'), config.get('config_file'))
conf = _config_ini(path)
return conf.get(section) | [
"def",
"_config_section",
"(",
"config",
",",
"section",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"config",
".",
"get",
"(",
"'config_path'",
")",
",",
"config",
".",
"get",
"(",
"'config_file'",
")",
")",
"conf",
"=",
"_config_ini",... | Read the configuration file and return a section. | [
"Read",
"the",
"configuration",
"file",
"and",
"return",
"a",
"section",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L188-L192 |
12,830 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | validate_file_permissions | def validate_file_permissions(config):
"""Verify that permissions on configuration files are secure enough."""
files = config.get('files', {})
for file_name, options in files.items():
for key in options.keys():
if key not in ["owner", "group", "mode"]:
raise RuntimeError(... | python | def validate_file_permissions(config):
"""Verify that permissions on configuration files are secure enough."""
files = config.get('files', {})
for file_name, options in files.items():
for key in options.keys():
if key not in ["owner", "group", "mode"]:
raise RuntimeError(... | [
"def",
"validate_file_permissions",
"(",
"config",
")",
":",
"files",
"=",
"config",
".",
"get",
"(",
"'files'",
",",
"{",
"}",
")",
"for",
"file_name",
",",
"options",
"in",
"files",
".",
"items",
"(",
")",
":",
"for",
"key",
"in",
"options",
".",
"... | Verify that permissions on configuration files are secure enough. | [
"Verify",
"that",
"permissions",
"on",
"configuration",
"files",
"are",
"secure",
"enough",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L220-L237 |
12,831 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | validate_uses_tls_for_keystone | def validate_uses_tls_for_keystone(audit_options):
"""Verify that TLS is used to communicate with Keystone."""
section = _config_section(audit_options, 'keystone_authtoken')
assert section is not None, "Missing section 'keystone_authtoken'"
assert not section.get('insecure') and \
"https://" in ... | python | def validate_uses_tls_for_keystone(audit_options):
"""Verify that TLS is used to communicate with Keystone."""
section = _config_section(audit_options, 'keystone_authtoken')
assert section is not None, "Missing section 'keystone_authtoken'"
assert not section.get('insecure') and \
"https://" in ... | [
"def",
"validate_uses_tls_for_keystone",
"(",
"audit_options",
")",
":",
"section",
"=",
"_config_section",
"(",
"audit_options",
",",
"'keystone_authtoken'",
")",
"assert",
"section",
"is",
"not",
"None",
",",
"\"Missing section 'keystone_authtoken'\"",
"assert",
"not",
... | Verify that TLS is used to communicate with Keystone. | [
"Verify",
"that",
"TLS",
"is",
"used",
"to",
"communicate",
"with",
"Keystone",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L250-L256 |
12,832 | juju/charm-helpers | charmhelpers/contrib/openstack/audits/openstack_security_guide.py | validate_uses_tls_for_glance | def validate_uses_tls_for_glance(audit_options):
"""Verify that TLS is used to communicate with Glance."""
section = _config_section(audit_options, 'glance')
assert section is not None, "Missing section 'glance'"
assert not section.get('insecure') and \
"https://" in section.get("api_servers"), ... | python | def validate_uses_tls_for_glance(audit_options):
"""Verify that TLS is used to communicate with Glance."""
section = _config_section(audit_options, 'glance')
assert section is not None, "Missing section 'glance'"
assert not section.get('insecure') and \
"https://" in section.get("api_servers"), ... | [
"def",
"validate_uses_tls_for_glance",
"(",
"audit_options",
")",
":",
"section",
"=",
"_config_section",
"(",
"audit_options",
",",
"'glance'",
")",
"assert",
"section",
"is",
"not",
"None",
",",
"\"Missing section 'glance'\"",
"assert",
"not",
"section",
".",
"get... | Verify that TLS is used to communicate with Glance. | [
"Verify",
"that",
"TLS",
"is",
"used",
"to",
"communicate",
"with",
"Glance",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/openstack_security_guide.py#L260-L266 |
12,833 | juju/charm-helpers | charmhelpers/core/services/helpers.py | RelationContext.is_ready | def is_ready(self):
"""
Returns True if all of the `required_keys` are available from any units.
"""
ready = len(self.get(self.name, [])) > 0
if not ready:
hookenv.log('Incomplete relation: {}'.format(self.__class__.__name__), hookenv.DEBUG)
return ready | python | def is_ready(self):
"""
Returns True if all of the `required_keys` are available from any units.
"""
ready = len(self.get(self.name, [])) > 0
if not ready:
hookenv.log('Incomplete relation: {}'.format(self.__class__.__name__), hookenv.DEBUG)
return ready | [
"def",
"is_ready",
"(",
"self",
")",
":",
"ready",
"=",
"len",
"(",
"self",
".",
"get",
"(",
"self",
".",
"name",
",",
"[",
"]",
")",
")",
">",
"0",
"if",
"not",
"ready",
":",
"hookenv",
".",
"log",
"(",
"'Incomplete relation: {}'",
".",
"format",
... | Returns True if all of the `required_keys` are available from any units. | [
"Returns",
"True",
"if",
"all",
"of",
"the",
"required_keys",
"are",
"available",
"from",
"any",
"units",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/helpers.py#L70-L77 |
12,834 | juju/charm-helpers | charmhelpers/core/services/helpers.py | RelationContext._is_ready | def _is_ready(self, unit_data):
"""
Helper method that tests a set of relation data and returns True if
all of the `required_keys` are present.
"""
return set(unit_data.keys()).issuperset(set(self.required_keys)) | python | def _is_ready(self, unit_data):
"""
Helper method that tests a set of relation data and returns True if
all of the `required_keys` are present.
"""
return set(unit_data.keys()).issuperset(set(self.required_keys)) | [
"def",
"_is_ready",
"(",
"self",
",",
"unit_data",
")",
":",
"return",
"set",
"(",
"unit_data",
".",
"keys",
"(",
")",
")",
".",
"issuperset",
"(",
"set",
"(",
"self",
".",
"required_keys",
")",
")"
] | Helper method that tests a set of relation data and returns True if
all of the `required_keys` are present. | [
"Helper",
"method",
"that",
"tests",
"a",
"set",
"of",
"relation",
"data",
"and",
"returns",
"True",
"if",
"all",
"of",
"the",
"required_keys",
"are",
"present",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/helpers.py#L79-L84 |
12,835 | juju/charm-helpers | charmhelpers/core/services/base.py | service_restart | def service_restart(service_name):
"""
Wrapper around host.service_restart to prevent spurious "unknown service"
messages in the logs.
"""
if host.service_available(service_name):
if host.service_running(service_name):
host.service_restart(service_name)
else:
... | python | def service_restart(service_name):
"""
Wrapper around host.service_restart to prevent spurious "unknown service"
messages in the logs.
"""
if host.service_available(service_name):
if host.service_running(service_name):
host.service_restart(service_name)
else:
... | [
"def",
"service_restart",
"(",
"service_name",
")",
":",
"if",
"host",
".",
"service_available",
"(",
"service_name",
")",
":",
"if",
"host",
".",
"service_running",
"(",
"service_name",
")",
":",
"host",
".",
"service_restart",
"(",
"service_name",
")",
"else... | Wrapper around host.service_restart to prevent spurious "unknown service"
messages in the logs. | [
"Wrapper",
"around",
"host",
".",
"service_restart",
"to",
"prevent",
"spurious",
"unknown",
"service",
"messages",
"in",
"the",
"logs",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L349-L358 |
12,836 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.manage | def manage(self):
"""
Handle the current hook by doing The Right Thing with the registered services.
"""
hookenv._run_atstart()
try:
hook_name = hookenv.hook_name()
if hook_name == 'stop':
self.stop_services()
else:
... | python | def manage(self):
"""
Handle the current hook by doing The Right Thing with the registered services.
"""
hookenv._run_atstart()
try:
hook_name = hookenv.hook_name()
if hook_name == 'stop':
self.stop_services()
else:
... | [
"def",
"manage",
"(",
"self",
")",
":",
"hookenv",
".",
"_run_atstart",
"(",
")",
"try",
":",
"hook_name",
"=",
"hookenv",
".",
"hook_name",
"(",
")",
"if",
"hook_name",
"==",
"'stop'",
":",
"self",
".",
"stop_services",
"(",
")",
"else",
":",
"self",
... | Handle the current hook by doing The Right Thing with the registered services. | [
"Handle",
"the",
"current",
"hook",
"by",
"doing",
"The",
"Right",
"Thing",
"with",
"the",
"registered",
"services",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L125-L140 |
12,837 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.provide_data | def provide_data(self):
"""
Set the relation data for each provider in the ``provided_data`` list.
A provider must have a `name` attribute, which indicates which relation
to set data on, and a `provide_data()` method, which returns a dict of
data to set.
The `provide_da... | python | def provide_data(self):
"""
Set the relation data for each provider in the ``provided_data`` list.
A provider must have a `name` attribute, which indicates which relation
to set data on, and a `provide_data()` method, which returns a dict of
data to set.
The `provide_da... | [
"def",
"provide_data",
"(",
"self",
")",
":",
"for",
"service_name",
",",
"service",
"in",
"self",
".",
"services",
".",
"items",
"(",
")",
":",
"service_ready",
"=",
"self",
".",
"is_ready",
"(",
"service_name",
")",
"for",
"provider",
"in",
"service",
... | Set the relation data for each provider in the ``provided_data`` list.
A provider must have a `name` attribute, which indicates which relation
to set data on, and a `provide_data()` method, which returns a dict of
data to set.
The `provide_data()` method can optionally accept two param... | [
"Set",
"the",
"relation",
"data",
"for",
"each",
"provider",
"in",
"the",
"provided_data",
"list",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L142-L178 |
12,838 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.reconfigure_services | def reconfigure_services(self, *service_names):
"""
Update all files for one or more registered services, and,
if ready, optionally restart them.
If no service names are given, reconfigures all registered services.
"""
for service_name in service_names or self.services.k... | python | def reconfigure_services(self, *service_names):
"""
Update all files for one or more registered services, and,
if ready, optionally restart them.
If no service names are given, reconfigures all registered services.
"""
for service_name in service_names or self.services.k... | [
"def",
"reconfigure_services",
"(",
"self",
",",
"*",
"service_names",
")",
":",
"for",
"service_name",
"in",
"service_names",
"or",
"self",
".",
"services",
".",
"keys",
"(",
")",
":",
"if",
"self",
".",
"is_ready",
"(",
"service_name",
")",
":",
"self",
... | Update all files for one or more registered services, and,
if ready, optionally restart them.
If no service names are given, reconfigures all registered services. | [
"Update",
"all",
"files",
"for",
"one",
"or",
"more",
"registered",
"services",
"and",
"if",
"ready",
"optionally",
"restart",
"them",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L180-L200 |
12,839 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.stop_services | def stop_services(self, *service_names):
"""
Stop one or more registered services, by name.
If no service names are given, stops all registered services.
"""
for service_name in service_names or self.services.keys():
self.fire_event('stop', service_name, default=[
... | python | def stop_services(self, *service_names):
"""
Stop one or more registered services, by name.
If no service names are given, stops all registered services.
"""
for service_name in service_names or self.services.keys():
self.fire_event('stop', service_name, default=[
... | [
"def",
"stop_services",
"(",
"self",
",",
"*",
"service_names",
")",
":",
"for",
"service_name",
"in",
"service_names",
"or",
"self",
".",
"services",
".",
"keys",
"(",
")",
":",
"self",
".",
"fire_event",
"(",
"'stop'",
",",
"service_name",
",",
"default"... | Stop one or more registered services, by name.
If no service names are given, stops all registered services. | [
"Stop",
"one",
"or",
"more",
"registered",
"services",
"by",
"name",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L202-L211 |
12,840 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.get_service | def get_service(self, service_name):
"""
Given the name of a registered service, return its service definition.
"""
service = self.services.get(service_name)
if not service:
raise KeyError('Service not registered: %s' % service_name)
return service | python | def get_service(self, service_name):
"""
Given the name of a registered service, return its service definition.
"""
service = self.services.get(service_name)
if not service:
raise KeyError('Service not registered: %s' % service_name)
return service | [
"def",
"get_service",
"(",
"self",
",",
"service_name",
")",
":",
"service",
"=",
"self",
".",
"services",
".",
"get",
"(",
"service_name",
")",
"if",
"not",
"service",
":",
"raise",
"KeyError",
"(",
"'Service not registered: %s'",
"%",
"service_name",
")",
... | Given the name of a registered service, return its service definition. | [
"Given",
"the",
"name",
"of",
"a",
"registered",
"service",
"return",
"its",
"service",
"definition",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L213-L220 |
12,841 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.fire_event | def fire_event(self, event_name, service_name, default=None):
"""
Fire a data_ready, data_lost, start, or stop event on a given service.
"""
service = self.get_service(service_name)
callbacks = service.get(event_name, default)
if not callbacks:
return
... | python | def fire_event(self, event_name, service_name, default=None):
"""
Fire a data_ready, data_lost, start, or stop event on a given service.
"""
service = self.get_service(service_name)
callbacks = service.get(event_name, default)
if not callbacks:
return
... | [
"def",
"fire_event",
"(",
"self",
",",
"event_name",
",",
"service_name",
",",
"default",
"=",
"None",
")",
":",
"service",
"=",
"self",
".",
"get_service",
"(",
"service_name",
")",
"callbacks",
"=",
"service",
".",
"get",
"(",
"event_name",
",",
"default... | Fire a data_ready, data_lost, start, or stop event on a given service. | [
"Fire",
"a",
"data_ready",
"data_lost",
"start",
"or",
"stop",
"event",
"on",
"a",
"given",
"service",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L222-L236 |
12,842 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.is_ready | def is_ready(self, service_name):
"""
Determine if a registered service is ready, by checking its 'required_data'.
A 'required_data' item can be any mapping type, and is considered ready
if `bool(item)` evaluates as True.
"""
service = self.get_service(service_name)
... | python | def is_ready(self, service_name):
"""
Determine if a registered service is ready, by checking its 'required_data'.
A 'required_data' item can be any mapping type, and is considered ready
if `bool(item)` evaluates as True.
"""
service = self.get_service(service_name)
... | [
"def",
"is_ready",
"(",
"self",
",",
"service_name",
")",
":",
"service",
"=",
"self",
".",
"get_service",
"(",
"service_name",
")",
"reqs",
"=",
"service",
".",
"get",
"(",
"'required_data'",
",",
"[",
"]",
")",
"return",
"all",
"(",
"bool",
"(",
"req... | Determine if a registered service is ready, by checking its 'required_data'.
A 'required_data' item can be any mapping type, and is considered ready
if `bool(item)` evaluates as True. | [
"Determine",
"if",
"a",
"registered",
"service",
"is",
"ready",
"by",
"checking",
"its",
"required_data",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L238-L247 |
12,843 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.save_ready | def save_ready(self, service_name):
"""
Save an indicator that the given service is now data_ready.
"""
self._load_ready_file()
self._ready.add(service_name)
self._save_ready_file() | python | def save_ready(self, service_name):
"""
Save an indicator that the given service is now data_ready.
"""
self._load_ready_file()
self._ready.add(service_name)
self._save_ready_file() | [
"def",
"save_ready",
"(",
"self",
",",
"service_name",
")",
":",
"self",
".",
"_load_ready_file",
"(",
")",
"self",
".",
"_ready",
".",
"add",
"(",
"service_name",
")",
"self",
".",
"_save_ready_file",
"(",
")"
] | Save an indicator that the given service is now data_ready. | [
"Save",
"an",
"indicator",
"that",
"the",
"given",
"service",
"is",
"now",
"data_ready",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L264-L270 |
12,844 | juju/charm-helpers | charmhelpers/core/services/base.py | ServiceManager.save_lost | def save_lost(self, service_name):
"""
Save an indicator that the given service is no longer data_ready.
"""
self._load_ready_file()
self._ready.discard(service_name)
self._save_ready_file() | python | def save_lost(self, service_name):
"""
Save an indicator that the given service is no longer data_ready.
"""
self._load_ready_file()
self._ready.discard(service_name)
self._save_ready_file() | [
"def",
"save_lost",
"(",
"self",
",",
"service_name",
")",
":",
"self",
".",
"_load_ready_file",
"(",
")",
"self",
".",
"_ready",
".",
"discard",
"(",
"service_name",
")",
"self",
".",
"_save_ready_file",
"(",
")"
] | Save an indicator that the given service is no longer data_ready. | [
"Save",
"an",
"indicator",
"that",
"the",
"given",
"service",
"is",
"no",
"longer",
"data_ready",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/services/base.py#L272-L278 |
12,845 | juju/charm-helpers | charmhelpers/contrib/network/ufw.py | is_enabled | def is_enabled():
"""
Check if `ufw` is enabled
:returns: True if ufw is enabled
"""
output = subprocess.check_output(['ufw', 'status'],
universal_newlines=True,
env={'LANG': 'en_US',
... | python | def is_enabled():
"""
Check if `ufw` is enabled
:returns: True if ufw is enabled
"""
output = subprocess.check_output(['ufw', 'status'],
universal_newlines=True,
env={'LANG': 'en_US',
... | [
"def",
"is_enabled",
"(",
")",
":",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"'ufw'",
",",
"'status'",
"]",
",",
"universal_newlines",
"=",
"True",
",",
"env",
"=",
"{",
"'LANG'",
":",
"'en_US'",
",",
"'PATH'",
":",
"os",
".",
"envir... | Check if `ufw` is enabled
:returns: True if ufw is enabled | [
"Check",
"if",
"ufw",
"is",
"enabled"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ufw.py#L56-L69 |
12,846 | juju/charm-helpers | charmhelpers/contrib/network/ufw.py | is_ipv6_ok | def is_ipv6_ok(soft_fail=False):
"""
Check if IPv6 support is present and ip6tables functional
:param soft_fail: If set to True and IPv6 support is broken, then reports
that the host doesn't have IPv6 support, otherwise a
UFWIPv6Error exception is raised.
:re... | python | def is_ipv6_ok(soft_fail=False):
"""
Check if IPv6 support is present and ip6tables functional
:param soft_fail: If set to True and IPv6 support is broken, then reports
that the host doesn't have IPv6 support, otherwise a
UFWIPv6Error exception is raised.
:re... | [
"def",
"is_ipv6_ok",
"(",
"soft_fail",
"=",
"False",
")",
":",
"# do we have IPv6 in the machine?",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"'/proc/sys/net/ipv6'",
")",
":",
"# is ip6tables kernel module loaded?",
"if",
"not",
"is_module_loaded",
"(",
"'ip6_tables... | Check if IPv6 support is present and ip6tables functional
:param soft_fail: If set to True and IPv6 support is broken, then reports
that the host doesn't have IPv6 support, otherwise a
UFWIPv6Error exception is raised.
:returns: True if IPv6 is working, False otherwi... | [
"Check",
"if",
"IPv6",
"support",
"is",
"present",
"and",
"ip6tables",
"functional"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ufw.py#L72-L106 |
12,847 | juju/charm-helpers | charmhelpers/contrib/network/ufw.py | default_policy | def default_policy(policy='deny', direction='incoming'):
"""
Changes the default policy for traffic `direction`
:param policy: allow, deny or reject
:param direction: traffic direction, possible values: incoming, outgoing,
routed
"""
if policy not in ['allow', 'deny', 'rej... | python | def default_policy(policy='deny', direction='incoming'):
"""
Changes the default policy for traffic `direction`
:param policy: allow, deny or reject
:param direction: traffic direction, possible values: incoming, outgoing,
routed
"""
if policy not in ['allow', 'deny', 'rej... | [
"def",
"default_policy",
"(",
"policy",
"=",
"'deny'",
",",
"direction",
"=",
"'incoming'",
")",
":",
"if",
"policy",
"not",
"in",
"[",
"'allow'",
",",
"'deny'",
",",
"'reject'",
"]",
":",
"raise",
"UFWError",
"(",
"(",
"'Unknown policy %s, valid values: '",
... | Changes the default policy for traffic `direction`
:param policy: allow, deny or reject
:param direction: traffic direction, possible values: incoming, outgoing,
routed | [
"Changes",
"the",
"default",
"policy",
"for",
"traffic",
"direction"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ufw.py#L203-L235 |
12,848 | juju/charm-helpers | charmhelpers/contrib/network/ufw.py | revoke_access | def revoke_access(src, dst='any', port=None, proto=None):
"""
Revoke access to an address or subnet
:param src: address (e.g. 192.168.1.234) or subnet
(e.g. 192.168.1.0/24).
:param dst: destiny of the connection, if the machine has multiple IPs and
connections to only on... | python | def revoke_access(src, dst='any', port=None, proto=None):
"""
Revoke access to an address or subnet
:param src: address (e.g. 192.168.1.234) or subnet
(e.g. 192.168.1.0/24).
:param dst: destiny of the connection, if the machine has multiple IPs and
connections to only on... | [
"def",
"revoke_access",
"(",
"src",
",",
"dst",
"=",
"'any'",
",",
"port",
"=",
"None",
",",
"proto",
"=",
"None",
")",
":",
"return",
"modify_access",
"(",
"src",
",",
"dst",
"=",
"dst",
",",
"port",
"=",
"port",
",",
"proto",
"=",
"proto",
",",
... | Revoke access to an address or subnet
:param src: address (e.g. 192.168.1.234) or subnet
(e.g. 192.168.1.0/24).
:param dst: destiny of the connection, if the machine has multiple IPs and
connections to only one of those have to accepted this is the
field has to b... | [
"Revoke",
"access",
"to",
"an",
"address",
"or",
"subnet"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ufw.py#L308-L320 |
12,849 | juju/charm-helpers | charmhelpers/core/kernel.py | rmmod | def rmmod(module, force=False):
"""Remove a module from the linux kernel"""
cmd = ['rmmod']
if force:
cmd.append('-f')
cmd.append(module)
log('Removing kernel module %s' % module, level=INFO)
return subprocess.check_call(cmd) | python | def rmmod(module, force=False):
"""Remove a module from the linux kernel"""
cmd = ['rmmod']
if force:
cmd.append('-f')
cmd.append(module)
log('Removing kernel module %s' % module, level=INFO)
return subprocess.check_call(cmd) | [
"def",
"rmmod",
"(",
"module",
",",
"force",
"=",
"False",
")",
":",
"cmd",
"=",
"[",
"'rmmod'",
"]",
"if",
"force",
":",
"cmd",
".",
"append",
"(",
"'-f'",
")",
"cmd",
".",
"append",
"(",
"module",
")",
"log",
"(",
"'Removing kernel module %s'",
"%"... | Remove a module from the linux kernel | [
"Remove",
"a",
"module",
"from",
"the",
"linux",
"kernel"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/kernel.py#L53-L60 |
12,850 | juju/charm-helpers | charmhelpers/core/kernel.py | is_module_loaded | def is_module_loaded(module):
"""Checks if a kernel module is already loaded"""
matches = re.findall('^%s[ ]+' % module, lsmod(), re.M)
return len(matches) > 0 | python | def is_module_loaded(module):
"""Checks if a kernel module is already loaded"""
matches = re.findall('^%s[ ]+' % module, lsmod(), re.M)
return len(matches) > 0 | [
"def",
"is_module_loaded",
"(",
"module",
")",
":",
"matches",
"=",
"re",
".",
"findall",
"(",
"'^%s[ ]+'",
"%",
"module",
",",
"lsmod",
"(",
")",
",",
"re",
".",
"M",
")",
"return",
"len",
"(",
"matches",
")",
">",
"0"
] | Checks if a kernel module is already loaded | [
"Checks",
"if",
"a",
"kernel",
"module",
"is",
"already",
"loaded"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/kernel.py#L69-L72 |
12,851 | juju/charm-helpers | charmhelpers/contrib/charmsupport/volumes.py | get_config | def get_config():
'''Gather and sanity-check volume configuration data'''
volume_config = {}
config = hookenv.config()
errors = False
if config.get('volume-ephemeral') in (True, 'True', 'true', 'Yes', 'yes'):
volume_config['ephemeral'] = True
else:
volume_config['ephemeral'] = ... | python | def get_config():
'''Gather and sanity-check volume configuration data'''
volume_config = {}
config = hookenv.config()
errors = False
if config.get('volume-ephemeral') in (True, 'True', 'true', 'Yes', 'yes'):
volume_config['ephemeral'] = True
else:
volume_config['ephemeral'] = ... | [
"def",
"get_config",
"(",
")",
":",
"volume_config",
"=",
"{",
"}",
"config",
"=",
"hookenv",
".",
"config",
"(",
")",
"errors",
"=",
"False",
"if",
"config",
".",
"get",
"(",
"'volume-ephemeral'",
")",
"in",
"(",
"True",
",",
"'True'",
",",
"'true'",
... | Gather and sanity-check volume configuration data | [
"Gather",
"and",
"sanity",
"-",
"check",
"volume",
"configuration",
"data"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/charmsupport/volumes.py#L73-L116 |
12,852 | juju/charm-helpers | charmhelpers/contrib/hardening/host/checks/limits.py | get_audits | def get_audits():
"""Get OS hardening security limits audits.
:returns: dictionary of audits
"""
audits = []
settings = utils.get_settings('os')
# Ensure that the /etc/security/limits.d directory is only writable
# by the root user, but others can execute and read.
audits.append(Direc... | python | def get_audits():
"""Get OS hardening security limits audits.
:returns: dictionary of audits
"""
audits = []
settings = utils.get_settings('os')
# Ensure that the /etc/security/limits.d directory is only writable
# by the root user, but others can execute and read.
audits.append(Direc... | [
"def",
"get_audits",
"(",
")",
":",
"audits",
"=",
"[",
"]",
"settings",
"=",
"utils",
".",
"get_settings",
"(",
"'os'",
")",
"# Ensure that the /etc/security/limits.d directory is only writable",
"# by the root user, but others can execute and read.",
"audits",
".",
"appen... | Get OS hardening security limits audits.
:returns: dictionary of audits | [
"Get",
"OS",
"hardening",
"security",
"limits",
"audits",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/host/checks/limits.py#L23-L44 |
12,853 | juju/charm-helpers | charmhelpers/contrib/hardening/audits/__init__.py | BaseAudit._take_action | def _take_action(self):
"""Determines whether to perform the action or not.
Checks whether or not an action should be taken. This is determined by
the truthy value for the unless parameter. If unless is a callback
method, it will be invoked with no parameters in order to determine
... | python | def _take_action(self):
"""Determines whether to perform the action or not.
Checks whether or not an action should be taken. This is determined by
the truthy value for the unless parameter. If unless is a callback
method, it will be invoked with no parameters in order to determine
... | [
"def",
"_take_action",
"(",
"self",
")",
":",
"# Do the action if there isn't an unless override.",
"if",
"self",
".",
"unless",
"is",
"None",
":",
"return",
"True",
"# Invoke the callback if there is one.",
"if",
"hasattr",
"(",
"self",
".",
"unless",
",",
"'__call__... | Determines whether to perform the action or not.
Checks whether or not an action should be taken. This is determined by
the truthy value for the unless parameter. If unless is a callback
method, it will be invoked with no parameters in order to determine
whether or not the action should... | [
"Determines",
"whether",
"to",
"perform",
"the",
"action",
"or",
"not",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/__init__.py#L36-L54 |
12,854 | juju/charm-helpers | charmhelpers/contrib/openstack/alternatives.py | install_alternative | def install_alternative(name, target, source, priority=50):
''' Install alternative configuration '''
if (os.path.exists(target) and not os.path.islink(target)):
# Move existing file/directory away before installing
shutil.move(target, '{}.bak'.format(target))
cmd = [
'update-alterna... | python | def install_alternative(name, target, source, priority=50):
''' Install alternative configuration '''
if (os.path.exists(target) and not os.path.islink(target)):
# Move existing file/directory away before installing
shutil.move(target, '{}.bak'.format(target))
cmd = [
'update-alterna... | [
"def",
"install_alternative",
"(",
"name",
",",
"target",
",",
"source",
",",
"priority",
"=",
"50",
")",
":",
"if",
"(",
"os",
".",
"path",
".",
"exists",
"(",
"target",
")",
"and",
"not",
"os",
".",
"path",
".",
"islink",
"(",
"target",
")",
")",... | Install alternative configuration | [
"Install",
"alternative",
"configuration"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/alternatives.py#L22-L31 |
12,855 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | ensure_packages | def ensure_packages(packages):
"""Install but do not upgrade required plugin packages."""
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True) | python | def ensure_packages(packages):
"""Install but do not upgrade required plugin packages."""
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True) | [
"def",
"ensure_packages",
"(",
"packages",
")",
":",
"required",
"=",
"filter_installed_packages",
"(",
"packages",
")",
"if",
"required",
":",
"apt_install",
"(",
"required",
",",
"fatal",
"=",
"True",
")"
] | Install but do not upgrade required plugin packages. | [
"Install",
"but",
"do",
"not",
"upgrade",
"required",
"plugin",
"packages",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L123-L127 |
12,856 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | _calculate_workers | def _calculate_workers():
'''
Determine the number of worker processes based on the CPU
count of the unit containing the application.
Workers will be limited to MAX_DEFAULT_WORKERS in
container environments where no worker-multipler configuration
option been set.
@returns int: number of wo... | python | def _calculate_workers():
'''
Determine the number of worker processes based on the CPU
count of the unit containing the application.
Workers will be limited to MAX_DEFAULT_WORKERS in
container environments where no worker-multipler configuration
option been set.
@returns int: number of wo... | [
"def",
"_calculate_workers",
"(",
")",
":",
"multiplier",
"=",
"config",
"(",
"'worker-multiplier'",
")",
"or",
"DEFAULT_MULTIPLIER",
"count",
"=",
"int",
"(",
"_num_cpus",
"(",
")",
"*",
"multiplier",
")",
"if",
"multiplier",
">",
"0",
"and",
"count",
"==",... | Determine the number of worker processes based on the CPU
count of the unit containing the application.
Workers will be limited to MAX_DEFAULT_WORKERS in
container environments where no worker-multipler configuration
option been set.
@returns int: number of worker processes to use | [
"Determine",
"the",
"number",
"of",
"worker",
"processes",
"based",
"on",
"the",
"CPU",
"count",
"of",
"the",
"unit",
"containing",
"the",
"application",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L1355-L1379 |
12,857 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | OSContextGenerator.get_related | def get_related(self):
"""Check if any of the context interfaces have relation ids.
Set self.related and return True if one of the interfaces
has relation ids.
"""
# Fresh start
self.related = False
try:
for interface in self.interfaces:
... | python | def get_related(self):
"""Check if any of the context interfaces have relation ids.
Set self.related and return True if one of the interfaces
has relation ids.
"""
# Fresh start
self.related = False
try:
for interface in self.interfaces:
... | [
"def",
"get_related",
"(",
"self",
")",
":",
"# Fresh start",
"self",
".",
"related",
"=",
"False",
"try",
":",
"for",
"interface",
"in",
"self",
".",
"interfaces",
":",
"if",
"relation_ids",
"(",
"interface",
")",
":",
"self",
".",
"related",
"=",
"True... | Check if any of the context interfaces have relation ids.
Set self.related and return True if one of the interfaces
has relation ids. | [
"Check",
"if",
"any",
"of",
"the",
"context",
"interfaces",
"have",
"relation",
"ids",
".",
"Set",
"self",
".",
"related",
"and",
"return",
"True",
"if",
"one",
"of",
"the",
"interfaces",
"has",
"relation",
"ids",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L174-L189 |
12,858 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | ApacheSSLContext.canonical_names | def canonical_names(self):
"""Figure out which canonical names clients will access this service.
"""
cns = []
for r_id in relation_ids('identity-service'):
for unit in related_units(r_id):
rdata = relation_get(rid=r_id, unit=unit)
for k in rdat... | python | def canonical_names(self):
"""Figure out which canonical names clients will access this service.
"""
cns = []
for r_id in relation_ids('identity-service'):
for unit in related_units(r_id):
rdata = relation_get(rid=r_id, unit=unit)
for k in rdat... | [
"def",
"canonical_names",
"(",
"self",
")",
":",
"cns",
"=",
"[",
"]",
"for",
"r_id",
"in",
"relation_ids",
"(",
"'identity-service'",
")",
":",
"for",
"unit",
"in",
"related_units",
"(",
"r_id",
")",
":",
"rdata",
"=",
"relation_get",
"(",
"rid",
"=",
... | Figure out which canonical names clients will access this service. | [
"Figure",
"out",
"which",
"canonical",
"names",
"clients",
"will",
"access",
"this",
"service",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L835-L846 |
12,859 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | VolumeAPIContext._determine_ctxt | def _determine_ctxt(self):
"""Determines the Volume API endpoint information.
Determines the appropriate version of the API that should be used
as well as the catalog_info string that would be supplied. Returns
a dict containing the volume_api_version and the volume_catalog_info.
... | python | def _determine_ctxt(self):
"""Determines the Volume API endpoint information.
Determines the appropriate version of the API that should be used
as well as the catalog_info string that would be supplied. Returns
a dict containing the volume_api_version and the volume_catalog_info.
... | [
"def",
"_determine_ctxt",
"(",
"self",
")",
":",
"rel",
"=",
"os_release",
"(",
"self",
".",
"pkg",
",",
"base",
"=",
"'icehouse'",
")",
"version",
"=",
"'2'",
"if",
"CompareOpenStackReleases",
"(",
"rel",
")",
">=",
"'pike'",
":",
"version",
"=",
"'3'",... | Determines the Volume API endpoint information.
Determines the appropriate version of the API that should be used
as well as the catalog_info string that would be supplied. Returns
a dict containing the volume_api_version and the volume_catalog_info. | [
"Determines",
"the",
"Volume",
"API",
"endpoint",
"information",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L1736-L1759 |
12,860 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | AppArmorContext._determine_ctxt | def _determine_ctxt(self):
"""
Validate aa-profile-mode settings is disable, enforce, or complain.
:return ctxt: Dictionary of the apparmor profile or None
"""
if config('aa-profile-mode') in ['disable', 'enforce', 'complain']:
ctxt = {'aa_profile_mode': config('aa-p... | python | def _determine_ctxt(self):
"""
Validate aa-profile-mode settings is disable, enforce, or complain.
:return ctxt: Dictionary of the apparmor profile or None
"""
if config('aa-profile-mode') in ['disable', 'enforce', 'complain']:
ctxt = {'aa_profile_mode': config('aa-p... | [
"def",
"_determine_ctxt",
"(",
"self",
")",
":",
"if",
"config",
"(",
"'aa-profile-mode'",
")",
"in",
"[",
"'disable'",
",",
"'enforce'",
",",
"'complain'",
"]",
":",
"ctxt",
"=",
"{",
"'aa_profile_mode'",
":",
"config",
"(",
"'aa-profile-mode'",
")",
",",
... | Validate aa-profile-mode settings is disable, enforce, or complain.
:return ctxt: Dictionary of the apparmor profile or None | [
"Validate",
"aa",
"-",
"profile",
"-",
"mode",
"settings",
"is",
"disable",
"enforce",
"or",
"complain",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L1780-L1793 |
12,861 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | AppArmorContext.manually_disable_aa_profile | def manually_disable_aa_profile(self):
"""
Manually disable an apparmor profile.
If aa-profile-mode is set to disabled (default) this is required as the
template has been written but apparmor is yet unaware of the profile
and aa-disable aa-profile fails. Without this the profile... | python | def manually_disable_aa_profile(self):
"""
Manually disable an apparmor profile.
If aa-profile-mode is set to disabled (default) this is required as the
template has been written but apparmor is yet unaware of the profile
and aa-disable aa-profile fails. Without this the profile... | [
"def",
"manually_disable_aa_profile",
"(",
"self",
")",
":",
"profile_path",
"=",
"'/etc/apparmor.d'",
"disable_path",
"=",
"'/etc/apparmor.d/disable'",
"if",
"not",
"os",
".",
"path",
".",
"lexists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"disable_path",
","... | Manually disable an apparmor profile.
If aa-profile-mode is set to disabled (default) this is required as the
template has been written but apparmor is yet unaware of the profile
and aa-disable aa-profile fails. Without this the profile would kick
into enforce mode on the next service r... | [
"Manually",
"disable",
"an",
"apparmor",
"profile",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L1805-L1819 |
12,862 | juju/charm-helpers | charmhelpers/contrib/openstack/context.py | AppArmorContext.setup_aa_profile | def setup_aa_profile(self):
"""
Setup an apparmor profile.
The ctxt dictionary will contain the apparmor profile mode and
the apparmor profile name.
Makes calls out to aa-disable, aa-complain, or aa-enforce to setup
the apparmor profile.
"""
self()
... | python | def setup_aa_profile(self):
"""
Setup an apparmor profile.
The ctxt dictionary will contain the apparmor profile mode and
the apparmor profile name.
Makes calls out to aa-disable, aa-complain, or aa-enforce to setup
the apparmor profile.
"""
self()
... | [
"def",
"setup_aa_profile",
"(",
"self",
")",
":",
"self",
"(",
")",
"if",
"not",
"self",
".",
"ctxt",
":",
"log",
"(",
"\"Not enabling apparmor Profile\"",
")",
"return",
"self",
".",
"install_aa_utils",
"(",
")",
"cmd",
"=",
"[",
"'aa-{}'",
".",
"format",... | Setup an apparmor profile.
The ctxt dictionary will contain the apparmor profile mode and
the apparmor profile name.
Makes calls out to aa-disable, aa-complain, or aa-enforce to setup
the apparmor profile. | [
"Setup",
"an",
"apparmor",
"profile",
".",
"The",
"ctxt",
"dictionary",
"will",
"contain",
"the",
"apparmor",
"profile",
"mode",
"and",
"the",
"apparmor",
"profile",
"name",
".",
"Makes",
"calls",
"out",
"to",
"aa",
"-",
"disable",
"aa",
"-",
"complain",
"... | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/context.py#L1821-L1854 |
12,863 | juju/charm-helpers | charmhelpers/payload/execd.py | execd_module_paths | def execd_module_paths(execd_dir=None):
"""Generate a list of full paths to modules within execd_dir."""
if not execd_dir:
execd_dir = default_execd_dir()
if not os.path.exists(execd_dir):
return
for subpath in os.listdir(execd_dir):
module = os.path.join(execd_dir, subpath)
... | python | def execd_module_paths(execd_dir=None):
"""Generate a list of full paths to modules within execd_dir."""
if not execd_dir:
execd_dir = default_execd_dir()
if not os.path.exists(execd_dir):
return
for subpath in os.listdir(execd_dir):
module = os.path.join(execd_dir, subpath)
... | [
"def",
"execd_module_paths",
"(",
"execd_dir",
"=",
"None",
")",
":",
"if",
"not",
"execd_dir",
":",
"execd_dir",
"=",
"default_execd_dir",
"(",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"execd_dir",
")",
":",
"return",
"for",
"subpath",
"... | Generate a list of full paths to modules within execd_dir. | [
"Generate",
"a",
"list",
"of",
"full",
"paths",
"to",
"modules",
"within",
"execd_dir",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/payload/execd.py#L27-L38 |
12,864 | juju/charm-helpers | charmhelpers/payload/execd.py | execd_submodule_paths | def execd_submodule_paths(command, execd_dir=None):
"""Generate a list of full paths to the specified command within exec_dir.
"""
for module_path in execd_module_paths(execd_dir):
path = os.path.join(module_path, command)
if os.access(path, os.X_OK) and os.path.isfile(path):
yie... | python | def execd_submodule_paths(command, execd_dir=None):
"""Generate a list of full paths to the specified command within exec_dir.
"""
for module_path in execd_module_paths(execd_dir):
path = os.path.join(module_path, command)
if os.access(path, os.X_OK) and os.path.isfile(path):
yie... | [
"def",
"execd_submodule_paths",
"(",
"command",
",",
"execd_dir",
"=",
"None",
")",
":",
"for",
"module_path",
"in",
"execd_module_paths",
"(",
"execd_dir",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"module_path",
",",
"command",
")",
"if... | Generate a list of full paths to the specified command within exec_dir. | [
"Generate",
"a",
"list",
"of",
"full",
"paths",
"to",
"the",
"specified",
"command",
"within",
"exec_dir",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/payload/execd.py#L41-L47 |
12,865 | juju/charm-helpers | charmhelpers/payload/execd.py | execd_run | def execd_run(command, execd_dir=None, die_on_error=True, stderr=subprocess.STDOUT):
"""Run command for each module within execd_dir which defines it."""
for submodule_path in execd_submodule_paths(command, execd_dir):
try:
subprocess.check_output(submodule_path, stderr=stderr,
... | python | def execd_run(command, execd_dir=None, die_on_error=True, stderr=subprocess.STDOUT):
"""Run command for each module within execd_dir which defines it."""
for submodule_path in execd_submodule_paths(command, execd_dir):
try:
subprocess.check_output(submodule_path, stderr=stderr,
... | [
"def",
"execd_run",
"(",
"command",
",",
"execd_dir",
"=",
"None",
",",
"die_on_error",
"=",
"True",
",",
"stderr",
"=",
"subprocess",
".",
"STDOUT",
")",
":",
"for",
"submodule_path",
"in",
"execd_submodule_paths",
"(",
"command",
",",
"execd_dir",
")",
":"... | Run command for each module within execd_dir which defines it. | [
"Run",
"command",
"for",
"each",
"module",
"within",
"execd_dir",
"which",
"defines",
"it",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/payload/execd.py#L50-L60 |
12,866 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.getrange | def getrange(self, key_prefix, strip=False):
"""
Get a range of keys starting with a common prefix as a mapping of
keys to values.
:param str key_prefix: Common prefix among all keys
:param bool strip: Optionally strip the common prefix from the key
names in the retu... | python | def getrange(self, key_prefix, strip=False):
"""
Get a range of keys starting with a common prefix as a mapping of
keys to values.
:param str key_prefix: Common prefix among all keys
:param bool strip: Optionally strip the common prefix from the key
names in the retu... | [
"def",
"getrange",
"(",
"self",
",",
"key_prefix",
",",
"strip",
"=",
"False",
")",
":",
"self",
".",
"cursor",
".",
"execute",
"(",
"\"select key, data from kv where key like ?\"",
",",
"[",
"'%s%%'",
"%",
"key_prefix",
"]",
")",
"result",
"=",
"self",
".",... | Get a range of keys starting with a common prefix as a mapping of
keys to values.
:param str key_prefix: Common prefix among all keys
:param bool strip: Optionally strip the common prefix from the key
names in the returned dict
:return dict: A (possibly empty) dict of key-va... | [
"Get",
"a",
"range",
"of",
"keys",
"starting",
"with",
"a",
"common",
"prefix",
"as",
"a",
"mapping",
"of",
"keys",
"to",
"values",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L208-L227 |
12,867 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.update | def update(self, mapping, prefix=""):
"""
Set the values of multiple keys at once.
:param dict mapping: Mapping of keys to values
:param str prefix: Optional prefix to apply to all keys in `mapping`
before setting
"""
for k, v in mapping.items():
... | python | def update(self, mapping, prefix=""):
"""
Set the values of multiple keys at once.
:param dict mapping: Mapping of keys to values
:param str prefix: Optional prefix to apply to all keys in `mapping`
before setting
"""
for k, v in mapping.items():
... | [
"def",
"update",
"(",
"self",
",",
"mapping",
",",
"prefix",
"=",
"\"\"",
")",
":",
"for",
"k",
",",
"v",
"in",
"mapping",
".",
"items",
"(",
")",
":",
"self",
".",
"set",
"(",
"\"%s%s\"",
"%",
"(",
"prefix",
",",
"k",
")",
",",
"v",
")"
] | Set the values of multiple keys at once.
:param dict mapping: Mapping of keys to values
:param str prefix: Optional prefix to apply to all keys in `mapping`
before setting | [
"Set",
"the",
"values",
"of",
"multiple",
"keys",
"at",
"once",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L229-L238 |
12,868 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.unset | def unset(self, key):
"""
Remove a key from the database entirely.
"""
self.cursor.execute('delete from kv where key=?', [key])
if self.revision and self.cursor.rowcount:
self.cursor.execute(
'insert into kv_revisions values (?, ?, ?)',
... | python | def unset(self, key):
"""
Remove a key from the database entirely.
"""
self.cursor.execute('delete from kv where key=?', [key])
if self.revision and self.cursor.rowcount:
self.cursor.execute(
'insert into kv_revisions values (?, ?, ?)',
... | [
"def",
"unset",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"cursor",
".",
"execute",
"(",
"'delete from kv where key=?'",
",",
"[",
"key",
"]",
")",
"if",
"self",
".",
"revision",
"and",
"self",
".",
"cursor",
".",
"rowcount",
":",
"self",
".",
... | Remove a key from the database entirely. | [
"Remove",
"a",
"key",
"from",
"the",
"database",
"entirely",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L240-L248 |
12,869 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.unsetrange | def unsetrange(self, keys=None, prefix=""):
"""
Remove a range of keys starting with a common prefix, from the database
entirely.
:param list keys: List of keys to remove.
:param str prefix: Optional prefix to apply to all keys in ``keys``
before removing.
""... | python | def unsetrange(self, keys=None, prefix=""):
"""
Remove a range of keys starting with a common prefix, from the database
entirely.
:param list keys: List of keys to remove.
:param str prefix: Optional prefix to apply to all keys in ``keys``
before removing.
""... | [
"def",
"unsetrange",
"(",
"self",
",",
"keys",
"=",
"None",
",",
"prefix",
"=",
"\"\"",
")",
":",
"if",
"keys",
"is",
"not",
"None",
":",
"keys",
"=",
"[",
"'%s%s'",
"%",
"(",
"prefix",
",",
"key",
")",
"for",
"key",
"in",
"keys",
"]",
"self",
... | Remove a range of keys starting with a common prefix, from the database
entirely.
:param list keys: List of keys to remove.
:param str prefix: Optional prefix to apply to all keys in ``keys``
before removing. | [
"Remove",
"a",
"range",
"of",
"keys",
"starting",
"with",
"a",
"common",
"prefix",
"from",
"the",
"database",
"entirely",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L250-L272 |
12,870 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.delta | def delta(self, mapping, prefix):
"""
return a delta containing values that have changed.
"""
previous = self.getrange(prefix, strip=True)
if not previous:
pk = set()
else:
pk = set(previous.keys())
ck = set(mapping.keys())
delta = ... | python | def delta(self, mapping, prefix):
"""
return a delta containing values that have changed.
"""
previous = self.getrange(prefix, strip=True)
if not previous:
pk = set()
else:
pk = set(previous.keys())
ck = set(mapping.keys())
delta = ... | [
"def",
"delta",
"(",
"self",
",",
"mapping",
",",
"prefix",
")",
":",
"previous",
"=",
"self",
".",
"getrange",
"(",
"prefix",
",",
"strip",
"=",
"True",
")",
"if",
"not",
"previous",
":",
"pk",
"=",
"set",
"(",
")",
"else",
":",
"pk",
"=",
"set"... | return a delta containing values that have changed. | [
"return",
"a",
"delta",
"containing",
"values",
"that",
"have",
"changed",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L326-L353 |
12,871 | juju/charm-helpers | charmhelpers/core/unitdata.py | Storage.hook_scope | def hook_scope(self, name=""):
"""Scope all future interactions to the current hook execution
revision."""
assert not self.revision
self.cursor.execute(
'insert into hooks (hook, date) values (?, ?)',
(name or sys.argv[0],
datetime.datetime.utcnow().i... | python | def hook_scope(self, name=""):
"""Scope all future interactions to the current hook execution
revision."""
assert not self.revision
self.cursor.execute(
'insert into hooks (hook, date) values (?, ?)',
(name or sys.argv[0],
datetime.datetime.utcnow().i... | [
"def",
"hook_scope",
"(",
"self",
",",
"name",
"=",
"\"\"",
")",
":",
"assert",
"not",
"self",
".",
"revision",
"self",
".",
"cursor",
".",
"execute",
"(",
"'insert into hooks (hook, date) values (?, ?)'",
",",
"(",
"name",
"or",
"sys",
".",
"argv",
"[",
"... | Scope all future interactions to the current hook execution
revision. | [
"Scope",
"all",
"future",
"interactions",
"to",
"the",
"current",
"hook",
"execution",
"revision",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/unitdata.py#L356-L373 |
12,872 | juju/charm-helpers | charmhelpers/contrib/network/ovs/__init__.py | add_bridge | def add_bridge(name, datapath_type=None):
''' Add the named bridge to openvswitch '''
log('Creating bridge {}'.format(name))
cmd = ["ovs-vsctl", "--", "--may-exist", "add-br", name]
if datapath_type is not None:
cmd += ['--', 'set', 'bridge', name,
'datapath_type={}'.format(datap... | python | def add_bridge(name, datapath_type=None):
''' Add the named bridge to openvswitch '''
log('Creating bridge {}'.format(name))
cmd = ["ovs-vsctl", "--", "--may-exist", "add-br", name]
if datapath_type is not None:
cmd += ['--', 'set', 'bridge', name,
'datapath_type={}'.format(datap... | [
"def",
"add_bridge",
"(",
"name",
",",
"datapath_type",
"=",
"None",
")",
":",
"log",
"(",
"'Creating bridge {}'",
".",
"format",
"(",
"name",
")",
")",
"cmd",
"=",
"[",
"\"ovs-vsctl\"",
",",
"\"--\"",
",",
"\"--may-exist\"",
",",
"\"add-br\"",
",",
"name"... | Add the named bridge to openvswitch | [
"Add",
"the",
"named",
"bridge",
"to",
"openvswitch"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ovs/__init__.py#L46-L53 |
12,873 | juju/charm-helpers | charmhelpers/contrib/network/ovs/__init__.py | add_bridge_port | def add_bridge_port(name, port, promisc=False):
''' Add a port to the named openvswitch bridge '''
log('Adding port {} to bridge {}'.format(port, name))
subprocess.check_call(["ovs-vsctl", "--", "--may-exist", "add-port",
name, port])
subprocess.check_call(["ip", "link", "set"... | python | def add_bridge_port(name, port, promisc=False):
''' Add a port to the named openvswitch bridge '''
log('Adding port {} to bridge {}'.format(port, name))
subprocess.check_call(["ovs-vsctl", "--", "--may-exist", "add-port",
name, port])
subprocess.check_call(["ip", "link", "set"... | [
"def",
"add_bridge_port",
"(",
"name",
",",
"port",
",",
"promisc",
"=",
"False",
")",
":",
"log",
"(",
"'Adding port {} to bridge {}'",
".",
"format",
"(",
"port",
",",
"name",
")",
")",
"subprocess",
".",
"check_call",
"(",
"[",
"\"ovs-vsctl\"",
",",
"\"... | Add a port to the named openvswitch bridge | [
"Add",
"a",
"port",
"to",
"the",
"named",
"openvswitch",
"bridge"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ovs/__init__.py#L62-L71 |
12,874 | juju/charm-helpers | charmhelpers/contrib/network/ovs/__init__.py | del_bridge_port | def del_bridge_port(name, port):
''' Delete a port from the named openvswitch bridge '''
log('Deleting port {} from bridge {}'.format(port, name))
subprocess.check_call(["ovs-vsctl", "--", "--if-exists", "del-port",
name, port])
subprocess.check_call(["ip", "link", "set", port... | python | def del_bridge_port(name, port):
''' Delete a port from the named openvswitch bridge '''
log('Deleting port {} from bridge {}'.format(port, name))
subprocess.check_call(["ovs-vsctl", "--", "--if-exists", "del-port",
name, port])
subprocess.check_call(["ip", "link", "set", port... | [
"def",
"del_bridge_port",
"(",
"name",
",",
"port",
")",
":",
"log",
"(",
"'Deleting port {} from bridge {}'",
".",
"format",
"(",
"port",
",",
"name",
")",
")",
"subprocess",
".",
"check_call",
"(",
"[",
"\"ovs-vsctl\"",
",",
"\"--\"",
",",
"\"--if-exists\"",... | Delete a port from the named openvswitch bridge | [
"Delete",
"a",
"port",
"from",
"the",
"named",
"openvswitch",
"bridge"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ovs/__init__.py#L74-L80 |
12,875 | juju/charm-helpers | charmhelpers/contrib/network/ovs/__init__.py | get_certificate | def get_certificate():
''' Read openvswitch certificate from disk '''
if os.path.exists(CERT_PATH):
log('Reading ovs certificate from {}'.format(CERT_PATH))
with open(CERT_PATH, 'r') as cert:
full_cert = cert.read()
begin_marker = "-----BEGIN CERTIFICATE-----"
... | python | def get_certificate():
''' Read openvswitch certificate from disk '''
if os.path.exists(CERT_PATH):
log('Reading ovs certificate from {}'.format(CERT_PATH))
with open(CERT_PATH, 'r') as cert:
full_cert = cert.read()
begin_marker = "-----BEGIN CERTIFICATE-----"
... | [
"def",
"get_certificate",
"(",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"CERT_PATH",
")",
":",
"log",
"(",
"'Reading ovs certificate from {}'",
".",
"format",
"(",
"CERT_PATH",
")",
")",
"with",
"open",
"(",
"CERT_PATH",
",",
"'r'",
")",
"a... | Read openvswitch certificate from disk | [
"Read",
"openvswitch",
"certificate",
"from",
"disk"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ovs/__init__.py#L180-L197 |
12,876 | juju/charm-helpers | charmhelpers/contrib/network/ovs/__init__.py | check_for_eni_source | def check_for_eni_source():
''' Juju removes the source line when setting up interfaces,
replace if missing '''
with open('/etc/network/interfaces', 'r') as eni:
for line in eni:
if line == 'source /etc/network/interfaces.d/*':
return
with open('/etc/network/interfac... | python | def check_for_eni_source():
''' Juju removes the source line when setting up interfaces,
replace if missing '''
with open('/etc/network/interfaces', 'r') as eni:
for line in eni:
if line == 'source /etc/network/interfaces.d/*':
return
with open('/etc/network/interfac... | [
"def",
"check_for_eni_source",
"(",
")",
":",
"with",
"open",
"(",
"'/etc/network/interfaces'",
",",
"'r'",
")",
"as",
"eni",
":",
"for",
"line",
"in",
"eni",
":",
"if",
"line",
"==",
"'source /etc/network/interfaces.d/*'",
":",
"return",
"with",
"open",
"(",
... | Juju removes the source line when setting up interfaces,
replace if missing | [
"Juju",
"removes",
"the",
"source",
"line",
"when",
"setting",
"up",
"interfaces",
"replace",
"if",
"missing"
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ovs/__init__.py#L200-L209 |
12,877 | juju/charm-helpers | charmhelpers/contrib/hardening/audits/apt.py | RestrictedPackages.delete_package | def delete_package(self, cache, pkg):
"""Deletes the package from the system.
Deletes the package form the system, properly handling virtual
packages.
:param cache: the apt cache
:param pkg: the package to remove
"""
if self.is_virtual_package(pkg):
... | python | def delete_package(self, cache, pkg):
"""Deletes the package from the system.
Deletes the package form the system, properly handling virtual
packages.
:param cache: the apt cache
:param pkg: the package to remove
"""
if self.is_virtual_package(pkg):
... | [
"def",
"delete_package",
"(",
"self",
",",
"cache",
",",
"pkg",
")",
":",
"if",
"self",
".",
"is_virtual_package",
"(",
"pkg",
")",
":",
"log",
"(",
"\"Package '%s' appears to be virtual - purging provides\"",
"%",
"pkg",
".",
"name",
",",
"level",
"=",
"DEBUG... | Deletes the package from the system.
Deletes the package form the system, properly handling virtual
packages.
:param cache: the apt cache
:param pkg: the package to remove | [
"Deletes",
"the",
"package",
"from",
"the",
"system",
"."
] | aa785c40c3b7a8c69dbfbc7921d6b9f30142e171 | https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/apt.py#L81-L100 |
12,878 | aschn/drf-tracking | rest_framework_tracking/base_mixins.py | BaseLoggingMixin._get_ip_address | def _get_ip_address(self, request):
"""Get the remote ip address the request was generated from. """
ipaddr = request.META.get("HTTP_X_FORWARDED_FOR", None)
if ipaddr:
# X_FORWARDED_FOR returns client1, proxy1, proxy2,...
return ipaddr.split(",")[0].strip()
return... | python | def _get_ip_address(self, request):
"""Get the remote ip address the request was generated from. """
ipaddr = request.META.get("HTTP_X_FORWARDED_FOR", None)
if ipaddr:
# X_FORWARDED_FOR returns client1, proxy1, proxy2,...
return ipaddr.split(",")[0].strip()
return... | [
"def",
"_get_ip_address",
"(",
"self",
",",
"request",
")",
":",
"ipaddr",
"=",
"request",
".",
"META",
".",
"get",
"(",
"\"HTTP_X_FORWARDED_FOR\"",
",",
"None",
")",
"if",
"ipaddr",
":",
"# X_FORWARDED_FOR returns client1, proxy1, proxy2,...",
"return",
"ipaddr",
... | Get the remote ip address the request was generated from. | [
"Get",
"the",
"remote",
"ip",
"address",
"the",
"request",
"was",
"generated",
"from",
"."
] | 1910f413bd5166bbeaf694c7c0101f331af4f47d | https://github.com/aschn/drf-tracking/blob/1910f413bd5166bbeaf694c7c0101f331af4f47d/rest_framework_tracking/base_mixins.py#L100-L106 |
12,879 | aschn/drf-tracking | rest_framework_tracking/base_mixins.py | BaseLoggingMixin._get_view_name | def _get_view_name(self, request):
"""Get view name."""
method = request.method.lower()
try:
attributes = getattr(self, method)
view_name = type(attributes.__self__).__module__ + '.' + type(attributes.__self__).__name__
return view_name
except Attribut... | python | def _get_view_name(self, request):
"""Get view name."""
method = request.method.lower()
try:
attributes = getattr(self, method)
view_name = type(attributes.__self__).__module__ + '.' + type(attributes.__self__).__name__
return view_name
except Attribut... | [
"def",
"_get_view_name",
"(",
"self",
",",
"request",
")",
":",
"method",
"=",
"request",
".",
"method",
".",
"lower",
"(",
")",
"try",
":",
"attributes",
"=",
"getattr",
"(",
"self",
",",
"method",
")",
"view_name",
"=",
"type",
"(",
"attributes",
"."... | Get view name. | [
"Get",
"view",
"name",
"."
] | 1910f413bd5166bbeaf694c7c0101f331af4f47d | https://github.com/aschn/drf-tracking/blob/1910f413bd5166bbeaf694c7c0101f331af4f47d/rest_framework_tracking/base_mixins.py#L108-L116 |
12,880 | aschn/drf-tracking | rest_framework_tracking/base_mixins.py | BaseLoggingMixin._get_view_method | def _get_view_method(self, request):
"""Get view method."""
if hasattr(self, 'action'):
return self.action if self.action else None
return request.method.lower() | python | def _get_view_method(self, request):
"""Get view method."""
if hasattr(self, 'action'):
return self.action if self.action else None
return request.method.lower() | [
"def",
"_get_view_method",
"(",
"self",
",",
"request",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'action'",
")",
":",
"return",
"self",
".",
"action",
"if",
"self",
".",
"action",
"else",
"None",
"return",
"request",
".",
"method",
".",
"lower",
"... | Get view method. | [
"Get",
"view",
"method",
"."
] | 1910f413bd5166bbeaf694c7c0101f331af4f47d | https://github.com/aschn/drf-tracking/blob/1910f413bd5166bbeaf694c7c0101f331af4f47d/rest_framework_tracking/base_mixins.py#L118-L122 |
12,881 | aschn/drf-tracking | rest_framework_tracking/base_mixins.py | BaseLoggingMixin._get_response_ms | def _get_response_ms(self):
"""
Get the duration of the request response cycle is milliseconds.
In case of negative duration 0 is returned.
"""
response_timedelta = now() - self.log['requested_at']
response_ms = int(response_timedelta.total_seconds() * 1000)
retur... | python | def _get_response_ms(self):
"""
Get the duration of the request response cycle is milliseconds.
In case of negative duration 0 is returned.
"""
response_timedelta = now() - self.log['requested_at']
response_ms = int(response_timedelta.total_seconds() * 1000)
retur... | [
"def",
"_get_response_ms",
"(",
"self",
")",
":",
"response_timedelta",
"=",
"now",
"(",
")",
"-",
"self",
".",
"log",
"[",
"'requested_at'",
"]",
"response_ms",
"=",
"int",
"(",
"response_timedelta",
".",
"total_seconds",
"(",
")",
"*",
"1000",
")",
"retu... | Get the duration of the request response cycle is milliseconds.
In case of negative duration 0 is returned. | [
"Get",
"the",
"duration",
"of",
"the",
"request",
"response",
"cycle",
"is",
"milliseconds",
".",
"In",
"case",
"of",
"negative",
"duration",
"0",
"is",
"returned",
"."
] | 1910f413bd5166bbeaf694c7c0101f331af4f47d | https://github.com/aschn/drf-tracking/blob/1910f413bd5166bbeaf694c7c0101f331af4f47d/rest_framework_tracking/base_mixins.py#L131-L138 |
12,882 | aschn/drf-tracking | rest_framework_tracking/base_mixins.py | BaseLoggingMixin.should_log | def should_log(self, request, response):
"""
Method that should return a value that evaluated to True if the request should be logged.
By default, check if the request method is in logging_methods.
"""
return self.logging_methods == '__all__' or request.method in self.logging_met... | python | def should_log(self, request, response):
"""
Method that should return a value that evaluated to True if the request should be logged.
By default, check if the request method is in logging_methods.
"""
return self.logging_methods == '__all__' or request.method in self.logging_met... | [
"def",
"should_log",
"(",
"self",
",",
"request",
",",
"response",
")",
":",
"return",
"self",
".",
"logging_methods",
"==",
"'__all__'",
"or",
"request",
".",
"method",
"in",
"self",
".",
"logging_methods"
] | Method that should return a value that evaluated to True if the request should be logged.
By default, check if the request method is in logging_methods. | [
"Method",
"that",
"should",
"return",
"a",
"value",
"that",
"evaluated",
"to",
"True",
"if",
"the",
"request",
"should",
"be",
"logged",
".",
"By",
"default",
"check",
"if",
"the",
"request",
"method",
"is",
"in",
"logging_methods",
"."
] | 1910f413bd5166bbeaf694c7c0101f331af4f47d | https://github.com/aschn/drf-tracking/blob/1910f413bd5166bbeaf694c7c0101f331af4f47d/rest_framework_tracking/base_mixins.py#L140-L145 |
12,883 | Esri/ArcREST | src/arcresthelper/common.py | merge_dicts | def merge_dicts(dicts, op=operator.add):
"""Merge a list of dictionaries.
Args:
dicts (list): a list of dictionary objects
op (operator): an operator item used to merge the dictionaries. Defaults to :py:func:`operator.add`.
Returns:
dict: the merged dictionary
"""
a = None... | python | def merge_dicts(dicts, op=operator.add):
"""Merge a list of dictionaries.
Args:
dicts (list): a list of dictionary objects
op (operator): an operator item used to merge the dictionaries. Defaults to :py:func:`operator.add`.
Returns:
dict: the merged dictionary
"""
a = None... | [
"def",
"merge_dicts",
"(",
"dicts",
",",
"op",
"=",
"operator",
".",
"add",
")",
":",
"a",
"=",
"None",
"for",
"b",
"in",
"dicts",
":",
"if",
"a",
"is",
"None",
":",
"a",
"=",
"b",
".",
"copy",
"(",
")",
"else",
":",
"a",
"=",
"dict",
"(",
... | Merge a list of dictionaries.
Args:
dicts (list): a list of dictionary objects
op (operator): an operator item used to merge the dictionaries. Defaults to :py:func:`operator.add`.
Returns:
dict: the merged dictionary | [
"Merge",
"a",
"list",
"of",
"dictionaries",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L39-L57 |
12,884 | Esri/ArcREST | src/arcresthelper/common.py | getLayerIndex | def getLayerIndex(url):
"""Extract the layer index from a url.
Args:
url (str): The url to parse.
Returns:
int: The layer index.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(... | python | def getLayerIndex(url):
"""Extract the layer index from a url.
Args:
url (str): The url to parse.
Returns:
int: The layer index.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(... | [
"def",
"getLayerIndex",
"(",
"url",
")",
":",
"urlInfo",
"=",
"None",
"urlSplit",
"=",
"None",
"inx",
"=",
"None",
"try",
":",
"urlInfo",
"=",
"urlparse",
".",
"urlparse",
"(",
"url",
")",
"urlSplit",
"=",
"str",
"(",
"urlInfo",
".",
"path",
")",
"."... | Extract the layer index from a url.
Args:
url (str): The url to parse.
Returns:
int: The layer index.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url)
12 | [
"Extract",
"the",
"layer",
"index",
"from",
"a",
"url",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L97-L132 |
12,885 | Esri/ArcREST | src/arcresthelper/common.py | getLayerName | def getLayerName(url):
"""Extract the layer name from a url.
Args:
url (str): The url to parse.
Returns:
str: The layer name.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url... | python | def getLayerName(url):
"""Extract the layer name from a url.
Args:
url (str): The url to parse.
Returns:
str: The layer name.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url... | [
"def",
"getLayerName",
"(",
"url",
")",
":",
"urlInfo",
"=",
"None",
"urlSplit",
"=",
"None",
"try",
":",
"urlInfo",
"=",
"urlparse",
".",
"urlparse",
"(",
"url",
")",
"urlSplit",
"=",
"str",
"(",
"urlInfo",
".",
"path",
")",
".",
"split",
"(",
"'/'"... | Extract the layer name from a url.
Args:
url (str): The url to parse.
Returns:
str: The layer name.
Examples:
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12"
>>> arcresthelper.common.getLayerIndex(url)
'test' | [
"Extract",
"the",
"layer",
"name",
"from",
"a",
"url",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L134-L166 |
12,886 | Esri/ArcREST | src/arcresthelper/common.py | random_string_generator | def random_string_generator(size=6, chars=string.ascii_uppercase):
"""Generates a random string from a set of characters.
Args:
size (int): The length of the resultant string. Defaults to 6.
chars (str): The characters to be used by :py:func:`random.choice`. Defaults to :py:const:`string.ascii_... | python | def random_string_generator(size=6, chars=string.ascii_uppercase):
"""Generates a random string from a set of characters.
Args:
size (int): The length of the resultant string. Defaults to 6.
chars (str): The characters to be used by :py:func:`random.choice`. Defaults to :py:const:`string.ascii_... | [
"def",
"random_string_generator",
"(",
"size",
"=",
"6",
",",
"chars",
"=",
"string",
".",
"ascii_uppercase",
")",
":",
"try",
":",
"return",
"''",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"chars",
")",
"for",
"_",
"in",
"range",
"(",
"size",
... | Generates a random string from a set of characters.
Args:
size (int): The length of the resultant string. Defaults to 6.
chars (str): The characters to be used by :py:func:`random.choice`. Defaults to :py:const:`string.ascii_uppercase`.
Returns:
str: The randomly generated string.
... | [
"Generates",
"a",
"random",
"string",
"from",
"a",
"set",
"of",
"characters",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L204-L233 |
12,887 | Esri/ArcREST | src/arcresthelper/common.py | random_int_generator | def random_int_generator(maxrange):
"""Generates a random integer from 0 to `maxrange`, inclusive.
Args:
maxrange (int): The upper range of integers to randomly choose.
Returns:
int: The randomly generated integer from :py:func:`random.randint`.
Examples:
>>> arcresthelper.com... | python | def random_int_generator(maxrange):
"""Generates a random integer from 0 to `maxrange`, inclusive.
Args:
maxrange (int): The upper range of integers to randomly choose.
Returns:
int: The randomly generated integer from :py:func:`random.randint`.
Examples:
>>> arcresthelper.com... | [
"def",
"random_int_generator",
"(",
"maxrange",
")",
":",
"try",
":",
"return",
"random",
".",
"randint",
"(",
"0",
",",
"maxrange",
")",
"except",
":",
"line",
",",
"filename",
",",
"synerror",
"=",
"trace",
"(",
")",
"raise",
"ArcRestHelperError",
"(",
... | Generates a random integer from 0 to `maxrange`, inclusive.
Args:
maxrange (int): The upper range of integers to randomly choose.
Returns:
int: The randomly generated integer from :py:func:`random.randint`.
Examples:
>>> arcresthelper.common.random_int_generator(15)
9 | [
"Generates",
"a",
"random",
"integer",
"from",
"0",
"to",
"maxrange",
"inclusive",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L235-L261 |
12,888 | Esri/ArcREST | src/arcresthelper/common.py | local_time_to_online | def local_time_to_online(dt=None):
"""Converts datetime object to a UTC timestamp for AGOL.
Args:
dt (datetime): The :py:class:`datetime.datetime` object to convert. Defaults to ``None``, i.e., :py:func:`datetime.datetime.now`.
Returns:
float: A UTC timestamp as understood by AGOL (time in... | python | def local_time_to_online(dt=None):
"""Converts datetime object to a UTC timestamp for AGOL.
Args:
dt (datetime): The :py:class:`datetime.datetime` object to convert. Defaults to ``None``, i.e., :py:func:`datetime.datetime.now`.
Returns:
float: A UTC timestamp as understood by AGOL (time in... | [
"def",
"local_time_to_online",
"(",
"dt",
"=",
"None",
")",
":",
"is_dst",
"=",
"None",
"utc_offset",
"=",
"None",
"try",
":",
"if",
"dt",
"is",
"None",
":",
"dt",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"is_dst",
"=",
"time",
".",
... | Converts datetime object to a UTC timestamp for AGOL.
Args:
dt (datetime): The :py:class:`datetime.datetime` object to convert. Defaults to ``None``, i.e., :py:func:`datetime.datetime.now`.
Returns:
float: A UTC timestamp as understood by AGOL (time in ms since Unix epoch * 1000)
Examples... | [
"Converts",
"datetime",
"object",
"to",
"a",
"UTC",
"timestamp",
"for",
"AGOL",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L263-L306 |
12,889 | Esri/ArcREST | src/arcresthelper/common.py | is_number | def is_number(s):
"""Determines if the input is numeric
Args:
s: The value to check.
Returns:
bool: ``True`` if the input is numeric, ``False`` otherwise.
"""
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
... | python | def is_number(s):
"""Determines if the input is numeric
Args:
s: The value to check.
Returns:
bool: ``True`` if the input is numeric, ``False`` otherwise.
"""
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
... | [
"def",
"is_number",
"(",
"s",
")",
":",
"try",
":",
"float",
"(",
"s",
")",
"return",
"True",
"except",
"ValueError",
":",
"pass",
"try",
":",
"import",
"unicodedata",
"unicodedata",
".",
"numeric",
"(",
"s",
")",
"return",
"True",
"except",
"(",
"Type... | Determines if the input is numeric
Args:
s: The value to check.
Returns:
bool: ``True`` if the input is numeric, ``False`` otherwise. | [
"Determines",
"if",
"the",
"input",
"is",
"numeric"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L345-L367 |
12,890 | Esri/ArcREST | src/arcresthelper/common.py | init_config_json | def init_config_json(config_file):
"""Deserializes a JSON configuration file.
Args:
config_file (str): The path to the JSON file.
Returns:
dict: A dictionary object containing the JSON data. If ``config_file`` does not exist, returns ``None``.
"""
json_data = None
try:
... | python | def init_config_json(config_file):
"""Deserializes a JSON configuration file.
Args:
config_file (str): The path to the JSON file.
Returns:
dict: A dictionary object containing the JSON data. If ``config_file`` does not exist, returns ``None``.
"""
json_data = None
try:
... | [
"def",
"init_config_json",
"(",
"config_file",
")",
":",
"json_data",
"=",
"None",
"try",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"config_file",
")",
":",
"#Load the config file",
"with",
"open",
"(",
"config_file",
")",
"as",
"json_file",
":",
"... | Deserializes a JSON configuration file.
Args:
config_file (str): The path to the JSON file.
Returns:
dict: A dictionary object containing the JSON data. If ``config_file`` does not exist, returns ``None``. | [
"Deserializes",
"a",
"JSON",
"configuration",
"file",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L369-L402 |
12,891 | Esri/ArcREST | src/arcresthelper/common.py | write_config_json | def write_config_json(config_file, data):
"""Serializes an object to disk.
Args:
config_file (str): The path on disk to save the file.
data (object): The object to serialize.
"""
outfile = None
try:
with open(config_file, 'w') as outfile:
json.dump(data, outfile... | python | def write_config_json(config_file, data):
"""Serializes an object to disk.
Args:
config_file (str): The path on disk to save the file.
data (object): The object to serialize.
"""
outfile = None
try:
with open(config_file, 'w') as outfile:
json.dump(data, outfile... | [
"def",
"write_config_json",
"(",
"config_file",
",",
"data",
")",
":",
"outfile",
"=",
"None",
"try",
":",
"with",
"open",
"(",
"config_file",
",",
"'w'",
")",
"as",
"outfile",
":",
"json",
".",
"dump",
"(",
"data",
",",
"outfile",
")",
"except",
":",
... | Serializes an object to disk.
Args:
config_file (str): The path on disk to save the file.
data (object): The object to serialize. | [
"Serializes",
"an",
"object",
"to",
"disk",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L405-L431 |
12,892 | Esri/ArcREST | src/arcresthelper/common.py | unicode_convert | def unicode_convert(obj):
"""Converts unicode objects to anscii.
Args:
obj (object): The object to convert.
Returns:
The object converted to anscii, if possible. For ``dict`` and ``list``, the object type is maintained.
"""
try:
if isinstance(obj, dict):
return ... | python | def unicode_convert(obj):
"""Converts unicode objects to anscii.
Args:
obj (object): The object to convert.
Returns:
The object converted to anscii, if possible. For ``dict`` and ``list``, the object type is maintained.
"""
try:
if isinstance(obj, dict):
return ... | [
"def",
"unicode_convert",
"(",
"obj",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"obj",
",",
"dict",
")",
":",
"return",
"{",
"unicode_convert",
"(",
"key",
")",
":",
"unicode_convert",
"(",
"value",
")",
"for",
"key",
",",
"value",
"in",
"obj",
... | Converts unicode objects to anscii.
Args:
obj (object): The object to convert.
Returns:
The object converted to anscii, if possible. For ``dict`` and ``list``, the object type is maintained. | [
"Converts",
"unicode",
"objects",
"to",
"anscii",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L434-L457 |
12,893 | Esri/ArcREST | src/arcresthelper/common.py | find_replace | def find_replace(obj, find, replace):
""" Searches an object and performs a find and replace.
Args:
obj (object): The object to iterate and find/replace.
find (str): The string to search for.
replace (str): The string to replace with.
Returns:
object: The object with replace... | python | def find_replace(obj, find, replace):
""" Searches an object and performs a find and replace.
Args:
obj (object): The object to iterate and find/replace.
find (str): The string to search for.
replace (str): The string to replace with.
Returns:
object: The object with replace... | [
"def",
"find_replace",
"(",
"obj",
",",
"find",
",",
"replace",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"obj",
",",
"dict",
")",
":",
"return",
"{",
"find_replace",
"(",
"key",
",",
"find",
",",
"replace",
")",
":",
"find_replace",
"(",
"value... | Searches an object and performs a find and replace.
Args:
obj (object): The object to iterate and find/replace.
find (str): The string to search for.
replace (str): The string to replace with.
Returns:
object: The object with replaced strings. | [
"Searches",
"an",
"object",
"and",
"performs",
"a",
"find",
"and",
"replace",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcresthelper/common.py#L490-L525 |
12,894 | Esri/ArcREST | src/arcrest/_abstract/abstract.py | BaseAGSServer._tostr | def _tostr(self,obj):
""" converts a object to list, if object is a list, it creates a
comma seperated string.
"""
if not obj:
return ''
if isinstance(obj, list):
return ', '.join(map(self._tostr, obj))
return str(obj) | python | def _tostr(self,obj):
""" converts a object to list, if object is a list, it creates a
comma seperated string.
"""
if not obj:
return ''
if isinstance(obj, list):
return ', '.join(map(self._tostr, obj))
return str(obj) | [
"def",
"_tostr",
"(",
"self",
",",
"obj",
")",
":",
"if",
"not",
"obj",
":",
"return",
"''",
"if",
"isinstance",
"(",
"obj",
",",
"list",
")",
":",
"return",
"', '",
".",
"join",
"(",
"map",
"(",
"self",
".",
"_tostr",
",",
"obj",
")",
")",
"re... | converts a object to list, if object is a list, it creates a
comma seperated string. | [
"converts",
"a",
"object",
"to",
"list",
"if",
"object",
"is",
"a",
"list",
"it",
"creates",
"a",
"comma",
"seperated",
"string",
"."
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/_abstract/abstract.py#L151-L159 |
12,895 | Esri/ArcREST | src/arcrest/_abstract/abstract.py | BaseAGOLClass._unzip_file | def _unzip_file(self, zip_file, out_folder):
""" unzips a file to a given folder """
try:
zf = zipfile.ZipFile(zip_file, 'r')
zf.extractall(path=out_folder)
zf.close()
del zf
return True
except:
return False | python | def _unzip_file(self, zip_file, out_folder):
""" unzips a file to a given folder """
try:
zf = zipfile.ZipFile(zip_file, 'r')
zf.extractall(path=out_folder)
zf.close()
del zf
return True
except:
return False | [
"def",
"_unzip_file",
"(",
"self",
",",
"zip_file",
",",
"out_folder",
")",
":",
"try",
":",
"zf",
"=",
"zipfile",
".",
"ZipFile",
"(",
"zip_file",
",",
"'r'",
")",
"zf",
".",
"extractall",
"(",
"path",
"=",
"out_folder",
")",
"zf",
".",
"close",
"("... | unzips a file to a given folder | [
"unzips",
"a",
"file",
"to",
"a",
"given",
"folder"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/_abstract/abstract.py#L235-L244 |
12,896 | Esri/ArcREST | src/arcrest/_abstract/abstract.py | BaseAGOLClass._list_files | def _list_files(self, path):
"""lists files in a given directory"""
files = []
for f in glob.glob(pathname=path):
files.append(f)
files.sort()
return files | python | def _list_files(self, path):
"""lists files in a given directory"""
files = []
for f in glob.glob(pathname=path):
files.append(f)
files.sort()
return files | [
"def",
"_list_files",
"(",
"self",
",",
"path",
")",
":",
"files",
"=",
"[",
"]",
"for",
"f",
"in",
"glob",
".",
"glob",
"(",
"pathname",
"=",
"path",
")",
":",
"files",
".",
"append",
"(",
"f",
")",
"files",
".",
"sort",
"(",
")",
"return",
"f... | lists files in a given directory | [
"lists",
"files",
"in",
"a",
"given",
"directory"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/_abstract/abstract.py#L252-L258 |
12,897 | Esri/ArcREST | src/arcrest/_abstract/abstract.py | BaseAGOLClass._get_content_type | def _get_content_type(self, filename):
""" gets the content type of a file """
mntype = mimetypes.guess_type(filename)[0]
filename, fileExtension = os.path.splitext(filename)
if mntype is None and\
fileExtension.lower() == ".csv":
mntype = "text/csv"
elif ... | python | def _get_content_type(self, filename):
""" gets the content type of a file """
mntype = mimetypes.guess_type(filename)[0]
filename, fileExtension = os.path.splitext(filename)
if mntype is None and\
fileExtension.lower() == ".csv":
mntype = "text/csv"
elif ... | [
"def",
"_get_content_type",
"(",
"self",
",",
"filename",
")",
":",
"mntype",
"=",
"mimetypes",
".",
"guess_type",
"(",
"filename",
")",
"[",
"0",
"]",
"filename",
",",
"fileExtension",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"if",... | gets the content type of a file | [
"gets",
"the",
"content",
"type",
"of",
"a",
"file"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/_abstract/abstract.py#L260-L273 |
12,898 | Esri/ArcREST | src/arcrest/common/symbology.py | SimpleMarkerSymbol.value | def value(self):
"""returns the object as dictionary"""
if self._outline is None:
return {
"type" : "esriSMS",
"style" : self._style,
"color" : self._color.value,
"size" : self._size,
"angle" : self._angle,
... | python | def value(self):
"""returns the object as dictionary"""
if self._outline is None:
return {
"type" : "esriSMS",
"style" : self._style,
"color" : self._color.value,
"size" : self._size,
"angle" : self._angle,
... | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"self",
".",
"_outline",
"is",
"None",
":",
"return",
"{",
"\"type\"",
":",
"\"esriSMS\"",
",",
"\"style\"",
":",
"self",
".",
"_style",
",",
"\"color\"",
":",
"self",
".",
"_color",
".",
"value",
",",
"\"... | returns the object as dictionary | [
"returns",
"the",
"object",
"as",
"dictionary"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/common/symbology.py#L157-L182 |
12,899 | Esri/ArcREST | src/arcrest/manageportal/administration.py | _Federation.unfederate | def unfederate(self, serverId):
"""
This operation unfederates an ArcGIS Server from Portal for ArcGIS
"""
url = self._url + "/servers/{serverid}/unfederate".format(
serverid=serverId)
params = {"f" : "json"}
return self._get(url=url,
... | python | def unfederate(self, serverId):
"""
This operation unfederates an ArcGIS Server from Portal for ArcGIS
"""
url = self._url + "/servers/{serverid}/unfederate".format(
serverid=serverId)
params = {"f" : "json"}
return self._get(url=url,
... | [
"def",
"unfederate",
"(",
"self",
",",
"serverId",
")",
":",
"url",
"=",
"self",
".",
"_url",
"+",
"\"/servers/{serverid}/unfederate\"",
".",
"format",
"(",
"serverid",
"=",
"serverId",
")",
"params",
"=",
"{",
"\"f\"",
":",
"\"json\"",
"}",
"return",
"sel... | This operation unfederates an ArcGIS Server from Portal for ArcGIS | [
"This",
"operation",
"unfederates",
"an",
"ArcGIS",
"Server",
"from",
"Portal",
"for",
"ArcGIS"
] | ab240fde2b0200f61d4a5f6df033516e53f2f416 | https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/manageportal/administration.py#L72-L82 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.