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
partition
stringclasses
1 value
juju/charm-helpers
charmhelpers/core/hookenv.py
expected_peer_units
def expected_peer_units(): """Get a generator for units we expect to join peer relation based on goal-state. The local unit is excluded from the result to make it easy to gauge completion of all peers joining the relation with existing hook tools. Example usage: log('peer {} of {} joined peer ...
python
def expected_peer_units(): """Get a generator for units we expect to join peer relation based on goal-state. The local unit is excluded from the result to make it easy to gauge completion of all peers joining the relation with existing hook tools. Example usage: log('peer {} of {} joined peer ...
[ "def", "expected_peer_units", "(", ")", ":", "if", "not", "has_juju_version", "(", "\"2.4.0\"", ")", ":", "# goal-state first appeared in 2.4.0.", "raise", "NotImplementedError", "(", "\"goal-state\"", ")", "_goal_state", "=", "goal_state", "(", ")", "return", "(", ...
Get a generator for units we expect to join peer relation based on goal-state. The local unit is excluded from the result to make it easy to gauge completion of all peers joining the relation with existing hook tools. Example usage: log('peer {} of {} joined peer relation' .format(len(rela...
[ "Get", "a", "generator", "for", "units", "we", "expect", "to", "join", "peer", "relation", "based", "on", "goal", "-", "state", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L518-L542
train
juju/charm-helpers
charmhelpers/core/hookenv.py
expected_related_units
def expected_related_units(reltype=None): """Get a generator for units we expect to join relation based on goal-state. Note that you can not use this function for the peer relation, take a look at expected_peer_units() for that. This function will raise KeyError if you request information for a ...
python
def expected_related_units(reltype=None): """Get a generator for units we expect to join relation based on goal-state. Note that you can not use this function for the peer relation, take a look at expected_peer_units() for that. This function will raise KeyError if you request information for a ...
[ "def", "expected_related_units", "(", "reltype", "=", "None", ")", ":", "if", "not", "has_juju_version", "(", "\"2.4.4\"", ")", ":", "# goal-state existed in 2.4.0, but did not list individual units to", "# join a relation in 2.4.1 through 2.4.3. (LP: #1794739)", "raise", "NotImp...
Get a generator for units we expect to join relation based on goal-state. Note that you can not use this function for the peer relation, take a look at expected_peer_units() for that. This function will raise KeyError if you request information for a relation type for which juju goal-state does no...
[ "Get", "a", "generator", "for", "units", "we", "expect", "to", "join", "relation", "based", "on", "goal", "-", "state", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L545-L576
train
juju/charm-helpers
charmhelpers/core/hookenv.py
relation_for_unit
def relation_for_unit(unit=None, rid=None): """Get the json represenation of a unit's relation""" unit = unit or remote_unit() relation = relation_get(unit=unit, rid=rid) for key in relation: if key.endswith('-list'): relation[key] = relation[key].split() relation['__unit__'] = u...
python
def relation_for_unit(unit=None, rid=None): """Get the json represenation of a unit's relation""" unit = unit or remote_unit() relation = relation_get(unit=unit, rid=rid) for key in relation: if key.endswith('-list'): relation[key] = relation[key].split() relation['__unit__'] = u...
[ "def", "relation_for_unit", "(", "unit", "=", "None", ",", "rid", "=", "None", ")", ":", "unit", "=", "unit", "or", "remote_unit", "(", ")", "relation", "=", "relation_get", "(", "unit", "=", "unit", ",", "rid", "=", "rid", ")", "for", "key", "in", ...
Get the json represenation of a unit's relation
[ "Get", "the", "json", "represenation", "of", "a", "unit", "s", "relation" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L580-L588
train
juju/charm-helpers
charmhelpers/core/hookenv.py
relations_for_id
def relations_for_id(relid=None): """Get relations of a specific relation ID""" relation_data = [] relid = relid or relation_ids() for unit in related_units(relid): unit_data = relation_for_unit(unit, relid) unit_data['__relid__'] = relid relation_data.append(unit_data) retur...
python
def relations_for_id(relid=None): """Get relations of a specific relation ID""" relation_data = [] relid = relid or relation_ids() for unit in related_units(relid): unit_data = relation_for_unit(unit, relid) unit_data['__relid__'] = relid relation_data.append(unit_data) retur...
[ "def", "relations_for_id", "(", "relid", "=", "None", ")", ":", "relation_data", "=", "[", "]", "relid", "=", "relid", "or", "relation_ids", "(", ")", "for", "unit", "in", "related_units", "(", "relid", ")", ":", "unit_data", "=", "relation_for_unit", "(",...
Get relations of a specific relation ID
[ "Get", "relations", "of", "a", "specific", "relation", "ID" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L592-L600
train
juju/charm-helpers
charmhelpers/core/hookenv.py
relations_of_type
def relations_of_type(reltype=None): """Get relations of a specific type""" relation_data = [] reltype = reltype or relation_type() for relid in relation_ids(reltype): for relation in relations_for_id(relid): relation['__relid__'] = relid relation_data.append(relation) ...
python
def relations_of_type(reltype=None): """Get relations of a specific type""" relation_data = [] reltype = reltype or relation_type() for relid in relation_ids(reltype): for relation in relations_for_id(relid): relation['__relid__'] = relid relation_data.append(relation) ...
[ "def", "relations_of_type", "(", "reltype", "=", "None", ")", ":", "relation_data", "=", "[", "]", "reltype", "=", "reltype", "or", "relation_type", "(", ")", "for", "relid", "in", "relation_ids", "(", "reltype", ")", ":", "for", "relation", "in", "relatio...
Get relations of a specific type
[ "Get", "relations", "of", "a", "specific", "type" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L604-L612
train
juju/charm-helpers
charmhelpers/core/hookenv.py
metadata
def metadata(): """Get the current charm metadata.yaml contents as a python object""" with open(os.path.join(charm_dir(), 'metadata.yaml')) as md: return yaml.safe_load(md)
python
def metadata(): """Get the current charm metadata.yaml contents as a python object""" with open(os.path.join(charm_dir(), 'metadata.yaml')) as md: return yaml.safe_load(md)
[ "def", "metadata", "(", ")", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(", "charm_dir", "(", ")", ",", "'metadata.yaml'", ")", ")", "as", "md", ":", "return", "yaml", ".", "safe_load", "(", "md", ")" ]
Get the current charm metadata.yaml contents as a python object
[ "Get", "the", "current", "charm", "metadata", ".", "yaml", "contents", "as", "a", "python", "object" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L616-L619
train
juju/charm-helpers
charmhelpers/core/hookenv.py
relation_types
def relation_types(): """Get a list of relation types supported by this charm""" rel_types = [] md = metadata() for key in ('provides', 'requires', 'peers'): section = md.get(key) if section: rel_types.extend(section.keys()) return rel_types
python
def relation_types(): """Get a list of relation types supported by this charm""" rel_types = [] md = metadata() for key in ('provides', 'requires', 'peers'): section = md.get(key) if section: rel_types.extend(section.keys()) return rel_types
[ "def", "relation_types", "(", ")", ":", "rel_types", "=", "[", "]", "md", "=", "metadata", "(", ")", "for", "key", "in", "(", "'provides'", ",", "'requires'", ",", "'peers'", ")", ":", "section", "=", "md", ".", "get", "(", "key", ")", "if", "secti...
Get a list of relation types supported by this charm
[ "Get", "a", "list", "of", "relation", "types", "supported", "by", "this", "charm" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L641-L649
train
juju/charm-helpers
charmhelpers/core/hookenv.py
peer_relation_id
def peer_relation_id(): '''Get the peers relation id if a peers relation has been joined, else None.''' md = metadata() section = md.get('peers') if section: for key in section: relids = relation_ids(key) if relids: return relids[0] return None
python
def peer_relation_id(): '''Get the peers relation id if a peers relation has been joined, else None.''' md = metadata() section = md.get('peers') if section: for key in section: relids = relation_ids(key) if relids: return relids[0] return None
[ "def", "peer_relation_id", "(", ")", ":", "md", "=", "metadata", "(", ")", "section", "=", "md", ".", "get", "(", "'peers'", ")", "if", "section", ":", "for", "key", "in", "section", ":", "relids", "=", "relation_ids", "(", "key", ")", "if", "relids"...
Get the peers relation id if a peers relation has been joined, else None.
[ "Get", "the", "peers", "relation", "id", "if", "a", "peers", "relation", "has", "been", "joined", "else", "None", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L653-L662
train
juju/charm-helpers
charmhelpers/core/hookenv.py
interface_to_relations
def interface_to_relations(interface_name): """ Given an interface, return a list of relation names for the current charm that use that interface. :returns: A list of relation names. """ results = [] for role in ('provides', 'requires', 'peers'): results.extend(role_and_interface_to...
python
def interface_to_relations(interface_name): """ Given an interface, return a list of relation names for the current charm that use that interface. :returns: A list of relation names. """ results = [] for role in ('provides', 'requires', 'peers'): results.extend(role_and_interface_to...
[ "def", "interface_to_relations", "(", "interface_name", ")", ":", "results", "=", "[", "]", "for", "role", "in", "(", "'provides'", ",", "'requires'", ",", "'peers'", ")", ":", "results", ".", "extend", "(", "role_and_interface_to_relations", "(", "role", ",",...
Given an interface, return a list of relation names for the current charm that use that interface. :returns: A list of relation names.
[ "Given", "an", "interface", "return", "a", "list", "of", "relation", "names", "for", "the", "current", "charm", "that", "use", "that", "interface", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L709-L719
train
juju/charm-helpers
charmhelpers/core/hookenv.py
relations
def relations(): """Get a nested dictionary of relation data for all related units""" rels = {} for reltype in relation_types(): relids = {} for relid in relation_ids(reltype): units = {local_unit(): relation_get(unit=local_unit(), rid=relid)} for unit in related_unit...
python
def relations(): """Get a nested dictionary of relation data for all related units""" rels = {} for reltype in relation_types(): relids = {} for relid in relation_ids(reltype): units = {local_unit(): relation_get(unit=local_unit(), rid=relid)} for unit in related_unit...
[ "def", "relations", "(", ")", ":", "rels", "=", "{", "}", "for", "reltype", "in", "relation_types", "(", ")", ":", "relids", "=", "{", "}", "for", "relid", "in", "relation_ids", "(", "reltype", ")", ":", "units", "=", "{", "local_unit", "(", ")", "...
Get a nested dictionary of relation data for all related units
[ "Get", "a", "nested", "dictionary", "of", "relation", "data", "for", "all", "related", "units" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L729-L741
train
juju/charm-helpers
charmhelpers/core/hookenv.py
_port_op
def _port_op(op_name, port, protocol="TCP"): """Open or close a service network port""" _args = [op_name] icmp = protocol.upper() == "ICMP" if icmp: _args.append(protocol) else: _args.append('{}/{}'.format(port, protocol)) try: subprocess.check_call(_args) except subp...
python
def _port_op(op_name, port, protocol="TCP"): """Open or close a service network port""" _args = [op_name] icmp = protocol.upper() == "ICMP" if icmp: _args.append(protocol) else: _args.append('{}/{}'.format(port, protocol)) try: subprocess.check_call(_args) except subp...
[ "def", "_port_op", "(", "op_name", ",", "port", ",", "protocol", "=", "\"TCP\"", ")", ":", "_args", "=", "[", "op_name", "]", "icmp", "=", "protocol", ".", "upper", "(", ")", "==", "\"ICMP\"", "if", "icmp", ":", "_args", ".", "append", "(", "protocol...
Open or close a service network port
[ "Open", "or", "close", "a", "service", "network", "port" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L764-L778
train
juju/charm-helpers
charmhelpers/core/hookenv.py
open_ports
def open_ports(start, end, protocol="TCP"): """Opens a range of service network ports""" _args = ['open-port'] _args.append('{}-{}/{}'.format(start, end, protocol)) subprocess.check_call(_args)
python
def open_ports(start, end, protocol="TCP"): """Opens a range of service network ports""" _args = ['open-port'] _args.append('{}-{}/{}'.format(start, end, protocol)) subprocess.check_call(_args)
[ "def", "open_ports", "(", "start", ",", "end", ",", "protocol", "=", "\"TCP\"", ")", ":", "_args", "=", "[", "'open-port'", "]", "_args", ".", "append", "(", "'{}-{}/{}'", ".", "format", "(", "start", ",", "end", ",", "protocol", ")", ")", "subprocess"...
Opens a range of service network ports
[ "Opens", "a", "range", "of", "service", "network", "ports" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L791-L795
train
juju/charm-helpers
charmhelpers/core/hookenv.py
unit_get
def unit_get(attribute): """Get the unit ID for the remote unit""" _args = ['unit-get', '--format=json', attribute] try: return json.loads(subprocess.check_output(_args).decode('UTF-8')) except ValueError: return None
python
def unit_get(attribute): """Get the unit ID for the remote unit""" _args = ['unit-get', '--format=json', attribute] try: return json.loads(subprocess.check_output(_args).decode('UTF-8')) except ValueError: return None
[ "def", "unit_get", "(", "attribute", ")", ":", "_args", "=", "[", "'unit-get'", ",", "'--format=json'", ",", "attribute", "]", "try", ":", "return", "json", ".", "loads", "(", "subprocess", ".", "check_output", "(", "_args", ")", ".", "decode", "(", "'UT...
Get the unit ID for the remote unit
[ "Get", "the", "unit", "ID", "for", "the", "remote", "unit" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L817-L823
train
juju/charm-helpers
charmhelpers/core/hookenv.py
storage_get
def storage_get(attribute=None, storage_id=None): """Get storage attributes""" _args = ['storage-get', '--format=json'] if storage_id: _args.extend(('-s', storage_id)) if attribute: _args.append(attribute) try: return json.loads(subprocess.check_output(_args).decode('UTF-8'))...
python
def storage_get(attribute=None, storage_id=None): """Get storage attributes""" _args = ['storage-get', '--format=json'] if storage_id: _args.extend(('-s', storage_id)) if attribute: _args.append(attribute) try: return json.loads(subprocess.check_output(_args).decode('UTF-8'))...
[ "def", "storage_get", "(", "attribute", "=", "None", ",", "storage_id", "=", "None", ")", ":", "_args", "=", "[", "'storage-get'", ",", "'--format=json'", "]", "if", "storage_id", ":", "_args", ".", "extend", "(", "(", "'-s'", ",", "storage_id", ")", ")"...
Get storage attributes
[ "Get", "storage", "attributes" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L837-L847
train
juju/charm-helpers
charmhelpers/core/hookenv.py
storage_list
def storage_list(storage_name=None): """List the storage IDs for the unit""" _args = ['storage-list', '--format=json'] if storage_name: _args.append(storage_name) try: return json.loads(subprocess.check_output(_args).decode('UTF-8')) except ValueError: return None except ...
python
def storage_list(storage_name=None): """List the storage IDs for the unit""" _args = ['storage-list', '--format=json'] if storage_name: _args.append(storage_name) try: return json.loads(subprocess.check_output(_args).decode('UTF-8')) except ValueError: return None except ...
[ "def", "storage_list", "(", "storage_name", "=", "None", ")", ":", "_args", "=", "[", "'storage-list'", ",", "'--format=json'", "]", "if", "storage_name", ":", "_args", ".", "append", "(", "storage_name", ")", "try", ":", "return", "json", ".", "loads", "(...
List the storage IDs for the unit
[ "List", "the", "storage", "IDs", "for", "the", "unit" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L851-L865
train
juju/charm-helpers
charmhelpers/core/hookenv.py
charm_dir
def charm_dir(): """Return the root directory of the current charm""" d = os.environ.get('JUJU_CHARM_DIR') if d is not None: return d return os.environ.get('CHARM_DIR')
python
def charm_dir(): """Return the root directory of the current charm""" d = os.environ.get('JUJU_CHARM_DIR') if d is not None: return d return os.environ.get('CHARM_DIR')
[ "def", "charm_dir", "(", ")", ":", "d", "=", "os", ".", "environ", ".", "get", "(", "'JUJU_CHARM_DIR'", ")", "if", "d", "is", "not", "None", ":", "return", "d", "return", "os", ".", "environ", ".", "get", "(", "'CHARM_DIR'", ")" ]
Return the root directory of the current charm
[ "Return", "the", "root", "directory", "of", "the", "current", "charm" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L941-L946
train
juju/charm-helpers
charmhelpers/core/hookenv.py
action_set
def action_set(values): """Sets the values to be returned after the action finishes""" cmd = ['action-set'] for k, v in list(values.items()): cmd.append('{}={}'.format(k, v)) subprocess.check_call(cmd)
python
def action_set(values): """Sets the values to be returned after the action finishes""" cmd = ['action-set'] for k, v in list(values.items()): cmd.append('{}={}'.format(k, v)) subprocess.check_call(cmd)
[ "def", "action_set", "(", "values", ")", ":", "cmd", "=", "[", "'action-set'", "]", "for", "k", ",", "v", "in", "list", "(", "values", ".", "items", "(", ")", ")", ":", "cmd", ".", "append", "(", "'{}={}'", ".", "format", "(", "k", ",", "v", ")...
Sets the values to be returned after the action finishes
[ "Sets", "the", "values", "to", "be", "returned", "after", "the", "action", "finishes" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L960-L965
train
juju/charm-helpers
charmhelpers/core/hookenv.py
status_set
def status_set(workload_state, message): """Set the workload state with a message Use status-set to set the workload state with a message which is visible to the user via juju status. If the status-set command is not found then assume this is juju < 1.23 and juju-log the message unstead. workload_...
python
def status_set(workload_state, message): """Set the workload state with a message Use status-set to set the workload state with a message which is visible to the user via juju status. If the status-set command is not found then assume this is juju < 1.23 and juju-log the message unstead. workload_...
[ "def", "status_set", "(", "workload_state", ",", "message", ")", ":", "valid_states", "=", "[", "'maintenance'", ",", "'blocked'", ",", "'waiting'", ",", "'active'", "]", "if", "workload_state", "not", "in", "valid_states", ":", "raise", "ValueError", "(", "'{...
Set the workload state with a message Use status-set to set the workload state with a message which is visible to the user via juju status. If the status-set command is not found then assume this is juju < 1.23 and juju-log the message unstead. workload_state -- valid juju workload state. message ...
[ "Set", "the", "workload", "state", "with", "a", "message" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L990-L1015
train
juju/charm-helpers
charmhelpers/core/hookenv.py
status_get
def status_get(): """Retrieve the previously set juju workload state and message If the status-get command is not found then assume this is juju < 1.23 and return 'unknown', "" """ cmd = ['status-get', "--format=json", "--include-data"] try: raw_status = subprocess.check_output(cmd) ...
python
def status_get(): """Retrieve the previously set juju workload state and message If the status-get command is not found then assume this is juju < 1.23 and return 'unknown', "" """ cmd = ['status-get', "--format=json", "--include-data"] try: raw_status = subprocess.check_output(cmd) ...
[ "def", "status_get", "(", ")", ":", "cmd", "=", "[", "'status-get'", ",", "\"--format=json\"", ",", "\"--include-data\"", "]", "try", ":", "raw_status", "=", "subprocess", ".", "check_output", "(", "cmd", ")", "except", "OSError", "as", "e", ":", "if", "e"...
Retrieve the previously set juju workload state and message If the status-get command is not found then assume this is juju < 1.23 and return 'unknown', ""
[ "Retrieve", "the", "previously", "set", "juju", "workload", "state", "and", "message" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1018-L1035
train
juju/charm-helpers
charmhelpers/core/hookenv.py
application_version_set
def application_version_set(version): """Charm authors may trigger this command from any hook to output what version of the application is running. This could be a package version, for instance postgres version 9.5. It could also be a build number or version control revision identifier, for instance git...
python
def application_version_set(version): """Charm authors may trigger this command from any hook to output what version of the application is running. This could be a package version, for instance postgres version 9.5. It could also be a build number or version control revision identifier, for instance git...
[ "def", "application_version_set", "(", "version", ")", ":", "cmd", "=", "[", "'application-version-set'", "]", "cmd", ".", "append", "(", "version", ")", "try", ":", "subprocess", ".", "check_call", "(", "cmd", ")", "except", "OSError", ":", "log", "(", "\...
Charm authors may trigger this command from any hook to output what version of the application is running. This could be a package version, for instance postgres version 9.5. It could also be a build number or version control revision identifier, for instance git sha 6fb7ba68.
[ "Charm", "authors", "may", "trigger", "this", "command", "from", "any", "hook", "to", "output", "what", "version", "of", "the", "application", "is", "running", ".", "This", "could", "be", "a", "package", "version", "for", "instance", "postgres", "version", "...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1052-L1063
train
juju/charm-helpers
charmhelpers/core/hookenv.py
payload_register
def payload_register(ptype, klass, pid): """ is used while a hook is running to let Juju know that a payload has been started.""" cmd = ['payload-register'] for x in [ptype, klass, pid]: cmd.append(x) subprocess.check_call(cmd)
python
def payload_register(ptype, klass, pid): """ is used while a hook is running to let Juju know that a payload has been started.""" cmd = ['payload-register'] for x in [ptype, klass, pid]: cmd.append(x) subprocess.check_call(cmd)
[ "def", "payload_register", "(", "ptype", ",", "klass", ",", "pid", ")", ":", "cmd", "=", "[", "'payload-register'", "]", "for", "x", "in", "[", "ptype", ",", "klass", ",", "pid", "]", ":", "cmd", ".", "append", "(", "x", ")", "subprocess", ".", "ch...
is used while a hook is running to let Juju know that a payload has been started.
[ "is", "used", "while", "a", "hook", "is", "running", "to", "let", "Juju", "know", "that", "a", "payload", "has", "been", "started", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1108-L1114
train
juju/charm-helpers
charmhelpers/core/hookenv.py
resource_get
def resource_get(name): """used to fetch the resource path of the given name. <name> must match a name of defined resource in metadata.yaml returns either a path or False if resource not available """ if not name: return False cmd = ['resource-get', name] try: return subpr...
python
def resource_get(name): """used to fetch the resource path of the given name. <name> must match a name of defined resource in metadata.yaml returns either a path or False if resource not available """ if not name: return False cmd = ['resource-get', name] try: return subpr...
[ "def", "resource_get", "(", "name", ")", ":", "if", "not", "name", ":", "return", "False", "cmd", "=", "[", "'resource-get'", ",", "name", "]", "try", ":", "return", "subprocess", ".", "check_output", "(", "cmd", ")", ".", "decode", "(", "'UTF-8'", ")"...
used to fetch the resource path of the given name. <name> must match a name of defined resource in metadata.yaml returns either a path or False if resource not available
[ "used", "to", "fetch", "the", "resource", "path", "of", "the", "given", "name", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1142-L1156
train
juju/charm-helpers
charmhelpers/core/hookenv.py
atstart
def atstart(callback, *args, **kwargs): '''Schedule a callback to run before the main hook. Callbacks are run in the order they were added. This is useful for modules and classes to perform initialization and inject behavior. In particular: - Run common code before all of your hooks, such as ...
python
def atstart(callback, *args, **kwargs): '''Schedule a callback to run before the main hook. Callbacks are run in the order they were added. This is useful for modules and classes to perform initialization and inject behavior. In particular: - Run common code before all of your hooks, such as ...
[ "def", "atstart", "(", "callback", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "global", "_atstart", "_atstart", ".", "append", "(", "(", "callback", ",", "args", ",", "kwargs", ")", ")" ]
Schedule a callback to run before the main hook. Callbacks are run in the order they were added. This is useful for modules and classes to perform initialization and inject behavior. In particular: - Run common code before all of your hooks, such as logging the hook name or interesting ...
[ "Schedule", "a", "callback", "to", "run", "before", "the", "main", "hook", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1177-L1197
train
juju/charm-helpers
charmhelpers/core/hookenv.py
_run_atstart
def _run_atstart(): '''Hook frameworks must invoke this before running the main hook body.''' global _atstart for callback, args, kwargs in _atstart: callback(*args, **kwargs) del _atstart[:]
python
def _run_atstart(): '''Hook frameworks must invoke this before running the main hook body.''' global _atstart for callback, args, kwargs in _atstart: callback(*args, **kwargs) del _atstart[:]
[ "def", "_run_atstart", "(", ")", ":", "global", "_atstart", "for", "callback", ",", "args", ",", "kwargs", "in", "_atstart", ":", "callback", "(", "*", "args", ",", "*", "*", "kwargs", ")", "del", "_atstart", "[", ":", "]" ]
Hook frameworks must invoke this before running the main hook body.
[ "Hook", "frameworks", "must", "invoke", "this", "before", "running", "the", "main", "hook", "body", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1207-L1212
train
juju/charm-helpers
charmhelpers/core/hookenv.py
_run_atexit
def _run_atexit(): '''Hook frameworks must invoke this after the main hook body has successfully completed. Do not invoke it if the hook fails.''' global _atexit for callback, args, kwargs in reversed(_atexit): callback(*args, **kwargs) del _atexit[:]
python
def _run_atexit(): '''Hook frameworks must invoke this after the main hook body has successfully completed. Do not invoke it if the hook fails.''' global _atexit for callback, args, kwargs in reversed(_atexit): callback(*args, **kwargs) del _atexit[:]
[ "def", "_run_atexit", "(", ")", ":", "global", "_atexit", "for", "callback", ",", "args", ",", "kwargs", "in", "reversed", "(", "_atexit", ")", ":", "callback", "(", "*", "args", ",", "*", "*", "kwargs", ")", "del", "_atexit", "[", ":", "]" ]
Hook frameworks must invoke this after the main hook body has successfully completed. Do not invoke it if the hook fails.
[ "Hook", "frameworks", "must", "invoke", "this", "after", "the", "main", "hook", "body", "has", "successfully", "completed", ".", "Do", "not", "invoke", "it", "if", "the", "hook", "fails", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1215-L1221
train
juju/charm-helpers
charmhelpers/core/hookenv.py
network_get
def network_get(endpoint, relation_id=None): """ Retrieve the network details for a relation endpoint :param endpoint: string. The name of a relation endpoint :param relation_id: int. The ID of the relation for the current context. :return: dict. The loaded YAML output of the network-get query. ...
python
def network_get(endpoint, relation_id=None): """ Retrieve the network details for a relation endpoint :param endpoint: string. The name of a relation endpoint :param relation_id: int. The ID of the relation for the current context. :return: dict. The loaded YAML output of the network-get query. ...
[ "def", "network_get", "(", "endpoint", ",", "relation_id", "=", "None", ")", ":", "if", "not", "has_juju_version", "(", "'2.2'", ")", ":", "raise", "NotImplementedError", "(", "juju_version", "(", ")", ")", "# earlier versions require --primary-address", "if", "re...
Retrieve the network details for a relation endpoint :param endpoint: string. The name of a relation endpoint :param relation_id: int. The ID of the relation for the current context. :return: dict. The loaded YAML output of the network-get query. :raise: NotImplementedError if request not supported by ...
[ "Retrieve", "the", "network", "details", "for", "a", "relation", "endpoint" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1249-L1270
train
juju/charm-helpers
charmhelpers/core/hookenv.py
add_metric
def add_metric(*args, **kwargs): """Add metric values. Values may be expressed with keyword arguments. For metric names containing dashes, these may be expressed as one or more 'key=value' positional arguments. May only be called from the collect-metrics hook.""" _args = ['add-metric'] _kvpairs ...
python
def add_metric(*args, **kwargs): """Add metric values. Values may be expressed with keyword arguments. For metric names containing dashes, these may be expressed as one or more 'key=value' positional arguments. May only be called from the collect-metrics hook.""" _args = ['add-metric'] _kvpairs ...
[ "def", "add_metric", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "_args", "=", "[", "'add-metric'", "]", "_kvpairs", "=", "[", "]", "_kvpairs", ".", "extend", "(", "args", ")", "_kvpairs", ".", "extend", "(", "[", "'{}={}'", ".", "format", ...
Add metric values. Values may be expressed with keyword arguments. For metric names containing dashes, these may be expressed as one or more 'key=value' positional arguments. May only be called from the collect-metrics hook.
[ "Add", "metric", "values", ".", "Values", "may", "be", "expressed", "with", "keyword", "arguments", ".", "For", "metric", "names", "containing", "dashes", "these", "may", "be", "expressed", "as", "one", "or", "more", "key", "=", "value", "positional", "argum...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1273-L1290
train
juju/charm-helpers
charmhelpers/core/hookenv.py
iter_units_for_relation_name
def iter_units_for_relation_name(relation_name): """Iterate through all units in a relation Generator that iterates through all the units in a relation and yields a named tuple with rid and unit field names. Usage: data = [(u.rid, u.unit) for u in iter_units_for_relation_name(relation_...
python
def iter_units_for_relation_name(relation_name): """Iterate through all units in a relation Generator that iterates through all the units in a relation and yields a named tuple with rid and unit field names. Usage: data = [(u.rid, u.unit) for u in iter_units_for_relation_name(relation_...
[ "def", "iter_units_for_relation_name", "(", "relation_name", ")", ":", "RelatedUnit", "=", "namedtuple", "(", "'RelatedUnit'", ",", "'rid, unit'", ")", "for", "rid", "in", "relation_ids", "(", "relation_name", ")", ":", "for", "unit", "in", "related_units", "(", ...
Iterate through all units in a relation Generator that iterates through all the units in a relation and yields a named tuple with rid and unit field names. Usage: data = [(u.rid, u.unit) for u in iter_units_for_relation_name(relation_name)] :param relation_name: string relation name ...
[ "Iterate", "through", "all", "units", "in", "a", "relation" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1304-L1320
train
juju/charm-helpers
charmhelpers/core/hookenv.py
ingress_address
def ingress_address(rid=None, unit=None): """ Retrieve the ingress-address from a relation when available. Otherwise, return the private-address. When used on the consuming side of the relation (unit is a remote unit), the ingress-address is the IP address that this unit needs to use to reach t...
python
def ingress_address(rid=None, unit=None): """ Retrieve the ingress-address from a relation when available. Otherwise, return the private-address. When used on the consuming side of the relation (unit is a remote unit), the ingress-address is the IP address that this unit needs to use to reach t...
[ "def", "ingress_address", "(", "rid", "=", "None", ",", "unit", "=", "None", ")", ":", "settings", "=", "relation_get", "(", "rid", "=", "rid", ",", "unit", "=", "unit", ")", "return", "(", "settings", ".", "get", "(", "'ingress-address'", ")", "or", ...
Retrieve the ingress-address from a relation when available. Otherwise, return the private-address. When used on the consuming side of the relation (unit is a remote unit), the ingress-address is the IP address that this unit needs to use to reach the provided service on the remote unit. When used...
[ "Retrieve", "the", "ingress", "-", "address", "from", "a", "relation", "when", "available", ".", "Otherwise", "return", "the", "private", "-", "address", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1323-L1354
train
juju/charm-helpers
charmhelpers/core/hookenv.py
egress_subnets
def egress_subnets(rid=None, unit=None): """ Retrieve the egress-subnets from a relation. This function is to be used on the providing side of the relation, and provides the ranges of addresses that client connections may come from. The result is uninteresting on the consuming side of a relatio...
python
def egress_subnets(rid=None, unit=None): """ Retrieve the egress-subnets from a relation. This function is to be used on the providing side of the relation, and provides the ranges of addresses that client connections may come from. The result is uninteresting on the consuming side of a relatio...
[ "def", "egress_subnets", "(", "rid", "=", "None", ",", "unit", "=", "None", ")", ":", "def", "_to_range", "(", "addr", ")", ":", "if", "re", ".", "search", "(", "r'^(?:\\d{1,3}\\.){3}\\d{1,3}$'", ",", "addr", ")", "is", "not", "None", ":", "addr", "+="...
Retrieve the egress-subnets from a relation. This function is to be used on the providing side of the relation, and provides the ranges of addresses that client connections may come from. The result is uninteresting on the consuming side of a relation (unit == local_unit()). Returns a stable list ...
[ "Retrieve", "the", "egress", "-", "subnets", "from", "a", "relation", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1357-L1391
train
juju/charm-helpers
charmhelpers/core/hookenv.py
unit_doomed
def unit_doomed(unit=None): """Determines if the unit is being removed from the model Requires Juju 2.4.1. :param unit: string unit name, defaults to local_unit :side effect: calls goal_state :side effect: calls local_unit :side effect: calls has_juju_version :return: True if the unit is b...
python
def unit_doomed(unit=None): """Determines if the unit is being removed from the model Requires Juju 2.4.1. :param unit: string unit name, defaults to local_unit :side effect: calls goal_state :side effect: calls local_unit :side effect: calls has_juju_version :return: True if the unit is b...
[ "def", "unit_doomed", "(", "unit", "=", "None", ")", ":", "if", "not", "has_juju_version", "(", "\"2.4.1\"", ")", ":", "# We cannot risk blindly returning False for 'we don't know',", "# because that could cause data loss; if call sites don't", "# need an accurate answer, they like...
Determines if the unit is being removed from the model Requires Juju 2.4.1. :param unit: string unit name, defaults to local_unit :side effect: calls goal_state :side effect: calls local_unit :side effect: calls has_juju_version :return: True if the unit is being removed, already gone, or neve...
[ "Determines", "if", "the", "unit", "is", "being", "removed", "from", "the", "model" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1394-L1421
train
juju/charm-helpers
charmhelpers/core/hookenv.py
env_proxy_settings
def env_proxy_settings(selected_settings=None): """Get proxy settings from process environment variables. Get charm proxy settings from environment variables that correspond to juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2, see lp:1782236) in a format suitable for passing t...
python
def env_proxy_settings(selected_settings=None): """Get proxy settings from process environment variables. Get charm proxy settings from environment variables that correspond to juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2, see lp:1782236) in a format suitable for passing t...
[ "def", "env_proxy_settings", "(", "selected_settings", "=", "None", ")", ":", "SUPPORTED_SETTINGS", "=", "{", "'http'", ":", "'HTTP_PROXY'", ",", "'https'", ":", "'HTTPS_PROXY'", ",", "'no_proxy'", ":", "'NO_PROXY'", ",", "'ftp'", ":", "'FTP_PROXY'", "}", "if", ...
Get proxy settings from process environment variables. Get charm proxy settings from environment variables that correspond to juju-http-proxy, juju-https-proxy and juju-no-proxy (available as of 2.4.2, see lp:1782236) in a format suitable for passing to an application that reacts to proxy settings pass...
[ "Get", "proxy", "settings", "from", "process", "environment", "variables", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L1424-L1470
train
juju/charm-helpers
charmhelpers/core/hookenv.py
Config.load_previous
def load_previous(self, path=None): """Load previous copy of config from disk. In normal usage you don't need to call this method directly - it is called automatically at object initialization. :param path: File path from which to load the previous config. If `None`, ...
python
def load_previous(self, path=None): """Load previous copy of config from disk. In normal usage you don't need to call this method directly - it is called automatically at object initialization. :param path: File path from which to load the previous config. If `None`, ...
[ "def", "load_previous", "(", "self", ",", "path", "=", "None", ")", ":", "self", ".", "path", "=", "path", "or", "self", ".", "path", "with", "open", "(", "self", ".", "path", ")", "as", "f", ":", "try", ":", "self", ".", "_prev_dict", "=", "json...
Load previous copy of config from disk. In normal usage you don't need to call this method directly - it is called automatically at object initialization. :param path: File path from which to load the previous config. If `None`, config is loaded from the default locati...
[ "Load", "previous", "copy", "of", "config", "from", "disk", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L327-L350
train
juju/charm-helpers
charmhelpers/core/hookenv.py
Config.changed
def changed(self, key): """Return True if the current value for this key is different from the previous value. """ if self._prev_dict is None: return True return self.previous(key) != self.get(key)
python
def changed(self, key): """Return True if the current value for this key is different from the previous value. """ if self._prev_dict is None: return True return self.previous(key) != self.get(key)
[ "def", "changed", "(", "self", ",", "key", ")", ":", "if", "self", ".", "_prev_dict", "is", "None", ":", "return", "True", "return", "self", ".", "previous", "(", "key", ")", "!=", "self", ".", "get", "(", "key", ")" ]
Return True if the current value for this key is different from the previous value.
[ "Return", "True", "if", "the", "current", "value", "for", "this", "key", "is", "different", "from", "the", "previous", "value", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L352-L359
train
juju/charm-helpers
charmhelpers/core/hookenv.py
Config.save
def save(self): """Save this config to disk. If the charm is using the :mod:`Services Framework <services.base>` or :meth:'@hook <Hooks.hook>' decorator, this is called automatically at the end of successful hook execution. Otherwise, it should be called directly by user code. ...
python
def save(self): """Save this config to disk. If the charm is using the :mod:`Services Framework <services.base>` or :meth:'@hook <Hooks.hook>' decorator, this is called automatically at the end of successful hook execution. Otherwise, it should be called directly by user code. ...
[ "def", "save", "(", "self", ")", ":", "with", "open", "(", "self", ".", "path", ",", "'w'", ")", "as", "f", ":", "os", ".", "fchmod", "(", "f", ".", "fileno", "(", ")", ",", "0o600", ")", "json", ".", "dump", "(", "self", ",", "f", ")" ]
Save this config to disk. If the charm is using the :mod:`Services Framework <services.base>` or :meth:'@hook <Hooks.hook>' decorator, this is called automatically at the end of successful hook execution. Otherwise, it should be called directly by user code. To disable automati...
[ "Save", "this", "config", "to", "disk", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L370-L384
train
juju/charm-helpers
charmhelpers/core/hookenv.py
Hooks.hook
def hook(self, *hook_names): """Decorator, registering them as hooks""" def wrapper(decorated): for hook_name in hook_names: self.register(hook_name, decorated) else: self.register(decorated.__name__, decorated) if '_' in decorated....
python
def hook(self, *hook_names): """Decorator, registering them as hooks""" def wrapper(decorated): for hook_name in hook_names: self.register(hook_name, decorated) else: self.register(decorated.__name__, decorated) if '_' in decorated....
[ "def", "hook", "(", "self", ",", "*", "hook_names", ")", ":", "def", "wrapper", "(", "decorated", ")", ":", "for", "hook_name", "in", "hook_names", ":", "self", ".", "register", "(", "hook_name", ",", "decorated", ")", "else", ":", "self", ".", "regist...
Decorator, registering them as hooks
[ "Decorator", "registering", "them", "as", "hooks" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/hookenv.py#L923-L934
train
juju/charm-helpers
charmhelpers/fetch/python/rpdb.py
Rpdb.shutdown
def shutdown(self): """Revert stdin and stdout, close the socket.""" sys.stdout = self.old_stdout sys.stdin = self.old_stdin self.skt.close() self.set_continue()
python
def shutdown(self): """Revert stdin and stdout, close the socket.""" sys.stdout = self.old_stdout sys.stdin = self.old_stdin self.skt.close() self.set_continue()
[ "def", "shutdown", "(", "self", ")", ":", "sys", ".", "stdout", "=", "self", ".", "old_stdout", "sys", ".", "stdin", "=", "self", ".", "old_stdin", "self", ".", "skt", ".", "close", "(", ")", "self", ".", "set_continue", "(", ")" ]
Revert stdin and stdout, close the socket.
[ "Revert", "stdin", "and", "stdout", "close", "the", "socket", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/python/rpdb.py#L44-L49
train
juju/charm-helpers
charmhelpers/contrib/benchmark/__init__.py
Benchmark.start
def start(): action_set('meta.start', time.strftime('%Y-%m-%dT%H:%M:%SZ')) """ If the collectd charm is also installed, tell it to send a snapshot of the current profile data. """ COLLECT_PROFILE_DATA = '/usr/local/bin/collect-profile-data' if os.path.exists(COLL...
python
def start(): action_set('meta.start', time.strftime('%Y-%m-%dT%H:%M:%SZ')) """ If the collectd charm is also installed, tell it to send a snapshot of the current profile data. """ COLLECT_PROFILE_DATA = '/usr/local/bin/collect-profile-data' if os.path.exists(COLL...
[ "def", "start", "(", ")", ":", "action_set", "(", "'meta.start'", ",", "time", ".", "strftime", "(", "'%Y-%m-%dT%H:%M:%SZ'", ")", ")", "COLLECT_PROFILE_DATA", "=", "'/usr/local/bin/collect-profile-data'", "if", "os", ".", "path", ".", "exists", "(", "COLLECT_PROFI...
If the collectd charm is also installed, tell it to send a snapshot of the current profile data.
[ "If", "the", "collectd", "charm", "is", "also", "installed", "tell", "it", "to", "send", "a", "snapshot", "of", "the", "current", "profile", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/benchmark/__init__.py#L99-L108
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_os_codename_install_source
def get_os_codename_install_source(src): '''Derive OpenStack release codename from a given installation source.''' ubuntu_rel = lsb_release()['DISTRIB_CODENAME'] rel = '' if src is None: return rel if src in ['distro', 'distro-proposed', 'proposed']: try: rel = UBUNTU_OPE...
python
def get_os_codename_install_source(src): '''Derive OpenStack release codename from a given installation source.''' ubuntu_rel = lsb_release()['DISTRIB_CODENAME'] rel = '' if src is None: return rel if src in ['distro', 'distro-proposed', 'proposed']: try: rel = UBUNTU_OPE...
[ "def", "get_os_codename_install_source", "(", "src", ")", ":", "ubuntu_rel", "=", "lsb_release", "(", ")", "[", "'DISTRIB_CODENAME'", "]", "rel", "=", "''", "if", "src", "is", "None", ":", "return", "rel", "if", "src", "in", "[", "'distro'", ",", "'distro-...
Derive OpenStack release codename from a given installation source.
[ "Derive", "OpenStack", "release", "codename", "from", "a", "given", "installation", "source", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L322-L348
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_os_version_codename
def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES): '''Determine OpenStack version number from codename.''' for k, v in six.iteritems(version_map): if v == codename: return k e = 'Could not derive OpenStack version for '\ 'codename: %s' % codename error_ou...
python
def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES): '''Determine OpenStack version number from codename.''' for k, v in six.iteritems(version_map): if v == codename: return k e = 'Could not derive OpenStack version for '\ 'codename: %s' % codename error_ou...
[ "def", "get_os_version_codename", "(", "codename", ",", "version_map", "=", "OPENSTACK_CODENAMES", ")", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "version_map", ")", ":", "if", "v", "==", "codename", ":", "return", "k", "e", "=", "'C...
Determine OpenStack version number from codename.
[ "Determine", "OpenStack", "version", "number", "from", "codename", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L365-L372
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_os_version_codename_swift
def get_os_version_codename_swift(codename): '''Determine OpenStack version number of swift from codename.''' for k, v in six.iteritems(SWIFT_CODENAMES): if k == codename: return v[-1] e = 'Could not derive swift version for '\ 'codename: %s' % codename error_out(e)
python
def get_os_version_codename_swift(codename): '''Determine OpenStack version number of swift from codename.''' for k, v in six.iteritems(SWIFT_CODENAMES): if k == codename: return v[-1] e = 'Could not derive swift version for '\ 'codename: %s' % codename error_out(e)
[ "def", "get_os_version_codename_swift", "(", "codename", ")", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "SWIFT_CODENAMES", ")", ":", "if", "k", "==", "codename", ":", "return", "v", "[", "-", "1", "]", "e", "=", "'Could not derive sw...
Determine OpenStack version number of swift from codename.
[ "Determine", "OpenStack", "version", "number", "of", "swift", "from", "codename", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L375-L382
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_swift_codename
def get_swift_codename(version): '''Determine OpenStack codename that corresponds to swift version.''' codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v] if len(codenames) > 1: # If more than one release codename contains this version we determine # the actual codena...
python
def get_swift_codename(version): '''Determine OpenStack codename that corresponds to swift version.''' codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v] if len(codenames) > 1: # If more than one release codename contains this version we determine # the actual codena...
[ "def", "get_swift_codename", "(", "version", ")", ":", "codenames", "=", "[", "k", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "SWIFT_CODENAMES", ")", "if", "version", "in", "v", "]", "if", "len", "(", "codenames", ")", ">", "1", ":", ...
Determine OpenStack codename that corresponds to swift version.
[ "Determine", "OpenStack", "codename", "that", "corresponds", "to", "swift", "version", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L385-L412
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_os_codename_package
def get_os_codename_package(package, fatal=True): '''Derive OpenStack release codename from an installed package.''' if snap_install_requested(): cmd = ['snap', 'list', package] try: out = subprocess.check_output(cmd) if six.PY3: out = out.decode('UTF-8')...
python
def get_os_codename_package(package, fatal=True): '''Derive OpenStack release codename from an installed package.''' if snap_install_requested(): cmd = ['snap', 'list', package] try: out = subprocess.check_output(cmd) if six.PY3: out = out.decode('UTF-8')...
[ "def", "get_os_codename_package", "(", "package", ",", "fatal", "=", "True", ")", ":", "if", "snap_install_requested", "(", ")", ":", "cmd", "=", "[", "'snap'", ",", "'list'", ",", "package", "]", "try", ":", "out", "=", "subprocess", ".", "check_output", ...
Derive OpenStack release codename from an installed package.
[ "Derive", "OpenStack", "release", "codename", "from", "an", "installed", "package", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L415-L483
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_os_version_package
def get_os_version_package(pkg, fatal=True): '''Derive OpenStack version number from an installed package.''' codename = get_os_codename_package(pkg, fatal=fatal) if not codename: return None if 'swift' in pkg: vers_map = SWIFT_CODENAMES for cname, version in six.iteritems(vers...
python
def get_os_version_package(pkg, fatal=True): '''Derive OpenStack version number from an installed package.''' codename = get_os_codename_package(pkg, fatal=fatal) if not codename: return None if 'swift' in pkg: vers_map = SWIFT_CODENAMES for cname, version in six.iteritems(vers...
[ "def", "get_os_version_package", "(", "pkg", ",", "fatal", "=", "True", ")", ":", "codename", "=", "get_os_codename_package", "(", "pkg", ",", "fatal", "=", "fatal", ")", "if", "not", "codename", ":", "return", "None", "if", "'swift'", "in", "pkg", ":", ...
Derive OpenStack version number from an installed package.
[ "Derive", "OpenStack", "version", "number", "from", "an", "installed", "package", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L486-L502
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
os_release
def os_release(package, base='essex', reset_cache=False): ''' Returns OpenStack release codename from a cached global. If reset_cache then unset the cached os_release version and return the freshly determined version. If the codename can not be determined from either an installed package or th...
python
def os_release(package, base='essex', reset_cache=False): ''' Returns OpenStack release codename from a cached global. If reset_cache then unset the cached os_release version and return the freshly determined version. If the codename can not be determined from either an installed package or th...
[ "def", "os_release", "(", "package", ",", "base", "=", "'essex'", ",", "reset_cache", "=", "False", ")", ":", "global", "_os_rel", "if", "reset_cache", ":", "reset_os_release", "(", ")", "if", "_os_rel", ":", "return", "_os_rel", "_os_rel", "=", "(", "get_...
Returns OpenStack release codename from a cached global. If reset_cache then unset the cached os_release version and return the freshly determined version. If the codename can not be determined from either an installed package or the installation source, the earliest release supported by the charm sho...
[ "Returns", "OpenStack", "release", "codename", "from", "a", "cached", "global", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L517-L537
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
import_key
def import_key(keyid): """Import a key, either ASCII armored, or a GPG key id. @param keyid: the key in ASCII armor format, or a GPG key id. @raises SystemExit() via sys.exit() on failure. """ try: return fetch_import_key(keyid) except GPGKeyError as e: error_out("Could not impo...
python
def import_key(keyid): """Import a key, either ASCII armored, or a GPG key id. @param keyid: the key in ASCII armor format, or a GPG key id. @raises SystemExit() via sys.exit() on failure. """ try: return fetch_import_key(keyid) except GPGKeyError as e: error_out("Could not impo...
[ "def", "import_key", "(", "keyid", ")", ":", "try", ":", "return", "fetch_import_key", "(", "keyid", ")", "except", "GPGKeyError", "as", "e", ":", "error_out", "(", "\"Could not import key: {}\"", ".", "format", "(", "str", "(", "e", ")", ")", ")" ]
Import a key, either ASCII armored, or a GPG key id. @param keyid: the key in ASCII armor format, or a GPG key id. @raises SystemExit() via sys.exit() on failure.
[ "Import", "a", "key", "either", "ASCII", "armored", "or", "a", "GPG", "key", "id", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L541-L550
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
get_source_and_pgp_key
def get_source_and_pgp_key(source_and_key): """Look for a pgp key ID or ascii-armor key in the given input. :param source_and_key: Sting, "source_spec|keyid" where '|keyid' is optional. :returns (source_spec, key_id OR None) as a tuple. Returns None for key_id if there was no '|' in the so...
python
def get_source_and_pgp_key(source_and_key): """Look for a pgp key ID or ascii-armor key in the given input. :param source_and_key: Sting, "source_spec|keyid" where '|keyid' is optional. :returns (source_spec, key_id OR None) as a tuple. Returns None for key_id if there was no '|' in the so...
[ "def", "get_source_and_pgp_key", "(", "source_and_key", ")", ":", "try", ":", "source", ",", "key", "=", "source_and_key", ".", "split", "(", "'|'", ",", "2", ")", "return", "source", ",", "key", "or", "None", "except", "ValueError", ":", "return", "source...
Look for a pgp key ID or ascii-armor key in the given input. :param source_and_key: Sting, "source_spec|keyid" where '|keyid' is optional. :returns (source_spec, key_id OR None) as a tuple. Returns None for key_id if there was no '|' in the source_and_key string.
[ "Look", "for", "a", "pgp", "key", "ID", "or", "ascii", "-", "armor", "key", "in", "the", "given", "input", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L553-L565
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
configure_installation_source
def configure_installation_source(source_plus_key): """Configure an installation source. The functionality is provided by charmhelpers.fetch.add_source() The difference between the two functions is that add_source() signature requires the key to be passed directly, whereas this function passes an o...
python
def configure_installation_source(source_plus_key): """Configure an installation source. The functionality is provided by charmhelpers.fetch.add_source() The difference between the two functions is that add_source() signature requires the key to be passed directly, whereas this function passes an o...
[ "def", "configure_installation_source", "(", "source_plus_key", ")", ":", "if", "source_plus_key", ".", "startswith", "(", "'snap'", ")", ":", "# Do nothing for snap installs", "return", "# extract the key if there is one, denoted by a '|' in the rel", "source", ",", "key", "...
Configure an installation source. The functionality is provided by charmhelpers.fetch.add_source() The difference between the two functions is that add_source() signature requires the key to be passed directly, whereas this function passes an optional key by appending '|<key>' to the end of the source ...
[ "Configure", "an", "installation", "source", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L570-L600
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
config_value_changed
def config_value_changed(option): """ Determine if config value changed since last call to this function. """ hook_data = unitdata.HookData() with hook_data(): db = unitdata.kv() current = config(option) saved = db.get(option) db.set(option, current) if saved ...
python
def config_value_changed(option): """ Determine if config value changed since last call to this function. """ hook_data = unitdata.HookData() with hook_data(): db = unitdata.kv() current = config(option) saved = db.get(option) db.set(option, current) if saved ...
[ "def", "config_value_changed", "(", "option", ")", ":", "hook_data", "=", "unitdata", ".", "HookData", "(", ")", "with", "hook_data", "(", ")", ":", "db", "=", "unitdata", ".", "kv", "(", ")", "current", "=", "config", "(", "option", ")", "saved", "=",...
Determine if config value changed since last call to this function.
[ "Determine", "if", "config", "value", "changed", "since", "last", "call", "to", "this", "function", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L603-L615
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
save_script_rc
def save_script_rc(script_path="scripts/scriptrc", **env_vars): """ Write an rc file in the charm-delivered directory containing exported environment variables provided by env_vars. Any charm scripts run outside the juju hook environment can source this scriptrc to obtain updated config information ...
python
def save_script_rc(script_path="scripts/scriptrc", **env_vars): """ Write an rc file in the charm-delivered directory containing exported environment variables provided by env_vars. Any charm scripts run outside the juju hook environment can source this scriptrc to obtain updated config information ...
[ "def", "save_script_rc", "(", "script_path", "=", "\"scripts/scriptrc\"", ",", "*", "*", "env_vars", ")", ":", "juju_rc_path", "=", "\"%s/%s\"", "%", "(", "charm_dir", "(", ")", ",", "script_path", ")", "if", "not", "os", ".", "path", ".", "exists", "(", ...
Write an rc file in the charm-delivered directory containing exported environment variables provided by env_vars. Any charm scripts run outside the juju hook environment can source this scriptrc to obtain updated config information necessary to perform health checks or service changes.
[ "Write", "an", "rc", "file", "in", "the", "charm", "-", "delivered", "directory", "containing", "exported", "environment", "variables", "provided", "by", "env_vars", ".", "Any", "charm", "scripts", "run", "outside", "the", "juju", "hook", "environment", "can", ...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L618-L633
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
openstack_upgrade_available
def openstack_upgrade_available(package): """ Determines if an OpenStack upgrade is available from installation source, based on version of installed package. :param package: str: Name of installed package. :returns: bool: : Returns True if configured installation source offers ...
python
def openstack_upgrade_available(package): """ Determines if an OpenStack upgrade is available from installation source, based on version of installed package. :param package: str: Name of installed package. :returns: bool: : Returns True if configured installation source offers ...
[ "def", "openstack_upgrade_available", "(", "package", ")", ":", "import", "apt_pkg", "as", "apt", "src", "=", "config", "(", "'openstack-origin'", ")", "cur_vers", "=", "get_os_version_package", "(", "package", ")", "if", "not", "cur_vers", ":", "# The package has...
Determines if an OpenStack upgrade is available from installation source, based on version of installed package. :param package: str: Name of installed package. :returns: bool: : Returns True if configured installation source offers a newer version of package.
[ "Determines", "if", "an", "OpenStack", "upgrade", "is", "available", "from", "installation", "source", "based", "on", "version", "of", "installed", "package", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L636-L659
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
ensure_block_device
def ensure_block_device(block_device): ''' Confirm block_device, create as loopback if necessary. :param block_device: str: Full path of block device to ensure. :returns: str: Full path of ensured block device. ''' _none = ['None', 'none', None] if (block_device in _none): error_ou...
python
def ensure_block_device(block_device): ''' Confirm block_device, create as loopback if necessary. :param block_device: str: Full path of block device to ensure. :returns: str: Full path of ensured block device. ''' _none = ['None', 'none', None] if (block_device in _none): error_ou...
[ "def", "ensure_block_device", "(", "block_device", ")", ":", "_none", "=", "[", "'None'", ",", "'none'", ",", "None", "]", "if", "(", "block_device", "in", "_none", ")", ":", "error_out", "(", "'prepare_storage(): Missing required input: block_device=%s.'", "%", "...
Confirm block_device, create as loopback if necessary. :param block_device: str: Full path of block device to ensure. :returns: str: Full path of ensured block device.
[ "Confirm", "block_device", "create", "as", "loopback", "if", "necessary", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L662-L691
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
os_requires_version
def os_requires_version(ostack_release, pkg): """ Decorator for hook to specify minimum supported release """ def wrap(f): @wraps(f) def wrapped_f(*args): if os_release(pkg) < ostack_release: raise Exception("This hook is not supported on releases" ...
python
def os_requires_version(ostack_release, pkg): """ Decorator for hook to specify minimum supported release """ def wrap(f): @wraps(f) def wrapped_f(*args): if os_release(pkg) < ostack_release: raise Exception("This hook is not supported on releases" ...
[ "def", "os_requires_version", "(", "ostack_release", ",", "pkg", ")", ":", "def", "wrap", "(", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapped_f", "(", "*", "args", ")", ":", "if", "os_release", "(", "pkg", ")", "<", "ostack_release", ":"...
Decorator for hook to specify minimum supported release
[ "Decorator", "for", "hook", "to", "specify", "minimum", "supported", "release" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L754-L766
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
os_workload_status
def os_workload_status(configs, required_interfaces, charm_func=None): """ Decorator to set workload status based on complete contexts """ def wrap(f): @wraps(f) def wrapped_f(*args, **kwargs): # Run the original function first f(*args, **kwargs) # Set...
python
def os_workload_status(configs, required_interfaces, charm_func=None): """ Decorator to set workload status based on complete contexts """ def wrap(f): @wraps(f) def wrapped_f(*args, **kwargs): # Run the original function first f(*args, **kwargs) # Set...
[ "def", "os_workload_status", "(", "configs", ",", "required_interfaces", ",", "charm_func", "=", "None", ")", ":", "def", "wrap", "(", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapped_f", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":"...
Decorator to set workload status based on complete contexts
[ "Decorator", "to", "set", "workload", "status", "based", "on", "complete", "contexts" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L769-L782
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
set_os_workload_status
def set_os_workload_status(configs, required_interfaces, charm_func=None, services=None, ports=None): """Set the state of the workload status for the charm. This calls _determine_os_workload_status() to get the new state, message and sets the status using status_set() @param...
python
def set_os_workload_status(configs, required_interfaces, charm_func=None, services=None, ports=None): """Set the state of the workload status for the charm. This calls _determine_os_workload_status() to get the new state, message and sets the status using status_set() @param...
[ "def", "set_os_workload_status", "(", "configs", ",", "required_interfaces", ",", "charm_func", "=", "None", ",", "services", "=", "None", ",", "ports", "=", "None", ")", ":", "state", ",", "message", "=", "_determine_os_workload_status", "(", "configs", ",", ...
Set the state of the workload status for the charm. This calls _determine_os_workload_status() to get the new state, message and sets the status using status_set() @param configs: a templating.OSConfigRenderer() object @param required_interfaces: {generic: [specific, specific2, ...]} @param charm_...
[ "Set", "the", "state", "of", "the", "workload", "status", "for", "the", "charm", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L785-L802
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
_determine_os_workload_status
def _determine_os_workload_status( configs, required_interfaces, charm_func=None, services=None, ports=None): """Determine the state of the workload status for the charm. This function returns the new workload status for the charm based on the state of the interfaces, the paused state and w...
python
def _determine_os_workload_status( configs, required_interfaces, charm_func=None, services=None, ports=None): """Determine the state of the workload status for the charm. This function returns the new workload status for the charm based on the state of the interfaces, the paused state and w...
[ "def", "_determine_os_workload_status", "(", "configs", ",", "required_interfaces", ",", "charm_func", "=", "None", ",", "services", "=", "None", ",", "ports", "=", "None", ")", ":", "state", ",", "message", "=", "_ows_check_if_paused", "(", "services", ",", "...
Determine the state of the workload status for the charm. This function returns the new workload status for the charm based on the state of the interfaces, the paused state and whether the services are actually running and any specified ports are open. This checks: 1. if the unit should be pause...
[ "Determine", "the", "state", "of", "the", "workload", "status", "for", "the", "charm", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L805-L853
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
_ows_check_generic_interfaces
def _ows_check_generic_interfaces(configs, required_interfaces): """Check the complete contexts to determine the workload status. - Checks for missing or incomplete contexts - juju log details of missing required data. - determines the correct workload status - creates an appropriate message fo...
python
def _ows_check_generic_interfaces(configs, required_interfaces): """Check the complete contexts to determine the workload status. - Checks for missing or incomplete contexts - juju log details of missing required data. - determines the correct workload status - creates an appropriate message fo...
[ "def", "_ows_check_generic_interfaces", "(", "configs", ",", "required_interfaces", ")", ":", "incomplete_rel_data", "=", "incomplete_relation_data", "(", "configs", ",", "required_interfaces", ")", "state", "=", "None", "message", "=", "None", "missing_relations", "=",...
Check the complete contexts to determine the workload status. - Checks for missing or incomplete contexts - juju log details of missing required data. - determines the correct workload status - creates an appropriate message for status_set(...) if there are no problems then the function return...
[ "Check", "the", "complete", "contexts", "to", "determine", "the", "workload", "status", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L890-L969
train
juju/charm-helpers
charmhelpers/contrib/openstack/utils.py
_ows_check_services_running
def _ows_check_services_running(services, ports): """Check that the services that should be running are actually running and that any ports specified are being listened to. @param services: list of strings OR dictionary specifying services/ports @param ports: list of ports @returns state, message: ...
python
def _ows_check_services_running(services, ports): """Check that the services that should be running are actually running and that any ports specified are being listened to. @param services: list of strings OR dictionary specifying services/ports @param ports: list of ports @returns state, message: ...
[ "def", "_ows_check_services_running", "(", "services", ",", "ports", ")", ":", "messages", "=", "[", "]", "state", "=", "None", "if", "services", "is", "not", "None", ":", "services", "=", "_extract_services_list_helper", "(", "services", ")", "services_running"...
Check that the services that should be running are actually running and that any ports specified are being listened to. @param services: list of strings OR dictionary specifying services/ports @param ports: list of ports @returns state, message: strings or None, None
[ "Check", "that", "the", "services", "that", "should", "be", "running", "are", "actually", "running", "and", "that", "any", "ports", "specified", "are", "being", "listened", "to", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/utils.py#L998-L1046
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train