id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
12,600
juju/charm-helpers
charmhelpers/contrib/ansible/__init__.py
AnsibleHooks.action
def action(self, *action_names): """Decorator, registering them as actions""" def action_wrapper(decorated): @functools.wraps(decorated) def wrapper(argv): kwargs = dict(arg.split('=') for arg in argv) try: return decorated(**k...
python
def action(self, *action_names): """Decorator, registering them as actions""" def action_wrapper(decorated): @functools.wraps(decorated) def wrapper(argv): kwargs = dict(arg.split('=') for arg in argv) try: return decorated(**k...
[ "def", "action", "(", "self", ",", "*", "action_names", ")", ":", "def", "action_wrapper", "(", "decorated", ")", ":", "@", "functools", ".", "wraps", "(", "decorated", ")", "def", "wrapper", "(", "argv", ")", ":", "kwargs", "=", "dict", "(", "arg", ...
Decorator, registering them as actions
[ "Decorator", "registering", "them", "as", "actions" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/ansible/__init__.py#L231-L252
12,601
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment.get_logger
def get_logger(self, name="deployment-logger", level=logging.DEBUG): """Get a logger object that will log to stdout.""" log = logging logger = log.getLogger(name) fmt = log.Formatter("%(asctime)s %(funcName)s " "%(levelname)s: %(message)s") handler = ...
python
def get_logger(self, name="deployment-logger", level=logging.DEBUG): """Get a logger object that will log to stdout.""" log = logging logger = log.getLogger(name) fmt = log.Formatter("%(asctime)s %(funcName)s " "%(levelname)s: %(message)s") handler = ...
[ "def", "get_logger", "(", "self", ",", "name", "=", "\"deployment-logger\"", ",", "level", "=", "logging", ".", "DEBUG", ")", ":", "log", "=", "logging", "logger", "=", "log", ".", "getLogger", "(", "name", ")", "fmt", "=", "log", ".", "Formatter", "("...
Get a logger object that will log to stdout.
[ "Get", "a", "logger", "object", "that", "will", "log", "to", "stdout", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L49-L63
12,602
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment._determine_branch_locations
def _determine_branch_locations(self, other_services): """Determine the branch locations for the other services. Determine if the local branch being tested is derived from its stable or next (dev) branch, and based on this, use the corresonding stable or next branches for the o...
python
def _determine_branch_locations(self, other_services): """Determine the branch locations for the other services. Determine if the local branch being tested is derived from its stable or next (dev) branch, and based on this, use the corresonding stable or next branches for the o...
[ "def", "_determine_branch_locations", "(", "self", ",", "other_services", ")", ":", "self", ".", "log", ".", "info", "(", "'OpenStackAmuletDeployment: determine branch locations'", ")", "# Charms outside the ~openstack-charmers", "base_charms", "=", "{", "'mysql'", ":", ...
Determine the branch locations for the other services. Determine if the local branch being tested is derived from its stable or next (dev) branch, and based on this, use the corresonding stable or next branches for the other_services.
[ "Determine", "the", "branch", "locations", "for", "the", "other", "services", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L65-L103
12,603
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment._auto_wait_for_status
def _auto_wait_for_status(self, message=None, exclude_services=None, include_only=None, timeout=None): """Wait for all units to have a specific extended status, except for any defined as excluded. Unless specified via message, any status containing any case of 'rea...
python
def _auto_wait_for_status(self, message=None, exclude_services=None, include_only=None, timeout=None): """Wait for all units to have a specific extended status, except for any defined as excluded. Unless specified via message, any status containing any case of 'rea...
[ "def", "_auto_wait_for_status", "(", "self", ",", "message", "=", "None", ",", "exclude_services", "=", "None", ",", "include_only", "=", "None", ",", "timeout", "=", "None", ")", ":", "if", "not", "timeout", ":", "timeout", "=", "int", "(", "os", ".", ...
Wait for all units to have a specific extended status, except for any defined as excluded. Unless specified via message, any status containing any case of 'ready' will be considered a match. Examples of message usage: Wait for all unit status to CONTAIN any case of 'ready' or 'ok': ...
[ "Wait", "for", "all", "units", "to", "have", "a", "specific", "extended", "status", "except", "for", "any", "defined", "as", "excluded", ".", "Unless", "specified", "via", "message", "any", "status", "containing", "any", "case", "of", "ready", "will", "be", ...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L192-L269
12,604
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment._get_openstack_release
def _get_openstack_release(self): """Get openstack release. Return an integer representing the enum value of the openstack release. """ # Must be ordered by OpenStack release (not by Ubuntu release): for i, os_pair in enumerate(OPENSTACK_RELEASES_PAIRS): ...
python
def _get_openstack_release(self): """Get openstack release. Return an integer representing the enum value of the openstack release. """ # Must be ordered by OpenStack release (not by Ubuntu release): for i, os_pair in enumerate(OPENSTACK_RELEASES_PAIRS): ...
[ "def", "_get_openstack_release", "(", "self", ")", ":", "# Must be ordered by OpenStack release (not by Ubuntu release):", "for", "i", ",", "os_pair", "in", "enumerate", "(", "OPENSTACK_RELEASES_PAIRS", ")", ":", "setattr", "(", "self", ",", "os_pair", ",", "i", ")", ...
Get openstack release. Return an integer representing the enum value of the openstack release.
[ "Get", "openstack", "release", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L271-L300
12,605
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment._get_openstack_release_string
def _get_openstack_release_string(self): """Get openstack release string. Return a string representing the openstack release. """ releases = OrderedDict([ ('trusty', 'icehouse'), ('xenial', 'mitaka'), ('yakkety', 'newton'), ('zesty',...
python
def _get_openstack_release_string(self): """Get openstack release string. Return a string representing the openstack release. """ releases = OrderedDict([ ('trusty', 'icehouse'), ('xenial', 'mitaka'), ('yakkety', 'newton'), ('zesty',...
[ "def", "_get_openstack_release_string", "(", "self", ")", ":", "releases", "=", "OrderedDict", "(", "[", "(", "'trusty'", ",", "'icehouse'", ")", ",", "(", "'xenial'", ",", "'mitaka'", ")", ",", "(", "'yakkety'", ",", "'newton'", ")", ",", "(", "'zesty'", ...
Get openstack release string. Return a string representing the openstack release.
[ "Get", "openstack", "release", "string", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L302-L321
12,606
juju/charm-helpers
charmhelpers/contrib/openstack/amulet/deployment.py
OpenStackAmuletDeployment.get_ceph_expected_pools
def get_ceph_expected_pools(self, radosgw=False): """Return a list of expected ceph pools in a ceph + cinder + glance test scenario, based on OpenStack release and whether ceph radosgw is flagged as present or not.""" if self._get_openstack_release() == self.trusty_icehouse: ...
python
def get_ceph_expected_pools(self, radosgw=False): """Return a list of expected ceph pools in a ceph + cinder + glance test scenario, based on OpenStack release and whether ceph radosgw is flagged as present or not.""" if self._get_openstack_release() == self.trusty_icehouse: ...
[ "def", "get_ceph_expected_pools", "(", "self", ",", "radosgw", "=", "False", ")", ":", "if", "self", ".", "_get_openstack_release", "(", ")", "==", "self", ".", "trusty_icehouse", ":", "# Icehouse", "pools", "=", "[", "'data'", ",", "'metadata'", ",", "'rbd'...
Return a list of expected ceph pools in a ceph + cinder + glance test scenario, based on OpenStack release and whether ceph radosgw is flagged as present or not.
[ "Return", "a", "list", "of", "expected", "ceph", "pools", "in", "a", "ceph", "+", "cinder", "+", "glance", "test", "scenario", "based", "on", "OpenStack", "release", "and", "whether", "ceph", "radosgw", "is", "flagged", "as", "present", "or", "not", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/amulet/deployment.py#L323-L361
12,607
juju/charm-helpers
charmhelpers/osplatform.py
get_platform
def get_platform(): """Return the current OS platform. For example: if current os platform is Ubuntu then a string "ubuntu" will be returned (which is the name of the module). This string is used to decide which platform module should be imported. """ # linux_distribution is deprecated and will...
python
def get_platform(): """Return the current OS platform. For example: if current os platform is Ubuntu then a string "ubuntu" will be returned (which is the name of the module). This string is used to decide which platform module should be imported. """ # linux_distribution is deprecated and will...
[ "def", "get_platform", "(", ")", ":", "# linux_distribution is deprecated and will be removed in Python 3.7", "# Warings *not* disabled, as we certainly need to fix this.", "tuple_platform", "=", "platform", ".", "linux_distribution", "(", ")", "current_platform", "=", "tuple_platfor...
Return the current OS platform. For example: if current os platform is Ubuntu then a string "ubuntu" will be returned (which is the name of the module). This string is used to decide which platform module should be imported.
[ "Return", "the", "current", "OS", "platform", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/osplatform.py#L4-L25
12,608
juju/charm-helpers
charmhelpers/fetch/python/version.py
current_version_string
def current_version_string(): """Current system python version as string major.minor.micro""" return "{0}.{1}.{2}".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
python
def current_version_string(): """Current system python version as string major.minor.micro""" return "{0}.{1}.{2}".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
[ "def", "current_version_string", "(", ")", ":", "return", "\"{0}.{1}.{2}\"", ".", "format", "(", "sys", ".", "version_info", ".", "major", ",", "sys", ".", "version_info", ".", "minor", ",", "sys", ".", "version_info", ".", "micro", ")" ]
Current system python version as string major.minor.micro
[ "Current", "system", "python", "version", "as", "string", "major", ".", "minor", ".", "micro" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/python/version.py#L28-L32
12,609
juju/charm-helpers
charmhelpers/contrib/hardening/mysql/checks/config.py
get_audits
def get_audits(): """Get MySQL hardening config audits. :returns: dictionary of audits """ if subprocess.call(['which', 'mysql'], stdout=subprocess.PIPE) != 0: log("MySQL does not appear to be installed on this node - " "skipping mysql hardening", level=WARNING) return [] ...
python
def get_audits(): """Get MySQL hardening config audits. :returns: dictionary of audits """ if subprocess.call(['which', 'mysql'], stdout=subprocess.PIPE) != 0: log("MySQL does not appear to be installed on this node - " "skipping mysql hardening", level=WARNING) return [] ...
[ "def", "get_audits", "(", ")", ":", "if", "subprocess", ".", "call", "(", "[", "'which'", ",", "'mysql'", "]", ",", "stdout", "=", "subprocess", ".", "PIPE", ")", "!=", "0", ":", "log", "(", "\"MySQL does not appear to be installed on this node - \"", "\"skipp...
Get MySQL hardening config audits. :returns: dictionary of audits
[ "Get", "MySQL", "hardening", "config", "audits", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/mysql/checks/config.py#L31-L73
12,610
juju/charm-helpers
charmhelpers/core/host.py
service_reload
def service_reload(service_name, restart_on_failure=False, **kwargs): """Reload a system service, optionally falling back to restart if reload fails. The specified service name is managed via the system level init system. Some init systems (e.g. upstart) require that additional arguments be provide...
python
def service_reload(service_name, restart_on_failure=False, **kwargs): """Reload a system service, optionally falling back to restart if reload fails. The specified service name is managed via the system level init system. Some init systems (e.g. upstart) require that additional arguments be provide...
[ "def", "service_reload", "(", "service_name", ",", "restart_on_failure", "=", "False", ",", "*", "*", "kwargs", ")", ":", "service_result", "=", "service", "(", "'reload'", ",", "service_name", ",", "*", "*", "kwargs", ")", "if", "not", "service_result", "an...
Reload a system service, optionally falling back to restart if reload fails. The specified service name is managed via the system level init system. Some init systems (e.g. upstart) require that additional arguments be provided in order to directly control service instances whereas other init syste...
[ "Reload", "a", "system", "service", "optionally", "falling", "back", "to", "restart", "if", "reload", "fails", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L143-L173
12,611
juju/charm-helpers
charmhelpers/core/host.py
service_pause
def service_pause(service_name, init_dir="/etc/init", initd_dir="/etc/init.d", **kwargs): """Pause a system service. Stop it, and prevent it from starting again at boot. :param service_name: the name of the service to pause :param init_dir: path to the upstart init directory :par...
python
def service_pause(service_name, init_dir="/etc/init", initd_dir="/etc/init.d", **kwargs): """Pause a system service. Stop it, and prevent it from starting again at boot. :param service_name: the name of the service to pause :param init_dir: path to the upstart init directory :par...
[ "def", "service_pause", "(", "service_name", ",", "init_dir", "=", "\"/etc/init\"", ",", "initd_dir", "=", "\"/etc/init.d\"", ",", "*", "*", "kwargs", ")", ":", "stopped", "=", "True", "if", "service_running", "(", "service_name", ",", "*", "*", "kwargs", ")...
Pause a system service. Stop it, and prevent it from starting again at boot. :param service_name: the name of the service to pause :param init_dir: path to the upstart init directory :param initd_dir: path to the sysv init directory :param **kwargs: additional parameters to pass to the init system...
[ "Pause", "a", "system", "service", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L176-L211
12,612
juju/charm-helpers
charmhelpers/core/host.py
service_resume
def service_resume(service_name, init_dir="/etc/init", initd_dir="/etc/init.d", **kwargs): """Resume a system service. Reenable starting again at boot. Start the service. :param service_name: the name of the service to resume :param init_dir: the path to the init dir :param init...
python
def service_resume(service_name, init_dir="/etc/init", initd_dir="/etc/init.d", **kwargs): """Resume a system service. Reenable starting again at boot. Start the service. :param service_name: the name of the service to resume :param init_dir: the path to the init dir :param init...
[ "def", "service_resume", "(", "service_name", ",", "init_dir", "=", "\"/etc/init\"", ",", "initd_dir", "=", "\"/etc/init.d\"", ",", "*", "*", "kwargs", ")", ":", "upstart_file", "=", "os", ".", "path", ".", "join", "(", "init_dir", ",", "\"{}.conf\"", ".", ...
Resume a system service. Reenable starting again at boot. Start the service. :param service_name: the name of the service to resume :param init_dir: the path to the init dir :param initd dir: the path to the initd dir :param **kwargs: additional parameters to pass to the init system when ...
[ "Resume", "a", "system", "service", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L214-L249
12,613
juju/charm-helpers
charmhelpers/core/host.py
service
def service(action, service_name, **kwargs): """Control a system service. :param action: the action to take on the service :param service_name: the name of the service to perform th action on :param **kwargs: additional params to be passed to the service command in the form of key=v...
python
def service(action, service_name, **kwargs): """Control a system service. :param action: the action to take on the service :param service_name: the name of the service to perform th action on :param **kwargs: additional params to be passed to the service command in the form of key=v...
[ "def", "service", "(", "action", ",", "service_name", ",", "*", "*", "kwargs", ")", ":", "if", "init_is_systemd", "(", ")", ":", "cmd", "=", "[", "'systemctl'", ",", "action", ",", "service_name", "]", "else", ":", "cmd", "=", "[", "'service'", ",", ...
Control a system service. :param action: the action to take on the service :param service_name: the name of the service to perform th action on :param **kwargs: additional params to be passed to the service command in the form of key=value.
[ "Control", "a", "system", "service", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L252-L267
12,614
juju/charm-helpers
charmhelpers/core/host.py
service_running
def service_running(service_name, **kwargs): """Determine whether a system service is running. :param service_name: the name of the service :param **kwargs: additional args to pass to the service command. This is used to pass additional key=value arguments to the s...
python
def service_running(service_name, **kwargs): """Determine whether a system service is running. :param service_name: the name of the service :param **kwargs: additional args to pass to the service command. This is used to pass additional key=value arguments to the s...
[ "def", "service_running", "(", "service_name", ",", "*", "*", "kwargs", ")", ":", "if", "init_is_systemd", "(", ")", ":", "return", "service", "(", "'is-active'", ",", "service_name", ")", "else", ":", "if", "os", ".", "path", ".", "exists", "(", "_UPSTA...
Determine whether a system service is running. :param service_name: the name of the service :param **kwargs: additional args to pass to the service command. This is used to pass additional key=value arguments to the service command line for managing specific instance ...
[ "Determine", "whether", "a", "system", "service", "is", "running", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L274-L308
12,615
juju/charm-helpers
charmhelpers/core/host.py
adduser
def adduser(username, password=None, shell='/bin/bash', system_user=False, primary_group=None, secondary_groups=None, uid=None, home_dir=None): """Add a user to the system. Will log but otherwise succeed if the user already exists. :param str username: Username to create :param...
python
def adduser(username, password=None, shell='/bin/bash', system_user=False, primary_group=None, secondary_groups=None, uid=None, home_dir=None): """Add a user to the system. Will log but otherwise succeed if the user already exists. :param str username: Username to create :param...
[ "def", "adduser", "(", "username", ",", "password", "=", "None", ",", "shell", "=", "'/bin/bash'", ",", "system_user", "=", "False", ",", "primary_group", "=", "None", ",", "secondary_groups", "=", "None", ",", "uid", "=", "None", ",", "home_dir", "=", "...
Add a user to the system. Will log but otherwise succeed if the user already exists. :param str username: Username to create :param str password: Password for user; if ``None``, create a system user :param str shell: The default shell for the user :param bool system_user: Whether to create a login...
[ "Add", "a", "user", "to", "the", "system", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L321-L373
12,616
juju/charm-helpers
charmhelpers/core/host.py
user_exists
def user_exists(username): """Check if a user exists""" try: pwd.getpwnam(username) user_exists = True except KeyError: user_exists = False return user_exists
python
def user_exists(username): """Check if a user exists""" try: pwd.getpwnam(username) user_exists = True except KeyError: user_exists = False return user_exists
[ "def", "user_exists", "(", "username", ")", ":", "try", ":", "pwd", ".", "getpwnam", "(", "username", ")", "user_exists", "=", "True", "except", "KeyError", ":", "user_exists", "=", "False", "return", "user_exists" ]
Check if a user exists
[ "Check", "if", "a", "user", "exists" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L376-L383
12,617
juju/charm-helpers
charmhelpers/core/host.py
uid_exists
def uid_exists(uid): """Check if a uid exists""" try: pwd.getpwuid(uid) uid_exists = True except KeyError: uid_exists = False return uid_exists
python
def uid_exists(uid): """Check if a uid exists""" try: pwd.getpwuid(uid) uid_exists = True except KeyError: uid_exists = False return uid_exists
[ "def", "uid_exists", "(", "uid", ")", ":", "try", ":", "pwd", ".", "getpwuid", "(", "uid", ")", "uid_exists", "=", "True", "except", "KeyError", ":", "uid_exists", "=", "False", "return", "uid_exists" ]
Check if a uid exists
[ "Check", "if", "a", "uid", "exists" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L386-L393
12,618
juju/charm-helpers
charmhelpers/core/host.py
group_exists
def group_exists(groupname): """Check if a group exists""" try: grp.getgrnam(groupname) group_exists = True except KeyError: group_exists = False return group_exists
python
def group_exists(groupname): """Check if a group exists""" try: grp.getgrnam(groupname) group_exists = True except KeyError: group_exists = False return group_exists
[ "def", "group_exists", "(", "groupname", ")", ":", "try", ":", "grp", ".", "getgrnam", "(", "groupname", ")", "group_exists", "=", "True", "except", "KeyError", ":", "group_exists", "=", "False", "return", "group_exists" ]
Check if a group exists
[ "Check", "if", "a", "group", "exists" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L396-L403
12,619
juju/charm-helpers
charmhelpers/core/host.py
gid_exists
def gid_exists(gid): """Check if a gid exists""" try: grp.getgrgid(gid) gid_exists = True except KeyError: gid_exists = False return gid_exists
python
def gid_exists(gid): """Check if a gid exists""" try: grp.getgrgid(gid) gid_exists = True except KeyError: gid_exists = False return gid_exists
[ "def", "gid_exists", "(", "gid", ")", ":", "try", ":", "grp", ".", "getgrgid", "(", "gid", ")", "gid_exists", "=", "True", "except", "KeyError", ":", "gid_exists", "=", "False", "return", "gid_exists" ]
Check if a gid exists
[ "Check", "if", "a", "gid", "exists" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L406-L413
12,620
juju/charm-helpers
charmhelpers/core/host.py
add_group
def add_group(group_name, system_group=False, gid=None): """Add a group to the system Will log but otherwise succeed if the group already exists. :param str group_name: group to create :param bool system_group: Create system group :param int gid: GID for user being created :returns: The passw...
python
def add_group(group_name, system_group=False, gid=None): """Add a group to the system Will log but otherwise succeed if the group already exists. :param str group_name: group to create :param bool system_group: Create system group :param int gid: GID for user being created :returns: The passw...
[ "def", "add_group", "(", "group_name", ",", "system_group", "=", "False", ",", "gid", "=", "None", ")", ":", "try", ":", "group_info", "=", "grp", ".", "getgrnam", "(", "group_name", ")", "log", "(", "'group {0} already exists!'", ".", "format", "(", "grou...
Add a group to the system Will log but otherwise succeed if the group already exists. :param str group_name: group to create :param bool system_group: Create system group :param int gid: GID for user being created :returns: The password database entry struct, as returned by `grp.getgrnam`
[ "Add", "a", "group", "to", "the", "system" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L416-L437
12,621
juju/charm-helpers
charmhelpers/core/host.py
chage
def chage(username, lastday=None, expiredate=None, inactive=None, mindays=None, maxdays=None, root=None, warndays=None): """Change user password expiry information :param str username: User to update :param str lastday: Set when password was changed in YYYY-MM-DD format :param str expiredate:...
python
def chage(username, lastday=None, expiredate=None, inactive=None, mindays=None, maxdays=None, root=None, warndays=None): """Change user password expiry information :param str username: User to update :param str lastday: Set when password was changed in YYYY-MM-DD format :param str expiredate:...
[ "def", "chage", "(", "username", ",", "lastday", "=", "None", ",", "expiredate", "=", "None", ",", "inactive", "=", "None", ",", "mindays", "=", "None", ",", "maxdays", "=", "None", ",", "root", "=", "None", ",", "warndays", "=", "None", ")", ":", ...
Change user password expiry information :param str username: User to update :param str lastday: Set when password was changed in YYYY-MM-DD format :param str expiredate: Set when user's account will no longer be accessible in YYYY-MM-DD format. -1 will ...
[ "Change", "user", "password", "expiry", "information" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L447-L486
12,622
juju/charm-helpers
charmhelpers/core/host.py
rsync
def rsync(from_path, to_path, flags='-r', options=None, timeout=None): """Replicate the contents of a path""" options = options or ['--delete', '--executability'] cmd = ['/usr/bin/rsync', flags] if timeout: cmd = ['timeout', str(timeout)] + cmd cmd.extend(options) cmd.append(from_path) ...
python
def rsync(from_path, to_path, flags='-r', options=None, timeout=None): """Replicate the contents of a path""" options = options or ['--delete', '--executability'] cmd = ['/usr/bin/rsync', flags] if timeout: cmd = ['timeout', str(timeout)] + cmd cmd.extend(options) cmd.append(from_path) ...
[ "def", "rsync", "(", "from_path", ",", "to_path", ",", "flags", "=", "'-r'", ",", "options", "=", "None", ",", "timeout", "=", "None", ")", ":", "options", "=", "options", "or", "[", "'--delete'", ",", "'--executability'", "]", "cmd", "=", "[", "'/usr/...
Replicate the contents of a path
[ "Replicate", "the", "contents", "of", "a", "path" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L492-L502
12,623
juju/charm-helpers
charmhelpers/core/host.py
write_file
def write_file(path, content, owner='root', group='root', perms=0o444): """Create or overwrite a file with the contents of a byte string.""" uid = pwd.getpwnam(owner).pw_uid gid = grp.getgrnam(group).gr_gid # lets see if we can grab the file and compare the context, to avoid doing # a write. exi...
python
def write_file(path, content, owner='root', group='root', perms=0o444): """Create or overwrite a file with the contents of a byte string.""" uid = pwd.getpwnam(owner).pw_uid gid = grp.getgrnam(group).gr_gid # lets see if we can grab the file and compare the context, to avoid doing # a write. exi...
[ "def", "write_file", "(", "path", ",", "content", ",", "owner", "=", "'root'", ",", "group", "=", "'root'", ",", "perms", "=", "0o444", ")", ":", "uid", "=", "pwd", ".", "getpwnam", "(", "owner", ")", ".", "pw_uid", "gid", "=", "grp", ".", "getgrna...
Create or overwrite a file with the contents of a byte string.
[ "Create", "or", "overwrite", "a", "file", "with", "the", "contents", "of", "a", "byte", "string", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L536-L576
12,624
juju/charm-helpers
charmhelpers/core/host.py
mount
def mount(device, mountpoint, options=None, persist=False, filesystem="ext3"): """Mount a filesystem at a particular mountpoint""" cmd_args = ['mount'] if options is not None: cmd_args.extend(['-o', options]) cmd_args.extend([device, mountpoint]) try: subprocess.check_output(cmd_args...
python
def mount(device, mountpoint, options=None, persist=False, filesystem="ext3"): """Mount a filesystem at a particular mountpoint""" cmd_args = ['mount'] if options is not None: cmd_args.extend(['-o', options]) cmd_args.extend([device, mountpoint]) try: subprocess.check_output(cmd_args...
[ "def", "mount", "(", "device", ",", "mountpoint", ",", "options", "=", "None", ",", "persist", "=", "False", ",", "filesystem", "=", "\"ext3\"", ")", ":", "cmd_args", "=", "[", "'mount'", "]", "if", "options", "is", "not", "None", ":", "cmd_args", ".",...
Mount a filesystem at a particular mountpoint
[ "Mount", "a", "filesystem", "at", "a", "particular", "mountpoint" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L589-L603
12,625
juju/charm-helpers
charmhelpers/core/host.py
umount
def umount(mountpoint, persist=False): """Unmount a filesystem""" cmd_args = ['umount', mountpoint] try: subprocess.check_output(cmd_args) except subprocess.CalledProcessError as e: log('Error unmounting {}\n{}'.format(mountpoint, e.output)) return False if persist: ...
python
def umount(mountpoint, persist=False): """Unmount a filesystem""" cmd_args = ['umount', mountpoint] try: subprocess.check_output(cmd_args) except subprocess.CalledProcessError as e: log('Error unmounting {}\n{}'.format(mountpoint, e.output)) return False if persist: ...
[ "def", "umount", "(", "mountpoint", ",", "persist", "=", "False", ")", ":", "cmd_args", "=", "[", "'umount'", ",", "mountpoint", "]", "try", ":", "subprocess", ".", "check_output", "(", "cmd_args", ")", "except", "subprocess", ".", "CalledProcessError", "as"...
Unmount a filesystem
[ "Unmount", "a", "filesystem" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L606-L617
12,626
juju/charm-helpers
charmhelpers/core/host.py
fstab_mount
def fstab_mount(mountpoint): """Mount filesystem using fstab""" cmd_args = ['mount', mountpoint] try: subprocess.check_output(cmd_args) except subprocess.CalledProcessError as e: log('Error unmounting {}\n{}'.format(mountpoint, e.output)) return False return True
python
def fstab_mount(mountpoint): """Mount filesystem using fstab""" cmd_args = ['mount', mountpoint] try: subprocess.check_output(cmd_args) except subprocess.CalledProcessError as e: log('Error unmounting {}\n{}'.format(mountpoint, e.output)) return False return True
[ "def", "fstab_mount", "(", "mountpoint", ")", ":", "cmd_args", "=", "[", "'mount'", ",", "mountpoint", "]", "try", ":", "subprocess", ".", "check_output", "(", "cmd_args", ")", "except", "subprocess", ".", "CalledProcessError", "as", "e", ":", "log", "(", ...
Mount filesystem using fstab
[ "Mount", "filesystem", "using", "fstab" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L629-L637
12,627
juju/charm-helpers
charmhelpers/core/host.py
file_hash
def file_hash(path, hash_type='md5'): """Generate a hash checksum of the contents of 'path' or None if not found. :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, such as md5, sha1, sha256, sha512, etc. """ if os.path.exists(path): h = getattr(has...
python
def file_hash(path, hash_type='md5'): """Generate a hash checksum of the contents of 'path' or None if not found. :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, such as md5, sha1, sha256, sha512, etc. """ if os.path.exists(path): h = getattr(has...
[ "def", "file_hash", "(", "path", ",", "hash_type", "=", "'md5'", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "h", "=", "getattr", "(", "hashlib", ",", "hash_type", ")", "(", ")", "with", "open", "(", "path", ",", "'rb...
Generate a hash checksum of the contents of 'path' or None if not found. :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, such as md5, sha1, sha256, sha512, etc.
[ "Generate", "a", "hash", "checksum", "of", "the", "contents", "of", "path", "or", "None", "if", "not", "found", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L640-L652
12,628
juju/charm-helpers
charmhelpers/core/host.py
check_hash
def check_hash(path, checksum, hash_type='md5'): """Validate a file using a cryptographic checksum. :param str checksum: Value of the checksum used to validate the file. :param str hash_type: Hash algorithm used to generate `checksum`. Can be any hash alrgorithm supported by :mod:`hashlib`, ...
python
def check_hash(path, checksum, hash_type='md5'): """Validate a file using a cryptographic checksum. :param str checksum: Value of the checksum used to validate the file. :param str hash_type: Hash algorithm used to generate `checksum`. Can be any hash alrgorithm supported by :mod:`hashlib`, ...
[ "def", "check_hash", "(", "path", ",", "checksum", ",", "hash_type", "=", "'md5'", ")", ":", "actual_checksum", "=", "file_hash", "(", "path", ",", "hash_type", ")", "if", "checksum", "!=", "actual_checksum", ":", "raise", "ChecksumError", "(", "\"'%s' != '%s'...
Validate a file using a cryptographic checksum. :param str checksum: Value of the checksum used to validate the file. :param str hash_type: Hash algorithm used to generate `checksum`. Can be any hash alrgorithm supported by :mod:`hashlib`, such as md5, sha1, sha256, sha512, etc. :raises Che...
[ "Validate", "a", "file", "using", "a", "cryptographic", "checksum", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L669-L681
12,629
juju/charm-helpers
charmhelpers/core/host.py
restart_on_change
def restart_on_change(restart_map, stopstart=False, restart_functions=None): """Restart services based on configuration files changing This function is used a decorator, for example:: @restart_on_change({ '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] '/etc/apache/sit...
python
def restart_on_change(restart_map, stopstart=False, restart_functions=None): """Restart services based on configuration files changing This function is used a decorator, for example:: @restart_on_change({ '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] '/etc/apache/sit...
[ "def", "restart_on_change", "(", "restart_map", ",", "stopstart", "=", "False", ",", "restart_functions", "=", "None", ")", ":", "def", "wrap", "(", "f", ")", ":", "@", "functools", ".", "wraps", "(", "f", ")", "def", "wrapped_f", "(", "*", "args", ","...
Restart services based on configuration files changing This function is used a decorator, for example:: @restart_on_change({ '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] '/etc/apache/sites-enabled/*': [ 'apache2' ] }) def config_changed(): ...
[ "Restart", "services", "based", "on", "configuration", "files", "changing" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L689-L721
12,630
juju/charm-helpers
charmhelpers/core/host.py
restart_on_change_helper
def restart_on_change_helper(lambda_f, restart_map, stopstart=False, restart_functions=None): """Helper function to perform the restart_on_change function. This is provided for decorators to restart services if files described in the restart_map have changed after an invocation...
python
def restart_on_change_helper(lambda_f, restart_map, stopstart=False, restart_functions=None): """Helper function to perform the restart_on_change function. This is provided for decorators to restart services if files described in the restart_map have changed after an invocation...
[ "def", "restart_on_change_helper", "(", "lambda_f", ",", "restart_map", ",", "stopstart", "=", "False", ",", "restart_functions", "=", "None", ")", ":", "if", "restart_functions", "is", "None", ":", "restart_functions", "=", "{", "}", "checksums", "=", "{", "p...
Helper function to perform the restart_on_change function. This is provided for decorators to restart services if files described in the restart_map have changed after an invocation of lambda_f(). @param lambda_f: function to call. @param restart_map: {file: [service, ...]} @param stopstart: wheth...
[ "Helper", "function", "to", "perform", "the", "restart_on_change", "function", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L724-L756
12,631
juju/charm-helpers
charmhelpers/core/host.py
pwgen
def pwgen(length=None): """Generate a random pasword.""" if length is None: # A random length is ok to use a weak PRNG length = random.choice(range(35, 45)) alphanumeric_chars = [ l for l in (string.ascii_letters + string.digits) if l not in 'l0QD1vAEIOUaeiou'] # Use a cr...
python
def pwgen(length=None): """Generate a random pasword.""" if length is None: # A random length is ok to use a weak PRNG length = random.choice(range(35, 45)) alphanumeric_chars = [ l for l in (string.ascii_letters + string.digits) if l not in 'l0QD1vAEIOUaeiou'] # Use a cr...
[ "def", "pwgen", "(", "length", "=", "None", ")", ":", "if", "length", "is", "None", ":", "# A random length is ok to use a weak PRNG", "length", "=", "random", ".", "choice", "(", "range", "(", "35", ",", "45", ")", ")", "alphanumeric_chars", "=", "[", "l"...
Generate a random pasword.
[ "Generate", "a", "random", "pasword", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L759-L772
12,632
juju/charm-helpers
charmhelpers/core/host.py
is_phy_iface
def is_phy_iface(interface): """Returns True if interface is not virtual, otherwise False.""" if interface: sys_net = '/sys/class/net' if os.path.isdir(sys_net): for iface in glob.glob(os.path.join(sys_net, '*')): if '/virtual/' in os.path.realpath(iface): ...
python
def is_phy_iface(interface): """Returns True if interface is not virtual, otherwise False.""" if interface: sys_net = '/sys/class/net' if os.path.isdir(sys_net): for iface in glob.glob(os.path.join(sys_net, '*')): if '/virtual/' in os.path.realpath(iface): ...
[ "def", "is_phy_iface", "(", "interface", ")", ":", "if", "interface", ":", "sys_net", "=", "'/sys/class/net'", "if", "os", ".", "path", ".", "isdir", "(", "sys_net", ")", ":", "for", "iface", "in", "glob", ".", "glob", "(", "os", ".", "path", ".", "j...
Returns True if interface is not virtual, otherwise False.
[ "Returns", "True", "if", "interface", "is", "not", "virtual", "otherwise", "False", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L775-L787
12,633
juju/charm-helpers
charmhelpers/core/host.py
get_bond_master
def get_bond_master(interface): """Returns bond master if interface is bond slave otherwise None. NOTE: the provided interface is expected to be physical """ if interface: iface_path = '/sys/class/net/%s' % (interface) if os.path.exists(iface_path): if '/virtual/' in os.path...
python
def get_bond_master(interface): """Returns bond master if interface is bond slave otherwise None. NOTE: the provided interface is expected to be physical """ if interface: iface_path = '/sys/class/net/%s' % (interface) if os.path.exists(iface_path): if '/virtual/' in os.path...
[ "def", "get_bond_master", "(", "interface", ")", ":", "if", "interface", ":", "iface_path", "=", "'/sys/class/net/%s'", "%", "(", "interface", ")", "if", "os", ".", "path", ".", "exists", "(", "iface_path", ")", ":", "if", "'/virtual/'", "in", "os", ".", ...
Returns bond master if interface is bond slave otherwise None. NOTE: the provided interface is expected to be physical
[ "Returns", "bond", "master", "if", "interface", "is", "bond", "slave", "otherwise", "None", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L790-L808
12,634
juju/charm-helpers
charmhelpers/core/host.py
chdir
def chdir(directory): """Change the current working directory to a different directory for a code block and return the previous directory after the block exits. Useful to run commands from a specificed directory. :param str directory: The directory path to change to for this context. """ cur = ...
python
def chdir(directory): """Change the current working directory to a different directory for a code block and return the previous directory after the block exits. Useful to run commands from a specificed directory. :param str directory: The directory path to change to for this context. """ cur = ...
[ "def", "chdir", "(", "directory", ")", ":", "cur", "=", "os", ".", "getcwd", "(", ")", "try", ":", "yield", "os", ".", "chdir", "(", "directory", ")", "finally", ":", "os", ".", "chdir", "(", "cur", ")" ]
Change the current working directory to a different directory for a code block and return the previous directory after the block exits. Useful to run commands from a specificed directory. :param str directory: The directory path to change to for this context.
[ "Change", "the", "current", "working", "directory", "to", "a", "different", "directory", "for", "a", "code", "block", "and", "return", "the", "previous", "directory", "after", "the", "block", "exits", ".", "Useful", "to", "run", "commands", "from", "a", "spe...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L883-L894
12,635
juju/charm-helpers
charmhelpers/core/host.py
chownr
def chownr(path, owner, group, follow_links=True, chowntopdir=False): """Recursively change user and group ownership of files and directories in given path. Doesn't chown path itself by default, only its children. :param str path: The string path to start changing ownership. :param str owner: The owner...
python
def chownr(path, owner, group, follow_links=True, chowntopdir=False): """Recursively change user and group ownership of files and directories in given path. Doesn't chown path itself by default, only its children. :param str path: The string path to start changing ownership. :param str owner: The owner...
[ "def", "chownr", "(", "path", ",", "owner", ",", "group", ",", "follow_links", "=", "True", ",", "chowntopdir", "=", "False", ")", ":", "uid", "=", "pwd", ".", "getpwnam", "(", "owner", ")", ".", "pw_uid", "gid", "=", "grp", ".", "getgrnam", "(", "...
Recursively change user and group ownership of files and directories in given path. Doesn't chown path itself by default, only its children. :param str path: The string path to start changing ownership. :param str owner: The owner string to use when looking up the uid. :param str group: The group strin...
[ "Recursively", "change", "user", "and", "group", "ownership", "of", "files", "and", "directories", "in", "given", "path", ".", "Doesn", "t", "chown", "path", "itself", "by", "default", "only", "its", "children", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L897-L923
12,636
juju/charm-helpers
charmhelpers/core/host.py
lchownr
def lchownr(path, owner, group): """Recursively change user and group ownership of files and directories in a given path, not following symbolic links. See the documentation for 'os.lchown' for more information. :param str path: The string path to start changing ownership. :param str owner: The own...
python
def lchownr(path, owner, group): """Recursively change user and group ownership of files and directories in a given path, not following symbolic links. See the documentation for 'os.lchown' for more information. :param str path: The string path to start changing ownership. :param str owner: The own...
[ "def", "lchownr", "(", "path", ",", "owner", ",", "group", ")", ":", "chownr", "(", "path", ",", "owner", ",", "group", ",", "follow_links", "=", "False", ")" ]
Recursively change user and group ownership of files and directories in a given path, not following symbolic links. See the documentation for 'os.lchown' for more information. :param str path: The string path to start changing ownership. :param str owner: The owner string to use when looking up the uid...
[ "Recursively", "change", "user", "and", "group", "ownership", "of", "files", "and", "directories", "in", "a", "given", "path", "not", "following", "symbolic", "links", ".", "See", "the", "documentation", "for", "os", ".", "lchown", "for", "more", "information"...
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L926-L935
12,637
juju/charm-helpers
charmhelpers/core/host.py
owner
def owner(path): """Returns a tuple containing the username & groupname owning the path. :param str path: the string path to retrieve the ownership :return tuple(str, str): A (username, groupname) tuple containing the name of the user and group owning the path. :raises OSEr...
python
def owner(path): """Returns a tuple containing the username & groupname owning the path. :param str path: the string path to retrieve the ownership :return tuple(str, str): A (username, groupname) tuple containing the name of the user and group owning the path. :raises OSEr...
[ "def", "owner", "(", "path", ")", ":", "stat", "=", "os", ".", "stat", "(", "path", ")", "username", "=", "pwd", ".", "getpwuid", "(", "stat", ".", "st_uid", ")", "[", "0", "]", "groupname", "=", "grp", ".", "getgrgid", "(", "stat", ".", "st_gid"...
Returns a tuple containing the username & groupname owning the path. :param str path: the string path to retrieve the ownership :return tuple(str, str): A (username, groupname) tuple containing the name of the user and group owning the path. :raises OSError: if the specified pa...
[ "Returns", "a", "tuple", "containing", "the", "username", "&", "groupname", "owning", "the", "path", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L938-L949
12,638
juju/charm-helpers
charmhelpers/core/host.py
get_total_ram
def get_total_ram(): """The total amount of system RAM in bytes. This is what is reported by the OS, and may be overcommitted when there are multiple containers hosted on the same machine. """ with open('/proc/meminfo', 'r') as f: for line in f.readlines(): if line: ...
python
def get_total_ram(): """The total amount of system RAM in bytes. This is what is reported by the OS, and may be overcommitted when there are multiple containers hosted on the same machine. """ with open('/proc/meminfo', 'r') as f: for line in f.readlines(): if line: ...
[ "def", "get_total_ram", "(", ")", ":", "with", "open", "(", "'/proc/meminfo'", ",", "'r'", ")", "as", "f", ":", "for", "line", "in", "f", ".", "readlines", "(", ")", ":", "if", "line", ":", "key", ",", "value", ",", "unit", "=", "line", ".", "spl...
The total amount of system RAM in bytes. This is what is reported by the OS, and may be overcommitted when there are multiple containers hosted on the same machine.
[ "The", "total", "amount", "of", "system", "RAM", "in", "bytes", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L952-L965
12,639
juju/charm-helpers
charmhelpers/core/host.py
add_to_updatedb_prunepath
def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH): """Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list. This method has no effect if the path specified by updatedb_path does not exist or is not a file. @param path: string the path to add to the updatedb.conf PRUNEPA...
python
def add_to_updatedb_prunepath(path, updatedb_path=UPDATEDB_PATH): """Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list. This method has no effect if the path specified by updatedb_path does not exist or is not a file. @param path: string the path to add to the updatedb.conf PRUNEPA...
[ "def", "add_to_updatedb_prunepath", "(", "path", ",", "updatedb_path", "=", "UPDATEDB_PATH", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "updatedb_path", ")", "or", "os", ".", "path", ".", "isdir", "(", "updatedb_path", ")", ":", "# If th...
Adds the specified path to the mlocate's udpatedb.conf PRUNEPATH list. This method has no effect if the path specified by updatedb_path does not exist or is not a file. @param path: string the path to add to the updatedb.conf PRUNEPATHS value @param updatedb_path: the path the updatedb.conf file
[ "Adds", "the", "specified", "path", "to", "the", "mlocate", "s", "udpatedb", ".", "conf", "PRUNEPATH", "list", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L985-L1005
12,640
juju/charm-helpers
charmhelpers/core/host.py
install_ca_cert
def install_ca_cert(ca_cert, name=None): """ Install the given cert as a trusted CA. The ``name`` is the stem of the filename where the cert is written, and if not provided, it will default to ``juju-{charm_name}``. If the cert is empty or None, or is unchanged, nothing is done. """ if not...
python
def install_ca_cert(ca_cert, name=None): """ Install the given cert as a trusted CA. The ``name`` is the stem of the filename where the cert is written, and if not provided, it will default to ``juju-{charm_name}``. If the cert is empty or None, or is unchanged, nothing is done. """ if not...
[ "def", "install_ca_cert", "(", "ca_cert", ",", "name", "=", "None", ")", ":", "if", "not", "ca_cert", ":", "return", "if", "not", "isinstance", "(", "ca_cert", ",", "bytes", ")", ":", "ca_cert", "=", "ca_cert", ".", "encode", "(", "'utf8'", ")", "if", ...
Install the given cert as a trusted CA. The ``name`` is the stem of the filename where the cert is written, and if not provided, it will default to ``juju-{charm_name}``. If the cert is empty or None, or is unchanged, nothing is done.
[ "Install", "the", "given", "cert", "as", "a", "trusted", "CA", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/host.py#L1056-L1077
12,641
juju/charm-helpers
charmhelpers/contrib/hardening/host/checks/securetty.py
get_audits
def get_audits(): """Get OS hardening Secure TTY audits. :returns: dictionary of audits """ audits = [] audits.append(TemplatedFile('/etc/securetty', SecureTTYContext(), template_dir=TEMPLATES_DIR, mode=0o0400, user='root', group='roo...
python
def get_audits(): """Get OS hardening Secure TTY audits. :returns: dictionary of audits """ audits = [] audits.append(TemplatedFile('/etc/securetty', SecureTTYContext(), template_dir=TEMPLATES_DIR, mode=0o0400, user='root', group='roo...
[ "def", "get_audits", "(", ")", ":", "audits", "=", "[", "]", "audits", ".", "append", "(", "TemplatedFile", "(", "'/etc/securetty'", ",", "SecureTTYContext", "(", ")", ",", "template_dir", "=", "TEMPLATES_DIR", ",", "mode", "=", "0o0400", ",", "user", "=",...
Get OS hardening Secure TTY audits. :returns: dictionary of audits
[ "Get", "OS", "hardening", "Secure", "TTY", "audits", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/host/checks/securetty.py#L20-L29
12,642
juju/charm-helpers
charmhelpers/contrib/templating/contexts.py
dict_keys_without_hyphens
def dict_keys_without_hyphens(a_dict): """Return the a new dict with underscores instead of hyphens in keys.""" return dict( (key.replace('-', '_'), val) for key, val in a_dict.items())
python
def dict_keys_without_hyphens(a_dict): """Return the a new dict with underscores instead of hyphens in keys.""" return dict( (key.replace('-', '_'), val) for key, val in a_dict.items())
[ "def", "dict_keys_without_hyphens", "(", "a_dict", ")", ":", "return", "dict", "(", "(", "key", ".", "replace", "(", "'-'", ",", "'_'", ")", ",", "val", ")", "for", "key", ",", "val", "in", "a_dict", ".", "items", "(", ")", ")" ]
Return the a new dict with underscores instead of hyphens in keys.
[ "Return", "the", "a", "new", "dict", "with", "underscores", "instead", "of", "hyphens", "in", "keys", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/templating/contexts.py#L31-L34
12,643
juju/charm-helpers
charmhelpers/contrib/templating/contexts.py
update_relations
def update_relations(context, namespace_separator=':'): """Update the context with the relation data.""" # Add any relation data prefixed with the relation type. relation_type = charmhelpers.core.hookenv.relation_type() relations = [] context['current_relation'] = {} if relation_type is not None...
python
def update_relations(context, namespace_separator=':'): """Update the context with the relation data.""" # Add any relation data prefixed with the relation type. relation_type = charmhelpers.core.hookenv.relation_type() relations = [] context['current_relation'] = {} if relation_type is not None...
[ "def", "update_relations", "(", "context", ",", "namespace_separator", "=", "':'", ")", ":", "# Add any relation data prefixed with the relation type.", "relation_type", "=", "charmhelpers", ".", "core", ".", "hookenv", ".", "relation_type", "(", ")", "relations", "=", ...
Update the context with the relation data.
[ "Update", "the", "context", "with", "the", "relation", "data", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/templating/contexts.py#L37-L77
12,644
juju/charm-helpers
charmhelpers/contrib/templating/contexts.py
juju_state_to_yaml
def juju_state_to_yaml(yaml_path, namespace_separator=':', allow_hyphens_in_keys=True, mode=None): """Update the juju config and state in a yaml file. This includes any current relation-get data, and the charm directory. This function was created for the ansible and saltstack ...
python
def juju_state_to_yaml(yaml_path, namespace_separator=':', allow_hyphens_in_keys=True, mode=None): """Update the juju config and state in a yaml file. This includes any current relation-get data, and the charm directory. This function was created for the ansible and saltstack ...
[ "def", "juju_state_to_yaml", "(", "yaml_path", ",", "namespace_separator", "=", "':'", ",", "allow_hyphens_in_keys", "=", "True", ",", "mode", "=", "None", ")", ":", "config", "=", "charmhelpers", ".", "core", ".", "hookenv", ".", "config", "(", ")", "# Add ...
Update the juju config and state in a yaml file. This includes any current relation-get data, and the charm directory. This function was created for the ansible and saltstack support, as those libraries can use a yaml file to supply context to templates, but it may be useful generally to creat...
[ "Update", "the", "juju", "config", "and", "state", "in", "a", "yaml", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/templating/contexts.py#L80-L137
12,645
juju/charm-helpers
charmhelpers/contrib/hardening/apache/checks/config.py
get_audits
def get_audits(): """Get Apache hardening config audits. :returns: dictionary of audits """ if subprocess.call(['which', 'apache2'], stdout=subprocess.PIPE) != 0: log("Apache server does not appear to be installed on this node - " "skipping apache hardening", level=INFO) re...
python
def get_audits(): """Get Apache hardening config audits. :returns: dictionary of audits """ if subprocess.call(['which', 'apache2'], stdout=subprocess.PIPE) != 0: log("Apache server does not appear to be installed on this node - " "skipping apache hardening", level=INFO) re...
[ "def", "get_audits", "(", ")", ":", "if", "subprocess", ".", "call", "(", "[", "'which'", ",", "'apache2'", "]", ",", "stdout", "=", "subprocess", ".", "PIPE", ")", "!=", "0", ":", "log", "(", "\"Apache server does not appear to be installed on this node - \"", ...
Get Apache hardening config audits. :returns: dictionary of audits
[ "Get", "Apache", "hardening", "config", "audits", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/apache/checks/config.py#L37-L84
12,646
juju/charm-helpers
charmhelpers/contrib/hardening/host/checks/minimize_access.py
get_audits
def get_audits(): """Get OS hardening access audits. :returns: dictionary of audits """ audits = [] settings = utils.get_settings('os') # Remove write permissions from $PATH folders for all regular users. # This prevents changing system-wide commands from normal users. path_folders = ...
python
def get_audits(): """Get OS hardening access audits. :returns: dictionary of audits """ audits = [] settings = utils.get_settings('os') # Remove write permissions from $PATH folders for all regular users. # This prevents changing system-wide commands from normal users. path_folders = ...
[ "def", "get_audits", "(", ")", ":", "audits", "=", "[", "]", "settings", "=", "utils", ".", "get_settings", "(", "'os'", ")", "# Remove write permissions from $PATH folders for all regular users.", "# This prevents changing system-wide commands from normal users.", "path_folder...
Get OS hardening access audits. :returns: dictionary of audits
[ "Get", "OS", "hardening", "access", "audits", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/host/checks/minimize_access.py#L22-L50
12,647
juju/charm-helpers
charmhelpers/contrib/hardening/harden.py
harden
def harden(overrides=None): """Hardening decorator. This is the main entry point for running the hardening stack. In order to run modules of the stack you must add this decorator to charm hook(s) and ensure that your charm config.yaml contains the 'harden' option set to one or more of the supported...
python
def harden(overrides=None): """Hardening decorator. This is the main entry point for running the hardening stack. In order to run modules of the stack you must add this decorator to charm hook(s) and ensure that your charm config.yaml contains the 'harden' option set to one or more of the supported...
[ "def", "harden", "(", "overrides", "=", "None", ")", ":", "if", "overrides", "is", "None", ":", "overrides", "=", "[", "]", "def", "_harden_inner1", "(", "f", ")", ":", "# As this has to be py2.7 compat, we can't use nonlocal. Use a trick", "# to capture the dictiona...
Hardening decorator. This is the main entry point for running the hardening stack. In order to run modules of the stack you must add this decorator to charm hook(s) and ensure that your charm config.yaml contains the 'harden' option set to one or more of the supported modules. Setting these will cause ...
[ "Hardening", "decorator", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/harden.py#L33-L96
12,648
juju/charm-helpers
charmhelpers/contrib/openstack/neutron.py
parse_mappings
def parse_mappings(mappings, key_rvalue=False): """By default mappings are lvalue keyed. If key_rvalue is True, the mapping will be reversed to allow multiple configs for the same lvalue. """ parsed = {} if mappings: mappings = mappings.split() for m in mappings: p =...
python
def parse_mappings(mappings, key_rvalue=False): """By default mappings are lvalue keyed. If key_rvalue is True, the mapping will be reversed to allow multiple configs for the same lvalue. """ parsed = {} if mappings: mappings = mappings.split() for m in mappings: p =...
[ "def", "parse_mappings", "(", "mappings", ",", "key_rvalue", "=", "False", ")", ":", "parsed", "=", "{", "}", "if", "mappings", ":", "mappings", "=", "mappings", ".", "split", "(", ")", "for", "m", "in", "mappings", ":", "p", "=", "m", ".", "partitio...
By default mappings are lvalue keyed. If key_rvalue is True, the mapping will be reversed to allow multiple configs for the same lvalue.
[ "By", "default", "mappings", "are", "lvalue", "keyed", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/neutron.py#L270-L295
12,649
juju/charm-helpers
charmhelpers/contrib/openstack/neutron.py
parse_data_port_mappings
def parse_data_port_mappings(mappings, default_bridge='br-data'): """Parse data port mappings. Mappings must be a space-delimited list of bridge:port. Returns dict of the form {port:bridge} where ports may be mac addresses or interface names. """ # NOTE(dosaboy): we use rvalue for key to allo...
python
def parse_data_port_mappings(mappings, default_bridge='br-data'): """Parse data port mappings. Mappings must be a space-delimited list of bridge:port. Returns dict of the form {port:bridge} where ports may be mac addresses or interface names. """ # NOTE(dosaboy): we use rvalue for key to allo...
[ "def", "parse_data_port_mappings", "(", "mappings", ",", "default_bridge", "=", "'br-data'", ")", ":", "# NOTE(dosaboy): we use rvalue for key to allow multiple values to be", "# proposed for <port> since it may be a mac address which will differ", "# across units this allowing first-known-g...
Parse data port mappings. Mappings must be a space-delimited list of bridge:port. Returns dict of the form {port:bridge} where ports may be mac addresses or interface names.
[ "Parse", "data", "port", "mappings", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/neutron.py#L308-L334
12,650
juju/charm-helpers
charmhelpers/contrib/openstack/neutron.py
parse_vlan_range_mappings
def parse_vlan_range_mappings(mappings): """Parse vlan range mappings. Mappings must be a space-delimited list of provider:start:end mappings. The start:end range is optional and may be omitted. Returns dict of the form {provider: (start, end)}. """ _mappings = parse_mappings(mappings) if...
python
def parse_vlan_range_mappings(mappings): """Parse vlan range mappings. Mappings must be a space-delimited list of provider:start:end mappings. The start:end range is optional and may be omitted. Returns dict of the form {provider: (start, end)}. """ _mappings = parse_mappings(mappings) if...
[ "def", "parse_vlan_range_mappings", "(", "mappings", ")", ":", "_mappings", "=", "parse_mappings", "(", "mappings", ")", "if", "not", "_mappings", ":", "return", "{", "}", "mappings", "=", "{", "}", "for", "p", ",", "r", "in", "six", ".", "iteritems", "(...
Parse vlan range mappings. Mappings must be a space-delimited list of provider:start:end mappings. The start:end range is optional and may be omitted. Returns dict of the form {provider: (start, end)}.
[ "Parse", "vlan", "range", "mappings", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/neutron.py#L337-L354
12,651
juju/charm-helpers
charmhelpers/payload/archive.py
extract_tarfile
def extract_tarfile(archive_name, destpath): "Unpack a tar archive, optionally compressed" archive = tarfile.open(archive_name) archive.extractall(destpath)
python
def extract_tarfile(archive_name, destpath): "Unpack a tar archive, optionally compressed" archive = tarfile.open(archive_name) archive.extractall(destpath)
[ "def", "extract_tarfile", "(", "archive_name", ",", "destpath", ")", ":", "archive", "=", "tarfile", ".", "open", "(", "archive_name", ")", "archive", ".", "extractall", "(", "destpath", ")" ]
Unpack a tar archive, optionally compressed
[ "Unpack", "a", "tar", "archive", "optionally", "compressed" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/payload/archive.py#L62-L65
12,652
juju/charm-helpers
charmhelpers/payload/archive.py
extract_zipfile
def extract_zipfile(archive_name, destpath): "Unpack a zip file" archive = zipfile.ZipFile(archive_name) archive.extractall(destpath)
python
def extract_zipfile(archive_name, destpath): "Unpack a zip file" archive = zipfile.ZipFile(archive_name) archive.extractall(destpath)
[ "def", "extract_zipfile", "(", "archive_name", ",", "destpath", ")", ":", "archive", "=", "zipfile", ".", "ZipFile", "(", "archive_name", ")", "archive", ".", "extractall", "(", "destpath", ")" ]
Unpack a zip file
[ "Unpack", "a", "zip", "file" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/payload/archive.py#L68-L71
12,653
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_address_in_network
def get_address_in_network(network, fallback=None, fatal=False): """Get an IPv4 or IPv6 address within the network from the host. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. Supports multiple networks as a space-delimited list. :param fallback (str): If no address...
python
def get_address_in_network(network, fallback=None, fatal=False): """Get an IPv4 or IPv6 address within the network from the host. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. Supports multiple networks as a space-delimited list. :param fallback (str): If no address...
[ "def", "get_address_in_network", "(", "network", ",", "fallback", "=", "None", ",", "fatal", "=", "False", ")", ":", "if", "network", "is", "None", ":", "if", "fallback", "is", "not", "None", ":", "return", "fallback", "if", "fatal", ":", "no_ip_found_erro...
Get an IPv4 or IPv6 address within the network from the host. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. Supports multiple networks as a space-delimited list. :param fallback (str): If no address is found, return fallback. :param fatal (boolean): If no address is...
[ "Get", "an", "IPv4", "or", "IPv6", "address", "within", "the", "network", "from", "the", "host", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L90-L138
12,654
juju/charm-helpers
charmhelpers/contrib/network/ip.py
is_ipv6
def is_ipv6(address): """Determine whether provided address is IPv6 or not.""" try: address = netaddr.IPAddress(address) except netaddr.AddrFormatError: # probably a hostname - so not an address at all! return False return address.version == 6
python
def is_ipv6(address): """Determine whether provided address is IPv6 or not.""" try: address = netaddr.IPAddress(address) except netaddr.AddrFormatError: # probably a hostname - so not an address at all! return False return address.version == 6
[ "def", "is_ipv6", "(", "address", ")", ":", "try", ":", "address", "=", "netaddr", ".", "IPAddress", "(", "address", ")", "except", "netaddr", ".", "AddrFormatError", ":", "# probably a hostname - so not an address at all!", "return", "False", "return", "address", ...
Determine whether provided address is IPv6 or not.
[ "Determine", "whether", "provided", "address", "is", "IPv6", "or", "not", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L141-L149
12,655
juju/charm-helpers
charmhelpers/contrib/network/ip.py
is_address_in_network
def is_address_in_network(network, address): """ Determine whether the provided address is within a network range. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. :param address: An individual IPv4 or IPv6 address without a net mask or subnet prefix. For e...
python
def is_address_in_network(network, address): """ Determine whether the provided address is within a network range. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. :param address: An individual IPv4 or IPv6 address without a net mask or subnet prefix. For e...
[ "def", "is_address_in_network", "(", "network", ",", "address", ")", ":", "try", ":", "network", "=", "netaddr", ".", "IPNetwork", "(", "network", ")", "except", "(", "netaddr", ".", "core", ".", "AddrFormatError", ",", "ValueError", ")", ":", "raise", "Va...
Determine whether the provided address is within a network range. :param network (str): CIDR presentation format. For example, '192.168.1.0/24'. :param address: An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, '192.168.1.1'. :returns boolean: Flag indicat...
[ "Determine", "whether", "the", "provided", "address", "is", "within", "a", "network", "range", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L152-L177
12,656
juju/charm-helpers
charmhelpers/contrib/network/ip.py
_get_for_address
def _get_for_address(address, key): """Retrieve an attribute of or the physical interface that the IP address provided could be bound to. :param address (str): An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, '192.168.1.1'. :param key: 'iface' for the physica...
python
def _get_for_address(address, key): """Retrieve an attribute of or the physical interface that the IP address provided could be bound to. :param address (str): An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, '192.168.1.1'. :param key: 'iface' for the physica...
[ "def", "_get_for_address", "(", "address", ",", "key", ")", ":", "address", "=", "netaddr", ".", "IPAddress", "(", "address", ")", "for", "iface", "in", "netifaces", ".", "interfaces", "(", ")", ":", "addresses", "=", "netifaces", ".", "ifaddresses", "(", ...
Retrieve an attribute of or the physical interface that the IP address provided could be bound to. :param address (str): An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, '192.168.1.1'. :param key: 'iface' for the physical interface name or an attribute of...
[ "Retrieve", "an", "attribute", "of", "or", "the", "physical", "interface", "that", "the", "IP", "address", "provided", "could", "be", "bound", "to", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L180-L218
12,657
juju/charm-helpers
charmhelpers/contrib/network/ip.py
resolve_network_cidr
def resolve_network_cidr(ip_address): ''' Resolves the full address cidr of an ip_address based on configured network interfaces ''' netmask = get_netmask_for_address(ip_address) return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
python
def resolve_network_cidr(ip_address): ''' Resolves the full address cidr of an ip_address based on configured network interfaces ''' netmask = get_netmask_for_address(ip_address) return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
[ "def", "resolve_network_cidr", "(", "ip_address", ")", ":", "netmask", "=", "get_netmask_for_address", "(", "ip_address", ")", "return", "str", "(", "netaddr", ".", "IPNetwork", "(", "\"%s/%s\"", "%", "(", "ip_address", ",", "netmask", ")", ")", ".", "cidr", ...
Resolves the full address cidr of an ip_address based on configured network interfaces
[ "Resolves", "the", "full", "address", "cidr", "of", "an", "ip_address", "based", "on", "configured", "network", "interfaces" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L227-L233
12,658
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_iface_addr
def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, fatal=True, exc_list=None): """Return the assigned IP address for a given interface, if any. :param iface: network interface on which address(es) are expected to be found. :param inet_type: inet ad...
python
def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, fatal=True, exc_list=None): """Return the assigned IP address for a given interface, if any. :param iface: network interface on which address(es) are expected to be found. :param inet_type: inet ad...
[ "def", "get_iface_addr", "(", "iface", "=", "'eth0'", ",", "inet_type", "=", "'AF_INET'", ",", "inc_aliases", "=", "False", ",", "fatal", "=", "True", ",", "exc_list", "=", "None", ")", ":", "# Extract nic if passed /dev/ethX", "if", "'/'", "in", "iface", ":...
Return the assigned IP address for a given interface, if any. :param iface: network interface on which address(es) are expected to be found. :param inet_type: inet address family :param inc_aliases: include alias interfaces in search :param fatal: if True, raise exception if address n...
[ "Return", "the", "assigned", "IP", "address", "for", "a", "given", "interface", "if", "any", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L260-L317
12,659
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_iface_from_addr
def get_iface_from_addr(addr): """Work out on which interface the provided address is configured.""" for iface in netifaces.interfaces(): addresses = netifaces.ifaddresses(iface) for inet_type in addresses: for _addr in addresses[inet_type]: _addr = _addr['addr'] ...
python
def get_iface_from_addr(addr): """Work out on which interface the provided address is configured.""" for iface in netifaces.interfaces(): addresses = netifaces.ifaddresses(iface) for inet_type in addresses: for _addr in addresses[inet_type]: _addr = _addr['addr'] ...
[ "def", "get_iface_from_addr", "(", "addr", ")", ":", "for", "iface", "in", "netifaces", ".", "interfaces", "(", ")", ":", "addresses", "=", "netifaces", ".", "ifaddresses", "(", "iface", ")", "for", "inet_type", "in", "addresses", ":", "for", "_addr", "in"...
Work out on which interface the provided address is configured.
[ "Work", "out", "on", "which", "interface", "the", "provided", "address", "is", "configured", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L323-L342
12,660
juju/charm-helpers
charmhelpers/contrib/network/ip.py
sniff_iface
def sniff_iface(f): """Ensure decorated function is called with a value for iface. If no iface provided, inject net iface inferred from unit private address. """ def iface_sniffer(*args, **kwargs): if not kwargs.get('iface', None): kwargs['iface'] = get_iface_from_addr(unit_get('pri...
python
def sniff_iface(f): """Ensure decorated function is called with a value for iface. If no iface provided, inject net iface inferred from unit private address. """ def iface_sniffer(*args, **kwargs): if not kwargs.get('iface', None): kwargs['iface'] = get_iface_from_addr(unit_get('pri...
[ "def", "sniff_iface", "(", "f", ")", ":", "def", "iface_sniffer", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "kwargs", ".", "get", "(", "'iface'", ",", "None", ")", ":", "kwargs", "[", "'iface'", "]", "=", "get_iface_from_addr"...
Ensure decorated function is called with a value for iface. If no iface provided, inject net iface inferred from unit private address.
[ "Ensure", "decorated", "function", "is", "called", "with", "a", "value", "for", "iface", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L345-L356
12,661
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_ipv6_addr
def get_ipv6_addr(iface=None, inc_aliases=False, fatal=True, exc_list=None, dynamic_only=True): """Get assigned IPv6 address for a given interface. Returns list of addresses found. If no address found, returns empty list. If iface is None, we infer the current primary interface by doing ...
python
def get_ipv6_addr(iface=None, inc_aliases=False, fatal=True, exc_list=None, dynamic_only=True): """Get assigned IPv6 address for a given interface. Returns list of addresses found. If no address found, returns empty list. If iface is None, we infer the current primary interface by doing ...
[ "def", "get_ipv6_addr", "(", "iface", "=", "None", ",", "inc_aliases", "=", "False", ",", "fatal", "=", "True", ",", "exc_list", "=", "None", ",", "dynamic_only", "=", "True", ")", ":", "addresses", "=", "get_iface_addr", "(", "iface", "=", "iface", ",",...
Get assigned IPv6 address for a given interface. Returns list of addresses found. If no address found, returns empty list. If iface is None, we infer the current primary interface by doing a reverse lookup on the unit private-address. We currently only support scope global IPv6 addresses i.e. non-tem...
[ "Get", "assigned", "IPv6", "address", "for", "a", "given", "interface", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L360-L424
12,662
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_bridges
def get_bridges(vnic_dir='/sys/devices/virtual/net'): """Return a list of bridges on the system.""" b_regex = "%s/*/bridge" % vnic_dir return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_regex)]
python
def get_bridges(vnic_dir='/sys/devices/virtual/net'): """Return a list of bridges on the system.""" b_regex = "%s/*/bridge" % vnic_dir return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_regex)]
[ "def", "get_bridges", "(", "vnic_dir", "=", "'/sys/devices/virtual/net'", ")", ":", "b_regex", "=", "\"%s/*/bridge\"", "%", "vnic_dir", "return", "[", "x", ".", "replace", "(", "vnic_dir", ",", "''", ")", ".", "split", "(", "'/'", ")", "[", "1", "]", "fo...
Return a list of bridges on the system.
[ "Return", "a", "list", "of", "bridges", "on", "the", "system", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L427-L430
12,663
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_bridge_nics
def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): """Return a list of nics comprising a given bridge on the system.""" brif_regex = "%s/%s/brif/*" % (vnic_dir, bridge) return [x.split('/')[-1] for x in glob.glob(brif_regex)]
python
def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): """Return a list of nics comprising a given bridge on the system.""" brif_regex = "%s/%s/brif/*" % (vnic_dir, bridge) return [x.split('/')[-1] for x in glob.glob(brif_regex)]
[ "def", "get_bridge_nics", "(", "bridge", ",", "vnic_dir", "=", "'/sys/devices/virtual/net'", ")", ":", "brif_regex", "=", "\"%s/%s/brif/*\"", "%", "(", "vnic_dir", ",", "bridge", ")", "return", "[", "x", ".", "split", "(", "'/'", ")", "[", "-", "1", "]", ...
Return a list of nics comprising a given bridge on the system.
[ "Return", "a", "list", "of", "nics", "comprising", "a", "given", "bridge", "on", "the", "system", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L433-L436
12,664
juju/charm-helpers
charmhelpers/contrib/network/ip.py
is_ip
def is_ip(address): """ Returns True if address is a valid IP address. """ try: # Test to see if already an IPv4/IPv6 address address = netaddr.IPAddress(address) return True except (netaddr.AddrFormatError, ValueError): return False
python
def is_ip(address): """ Returns True if address is a valid IP address. """ try: # Test to see if already an IPv4/IPv6 address address = netaddr.IPAddress(address) return True except (netaddr.AddrFormatError, ValueError): return False
[ "def", "is_ip", "(", "address", ")", ":", "try", ":", "# Test to see if already an IPv4/IPv6 address", "address", "=", "netaddr", ".", "IPAddress", "(", "address", ")", "return", "True", "except", "(", "netaddr", ".", "AddrFormatError", ",", "ValueError", ")", "...
Returns True if address is a valid IP address.
[ "Returns", "True", "if", "address", "is", "a", "valid", "IP", "address", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L448-L457
12,665
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_host_ip
def get_host_ip(hostname, fallback=None): """ Resolves the IP for a given hostname, or returns the input if it is already an IP. """ if is_ip(hostname): return hostname ip_addr = ns_query(hostname) if not ip_addr: try: ip_addr = socket.gethostbyname(hostname) ...
python
def get_host_ip(hostname, fallback=None): """ Resolves the IP for a given hostname, or returns the input if it is already an IP. """ if is_ip(hostname): return hostname ip_addr = ns_query(hostname) if not ip_addr: try: ip_addr = socket.gethostbyname(hostname) ...
[ "def", "get_host_ip", "(", "hostname", ",", "fallback", "=", "None", ")", ":", "if", "is_ip", "(", "hostname", ")", ":", "return", "hostname", "ip_addr", "=", "ns_query", "(", "hostname", ")", "if", "not", "ip_addr", ":", "try", ":", "ip_addr", "=", "s...
Resolves the IP for a given hostname, or returns the input if it is already an IP.
[ "Resolves", "the", "IP", "for", "a", "given", "hostname", "or", "returns", "the", "input", "if", "it", "is", "already", "an", "IP", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L487-L503
12,666
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_hostname
def get_hostname(address, fqdn=True): """ Resolves hostname for given IP, or returns the input if it is already a hostname. """ if is_ip(address): try: import dns.reversename except ImportError: if six.PY2: apt_install("python-dnspython", fatal...
python
def get_hostname(address, fqdn=True): """ Resolves hostname for given IP, or returns the input if it is already a hostname. """ if is_ip(address): try: import dns.reversename except ImportError: if six.PY2: apt_install("python-dnspython", fatal...
[ "def", "get_hostname", "(", "address", ",", "fqdn", "=", "True", ")", ":", "if", "is_ip", "(", "address", ")", ":", "try", ":", "import", "dns", ".", "reversename", "except", "ImportError", ":", "if", "six", ".", "PY2", ":", "apt_install", "(", "\"pyth...
Resolves hostname for given IP, or returns the input if it is already a hostname.
[ "Resolves", "hostname", "for", "given", "IP", "or", "returns", "the", "input", "if", "it", "is", "already", "a", "hostname", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L506-L539
12,667
juju/charm-helpers
charmhelpers/contrib/network/ip.py
get_relation_ip
def get_relation_ip(interface, cidr_network=None): """Return this unit's IP for the given interface. Allow for an arbitrary interface to use with network-get to select an IP. Handle all address selection options including passed cidr network and IPv6. Usage: get_relation_ip('amqp', cidr_network='1...
python
def get_relation_ip(interface, cidr_network=None): """Return this unit's IP for the given interface. Allow for an arbitrary interface to use with network-get to select an IP. Handle all address selection options including passed cidr network and IPv6. Usage: get_relation_ip('amqp', cidr_network='1...
[ "def", "get_relation_ip", "(", "interface", ",", "cidr_network", "=", "None", ")", ":", "# Select the interface address first", "# For possible use as a fallback bellow with get_address_in_network", "try", ":", "# Get the interface specific IP", "address", "=", "network_get_primary...
Return this unit's IP for the given interface. Allow for an arbitrary interface to use with network-get to select an IP. Handle all address selection options including passed cidr network and IPv6. Usage: get_relation_ip('amqp', cidr_network='10.0.0.0/8') @param interface: string name of the rela...
[ "Return", "this", "unit", "s", "IP", "for", "the", "given", "interface", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/network/ip.py#L565-L602
12,668
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
BaseFileAudit.ensure_compliance
def ensure_compliance(self): """Ensure that the all registered files comply to registered criteria. """ for p in self.paths: if os.path.exists(p): if self.is_compliant(p): continue log('File %s is not in compliance.' % p, level=INF...
python
def ensure_compliance(self): """Ensure that the all registered files comply to registered criteria. """ for p in self.paths: if os.path.exists(p): if self.is_compliant(p): continue log('File %s is not in compliance.' % p, level=INF...
[ "def", "ensure_compliance", "(", "self", ")", ":", "for", "p", "in", "self", ".", "paths", ":", "if", "os", ".", "path", ".", "exists", "(", "p", ")", ":", "if", "self", ".", "is_compliant", "(", "p", ")", ":", "continue", "log", "(", "'File %s is ...
Ensure that the all registered files comply to registered criteria.
[ "Ensure", "that", "the", "all", "registered", "files", "comply", "to", "registered", "criteria", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L71-L88
12,669
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
FilePermissionAudit.is_compliant
def is_compliant(self, path): """Checks if the path is in compliance. Used to determine if the path specified meets the necessary requirements to be in compliance with the check itself. :param path: the file path to check :returns: True if the path is compliant, False otherwise...
python
def is_compliant(self, path): """Checks if the path is in compliance. Used to determine if the path specified meets the necessary requirements to be in compliance with the check itself. :param path: the file path to check :returns: True if the path is compliant, False otherwise...
[ "def", "is_compliant", "(", "self", ",", "path", ")", ":", "stat", "=", "self", ".", "_get_stat", "(", "path", ")", "user", "=", "self", ".", "user", "group", "=", "self", ".", "group", "compliant", "=", "True", "if", "stat", ".", "st_uid", "!=", "...
Checks if the path is in compliance. Used to determine if the path specified meets the necessary requirements to be in compliance with the check itself. :param path: the file path to check :returns: True if the path is compliant, False otherwise.
[ "Checks", "if", "the", "path", "is", "in", "compliance", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L158-L188
12,670
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
FilePermissionAudit.comply
def comply(self, path): """Issues a chown and chmod to the file paths specified.""" utils.ensure_permissions(path, self.user.pw_name, self.group.gr_name, self.mode)
python
def comply(self, path): """Issues a chown and chmod to the file paths specified.""" utils.ensure_permissions(path, self.user.pw_name, self.group.gr_name, self.mode)
[ "def", "comply", "(", "self", ",", "path", ")", ":", "utils", ".", "ensure_permissions", "(", "path", ",", "self", ".", "user", ".", "pw_name", ",", "self", ".", "group", ".", "gr_name", ",", "self", ".", "mode", ")" ]
Issues a chown and chmod to the file paths specified.
[ "Issues", "a", "chown", "and", "chmod", "to", "the", "file", "paths", "specified", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L190-L193
12,671
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
DirectoryPermissionAudit.is_compliant
def is_compliant(self, path): """Checks if the directory is compliant. Used to determine if the path specified and all of its children directories are in compliance with the check itself. :param path: the directory path to check :returns: True if the directory tree is compliant...
python
def is_compliant(self, path): """Checks if the directory is compliant. Used to determine if the path specified and all of its children directories are in compliance with the check itself. :param path: the directory path to check :returns: True if the directory tree is compliant...
[ "def", "is_compliant", "(", "self", ",", "path", ")", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "log", "(", "'Path specified %s is not a directory.'", "%", "path", ",", "level", "=", "ERROR", ")", "raise", "ValueError", "(...
Checks if the directory is compliant. Used to determine if the path specified and all of its children directories are in compliance with the check itself. :param path: the directory path to check :returns: True if the directory tree is compliant, otherwise False.
[ "Checks", "if", "the", "directory", "is", "compliant", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L205-L230
12,672
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.is_compliant
def is_compliant(self, path): """Determines if the templated file is compliant. A templated file is only compliant if it has not changed (as determined by its sha256 hashsum) AND its file permissions are set appropriately. :param path: the path to check compliance. """ ...
python
def is_compliant(self, path): """Determines if the templated file is compliant. A templated file is only compliant if it has not changed (as determined by its sha256 hashsum) AND its file permissions are set appropriately. :param path: the path to check compliance. """ ...
[ "def", "is_compliant", "(", "self", ",", "path", ")", ":", "same_templates", "=", "self", ".", "templates_match", "(", "path", ")", "same_content", "=", "self", ".", "contents_match", "(", "path", ")", "same_permissions", "=", "self", ".", "permissions_match",...
Determines if the templated file is compliant. A templated file is only compliant if it has not changed (as determined by its sha256 hashsum) AND its file permissions are set appropriately. :param path: the path to check compliance.
[ "Determines", "if", "the", "templated", "file", "is", "compliant", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L347-L363
12,673
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.run_service_actions
def run_service_actions(self): """Run any actions on services requested.""" if not self.service_actions: return for svc_action in self.service_actions: name = svc_action['service'] actions = svc_action['actions'] log("Running service '%s' actions ...
python
def run_service_actions(self): """Run any actions on services requested.""" if not self.service_actions: return for svc_action in self.service_actions: name = svc_action['service'] actions = svc_action['actions'] log("Running service '%s' actions ...
[ "def", "run_service_actions", "(", "self", ")", ":", "if", "not", "self", ".", "service_actions", ":", "return", "for", "svc_action", "in", "self", ".", "service_actions", ":", "name", "=", "svc_action", "[", "'service'", "]", "actions", "=", "svc_action", "...
Run any actions on services requested.
[ "Run", "any", "actions", "on", "services", "requested", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L365-L381
12,674
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.comply
def comply(self, path): """Ensures the contents and the permissions of the file. :param path: the path to correct """ dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) self.pre_write() render_and_write(self.template...
python
def comply(self, path): """Ensures the contents and the permissions of the file. :param path: the path to correct """ dirname = os.path.dirname(path) if not os.path.exists(dirname): os.makedirs(dirname) self.pre_write() render_and_write(self.template...
[ "def", "comply", "(", "self", ",", "path", ")", ":", "dirname", "=", "os", ".", "path", ".", "dirname", "(", "path", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "dirname", ")", ":", "os", ".", "makedirs", "(", "dirname", ")", "self",...
Ensures the contents and the permissions of the file. :param path: the path to correct
[ "Ensures", "the", "contents", "and", "the", "permissions", "of", "the", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L383-L397
12,675
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.templates_match
def templates_match(self, path): """Determines if the template files are the same. The template file equality is determined by the hashsum of the template files themselves. If there is no hashsum, then the content cannot be sure to be the same so treat it as if they changed. Oth...
python
def templates_match(self, path): """Determines if the template files are the same. The template file equality is determined by the hashsum of the template files themselves. If there is no hashsum, then the content cannot be sure to be the same so treat it as if they changed. Oth...
[ "def", "templates_match", "(", "self", ",", "path", ")", ":", "template_path", "=", "get_template_path", "(", "self", ".", "template_dir", ",", "path", ")", "key", "=", "'hardening:template:%s'", "%", "template_path", "template_checksum", "=", "file_hash", "(", ...
Determines if the template files are the same. The template file equality is determined by the hashsum of the template files themselves. If there is no hashsum, then the content cannot be sure to be the same so treat it as if they changed. Otherwise, return whether or not the hashsums a...
[ "Determines", "if", "the", "template", "files", "are", "the", "same", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L407-L440
12,676
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.contents_match
def contents_match(self, path): """Determines if the file content is the same. This is determined by comparing hashsum of the file contents and the saved hashsum. If there is no hashsum, then the content cannot be sure to be the same so treat them as if they are not the same. Ot...
python
def contents_match(self, path): """Determines if the file content is the same. This is determined by comparing hashsum of the file contents and the saved hashsum. If there is no hashsum, then the content cannot be sure to be the same so treat them as if they are not the same. Ot...
[ "def", "contents_match", "(", "self", ",", "path", ")", ":", "checksum", "=", "file_hash", "(", "path", ")", "kv", "=", "unitdata", ".", "kv", "(", ")", "stored_checksum", "=", "kv", ".", "get", "(", "'hardening:%s'", "%", "path", ")", "if", "not", "...
Determines if the file content is the same. This is determined by comparing hashsum of the file contents and the saved hashsum. If there is no hashsum, then the content cannot be sure to be the same so treat them as if they are not the same. Otherwise, return True if the hashsums are th...
[ "Determines", "if", "the", "file", "content", "is", "the", "same", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L442-L466
12,677
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.permissions_match
def permissions_match(self, path): """Determines if the file owner and permissions match. :param path: the path to check. """ audit = FilePermissionAudit(path, self.user, self.group, self.mode) return audit.is_compliant(path)
python
def permissions_match(self, path): """Determines if the file owner and permissions match. :param path: the path to check. """ audit = FilePermissionAudit(path, self.user, self.group, self.mode) return audit.is_compliant(path)
[ "def", "permissions_match", "(", "self", ",", "path", ")", ":", "audit", "=", "FilePermissionAudit", "(", "path", ",", "self", ".", "user", ",", "self", ".", "group", ",", "self", ".", "mode", ")", "return", "audit", ".", "is_compliant", "(", "path", "...
Determines if the file owner and permissions match. :param path: the path to check.
[ "Determines", "if", "the", "file", "owner", "and", "permissions", "match", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L468-L474
12,678
juju/charm-helpers
charmhelpers/contrib/hardening/audits/file.py
TemplatedFile.save_checksum
def save_checksum(self, path): """Calculates and saves the checksum for the path specified. :param path: the path of the file to save the checksum. """ checksum = file_hash(path) kv = unitdata.kv() kv.set('hardening:%s' % path, checksum) kv.flush()
python
def save_checksum(self, path): """Calculates and saves the checksum for the path specified. :param path: the path of the file to save the checksum. """ checksum = file_hash(path) kv = unitdata.kv() kv.set('hardening:%s' % path, checksum) kv.flush()
[ "def", "save_checksum", "(", "self", ",", "path", ")", ":", "checksum", "=", "file_hash", "(", "path", ")", "kv", "=", "unitdata", ".", "kv", "(", ")", "kv", ".", "set", "(", "'hardening:%s'", "%", "path", ",", "checksum", ")", "kv", ".", "flush", ...
Calculates and saves the checksum for the path specified. :param path: the path of the file to save the checksum.
[ "Calculates", "and", "saves", "the", "checksum", "for", "the", "path", "specified", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/hardening/audits/file.py#L476-L484
12,679
juju/charm-helpers
charmhelpers/core/strutils.py
bool_from_string
def bool_from_string(value): """Interpret string value as boolean. Returns True if value translates to True otherwise False. """ if isinstance(value, six.string_types): value = six.text_type(value) else: msg = "Unable to interpret non-string value '%s' as boolean" % (value) ...
python
def bool_from_string(value): """Interpret string value as boolean. Returns True if value translates to True otherwise False. """ if isinstance(value, six.string_types): value = six.text_type(value) else: msg = "Unable to interpret non-string value '%s' as boolean" % (value) ...
[ "def", "bool_from_string", "(", "value", ")", ":", "if", "isinstance", "(", "value", ",", "six", ".", "string_types", ")", ":", "value", "=", "six", ".", "text_type", "(", "value", ")", "else", ":", "msg", "=", "\"Unable to interpret non-string value '%s' as b...
Interpret string value as boolean. Returns True if value translates to True otherwise False.
[ "Interpret", "string", "value", "as", "boolean", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/strutils.py#L22-L41
12,680
juju/charm-helpers
charmhelpers/core/strutils.py
bytes_from_string
def bytes_from_string(value): """Interpret human readable string value as bytes. Returns int """ BYTE_POWER = { 'K': 1, 'KB': 1, 'M': 2, 'MB': 2, 'G': 3, 'GB': 3, 'T': 4, 'TB': 4, 'P': 5, 'PB': 5, } if isinstance(va...
python
def bytes_from_string(value): """Interpret human readable string value as bytes. Returns int """ BYTE_POWER = { 'K': 1, 'KB': 1, 'M': 2, 'MB': 2, 'G': 3, 'GB': 3, 'T': 4, 'TB': 4, 'P': 5, 'PB': 5, } if isinstance(va...
[ "def", "bytes_from_string", "(", "value", ")", ":", "BYTE_POWER", "=", "{", "'K'", ":", "1", ",", "'KB'", ":", "1", ",", "'M'", ":", "2", ",", "'MB'", ":", "2", ",", "'G'", ":", "3", ",", "'GB'", ":", "3", ",", "'T'", ":", "4", ",", "'TB'", ...
Interpret human readable string value as bytes. Returns int
[ "Interpret", "human", "readable", "string", "value", "as", "bytes", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/core/strutils.py#L44-L76
12,681
juju/charm-helpers
charmhelpers/contrib/openstack/audits/__init__.py
audit
def audit(*args): """Decorator to register an audit. These are used to generate audits that can be run on a deployed system that matches the given configuration :param args: List of functions to filter tests against :type args: List[Callable[Dict]] """ def wrapper(f): test_name = f...
python
def audit(*args): """Decorator to register an audit. These are used to generate audits that can be run on a deployed system that matches the given configuration :param args: List of functions to filter tests against :type args: List[Callable[Dict]] """ def wrapper(f): test_name = f...
[ "def", "audit", "(", "*", "args", ")", ":", "def", "wrapper", "(", "f", ")", ":", "test_name", "=", "f", ".", "__name__", "if", "_audits", ".", "get", "(", "test_name", ")", ":", "raise", "RuntimeError", "(", "\"Test name '{}' used more than once\"", ".", ...
Decorator to register an audit. These are used to generate audits that can be run on a deployed system that matches the given configuration :param args: List of functions to filter tests against :type args: List[Callable[Dict]]
[ "Decorator", "to", "register", "an", "audit", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/__init__.py#L35-L57
12,682
juju/charm-helpers
charmhelpers/contrib/openstack/audits/__init__.py
is_audit_type
def is_audit_type(*args): """This audit is included in the specified kinds of audits. :param *args: List of AuditTypes to include this audit in :type args: List[AuditType] :rtype: Callable[Dict] """ def _is_audit_type(audit_options): if audit_options.get('audit_type') in args: ...
python
def is_audit_type(*args): """This audit is included in the specified kinds of audits. :param *args: List of AuditTypes to include this audit in :type args: List[AuditType] :rtype: Callable[Dict] """ def _is_audit_type(audit_options): if audit_options.get('audit_type') in args: ...
[ "def", "is_audit_type", "(", "*", "args", ")", ":", "def", "_is_audit_type", "(", "audit_options", ")", ":", "if", "audit_options", ".", "get", "(", "'audit_type'", ")", "in", "args", ":", "return", "True", "else", ":", "return", "False", "return", "_is_au...
This audit is included in the specified kinds of audits. :param *args: List of AuditTypes to include this audit in :type args: List[AuditType] :rtype: Callable[Dict]
[ "This", "audit", "is", "included", "in", "the", "specified", "kinds", "of", "audits", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/__init__.py#L60-L72
12,683
juju/charm-helpers
charmhelpers/contrib/openstack/audits/__init__.py
run
def run(audit_options): """Run the configured audits with the specified audit_options. :param audit_options: Configuration for the audit :type audit_options: Config :rtype: Dict[str, str] """ errors = {} results = {} for name, audit in sorted(_audits.items()): result_name = nam...
python
def run(audit_options): """Run the configured audits with the specified audit_options. :param audit_options: Configuration for the audit :type audit_options: Config :rtype: Dict[str, str] """ errors = {} results = {} for name, audit in sorted(_audits.items()): result_name = nam...
[ "def", "run", "(", "audit_options", ")", ":", "errors", "=", "{", "}", "results", "=", "{", "}", "for", "name", ",", "audit", "in", "sorted", "(", "_audits", ".", "items", "(", ")", ")", ":", "result_name", "=", "name", ".", "replace", "(", "'_'", ...
Run the configured audits with the specified audit_options. :param audit_options: Configuration for the audit :type audit_options: Config :rtype: Dict[str, str]
[ "Run", "the", "configured", "audits", "with", "the", "specified", "audit_options", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/__init__.py#L149-L192
12,684
juju/charm-helpers
charmhelpers/contrib/openstack/audits/__init__.py
action_parse_results
def action_parse_results(result): """Parse the result of `run` in the context of an action. :param result: The result of running the security-checklist action on a unit :type result: Dict[str, Dict[str, str]] :rtype: int """ passed = True for test, result in result.items(): ...
python
def action_parse_results(result): """Parse the result of `run` in the context of an action. :param result: The result of running the security-checklist action on a unit :type result: Dict[str, Dict[str, str]] :rtype: int """ passed = True for test, result in result.items(): ...
[ "def", "action_parse_results", "(", "result", ")", ":", "passed", "=", "True", "for", "test", ",", "result", "in", "result", ".", "items", "(", ")", ":", "if", "result", "[", "'success'", "]", ":", "hookenv", ".", "action_set", "(", "{", "test", ":", ...
Parse the result of `run` in the context of an action. :param result: The result of running the security-checklist action on a unit :type result: Dict[str, Dict[str, str]] :rtype: int
[ "Parse", "the", "result", "of", "run", "in", "the", "context", "of", "an", "action", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/audits/__init__.py#L195-L212
12,685
juju/charm-helpers
charmhelpers/contrib/ssl/__init__.py
generate_selfsigned
def generate_selfsigned(keyfile, certfile, keysize="1024", config=None, subject=None, cn=None): """Generate selfsigned SSL keypair You must provide one of the 3 optional arguments: config, subject or cn If more than one is provided the leftmost will be used Arguments: keyfile -- (required) ful...
python
def generate_selfsigned(keyfile, certfile, keysize="1024", config=None, subject=None, cn=None): """Generate selfsigned SSL keypair You must provide one of the 3 optional arguments: config, subject or cn If more than one is provided the leftmost will be used Arguments: keyfile -- (required) ful...
[ "def", "generate_selfsigned", "(", "keyfile", ",", "certfile", ",", "keysize", "=", "\"1024\"", ",", "config", "=", "None", ",", "subject", "=", "None", ",", "cn", "=", "None", ")", ":", "cmd", "=", "[", "]", "if", "config", ":", "cmd", "=", "[", "...
Generate selfsigned SSL keypair You must provide one of the 3 optional arguments: config, subject or cn If more than one is provided the leftmost will be used Arguments: keyfile -- (required) full path to the keyfile to be created certfile -- (required) full path to the certfile to be created ...
[ "Generate", "selfsigned", "SSL", "keypair" ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/ssl/__init__.py#L19-L92
12,686
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_directory_for_unit
def ssh_directory_for_unit(application_name, user=None): """Return the directory used to store ssh assets for the application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str :...
python
def ssh_directory_for_unit(application_name, user=None): """Return the directory used to store ssh assets for the application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str :...
[ "def", "ssh_directory_for_unit", "(", "application_name", ",", "user", "=", "None", ")", ":", "if", "user", ":", "application_name", "=", "\"{}_{}\"", ".", "format", "(", "application_name", ",", "user", ")", "_dir", "=", "os", ".", "path", ".", "join", "(...
Return the directory used to store ssh assets for the application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str :returns: Fully qualified directory path. :rtype: str
[ "Return", "the", "directory", "used", "to", "store", "ssh", "assets", "for", "the", "application", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L36-L56
12,687
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_known_host_key
def ssh_known_host_key(host, application_name, user=None): """Return the first entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that th...
python
def ssh_known_host_key(host, application_name, user=None): """Return the first entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that th...
[ "def", "ssh_known_host_key", "(", "host", ",", "application_name", ",", "user", "=", "None", ")", ":", "cmd", "=", "[", "'ssh-keygen'", ",", "'-f'", ",", "known_hosts", "(", "application_name", ",", "user", ")", ",", "'-H'", ",", "'-F'", ",", "host", "]"...
Return the first entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str :returns: Host key ...
[ "Return", "the", "first", "entry", "in", "known_hosts", "for", "host", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L89-L125
12,688
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
remove_known_host
def remove_known_host(host, application_name, user=None): """Remove the entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh a...
python
def remove_known_host(host, application_name, user=None): """Remove the entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh a...
[ "def", "remove_known_host", "(", "host", ",", "application_name", ",", "user", "=", "None", ")", ":", "log", "(", "'Removing SSH known host entry for compute host at %s'", "%", "host", ")", "cmd", "=", "[", "'ssh-keygen'", ",", "'-f'", ",", "known_hosts", "(", "...
Remove the entry in known_hosts for host. :param host: hostname to lookup in file. :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Remove", "the", "entry", "in", "known_hosts", "for", "host", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L128-L140
12,689
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
is_same_key
def is_same_key(key_1, key_2): """Extract the key from two host entries and compare them. :param key_1: Host key :type key_1: str :param key_2: Host key :type key_2: str """ # The key format get will be like '|1|2rUumCavEXWVaVyB5uMl6m85pZo=|Cp' # 'EL6l7VTY37T/fg/ihhNb/GPgs= ssh-rsa AAAA...
python
def is_same_key(key_1, key_2): """Extract the key from two host entries and compare them. :param key_1: Host key :type key_1: str :param key_2: Host key :type key_2: str """ # The key format get will be like '|1|2rUumCavEXWVaVyB5uMl6m85pZo=|Cp' # 'EL6l7VTY37T/fg/ihhNb/GPgs= ssh-rsa AAAA...
[ "def", "is_same_key", "(", "key_1", ",", "key_2", ")", ":", "# The key format get will be like '|1|2rUumCavEXWVaVyB5uMl6m85pZo=|Cp'", "# 'EL6l7VTY37T/fg/ihhNb/GPgs= ssh-rsa AAAAB', we only need to compare", "# the part start with 'ssh-rsa' followed with '= ', because the hash", "# value in the...
Extract the key from two host entries and compare them. :param key_1: Host key :type key_1: str :param key_2: Host key :type key_2: str
[ "Extract", "the", "key", "from", "two", "host", "entries", "and", "compare", "them", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L143-L157
12,690
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
add_known_host
def add_known_host(host, application_name, user=None): """Add the given host key to the known hosts file. :param host: host name :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for....
python
def add_known_host(host, application_name, user=None): """Add the given host key to the known hosts file. :param host: host name :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for....
[ "def", "add_known_host", "(", "host", ",", "application_name", ",", "user", "=", "None", ")", ":", "cmd", "=", "[", "'ssh-keyscan'", ",", "'-H'", ",", "'-t'", ",", "'rsa'", ",", "host", "]", "try", ":", "remote_key", "=", "subprocess", ".", "check_output...
Add the given host key to the known hosts file. :param host: host name :type host: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Add", "the", "given", "host", "key", "to", "the", "known", "hosts", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L160-L187
12,691
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_authorized_key_exists
def ssh_authorized_key_exists(public_key, application_name, user=None): """Check if given key is in the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The u...
python
def ssh_authorized_key_exists(public_key, application_name, user=None): """Check if given key is in the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The u...
[ "def", "ssh_authorized_key_exists", "(", "public_key", ",", "application_name", ",", "user", "=", "None", ")", ":", "with", "open", "(", "authorized_keys", "(", "application_name", ",", "user", ")", ")", "as", "keys", ":", "return", "(", "'%s'", "%", "public...
Check if given key is in the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str :returns: Whether giv...
[ "Check", "if", "given", "key", "is", "in", "the", "authorized_key", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L190-L203
12,692
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
add_authorized_key
def add_authorized_key(public_key, application_name, user=None): """Add given key to the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ss...
python
def add_authorized_key(public_key, application_name, user=None): """Add given key to the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ss...
[ "def", "add_authorized_key", "(", "public_key", ",", "application_name", ",", "user", "=", "None", ")", ":", "with", "open", "(", "authorized_keys", "(", "application_name", ",", "user", ")", ",", "'a'", ")", "as", "keys", ":", "keys", ".", "write", "(", ...
Add given key to the authorized_key file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Add", "given", "key", "to", "the", "authorized_key", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L206-L217
12,693
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_known_hosts_lines
def ssh_known_hosts_lines(application_name, user=None): """Return contents of known_hosts file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str """ kn...
python
def ssh_known_hosts_lines(application_name, user=None): """Return contents of known_hosts file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str """ kn...
[ "def", "ssh_known_hosts_lines", "(", "application_name", ",", "user", "=", "None", ")", ":", "known_hosts_list", "=", "[", "]", "with", "open", "(", "known_hosts", "(", "application_name", ",", "user", ")", ")", "as", "hosts", ":", "for", "hosts_line", "in",...
Return contents of known_hosts file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Return", "contents", "of", "known_hosts", "file", "for", "given", "application", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L300-L313
12,694
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_authorized_keys_lines
def ssh_authorized_keys_lines(application_name, user=None): """Return contents of authorized_keys file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str ""...
python
def ssh_authorized_keys_lines(application_name, user=None): """Return contents of authorized_keys file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str ""...
[ "def", "ssh_authorized_keys_lines", "(", "application_name", ",", "user", "=", "None", ")", ":", "authorized_keys_list", "=", "[", "]", "with", "open", "(", "authorized_keys", "(", "application_name", ",", "user", ")", ")", "as", "keys", ":", "for", "authkey_l...
Return contents of authorized_keys file for given application. :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Return", "contents", "of", "authorized_keys", "file", "for", "given", "application", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L316-L330
12,695
juju/charm-helpers
charmhelpers/contrib/openstack/ssh_migrations.py
ssh_compute_remove
def ssh_compute_remove(public_key, application_name, user=None): """Remove given public key from authorized_keys file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user th...
python
def ssh_compute_remove(public_key, application_name, user=None): """Remove given public key from authorized_keys file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user th...
[ "def", "ssh_compute_remove", "(", "public_key", ",", "application_name", ",", "user", "=", "None", ")", ":", "if", "not", "(", "os", ".", "path", ".", "isfile", "(", "authorized_keys", "(", "application_name", ",", "user", ")", ")", "or", "os", ".", "pat...
Remove given public key from authorized_keys file. :param public_key: Public key. :type public_key: str :param application_name: Name of application eg nova-compute-something :type application_name: str :param user: The user that the ssh asserts are for. :type user: str
[ "Remove", "given", "public", "key", "from", "authorized_keys", "file", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/contrib/openstack/ssh_migrations.py#L333-L359
12,696
juju/charm-helpers
charmhelpers/fetch/ubuntu.py
apt_cache
def apt_cache(in_memory=True, progress=None): """Build and return an apt cache.""" from apt import apt_pkg apt_pkg.init() if in_memory: apt_pkg.config.set("Dir::Cache::pkgcache", "") apt_pkg.config.set("Dir::Cache::srcpkgcache", "") return apt_pkg.Cache(progress)
python
def apt_cache(in_memory=True, progress=None): """Build and return an apt cache.""" from apt import apt_pkg apt_pkg.init() if in_memory: apt_pkg.config.set("Dir::Cache::pkgcache", "") apt_pkg.config.set("Dir::Cache::srcpkgcache", "") return apt_pkg.Cache(progress)
[ "def", "apt_cache", "(", "in_memory", "=", "True", ",", "progress", "=", "None", ")", ":", "from", "apt", "import", "apt_pkg", "apt_pkg", ".", "init", "(", ")", "if", "in_memory", ":", "apt_pkg", ".", "config", ".", "set", "(", "\"Dir::Cache::pkgcache\"", ...
Build and return an apt cache.
[ "Build", "and", "return", "an", "apt", "cache", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L211-L218
12,697
juju/charm-helpers
charmhelpers/fetch/ubuntu.py
apt_mark
def apt_mark(packages, mark, fatal=False): """Flag one or more packages using apt-mark.""" log("Marking {} as {}".format(packages, mark)) cmd = ['apt-mark', mark] if isinstance(packages, six.string_types): cmd.append(packages) else: cmd.extend(packages) if fatal: subproc...
python
def apt_mark(packages, mark, fatal=False): """Flag one or more packages using apt-mark.""" log("Marking {} as {}".format(packages, mark)) cmd = ['apt-mark', mark] if isinstance(packages, six.string_types): cmd.append(packages) else: cmd.extend(packages) if fatal: subproc...
[ "def", "apt_mark", "(", "packages", ",", "mark", ",", "fatal", "=", "False", ")", ":", "log", "(", "\"Marking {} as {}\"", ".", "format", "(", "packages", ",", "mark", ")", ")", "cmd", "=", "[", "'apt-mark'", ",", "mark", "]", "if", "isinstance", "(", ...
Flag one or more packages using apt-mark.
[ "Flag", "one", "or", "more", "packages", "using", "apt", "-", "mark", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L278-L290
12,698
juju/charm-helpers
charmhelpers/fetch/ubuntu.py
import_key
def import_key(key): """Import an ASCII Armor key. A Radix64 format keyid is also supported for backwards compatibility. In this case Ubuntu keyserver will be queried for a key via HTTPS by its keyid. This method is less preferrable because https proxy servers may require traffic decryption whi...
python
def import_key(key): """Import an ASCII Armor key. A Radix64 format keyid is also supported for backwards compatibility. In this case Ubuntu keyserver will be queried for a key via HTTPS by its keyid. This method is less preferrable because https proxy servers may require traffic decryption whi...
[ "def", "import_key", "(", "key", ")", ":", "key", "=", "key", ".", "strip", "(", ")", "if", "'-'", "in", "key", "or", "'\\n'", "in", "key", ":", "# Send everything not obviously a keyid to GPG to import, as", "# we trust its validation better than our own. eg. handling"...
Import an ASCII Armor key. A Radix64 format keyid is also supported for backwards compatibility. In this case Ubuntu keyserver will be queried for a key via HTTPS by its keyid. This method is less preferrable because https proxy servers may require traffic decryption which is equivalent to a ma...
[ "Import", "an", "ASCII", "Armor", "key", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L301-L348
12,699
juju/charm-helpers
charmhelpers/fetch/ubuntu.py
_dearmor_gpg_key
def _dearmor_gpg_key(key_asc): """Converts a GPG key in the ASCII armor format to the binary format. :param key_asc: A GPG key in ASCII armor format. :type key_asc: (str, bytes) :returns: A GPG key in binary format :rtype: (str, bytes) :raises: GPGKeyError """ ps = subprocess.Popen(['gp...
python
def _dearmor_gpg_key(key_asc): """Converts a GPG key in the ASCII armor format to the binary format. :param key_asc: A GPG key in ASCII armor format. :type key_asc: (str, bytes) :returns: A GPG key in binary format :rtype: (str, bytes) :raises: GPGKeyError """ ps = subprocess.Popen(['gp...
[ "def", "_dearmor_gpg_key", "(", "key_asc", ")", ":", "ps", "=", "subprocess", ".", "Popen", "(", "[", "'gpg'", ",", "'--dearmor'", "]", ",", "stdout", "=", "subprocess", ".", "PIPE", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "stdin", "=", "su...
Converts a GPG key in the ASCII armor format to the binary format. :param key_asc: A GPG key in ASCII armor format. :type key_asc: (str, bytes) :returns: A GPG key in binary format :rtype: (str, bytes) :raises: GPGKeyError
[ "Converts", "a", "GPG", "key", "in", "the", "ASCII", "armor", "format", "to", "the", "binary", "format", "." ]
aa785c40c3b7a8c69dbfbc7921d6b9f30142e171
https://github.com/juju/charm-helpers/blob/aa785c40c3b7a8c69dbfbc7921d6b9f30142e171/charmhelpers/fetch/ubuntu.py#L415-L437