repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1 value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
saltstack/salt | salt/cloud/__init__.py | Cloud.do_function | def do_function(self, prov, func, kwargs):
'''
Perform a function against a cloud provider
'''
matches = self.lookup_providers(prov)
if len(matches) > 1:
raise SaltCloudSystemExit(
'More than one results matched \'{0}\'. Please specify '
'one of: {1}'.format(
prov,
', '.join([
'{0}:{1}'.format(alias, driver) for
(alias, driver) in matches
])
)
)
alias, driver = matches.pop()
fun = '{0}.{1}'.format(driver, func)
if fun not in self.clouds:
raise SaltCloudSystemExit(
'The \'{0}\' cloud provider alias, for the \'{1}\' driver, does '
'not define the function \'{2}\''.format(alias, driver, func)
)
log.debug(
'Trying to execute \'%s\' with the following kwargs: %s',
fun, kwargs
)
with salt.utils.context.func_globals_inject(
self.clouds[fun],
__active_provider_name__=':'.join([alias, driver])
):
if kwargs:
return {
alias: {
driver: self.clouds[fun](
call='function', kwargs=kwargs
)
}
}
return {
alias: {
driver: self.clouds[fun](call='function')
}
} | python | def do_function(self, prov, func, kwargs):
'''
Perform a function against a cloud provider
'''
matches = self.lookup_providers(prov)
if len(matches) > 1:
raise SaltCloudSystemExit(
'More than one results matched \'{0}\'. Please specify '
'one of: {1}'.format(
prov,
', '.join([
'{0}:{1}'.format(alias, driver) for
(alias, driver) in matches
])
)
)
alias, driver = matches.pop()
fun = '{0}.{1}'.format(driver, func)
if fun not in self.clouds:
raise SaltCloudSystemExit(
'The \'{0}\' cloud provider alias, for the \'{1}\' driver, does '
'not define the function \'{2}\''.format(alias, driver, func)
)
log.debug(
'Trying to execute \'%s\' with the following kwargs: %s',
fun, kwargs
)
with salt.utils.context.func_globals_inject(
self.clouds[fun],
__active_provider_name__=':'.join([alias, driver])
):
if kwargs:
return {
alias: {
driver: self.clouds[fun](
call='function', kwargs=kwargs
)
}
}
return {
alias: {
driver: self.clouds[fun](call='function')
}
} | [
"def",
"do_function",
"(",
"self",
",",
"prov",
",",
"func",
",",
"kwargs",
")",
":",
"matches",
"=",
"self",
".",
"lookup_providers",
"(",
"prov",
")",
"if",
"len",
"(",
"matches",
")",
">",
"1",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'More than one... | Perform a function against a cloud provider | [
"Perform",
"a",
"function",
"against",
"a",
"cloud",
"provider"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/__init__.py#L1549-L1595 | train |
saltstack/salt | salt/cloud/__init__.py | Cloud.__filter_non_working_providers | def __filter_non_working_providers(self):
'''
Remove any mis-configured cloud providers from the available listing
'''
for alias, drivers in six.iteritems(self.opts['providers'].copy()):
for driver in drivers.copy():
fun = '{0}.get_configured_provider'.format(driver)
if fun not in self.clouds:
# Mis-configured provider that got removed?
log.warning(
'The cloud driver, \'%s\', configured under the '
'\'%s\' cloud provider alias, could not be loaded. '
'Please check your provider configuration files and '
'ensure all required dependencies are installed '
'for the \'%s\' driver.\n'
'In rare cases, this could indicate the \'%s()\' '
'function could not be found.\nRemoving \'%s\' from '
'the available providers list',
driver, alias, driver, fun, driver
)
self.opts['providers'][alias].pop(driver)
if alias not in self.opts['providers']:
continue
if not self.opts['providers'][alias]:
self.opts['providers'].pop(alias)
continue
with salt.utils.context.func_globals_inject(
self.clouds[fun],
__active_provider_name__=':'.join([alias, driver])
):
if self.clouds[fun]() is False:
log.warning(
'The cloud driver, \'%s\', configured under the '
'\'%s\' cloud provider alias is not properly '
'configured. Removing it from the available '
'providers list.', driver, alias
)
self.opts['providers'][alias].pop(driver)
if alias not in self.opts['providers']:
continue
if not self.opts['providers'][alias]:
self.opts['providers'].pop(alias) | python | def __filter_non_working_providers(self):
'''
Remove any mis-configured cloud providers from the available listing
'''
for alias, drivers in six.iteritems(self.opts['providers'].copy()):
for driver in drivers.copy():
fun = '{0}.get_configured_provider'.format(driver)
if fun not in self.clouds:
# Mis-configured provider that got removed?
log.warning(
'The cloud driver, \'%s\', configured under the '
'\'%s\' cloud provider alias, could not be loaded. '
'Please check your provider configuration files and '
'ensure all required dependencies are installed '
'for the \'%s\' driver.\n'
'In rare cases, this could indicate the \'%s()\' '
'function could not be found.\nRemoving \'%s\' from '
'the available providers list',
driver, alias, driver, fun, driver
)
self.opts['providers'][alias].pop(driver)
if alias not in self.opts['providers']:
continue
if not self.opts['providers'][alias]:
self.opts['providers'].pop(alias)
continue
with salt.utils.context.func_globals_inject(
self.clouds[fun],
__active_provider_name__=':'.join([alias, driver])
):
if self.clouds[fun]() is False:
log.warning(
'The cloud driver, \'%s\', configured under the '
'\'%s\' cloud provider alias is not properly '
'configured. Removing it from the available '
'providers list.', driver, alias
)
self.opts['providers'][alias].pop(driver)
if alias not in self.opts['providers']:
continue
if not self.opts['providers'][alias]:
self.opts['providers'].pop(alias) | [
"def",
"__filter_non_working_providers",
"(",
"self",
")",
":",
"for",
"alias",
",",
"drivers",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"opts",
"[",
"'providers'",
"]",
".",
"copy",
"(",
")",
")",
":",
"for",
"driver",
"in",
"drivers",
".",
"c... | Remove any mis-configured cloud providers from the available listing | [
"Remove",
"any",
"mis",
"-",
"configured",
"cloud",
"providers",
"from",
"the",
"available",
"listing"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/__init__.py#L1597-L1643 | train |
saltstack/salt | salt/cloud/__init__.py | Map.read | def read(self):
'''
Read in the specified map and return the map structure
'''
map_ = None
if self.opts.get('map', None) is None:
if self.opts.get('map_data', None) is None:
if self.opts.get('map_pillar', None) is None:
pass
elif self.opts.get('map_pillar') not in self.opts.get('maps'):
log.error(
'The specified map not found in pillar at '
'\'cloud:maps:%s\'', self.opts['map_pillar']
)
raise SaltCloudNotFound()
else:
# 'map_pillar' is provided, try to use it
map_ = self.opts['maps'][self.opts.get('map_pillar')]
else:
# 'map_data' is provided, try to use it
map_ = self.opts['map_data']
else:
# 'map' is provided, try to use it
local_minion_opts = copy.deepcopy(self.opts)
local_minion_opts['file_client'] = 'local'
self.minion = salt.minion.MasterMinion(local_minion_opts)
if not os.path.isfile(self.opts['map']):
if not (self.opts['map']).startswith('salt://'):
log.error(
'The specified map file does not exist: \'%s\'',
self.opts['map']
)
raise SaltCloudNotFound()
if (self.opts['map']).startswith('salt://'):
cached_map = self.minion.functions['cp.cache_file'](self.opts['map'])
else:
cached_map = self.opts['map']
try:
renderer = self.opts.get('renderer', 'jinja|yaml')
rend = salt.loader.render(self.opts, {})
blacklist = self.opts.get('renderer_blacklist')
whitelist = self.opts.get('renderer_whitelist')
map_ = compile_template(
cached_map, rend, renderer, blacklist, whitelist
)
except Exception as exc:
log.error(
'Rendering map %s failed, render error:\n%s',
self.opts['map'], exc,
exc_info_on_loglevel=logging.DEBUG
)
return {}
if 'include' in map_:
map_ = salt.config.include_config(
map_, self.opts['map'], verbose=False
)
if not map_:
return {}
# Create expected data format if needed
for profile, mapped in six.iteritems(map_.copy()):
if isinstance(mapped, (list, tuple)):
entries = {}
for mapping in mapped:
if isinstance(mapping, six.string_types):
# Foo:
# - bar1
# - bar2
mapping = {mapping: None}
for name, overrides in six.iteritems(mapping):
if overrides is None or isinstance(overrides, bool):
# Foo:
# - bar1:
# - bar2:
overrides = {}
try:
overrides.setdefault('name', name)
except AttributeError:
log.error(
'Cannot use \'name\' as a minion id in a cloud map as it '
'is a reserved word. Please change \'name\' to a different '
'minion id reference.'
)
return {}
entries[name] = overrides
map_[profile] = entries
continue
if isinstance(mapped, dict):
# Convert the dictionary mapping to a list of dictionaries
# Foo:
# bar1:
# grains:
# foo: bar
# bar2:
# grains:
# foo: bar
entries = {}
for name, overrides in six.iteritems(mapped):
overrides.setdefault('name', name)
entries[name] = overrides
map_[profile] = entries
continue
if isinstance(mapped, six.string_types):
# If it's a single string entry, let's make iterable because of
# the next step
mapped = [mapped]
map_[profile] = {}
for name in mapped:
map_[profile][name] = {'name': name}
return map_ | python | def read(self):
'''
Read in the specified map and return the map structure
'''
map_ = None
if self.opts.get('map', None) is None:
if self.opts.get('map_data', None) is None:
if self.opts.get('map_pillar', None) is None:
pass
elif self.opts.get('map_pillar') not in self.opts.get('maps'):
log.error(
'The specified map not found in pillar at '
'\'cloud:maps:%s\'', self.opts['map_pillar']
)
raise SaltCloudNotFound()
else:
# 'map_pillar' is provided, try to use it
map_ = self.opts['maps'][self.opts.get('map_pillar')]
else:
# 'map_data' is provided, try to use it
map_ = self.opts['map_data']
else:
# 'map' is provided, try to use it
local_minion_opts = copy.deepcopy(self.opts)
local_minion_opts['file_client'] = 'local'
self.minion = salt.minion.MasterMinion(local_minion_opts)
if not os.path.isfile(self.opts['map']):
if not (self.opts['map']).startswith('salt://'):
log.error(
'The specified map file does not exist: \'%s\'',
self.opts['map']
)
raise SaltCloudNotFound()
if (self.opts['map']).startswith('salt://'):
cached_map = self.minion.functions['cp.cache_file'](self.opts['map'])
else:
cached_map = self.opts['map']
try:
renderer = self.opts.get('renderer', 'jinja|yaml')
rend = salt.loader.render(self.opts, {})
blacklist = self.opts.get('renderer_blacklist')
whitelist = self.opts.get('renderer_whitelist')
map_ = compile_template(
cached_map, rend, renderer, blacklist, whitelist
)
except Exception as exc:
log.error(
'Rendering map %s failed, render error:\n%s',
self.opts['map'], exc,
exc_info_on_loglevel=logging.DEBUG
)
return {}
if 'include' in map_:
map_ = salt.config.include_config(
map_, self.opts['map'], verbose=False
)
if not map_:
return {}
# Create expected data format if needed
for profile, mapped in six.iteritems(map_.copy()):
if isinstance(mapped, (list, tuple)):
entries = {}
for mapping in mapped:
if isinstance(mapping, six.string_types):
# Foo:
# - bar1
# - bar2
mapping = {mapping: None}
for name, overrides in six.iteritems(mapping):
if overrides is None or isinstance(overrides, bool):
# Foo:
# - bar1:
# - bar2:
overrides = {}
try:
overrides.setdefault('name', name)
except AttributeError:
log.error(
'Cannot use \'name\' as a minion id in a cloud map as it '
'is a reserved word. Please change \'name\' to a different '
'minion id reference.'
)
return {}
entries[name] = overrides
map_[profile] = entries
continue
if isinstance(mapped, dict):
# Convert the dictionary mapping to a list of dictionaries
# Foo:
# bar1:
# grains:
# foo: bar
# bar2:
# grains:
# foo: bar
entries = {}
for name, overrides in six.iteritems(mapped):
overrides.setdefault('name', name)
entries[name] = overrides
map_[profile] = entries
continue
if isinstance(mapped, six.string_types):
# If it's a single string entry, let's make iterable because of
# the next step
mapped = [mapped]
map_[profile] = {}
for name in mapped:
map_[profile][name] = {'name': name}
return map_ | [
"def",
"read",
"(",
"self",
")",
":",
"map_",
"=",
"None",
"if",
"self",
".",
"opts",
".",
"get",
"(",
"'map'",
",",
"None",
")",
"is",
"None",
":",
"if",
"self",
".",
"opts",
".",
"get",
"(",
"'map_data'",
",",
"None",
")",
"is",
"None",
":",
... | Read in the specified map and return the map structure | [
"Read",
"in",
"the",
"specified",
"map",
"and",
"return",
"the",
"map",
"structure"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/__init__.py#L1742-L1857 | train |
saltstack/salt | salt/cloud/__init__.py | Map.map_data | def map_data(self, cached=False):
'''
Create a data map of what to execute on
'''
ret = {'create': {}}
pmap = self.map_providers_parallel(cached=cached)
exist = set()
defined = set()
rendered_map = copy.deepcopy(self.rendered_map)
for profile_name, nodes in six.iteritems(rendered_map):
if profile_name not in self.opts['profiles']:
msg = (
'The required profile, \'{0}\', defined in the map '
'does not exist. The defined nodes, {1}, will not '
'be created.'.format(
profile_name,
', '.join('\'{0}\''.format(node) for node in nodes)
)
)
log.error(msg)
if 'errors' not in ret:
ret['errors'] = {}
ret['errors'][profile_name] = msg
continue
profile_data = self.opts['profiles'].get(profile_name)
for nodename, overrides in six.iteritems(nodes):
# Get associated provider data, in case something like size
# or image is specified in the provider file. See issue #32510.
if 'provider' in overrides and overrides['provider'] != profile_data['provider']:
alias, driver = overrides.get('provider').split(':')
else:
alias, driver = profile_data.get('provider').split(':')
provider_details = copy.deepcopy(self.opts['providers'][alias][driver])
del provider_details['profiles']
# Update the provider details information with profile data
# Profile data and node overrides should override provider data, if defined.
# This keeps map file data definitions consistent with -p usage.
salt.utils.dictupdate.update(provider_details, profile_data)
nodedata = copy.deepcopy(provider_details)
# Update profile data with the map overrides
for setting in ('grains', 'master', 'minion', 'volumes',
'requires'):
deprecated = 'map_{0}'.format(setting)
if deprecated in overrides:
log.warning(
'The use of \'%s\' on the \'%s\' mapping has '
'been deprecated. The preferred way now is to '
'just define \'%s\'. For now, salt-cloud will do '
'the proper thing and convert the deprecated '
'mapping into the preferred one.',
deprecated, nodename, setting
)
overrides[setting] = overrides.pop(deprecated)
# merge minion grains from map file
if 'minion' in overrides and \
'minion' in nodedata and \
'grains' in overrides['minion'] and \
'grains' in nodedata['minion']:
nodedata['minion']['grains'].update(
overrides['minion']['grains']
)
del overrides['minion']['grains']
# remove minion key if now is empty dict
if not overrides['minion']:
del overrides['minion']
nodedata = salt.utils.dictupdate.update(nodedata, overrides)
# Add the computed information to the return data
ret['create'][nodename] = nodedata
# Add the node name to the defined set
alias, driver = nodedata['provider'].split(':')
defined.add((alias, driver, nodename))
def get_matching_by_name(name):
matches = {}
for alias, drivers in six.iteritems(pmap):
for driver, vms in six.iteritems(drivers):
for vm_name, details in six.iteritems(vms):
if vm_name == name and driver not in matches:
matches[driver] = details['state']
return matches
for alias, drivers in six.iteritems(pmap):
for driver, vms in six.iteritems(drivers):
for name, details in six.iteritems(vms):
exist.add((alias, driver, name))
if name not in ret['create']:
continue
# The machine is set to be created. Does it already exist?
matching = get_matching_by_name(name)
if not matching:
continue
# A machine by the same name exists
for item in matching:
if name not in ret['create']:
# Machine already removed
break
log.warning("'%s' already exists, removing from "
'the create map.', name)
if 'existing' not in ret:
ret['existing'] = {}
ret['existing'][name] = ret['create'].pop(name)
if 'hard' in self.opts and self.opts['hard']:
if self.opts['enable_hard_maps'] is False:
raise SaltCloudSystemExit(
'The --hard map can be extremely dangerous to use, '
'and therefore must explicitly be enabled in the main '
'configuration file, by setting \'enable_hard_maps\' '
'to True'
)
# Hard maps are enabled, Look for the items to delete.
ret['destroy'] = exist.difference(defined)
return ret | python | def map_data(self, cached=False):
'''
Create a data map of what to execute on
'''
ret = {'create': {}}
pmap = self.map_providers_parallel(cached=cached)
exist = set()
defined = set()
rendered_map = copy.deepcopy(self.rendered_map)
for profile_name, nodes in six.iteritems(rendered_map):
if profile_name not in self.opts['profiles']:
msg = (
'The required profile, \'{0}\', defined in the map '
'does not exist. The defined nodes, {1}, will not '
'be created.'.format(
profile_name,
', '.join('\'{0}\''.format(node) for node in nodes)
)
)
log.error(msg)
if 'errors' not in ret:
ret['errors'] = {}
ret['errors'][profile_name] = msg
continue
profile_data = self.opts['profiles'].get(profile_name)
for nodename, overrides in six.iteritems(nodes):
# Get associated provider data, in case something like size
# or image is specified in the provider file. See issue #32510.
if 'provider' in overrides and overrides['provider'] != profile_data['provider']:
alias, driver = overrides.get('provider').split(':')
else:
alias, driver = profile_data.get('provider').split(':')
provider_details = copy.deepcopy(self.opts['providers'][alias][driver])
del provider_details['profiles']
# Update the provider details information with profile data
# Profile data and node overrides should override provider data, if defined.
# This keeps map file data definitions consistent with -p usage.
salt.utils.dictupdate.update(provider_details, profile_data)
nodedata = copy.deepcopy(provider_details)
# Update profile data with the map overrides
for setting in ('grains', 'master', 'minion', 'volumes',
'requires'):
deprecated = 'map_{0}'.format(setting)
if deprecated in overrides:
log.warning(
'The use of \'%s\' on the \'%s\' mapping has '
'been deprecated. The preferred way now is to '
'just define \'%s\'. For now, salt-cloud will do '
'the proper thing and convert the deprecated '
'mapping into the preferred one.',
deprecated, nodename, setting
)
overrides[setting] = overrides.pop(deprecated)
# merge minion grains from map file
if 'minion' in overrides and \
'minion' in nodedata and \
'grains' in overrides['minion'] and \
'grains' in nodedata['minion']:
nodedata['minion']['grains'].update(
overrides['minion']['grains']
)
del overrides['minion']['grains']
# remove minion key if now is empty dict
if not overrides['minion']:
del overrides['minion']
nodedata = salt.utils.dictupdate.update(nodedata, overrides)
# Add the computed information to the return data
ret['create'][nodename] = nodedata
# Add the node name to the defined set
alias, driver = nodedata['provider'].split(':')
defined.add((alias, driver, nodename))
def get_matching_by_name(name):
matches = {}
for alias, drivers in six.iteritems(pmap):
for driver, vms in six.iteritems(drivers):
for vm_name, details in six.iteritems(vms):
if vm_name == name and driver not in matches:
matches[driver] = details['state']
return matches
for alias, drivers in six.iteritems(pmap):
for driver, vms in six.iteritems(drivers):
for name, details in six.iteritems(vms):
exist.add((alias, driver, name))
if name not in ret['create']:
continue
# The machine is set to be created. Does it already exist?
matching = get_matching_by_name(name)
if not matching:
continue
# A machine by the same name exists
for item in matching:
if name not in ret['create']:
# Machine already removed
break
log.warning("'%s' already exists, removing from "
'the create map.', name)
if 'existing' not in ret:
ret['existing'] = {}
ret['existing'][name] = ret['create'].pop(name)
if 'hard' in self.opts and self.opts['hard']:
if self.opts['enable_hard_maps'] is False:
raise SaltCloudSystemExit(
'The --hard map can be extremely dangerous to use, '
'and therefore must explicitly be enabled in the main '
'configuration file, by setting \'enable_hard_maps\' '
'to True'
)
# Hard maps are enabled, Look for the items to delete.
ret['destroy'] = exist.difference(defined)
return ret | [
"def",
"map_data",
"(",
"self",
",",
"cached",
"=",
"False",
")",
":",
"ret",
"=",
"{",
"'create'",
":",
"{",
"}",
"}",
"pmap",
"=",
"self",
".",
"map_providers_parallel",
"(",
"cached",
"=",
"cached",
")",
"exist",
"=",
"set",
"(",
")",
"defined",
... | Create a data map of what to execute on | [
"Create",
"a",
"data",
"map",
"of",
"what",
"to",
"execute",
"on"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/__init__.py#L1905-L2029 | train |
saltstack/salt | salt/cloud/__init__.py | Map.run_map | def run_map(self, dmap):
'''
Execute the contents of the VM map
'''
if self._has_loop(dmap):
msg = 'Uh-oh, that cloud map has a dependency loop!'
log.error(msg)
raise SaltCloudException(msg)
# Go through the create list and calc dependencies
for key, val in six.iteritems(dmap['create']):
log.info('Calculating dependencies for %s', key)
level = 0
level = self._calcdep(dmap, key, val, level)
log.debug('Got execution order %s for %s', level, key)
dmap['create'][key]['level'] = level
try:
existing_list = six.iteritems(dmap['existing'])
except KeyError:
existing_list = six.iteritems({})
for key, val in existing_list:
log.info('Calculating dependencies for %s', key)
level = 0
level = self._calcdep(dmap, key, val, level)
log.debug('Got execution order %s for %s', level, key)
dmap['existing'][key]['level'] = level
# Now sort the create list based on dependencies
create_list = sorted(six.iteritems(dmap['create']), key=lambda x: x[1]['level'])
full_map = dmap['create'].copy()
if 'existing' in dmap:
full_map.update(dmap['existing'])
possible_master_list = sorted(six.iteritems(full_map), key=lambda x: x[1]['level'])
output = {}
if self.opts['parallel']:
parallel_data = []
master_name = None
master_minion_name = None
master_host = None
master_finger = None
for name, profile in possible_master_list:
if profile.get('make_master', False) is True:
master_name = name
master_profile = profile
if master_name:
# If the master already exists, get the host
if master_name not in dmap['create']:
master_host = self.client.query()
for provider_part in master_profile['provider'].split(':'):
master_host = master_host[provider_part]
master_host = master_host[master_name][master_profile.get('ssh_interface', 'public_ips')]
if not master_host:
raise SaltCloudSystemExit(
'Could not get the hostname of master {}.'.format(master_name)
)
# Otherwise, deploy it as a new master
else:
master_minion_name = master_name
log.debug('Creating new master \'%s\'', master_name)
if salt.config.get_cloud_config_value(
'deploy',
master_profile,
self.opts
) is False:
raise SaltCloudSystemExit(
'Cannot proceed with \'make_master\' when salt deployment '
'is disabled(ex: --no-deploy).'
)
# Generate the master keys
log.debug('Generating master keys for \'%s\'', master_profile['name'])
priv, pub = salt.utils.cloud.gen_keys(
salt.config.get_cloud_config_value(
'keysize',
master_profile,
self.opts
)
)
master_profile['master_pub'] = pub
master_profile['master_pem'] = priv
# Generate the fingerprint of the master pubkey in order to
# mitigate man-in-the-middle attacks
master_temp_pub = salt.utils.files.mkstemp()
with salt.utils.files.fopen(master_temp_pub, 'w') as mtp:
mtp.write(pub)
master_finger = salt.utils.crypt.pem_finger(master_temp_pub, sum_type=self.opts['hash_type'])
os.unlink(master_temp_pub)
if master_profile.get('make_minion', True) is True:
master_profile.setdefault('minion', {})
if 'id' in master_profile['minion']:
master_minion_name = master_profile['minion']['id']
# Set this minion's master as local if the user has not set it
if 'master' not in master_profile['minion']:
master_profile['minion']['master'] = '127.0.0.1'
if master_finger is not None:
master_profile['master_finger'] = master_finger
# Generate the minion keys to pre-seed the master:
for name, profile in create_list:
make_minion = salt.config.get_cloud_config_value(
'make_minion', profile, self.opts, default=True
)
if make_minion is False:
continue
log.debug('Generating minion keys for \'%s\'', profile['name'])
priv, pub = salt.utils.cloud.gen_keys(
salt.config.get_cloud_config_value(
'keysize',
profile,
self.opts
)
)
profile['pub_key'] = pub
profile['priv_key'] = priv
# Store the minion's public key in order to be pre-seeded in
# the master
master_profile.setdefault('preseed_minion_keys', {})
master_profile['preseed_minion_keys'].update({name: pub})
local_master = False
if master_profile['minion'].get('local_master', False) and \
master_profile['minion'].get('master', None) is not None:
# The minion is explicitly defining a master and it's
# explicitly saying it's the local one
local_master = True
out = self.create(master_profile, local_master=local_master)
if not isinstance(out, dict):
log.debug('Master creation details is not a dictionary: %s', out)
elif 'Errors' in out:
raise SaltCloudSystemExit(
'An error occurred while creating the master, not '
'continuing: {0}'.format(out['Errors'])
)
deploy_kwargs = (
self.opts.get('show_deploy_args', False) is True and
# Get the needed data
out.get('deploy_kwargs', {}) or
# Strip the deploy_kwargs from the returned data since we don't
# want it shown in the console.
out.pop('deploy_kwargs', {})
)
master_host = deploy_kwargs.get('salt_host', deploy_kwargs.get('host', None))
if master_host is None:
raise SaltCloudSystemExit(
'Host for new master {0} was not found, '
'aborting map'.format(
master_name
)
)
output[master_name] = out
else:
log.debug('No make_master found in map')
# Local master?
# Generate the fingerprint of the master pubkey in order to
# mitigate man-in-the-middle attacks
master_pub = os.path.join(self.opts['pki_dir'], 'master.pub')
if os.path.isfile(master_pub):
master_finger = salt.utils.crypt.pem_finger(master_pub, sum_type=self.opts['hash_type'])
opts = self.opts.copy()
if self.opts['parallel']:
# Force display_ssh_output to be False since the console will
# need to be reset afterwards
log.info(
'Since parallel deployment is in use, ssh console output '
'is disabled. All ssh output will be logged though'
)
opts['display_ssh_output'] = False
local_master = master_name is None
for name, profile in create_list:
if name in (master_name, master_minion_name):
# Already deployed, it's the master's minion
continue
if 'minion' in profile and profile['minion'].get('local_master', False) and \
profile['minion'].get('master', None) is not None:
# The minion is explicitly defining a master and it's
# explicitly saying it's the local one
local_master = True
if master_finger is not None and local_master is False:
profile['master_finger'] = master_finger
if master_host is not None:
profile.setdefault('minion', {})
profile['minion'].setdefault('master', master_host)
if self.opts['parallel']:
parallel_data.append({
'opts': opts,
'name': name,
'profile': profile,
'local_master': local_master
})
continue
# Not deploying in parallel
try:
output[name] = self.create(
profile, local_master=local_master
)
if self.opts.get('show_deploy_args', False) is False \
and 'deploy_kwargs' in output \
and isinstance(output[name], dict):
output[name].pop('deploy_kwargs', None)
except SaltCloudException as exc:
log.error(
'Failed to deploy \'%s\'. Error: %s',
name, exc, exc_info_on_loglevel=logging.DEBUG
)
output[name] = {'Error': str(exc)}
for name in dmap.get('destroy', ()):
output[name] = self.destroy(name)
if self.opts['parallel'] and parallel_data:
if 'pool_size' in self.opts:
pool_size = self.opts['pool_size']
else:
pool_size = len(parallel_data)
log.info('Cloud pool size: %s', pool_size)
output_multip = enter_mainloop(
_create_multiprocessing, parallel_data, pool_size=pool_size)
# We have deployed in parallel, now do start action in
# correct order based on dependencies.
if self.opts['start_action']:
actionlist = []
grp = -1
for key, val in groupby(six.itervalues(dmap['create']), lambda x: x['level']):
actionlist.append([])
grp += 1
for item in val:
actionlist[grp].append(item['name'])
out = {}
for group in actionlist:
log.info('Running %s on %s', self.opts['start_action'], ', '.join(group))
client = salt.client.get_local_client()
out.update(client.cmd(
','.join(group), self.opts['start_action'],
timeout=self.opts['timeout'] * 60, tgt_type='list'
))
for obj in output_multip:
next(six.itervalues(obj))['ret'] = out[next(six.iterkeys(obj))]
output.update(obj)
else:
for obj in output_multip:
output.update(obj)
return output | python | def run_map(self, dmap):
'''
Execute the contents of the VM map
'''
if self._has_loop(dmap):
msg = 'Uh-oh, that cloud map has a dependency loop!'
log.error(msg)
raise SaltCloudException(msg)
# Go through the create list and calc dependencies
for key, val in six.iteritems(dmap['create']):
log.info('Calculating dependencies for %s', key)
level = 0
level = self._calcdep(dmap, key, val, level)
log.debug('Got execution order %s for %s', level, key)
dmap['create'][key]['level'] = level
try:
existing_list = six.iteritems(dmap['existing'])
except KeyError:
existing_list = six.iteritems({})
for key, val in existing_list:
log.info('Calculating dependencies for %s', key)
level = 0
level = self._calcdep(dmap, key, val, level)
log.debug('Got execution order %s for %s', level, key)
dmap['existing'][key]['level'] = level
# Now sort the create list based on dependencies
create_list = sorted(six.iteritems(dmap['create']), key=lambda x: x[1]['level'])
full_map = dmap['create'].copy()
if 'existing' in dmap:
full_map.update(dmap['existing'])
possible_master_list = sorted(six.iteritems(full_map), key=lambda x: x[1]['level'])
output = {}
if self.opts['parallel']:
parallel_data = []
master_name = None
master_minion_name = None
master_host = None
master_finger = None
for name, profile in possible_master_list:
if profile.get('make_master', False) is True:
master_name = name
master_profile = profile
if master_name:
# If the master already exists, get the host
if master_name not in dmap['create']:
master_host = self.client.query()
for provider_part in master_profile['provider'].split(':'):
master_host = master_host[provider_part]
master_host = master_host[master_name][master_profile.get('ssh_interface', 'public_ips')]
if not master_host:
raise SaltCloudSystemExit(
'Could not get the hostname of master {}.'.format(master_name)
)
# Otherwise, deploy it as a new master
else:
master_minion_name = master_name
log.debug('Creating new master \'%s\'', master_name)
if salt.config.get_cloud_config_value(
'deploy',
master_profile,
self.opts
) is False:
raise SaltCloudSystemExit(
'Cannot proceed with \'make_master\' when salt deployment '
'is disabled(ex: --no-deploy).'
)
# Generate the master keys
log.debug('Generating master keys for \'%s\'', master_profile['name'])
priv, pub = salt.utils.cloud.gen_keys(
salt.config.get_cloud_config_value(
'keysize',
master_profile,
self.opts
)
)
master_profile['master_pub'] = pub
master_profile['master_pem'] = priv
# Generate the fingerprint of the master pubkey in order to
# mitigate man-in-the-middle attacks
master_temp_pub = salt.utils.files.mkstemp()
with salt.utils.files.fopen(master_temp_pub, 'w') as mtp:
mtp.write(pub)
master_finger = salt.utils.crypt.pem_finger(master_temp_pub, sum_type=self.opts['hash_type'])
os.unlink(master_temp_pub)
if master_profile.get('make_minion', True) is True:
master_profile.setdefault('minion', {})
if 'id' in master_profile['minion']:
master_minion_name = master_profile['minion']['id']
# Set this minion's master as local if the user has not set it
if 'master' not in master_profile['minion']:
master_profile['minion']['master'] = '127.0.0.1'
if master_finger is not None:
master_profile['master_finger'] = master_finger
# Generate the minion keys to pre-seed the master:
for name, profile in create_list:
make_minion = salt.config.get_cloud_config_value(
'make_minion', profile, self.opts, default=True
)
if make_minion is False:
continue
log.debug('Generating minion keys for \'%s\'', profile['name'])
priv, pub = salt.utils.cloud.gen_keys(
salt.config.get_cloud_config_value(
'keysize',
profile,
self.opts
)
)
profile['pub_key'] = pub
profile['priv_key'] = priv
# Store the minion's public key in order to be pre-seeded in
# the master
master_profile.setdefault('preseed_minion_keys', {})
master_profile['preseed_minion_keys'].update({name: pub})
local_master = False
if master_profile['minion'].get('local_master', False) and \
master_profile['minion'].get('master', None) is not None:
# The minion is explicitly defining a master and it's
# explicitly saying it's the local one
local_master = True
out = self.create(master_profile, local_master=local_master)
if not isinstance(out, dict):
log.debug('Master creation details is not a dictionary: %s', out)
elif 'Errors' in out:
raise SaltCloudSystemExit(
'An error occurred while creating the master, not '
'continuing: {0}'.format(out['Errors'])
)
deploy_kwargs = (
self.opts.get('show_deploy_args', False) is True and
# Get the needed data
out.get('deploy_kwargs', {}) or
# Strip the deploy_kwargs from the returned data since we don't
# want it shown in the console.
out.pop('deploy_kwargs', {})
)
master_host = deploy_kwargs.get('salt_host', deploy_kwargs.get('host', None))
if master_host is None:
raise SaltCloudSystemExit(
'Host for new master {0} was not found, '
'aborting map'.format(
master_name
)
)
output[master_name] = out
else:
log.debug('No make_master found in map')
# Local master?
# Generate the fingerprint of the master pubkey in order to
# mitigate man-in-the-middle attacks
master_pub = os.path.join(self.opts['pki_dir'], 'master.pub')
if os.path.isfile(master_pub):
master_finger = salt.utils.crypt.pem_finger(master_pub, sum_type=self.opts['hash_type'])
opts = self.opts.copy()
if self.opts['parallel']:
# Force display_ssh_output to be False since the console will
# need to be reset afterwards
log.info(
'Since parallel deployment is in use, ssh console output '
'is disabled. All ssh output will be logged though'
)
opts['display_ssh_output'] = False
local_master = master_name is None
for name, profile in create_list:
if name in (master_name, master_minion_name):
# Already deployed, it's the master's minion
continue
if 'minion' in profile and profile['minion'].get('local_master', False) and \
profile['minion'].get('master', None) is not None:
# The minion is explicitly defining a master and it's
# explicitly saying it's the local one
local_master = True
if master_finger is not None and local_master is False:
profile['master_finger'] = master_finger
if master_host is not None:
profile.setdefault('minion', {})
profile['minion'].setdefault('master', master_host)
if self.opts['parallel']:
parallel_data.append({
'opts': opts,
'name': name,
'profile': profile,
'local_master': local_master
})
continue
# Not deploying in parallel
try:
output[name] = self.create(
profile, local_master=local_master
)
if self.opts.get('show_deploy_args', False) is False \
and 'deploy_kwargs' in output \
and isinstance(output[name], dict):
output[name].pop('deploy_kwargs', None)
except SaltCloudException as exc:
log.error(
'Failed to deploy \'%s\'. Error: %s',
name, exc, exc_info_on_loglevel=logging.DEBUG
)
output[name] = {'Error': str(exc)}
for name in dmap.get('destroy', ()):
output[name] = self.destroy(name)
if self.opts['parallel'] and parallel_data:
if 'pool_size' in self.opts:
pool_size = self.opts['pool_size']
else:
pool_size = len(parallel_data)
log.info('Cloud pool size: %s', pool_size)
output_multip = enter_mainloop(
_create_multiprocessing, parallel_data, pool_size=pool_size)
# We have deployed in parallel, now do start action in
# correct order based on dependencies.
if self.opts['start_action']:
actionlist = []
grp = -1
for key, val in groupby(six.itervalues(dmap['create']), lambda x: x['level']):
actionlist.append([])
grp += 1
for item in val:
actionlist[grp].append(item['name'])
out = {}
for group in actionlist:
log.info('Running %s on %s', self.opts['start_action'], ', '.join(group))
client = salt.client.get_local_client()
out.update(client.cmd(
','.join(group), self.opts['start_action'],
timeout=self.opts['timeout'] * 60, tgt_type='list'
))
for obj in output_multip:
next(six.itervalues(obj))['ret'] = out[next(six.iterkeys(obj))]
output.update(obj)
else:
for obj in output_multip:
output.update(obj)
return output | [
"def",
"run_map",
"(",
"self",
",",
"dmap",
")",
":",
"if",
"self",
".",
"_has_loop",
"(",
"dmap",
")",
":",
"msg",
"=",
"'Uh-oh, that cloud map has a dependency loop!'",
"log",
".",
"error",
"(",
"msg",
")",
"raise",
"SaltCloudException",
"(",
"msg",
")",
... | Execute the contents of the VM map | [
"Execute",
"the",
"contents",
"of",
"the",
"VM",
"map"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/__init__.py#L2031-L2293 | train |
saltstack/salt | salt/modules/gpg.py | _get_user_info | def _get_user_info(user=None):
'''
Wrapper for user.info Salt function
'''
if not user:
# Get user Salt runnining as
user = __salt__['config.option']('user')
userinfo = __salt__['user.info'](user)
if not userinfo:
if user == 'salt':
# Special case with `salt` user:
# if it doesn't exist then fall back to user Salt running as
userinfo = _get_user_info()
else:
raise SaltInvocationError('User {0} does not exist'.format(user))
return userinfo | python | def _get_user_info(user=None):
'''
Wrapper for user.info Salt function
'''
if not user:
# Get user Salt runnining as
user = __salt__['config.option']('user')
userinfo = __salt__['user.info'](user)
if not userinfo:
if user == 'salt':
# Special case with `salt` user:
# if it doesn't exist then fall back to user Salt running as
userinfo = _get_user_info()
else:
raise SaltInvocationError('User {0} does not exist'.format(user))
return userinfo | [
"def",
"_get_user_info",
"(",
"user",
"=",
"None",
")",
":",
"if",
"not",
"user",
":",
"# Get user Salt runnining as",
"user",
"=",
"__salt__",
"[",
"'config.option'",
"]",
"(",
"'user'",
")",
"userinfo",
"=",
"__salt__",
"[",
"'user.info'",
"]",
"(",
"user"... | Wrapper for user.info Salt function | [
"Wrapper",
"for",
"user",
".",
"info",
"Salt",
"function"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L104-L122 | train |
saltstack/salt | salt/modules/gpg.py | _get_user_gnupghome | def _get_user_gnupghome(user):
'''
Return default GnuPG home directory path for a user
'''
if user == 'salt':
gnupghome = os.path.join(__salt__['config.get']('config_dir'), 'gpgkeys')
else:
gnupghome = os.path.join(_get_user_info(user)['home'], '.gnupg')
return gnupghome | python | def _get_user_gnupghome(user):
'''
Return default GnuPG home directory path for a user
'''
if user == 'salt':
gnupghome = os.path.join(__salt__['config.get']('config_dir'), 'gpgkeys')
else:
gnupghome = os.path.join(_get_user_info(user)['home'], '.gnupg')
return gnupghome | [
"def",
"_get_user_gnupghome",
"(",
"user",
")",
":",
"if",
"user",
"==",
"'salt'",
":",
"gnupghome",
"=",
"os",
".",
"path",
".",
"join",
"(",
"__salt__",
"[",
"'config.get'",
"]",
"(",
"'config_dir'",
")",
",",
"'gpgkeys'",
")",
"else",
":",
"gnupghome"... | Return default GnuPG home directory path for a user | [
"Return",
"default",
"GnuPG",
"home",
"directory",
"path",
"for",
"a",
"user"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L125-L134 | train |
saltstack/salt | salt/modules/gpg.py | _create_gpg | def _create_gpg(user=None, gnupghome=None):
'''
Create the GPG object
'''
if not gnupghome:
gnupghome = _get_user_gnupghome(user)
if GPG_1_3_1:
gpg = gnupg.GPG(homedir=gnupghome)
else:
gpg = gnupg.GPG(gnupghome=gnupghome)
return gpg | python | def _create_gpg(user=None, gnupghome=None):
'''
Create the GPG object
'''
if not gnupghome:
gnupghome = _get_user_gnupghome(user)
if GPG_1_3_1:
gpg = gnupg.GPG(homedir=gnupghome)
else:
gpg = gnupg.GPG(gnupghome=gnupghome)
return gpg | [
"def",
"_create_gpg",
"(",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"if",
"not",
"gnupghome",
":",
"gnupghome",
"=",
"_get_user_gnupghome",
"(",
"user",
")",
"if",
"GPG_1_3_1",
":",
"gpg",
"=",
"gnupg",
".",
"GPG",
"(",
"homedir",
... | Create the GPG object | [
"Create",
"the",
"GPG",
"object"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L176-L188 | train |
saltstack/salt | salt/modules/gpg.py | _list_keys | def _list_keys(user=None, gnupghome=None, secret=False):
'''
Helper function for Listing keys
'''
gpg = _create_gpg(user, gnupghome)
_keys = gpg.list_keys(secret)
return _keys | python | def _list_keys(user=None, gnupghome=None, secret=False):
'''
Helper function for Listing keys
'''
gpg = _create_gpg(user, gnupghome)
_keys = gpg.list_keys(secret)
return _keys | [
"def",
"_list_keys",
"(",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
",",
"secret",
"=",
"False",
")",
":",
"gpg",
"=",
"_create_gpg",
"(",
"user",
",",
"gnupghome",
")",
"_keys",
"=",
"gpg",
".",
"list_keys",
"(",
"secret",
")",
"return",
"... | Helper function for Listing keys | [
"Helper",
"function",
"for",
"Listing",
"keys"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L191-L197 | train |
saltstack/salt | salt/modules/gpg.py | _search_keys | def _search_keys(text, keyserver, user=None):
'''
Helper function for searching keys from keyserver
'''
gpg = _create_gpg(user)
if keyserver:
_keys = gpg.search_keys(text, keyserver)
else:
_keys = gpg.search_keys(text)
return _keys | python | def _search_keys(text, keyserver, user=None):
'''
Helper function for searching keys from keyserver
'''
gpg = _create_gpg(user)
if keyserver:
_keys = gpg.search_keys(text, keyserver)
else:
_keys = gpg.search_keys(text)
return _keys | [
"def",
"_search_keys",
"(",
"text",
",",
"keyserver",
",",
"user",
"=",
"None",
")",
":",
"gpg",
"=",
"_create_gpg",
"(",
"user",
")",
"if",
"keyserver",
":",
"_keys",
"=",
"gpg",
".",
"search_keys",
"(",
"text",
",",
"keyserver",
")",
"else",
":",
"... | Helper function for searching keys from keyserver | [
"Helper",
"function",
"for",
"searching",
"keys",
"from",
"keyserver"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L200-L209 | train |
saltstack/salt | salt/modules/gpg.py | search_keys | def search_keys(text, keyserver=None, user=None):
'''
Search keys from keyserver
text
Text to search the keyserver for, e.g. email address, keyID or fingerprint.
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.search_keys user@example.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com user=username
'''
if GPG_1_3_1:
raise SaltInvocationError('The search_keys function is not support with this version of python-gnupg.')
else:
if not keyserver:
keyserver = 'pgp.mit.edu'
_keys = []
for _key in _search_keys(text, keyserver, user):
tmp = {'keyid': _key['keyid'],
'uids': _key['uids']}
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
_keys.append(tmp)
return _keys | python | def search_keys(text, keyserver=None, user=None):
'''
Search keys from keyserver
text
Text to search the keyserver for, e.g. email address, keyID or fingerprint.
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.search_keys user@example.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com user=username
'''
if GPG_1_3_1:
raise SaltInvocationError('The search_keys function is not support with this version of python-gnupg.')
else:
if not keyserver:
keyserver = 'pgp.mit.edu'
_keys = []
for _key in _search_keys(text, keyserver, user):
tmp = {'keyid': _key['keyid'],
'uids': _key['uids']}
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
_keys.append(tmp)
return _keys | [
"def",
"search_keys",
"(",
"text",
",",
"keyserver",
"=",
"None",
",",
"user",
"=",
"None",
")",
":",
"if",
"GPG_1_3_1",
":",
"raise",
"SaltInvocationError",
"(",
"'The search_keys function is not support with this version of python-gnupg.'",
")",
"else",
":",
"if",
... | Search keys from keyserver
text
Text to search the keyserver for, e.g. email address, keyID or fingerprint.
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.search_keys user@example.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com user=username | [
"Search",
"keys",
"from",
"keyserver"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L212-L262 | train |
saltstack/salt | salt/modules/gpg.py | list_keys | def list_keys(user=None, gnupghome=None):
'''
List keys in GPG keychain
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.list_keys
'''
_keys = []
for _key in _list_keys(user, gnupghome):
tmp = {'keyid': _key['keyid'],
'fingerprint': _key['fingerprint'],
'uids': _key['uids']}
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
owner_trust = _key.get('ownertrust', None)
trust = _key.get('trust', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
if owner_trust:
tmp['ownerTrust'] = LETTER_TRUST_DICT[_key['ownertrust']]
if trust:
tmp['trust'] = LETTER_TRUST_DICT[_key['trust']]
_keys.append(tmp)
return _keys | python | def list_keys(user=None, gnupghome=None):
'''
List keys in GPG keychain
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.list_keys
'''
_keys = []
for _key in _list_keys(user, gnupghome):
tmp = {'keyid': _key['keyid'],
'fingerprint': _key['fingerprint'],
'uids': _key['uids']}
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
owner_trust = _key.get('ownertrust', None)
trust = _key.get('trust', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
if owner_trust:
tmp['ownerTrust'] = LETTER_TRUST_DICT[_key['ownertrust']]
if trust:
tmp['trust'] = LETTER_TRUST_DICT[_key['trust']]
_keys.append(tmp)
return _keys | [
"def",
"list_keys",
"(",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"_keys",
"=",
"[",
"]",
"for",
"_key",
"in",
"_list_keys",
"(",
"user",
",",
"gnupghome",
")",
":",
"tmp",
"=",
"{",
"'keyid'",
":",
"_key",
"[",
"'keyid'",
"]",... | List keys in GPG keychain
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.list_keys | [
"List",
"keys",
"in",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L265-L309 | train |
saltstack/salt | salt/modules/gpg.py | create_key | def create_key(key_type='RSA',
key_length=1024,
name_real='Autogenerated Key',
name_comment='Generated by SaltStack',
name_email=None,
subkey_type=None,
subkey_length=None,
expire_date=None,
use_passphrase=False,
user=None,
gnupghome=None):
'''
Create a key in the GPG keychain
.. note::
GPG key generation requires *a lot* of entropy and randomness.
Difficult to do over a remote connection, consider having
another process available which is generating randomness for
the machine. Also especially difficult on virtual machines,
consider the `rng-tools
<http://www.gnu.org/software/hurd/user/tlecarrour/rng-tools.html>`_
package.
The create_key process takes awhile so increasing the timeout
may be necessary, e.g. -t 15.
key_type
The type of the primary key to generate. It must be capable of signing.
'RSA' or 'DSA'.
key_length
The length of the primary key in bits.
name_real
The real name of the user identity which is represented by the key.
name_comment
A comment to attach to the user id.
name_email
An email address for the user.
subkey_type
The type of the secondary key to generate.
subkey_length
The length of the secondary key in bits.
expire_date
The expiration date for the primary and any secondary key.
You can specify an ISO date, A number of days/weeks/months/years,
an epoch value, or 0 for a non-expiring key.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt -t 15 '*' gpg.create_key
'''
ret = {
'res': True,
'fingerprint': '',
'message': ''
}
create_params = {'key_type': key_type,
'key_length': key_length,
'name_real': name_real,
'name_comment': name_comment,
}
gpg = _create_gpg(user, gnupghome)
if name_email:
create_params['name_email'] = name_email
if subkey_type:
create_params['subkey_type'] = subkey_type
if subkey_length:
create_params['subkey_length'] = subkey_length
if expire_date:
create_params['expire_date'] = expire_date
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
ret['res'] = False
ret['message'] = "gpg_passphrase not available in pillar."
return ret
else:
create_params['passphrase'] = gpg_passphrase
input_data = gpg.gen_key_input(**create_params)
key = gpg.gen_key(input_data)
if key.fingerprint:
ret['fingerprint'] = key.fingerprint
ret['message'] = 'GPG key pair successfully generated.'
else:
ret['res'] = False
ret['message'] = 'Unable to generate GPG key pair.'
return ret | python | def create_key(key_type='RSA',
key_length=1024,
name_real='Autogenerated Key',
name_comment='Generated by SaltStack',
name_email=None,
subkey_type=None,
subkey_length=None,
expire_date=None,
use_passphrase=False,
user=None,
gnupghome=None):
'''
Create a key in the GPG keychain
.. note::
GPG key generation requires *a lot* of entropy and randomness.
Difficult to do over a remote connection, consider having
another process available which is generating randomness for
the machine. Also especially difficult on virtual machines,
consider the `rng-tools
<http://www.gnu.org/software/hurd/user/tlecarrour/rng-tools.html>`_
package.
The create_key process takes awhile so increasing the timeout
may be necessary, e.g. -t 15.
key_type
The type of the primary key to generate. It must be capable of signing.
'RSA' or 'DSA'.
key_length
The length of the primary key in bits.
name_real
The real name of the user identity which is represented by the key.
name_comment
A comment to attach to the user id.
name_email
An email address for the user.
subkey_type
The type of the secondary key to generate.
subkey_length
The length of the secondary key in bits.
expire_date
The expiration date for the primary and any secondary key.
You can specify an ISO date, A number of days/weeks/months/years,
an epoch value, or 0 for a non-expiring key.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt -t 15 '*' gpg.create_key
'''
ret = {
'res': True,
'fingerprint': '',
'message': ''
}
create_params = {'key_type': key_type,
'key_length': key_length,
'name_real': name_real,
'name_comment': name_comment,
}
gpg = _create_gpg(user, gnupghome)
if name_email:
create_params['name_email'] = name_email
if subkey_type:
create_params['subkey_type'] = subkey_type
if subkey_length:
create_params['subkey_length'] = subkey_length
if expire_date:
create_params['expire_date'] = expire_date
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
ret['res'] = False
ret['message'] = "gpg_passphrase not available in pillar."
return ret
else:
create_params['passphrase'] = gpg_passphrase
input_data = gpg.gen_key_input(**create_params)
key = gpg.gen_key(input_data)
if key.fingerprint:
ret['fingerprint'] = key.fingerprint
ret['message'] = 'GPG key pair successfully generated.'
else:
ret['res'] = False
ret['message'] = 'Unable to generate GPG key pair.'
return ret | [
"def",
"create_key",
"(",
"key_type",
"=",
"'RSA'",
",",
"key_length",
"=",
"1024",
",",
"name_real",
"=",
"'Autogenerated Key'",
",",
"name_comment",
"=",
"'Generated by SaltStack'",
",",
"name_email",
"=",
"None",
",",
"subkey_type",
"=",
"None",
",",
"subkey_... | Create a key in the GPG keychain
.. note::
GPG key generation requires *a lot* of entropy and randomness.
Difficult to do over a remote connection, consider having
another process available which is generating randomness for
the machine. Also especially difficult on virtual machines,
consider the `rng-tools
<http://www.gnu.org/software/hurd/user/tlecarrour/rng-tools.html>`_
package.
The create_key process takes awhile so increasing the timeout
may be necessary, e.g. -t 15.
key_type
The type of the primary key to generate. It must be capable of signing.
'RSA' or 'DSA'.
key_length
The length of the primary key in bits.
name_real
The real name of the user identity which is represented by the key.
name_comment
A comment to attach to the user id.
name_email
An email address for the user.
subkey_type
The type of the secondary key to generate.
subkey_length
The length of the secondary key in bits.
expire_date
The expiration date for the primary and any secondary key.
You can specify an ISO date, A number of days/weeks/months/years,
an epoch value, or 0 for a non-expiring key.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt -t 15 '*' gpg.create_key | [
"Create",
"a",
"key",
"in",
"the",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L360-L477 | train |
saltstack/salt | salt/modules/gpg.py | delete_key | def delete_key(keyid=None,
fingerprint=None,
delete_secret=False,
user=None,
gnupghome=None):
'''
Get a key from the GPG keychain
keyid
The keyid of the key to be deleted.
fingerprint
The fingerprint of the key to be deleted.
delete_secret
Whether to delete a corresponding secret key prior to deleting the public key.
Secret keys must be deleted before deleting any corresponding public keys.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.delete_key keyid=3FAD9F1E
salt '*' gpg.delete_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.delete_key keyid=3FAD9F1E user=username
salt '*' gpg.delete_key keyid=3FAD9F1E user=username delete_secret=True
'''
ret = {
'res': True,
'message': ''
}
if fingerprint and keyid:
ret['res'] = False
ret['message'] = 'Only specify one argument, fingerprint or keyid'
return ret
if not fingerprint and not keyid:
ret['res'] = False
ret['message'] = 'Required argument, fingerprint or keyid'
return ret
gpg = _create_gpg(user, gnupghome)
key = get_key(keyid, fingerprint, user)
if key:
fingerprint = key['fingerprint']
skey = get_secret_key(keyid, fingerprint, user)
if skey and not delete_secret:
ret['res'] = False
ret['message'] = 'Secret key exists, delete first or pass delete_secret=True.'
return ret
elif skey and delete_secret and six.text_type(gpg.delete_keys(fingerprint, True)) == 'ok':
# Delete the secret key
ret['message'] = 'Secret key for {0} deleted\n'.format(fingerprint)
# Delete the public key
if six.text_type(gpg.delete_keys(fingerprint)) == 'ok':
ret['message'] += 'Public key for {0} deleted'.format(fingerprint)
ret['res'] = True
return ret
else:
ret['res'] = False
ret['message'] = 'Key not available in keychain.'
return ret | python | def delete_key(keyid=None,
fingerprint=None,
delete_secret=False,
user=None,
gnupghome=None):
'''
Get a key from the GPG keychain
keyid
The keyid of the key to be deleted.
fingerprint
The fingerprint of the key to be deleted.
delete_secret
Whether to delete a corresponding secret key prior to deleting the public key.
Secret keys must be deleted before deleting any corresponding public keys.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.delete_key keyid=3FAD9F1E
salt '*' gpg.delete_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.delete_key keyid=3FAD9F1E user=username
salt '*' gpg.delete_key keyid=3FAD9F1E user=username delete_secret=True
'''
ret = {
'res': True,
'message': ''
}
if fingerprint and keyid:
ret['res'] = False
ret['message'] = 'Only specify one argument, fingerprint or keyid'
return ret
if not fingerprint and not keyid:
ret['res'] = False
ret['message'] = 'Required argument, fingerprint or keyid'
return ret
gpg = _create_gpg(user, gnupghome)
key = get_key(keyid, fingerprint, user)
if key:
fingerprint = key['fingerprint']
skey = get_secret_key(keyid, fingerprint, user)
if skey and not delete_secret:
ret['res'] = False
ret['message'] = 'Secret key exists, delete first or pass delete_secret=True.'
return ret
elif skey and delete_secret and six.text_type(gpg.delete_keys(fingerprint, True)) == 'ok':
# Delete the secret key
ret['message'] = 'Secret key for {0} deleted\n'.format(fingerprint)
# Delete the public key
if six.text_type(gpg.delete_keys(fingerprint)) == 'ok':
ret['message'] += 'Public key for {0} deleted'.format(fingerprint)
ret['res'] = True
return ret
else:
ret['res'] = False
ret['message'] = 'Key not available in keychain.'
return ret | [
"def",
"delete_key",
"(",
"keyid",
"=",
"None",
",",
"fingerprint",
"=",
"None",
",",
"delete_secret",
"=",
"False",
",",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'res'",
":",
"True",
",",
"'message'",
":",
"''"... | Get a key from the GPG keychain
keyid
The keyid of the key to be deleted.
fingerprint
The fingerprint of the key to be deleted.
delete_secret
Whether to delete a corresponding secret key prior to deleting the public key.
Secret keys must be deleted before deleting any corresponding public keys.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.delete_key keyid=3FAD9F1E
salt '*' gpg.delete_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.delete_key keyid=3FAD9F1E user=username
salt '*' gpg.delete_key keyid=3FAD9F1E user=username delete_secret=True | [
"Get",
"a",
"key",
"from",
"the",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L480-L555 | train |
saltstack/salt | salt/modules/gpg.py | get_key | def get_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
'''
Get a key from the GPG keychain
keyid
The key ID (short or long) of the key to be retrieved.
fingerprint
The fingerprint of the key to be retrieved.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.get_key keyid=3FAD9F1E
salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.get_key keyid=3FAD9F1E user=username
'''
tmp = {}
for _key in _list_keys(user, gnupghome):
if (_key['fingerprint'] == fingerprint or
_key['keyid'] == keyid or
_key['keyid'][8:] == keyid):
tmp['keyid'] = _key['keyid']
tmp['fingerprint'] = _key['fingerprint']
tmp['uids'] = _key['uids']
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
owner_trust = _key.get('ownertrust', None)
trust = _key.get('trust', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
if owner_trust:
tmp['ownerTrust'] = LETTER_TRUST_DICT[_key['ownertrust']]
if trust:
tmp['trust'] = LETTER_TRUST_DICT[_key['trust']]
if not tmp:
return False
else:
return tmp | python | def get_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
'''
Get a key from the GPG keychain
keyid
The key ID (short or long) of the key to be retrieved.
fingerprint
The fingerprint of the key to be retrieved.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.get_key keyid=3FAD9F1E
salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.get_key keyid=3FAD9F1E user=username
'''
tmp = {}
for _key in _list_keys(user, gnupghome):
if (_key['fingerprint'] == fingerprint or
_key['keyid'] == keyid or
_key['keyid'][8:] == keyid):
tmp['keyid'] = _key['keyid']
tmp['fingerprint'] = _key['fingerprint']
tmp['uids'] = _key['uids']
expires = _key.get('expires', None)
date = _key.get('date', None)
length = _key.get('length', None)
owner_trust = _key.get('ownertrust', None)
trust = _key.get('trust', None)
if expires:
tmp['expires'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['expires'])))
if date:
tmp['created'] = time.strftime('%Y-%m-%d',
time.localtime(float(_key['date'])))
if length:
tmp['keyLength'] = _key['length']
if owner_trust:
tmp['ownerTrust'] = LETTER_TRUST_DICT[_key['ownertrust']]
if trust:
tmp['trust'] = LETTER_TRUST_DICT[_key['trust']]
if not tmp:
return False
else:
return tmp | [
"def",
"get_key",
"(",
"keyid",
"=",
"None",
",",
"fingerprint",
"=",
"None",
",",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"tmp",
"=",
"{",
"}",
"for",
"_key",
"in",
"_list_keys",
"(",
"user",
",",
"gnupghome",
")",
":",
"if",... | Get a key from the GPG keychain
keyid
The key ID (short or long) of the key to be retrieved.
fingerprint
The fingerprint of the key to be retrieved.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.get_key keyid=3FAD9F1E
salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192
salt '*' gpg.get_key keyid=3FAD9F1E user=username | [
"Get",
"a",
"key",
"from",
"the",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L558-L617 | train |
saltstack/salt | salt/modules/gpg.py | import_key | def import_key(text=None,
filename=None,
user=None,
gnupghome=None):
r'''
Import a key from text or file
text
The text containing to import.
filename
The filename containing the key to import.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.import_key text='-----BEGIN PGP PUBLIC KEY BLOCK-----\n ... -----END PGP PUBLIC KEY BLOCK-----'
salt '*' gpg.import_key filename='/path/to/public-key-file'
'''
ret = {
'res': True,
'message': ''
}
gpg = _create_gpg(user, gnupghome)
if not text and not filename:
raise SaltInvocationError('filename or text must be passed.')
if filename:
try:
with salt.utils.files.flopen(filename, 'rb') as _fp:
lines = _fp.readlines()
text = ''.join(lines)
except IOError:
raise SaltInvocationError('filename does not exist.')
imported_data = gpg.import_keys(text)
if GPG_1_3_1:
counts = imported_data.counts
if counts.get('imported') or counts.get('imported_rsa'):
ret['message'] = 'Successfully imported key(s).'
elif counts.get('unchanged'):
ret['message'] = 'Key(s) already exist in keychain.'
elif counts.get('not_imported'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not counts.get('count'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
else:
if imported_data.imported or imported_data.imported_rsa:
ret['message'] = 'Successfully imported key(s).'
elif imported_data.unchanged:
ret['message'] = 'Key(s) already exist in keychain.'
elif imported_data.not_imported:
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not imported_data.count:
ret['res'] = False
ret['message'] = 'Unable to import key.'
return ret | python | def import_key(text=None,
filename=None,
user=None,
gnupghome=None):
r'''
Import a key from text or file
text
The text containing to import.
filename
The filename containing the key to import.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.import_key text='-----BEGIN PGP PUBLIC KEY BLOCK-----\n ... -----END PGP PUBLIC KEY BLOCK-----'
salt '*' gpg.import_key filename='/path/to/public-key-file'
'''
ret = {
'res': True,
'message': ''
}
gpg = _create_gpg(user, gnupghome)
if not text and not filename:
raise SaltInvocationError('filename or text must be passed.')
if filename:
try:
with salt.utils.files.flopen(filename, 'rb') as _fp:
lines = _fp.readlines()
text = ''.join(lines)
except IOError:
raise SaltInvocationError('filename does not exist.')
imported_data = gpg.import_keys(text)
if GPG_1_3_1:
counts = imported_data.counts
if counts.get('imported') or counts.get('imported_rsa'):
ret['message'] = 'Successfully imported key(s).'
elif counts.get('unchanged'):
ret['message'] = 'Key(s) already exist in keychain.'
elif counts.get('not_imported'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not counts.get('count'):
ret['res'] = False
ret['message'] = 'Unable to import key.'
else:
if imported_data.imported or imported_data.imported_rsa:
ret['message'] = 'Successfully imported key(s).'
elif imported_data.unchanged:
ret['message'] = 'Key(s) already exist in keychain.'
elif imported_data.not_imported:
ret['res'] = False
ret['message'] = 'Unable to import key.'
elif not imported_data.count:
ret['res'] = False
ret['message'] = 'Unable to import key.'
return ret | [
"def",
"import_key",
"(",
"text",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'res'",
":",
"True",
",",
"'message'",
":",
"''",
"}",
"gpg",
"=",
"_create_gpg",
"(",... | r'''
Import a key from text or file
text
The text containing to import.
filename
The filename containing the key to import.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.import_key text='-----BEGIN PGP PUBLIC KEY BLOCK-----\n ... -----END PGP PUBLIC KEY BLOCK-----'
salt '*' gpg.import_key filename='/path/to/public-key-file' | [
"r",
"Import",
"a",
"key",
"from",
"text",
"or",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L683-L755 | train |
saltstack/salt | salt/modules/gpg.py | export_key | def export_key(keyids=None, secret=False, user=None, gnupghome=None):
'''
Export a key from the GPG keychain
keyids
The key ID(s) of the key(s) to be exported. Can be specified as a comma
separated string or a list. Anything which GnuPG itself accepts to
identify a key - for example, the key ID or the fingerprint could be
used.
secret
Export the secret key identified by the ``keyids`` information passed.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.export_key keyids=3FAD9F1E
salt '*' gpg.export_key keyids=3FAD9F1E secret=True
salt '*' gpg.export_key keyids="['3FAD9F1E','3FBD8F1E']" user=username
'''
gpg = _create_gpg(user, gnupghome)
if isinstance(keyids, six.string_types):
keyids = keyids.split(',')
return gpg.export_keys(keyids, secret) | python | def export_key(keyids=None, secret=False, user=None, gnupghome=None):
'''
Export a key from the GPG keychain
keyids
The key ID(s) of the key(s) to be exported. Can be specified as a comma
separated string or a list. Anything which GnuPG itself accepts to
identify a key - for example, the key ID or the fingerprint could be
used.
secret
Export the secret key identified by the ``keyids`` information passed.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.export_key keyids=3FAD9F1E
salt '*' gpg.export_key keyids=3FAD9F1E secret=True
salt '*' gpg.export_key keyids="['3FAD9F1E','3FBD8F1E']" user=username
'''
gpg = _create_gpg(user, gnupghome)
if isinstance(keyids, six.string_types):
keyids = keyids.split(',')
return gpg.export_keys(keyids, secret) | [
"def",
"export_key",
"(",
"keyids",
"=",
"None",
",",
"secret",
"=",
"False",
",",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"gpg",
"=",
"_create_gpg",
"(",
"user",
",",
"gnupghome",
")",
"if",
"isinstance",
"(",
"keyids",
",",
"s... | Export a key from the GPG keychain
keyids
The key ID(s) of the key(s) to be exported. Can be specified as a comma
separated string or a list. Anything which GnuPG itself accepts to
identify a key - for example, the key ID or the fingerprint could be
used.
secret
Export the secret key identified by the ``keyids`` information passed.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.export_key keyids=3FAD9F1E
salt '*' gpg.export_key keyids=3FAD9F1E secret=True
salt '*' gpg.export_key keyids="['3FAD9F1E','3FBD8F1E']" user=username | [
"Export",
"a",
"key",
"from",
"the",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L758-L794 | train |
saltstack/salt | salt/modules/gpg.py | receive_keys | def receive_keys(keyserver=None, keys=None, user=None, gnupghome=None):
'''
Receive key(s) from keyserver and add them to keychain
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu
keys
The keyID(s) to retrieve from the keyserver. Can be specified as a comma
separated string or a list.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.receive_keys keys='3FAD9F1E'
salt '*' gpg.receive_keys keys="['3FAD9F1E','3FBD9F2E']"
salt '*' gpg.receive_keys keys=3FAD9F1E user=username
'''
ret = {
'res': True,
'changes': {},
'message': []
}
gpg = _create_gpg(user, gnupghome)
if not keyserver:
keyserver = 'pgp.mit.edu'
if isinstance(keys, six.string_types):
keys = keys.split(',')
recv_data = gpg.recv_keys(keyserver, *keys)
for result in recv_data.results:
if 'ok' in result:
if result['ok'] == '1':
ret['message'].append('Key {0} added to keychain'.format(result['fingerprint']))
elif result['ok'] == '0':
ret['message'].append('Key {0} already exists in keychain'.format(result['fingerprint']))
elif 'problem' in result:
ret['message'].append('Unable to add key to keychain')
return ret | python | def receive_keys(keyserver=None, keys=None, user=None, gnupghome=None):
'''
Receive key(s) from keyserver and add them to keychain
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu
keys
The keyID(s) to retrieve from the keyserver. Can be specified as a comma
separated string or a list.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.receive_keys keys='3FAD9F1E'
salt '*' gpg.receive_keys keys="['3FAD9F1E','3FBD9F2E']"
salt '*' gpg.receive_keys keys=3FAD9F1E user=username
'''
ret = {
'res': True,
'changes': {},
'message': []
}
gpg = _create_gpg(user, gnupghome)
if not keyserver:
keyserver = 'pgp.mit.edu'
if isinstance(keys, six.string_types):
keys = keys.split(',')
recv_data = gpg.recv_keys(keyserver, *keys)
for result in recv_data.results:
if 'ok' in result:
if result['ok'] == '1':
ret['message'].append('Key {0} added to keychain'.format(result['fingerprint']))
elif result['ok'] == '0':
ret['message'].append('Key {0} already exists in keychain'.format(result['fingerprint']))
elif 'problem' in result:
ret['message'].append('Unable to add key to keychain')
return ret | [
"def",
"receive_keys",
"(",
"keyserver",
"=",
"None",
",",
"keys",
"=",
"None",
",",
"user",
"=",
"None",
",",
"gnupghome",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'res'",
":",
"True",
",",
"'changes'",
":",
"{",
"}",
",",
"'message'",
":",
"[",
... | Receive key(s) from keyserver and add them to keychain
keyserver
Keyserver to use for searching for GPG keys, defaults to pgp.mit.edu
keys
The keyID(s) to retrieve from the keyserver. Can be specified as a comma
separated string or a list.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.receive_keys keys='3FAD9F1E'
salt '*' gpg.receive_keys keys="['3FAD9F1E','3FBD9F2E']"
salt '*' gpg.receive_keys keys=3FAD9F1E user=username | [
"Receive",
"key",
"(",
"s",
")",
"from",
"keyserver",
"and",
"add",
"them",
"to",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L798-L851 | train |
saltstack/salt | salt/modules/gpg.py | trust_key | def trust_key(keyid=None,
fingerprint=None,
trust_level=None,
user=None):
'''
Set the trust level for a key in GPG keychain
keyid
The keyid of the key to set the trust level for.
fingerprint
The fingerprint of the key to set the trust level for.
trust_level
The trust level to set for the specified key, must be one
of the following:
expired, unknown, not_trusted, marginally, fully, ultimately
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.trust_key keyid='3FAD9F1E' trust_level='marginally'
salt '*' gpg.trust_key fingerprint='53C96788253E58416D20BCD352952C84C3252192' trust_level='not_trusted'
salt '*' gpg.trust_key keys=3FAD9F1E trust_level='ultimately' user='username'
'''
ret = {
'res': True,
'message': ''
}
_VALID_TRUST_LEVELS = ['expired', 'unknown',
'not_trusted', 'marginally',
'fully', 'ultimately']
if fingerprint and keyid:
ret['res'] = False
ret['message'] = 'Only specify one argument, fingerprint or keyid'
return ret
if not fingerprint:
if keyid:
key = get_key(keyid, user=user)
if key:
if 'fingerprint' not in key:
ret['res'] = False
ret['message'] = 'Fingerprint not found for keyid {0}'.format(keyid)
return ret
fingerprint = key['fingerprint']
else:
ret['res'] = False
ret['message'] = 'KeyID {0} not in GPG keychain'.format(keyid)
return ret
else:
ret['res'] = False
ret['message'] = 'Required argument, fingerprint or keyid'
return ret
if trust_level not in _VALID_TRUST_LEVELS:
return 'ERROR: Valid trust levels - {0}'.format(','.join(_VALID_TRUST_LEVELS))
stdin = '{0}:{1}\n'.format(fingerprint, NUM_TRUST_DICT[trust_level])
cmd = [_gpg(), '--import-ownertrust']
_user = user
if user == 'salt':
homeDir = os.path.join(__salt__['config.get']('config_dir'), 'gpgkeys')
cmd.extend(['--homedir', homeDir])
_user = 'root'
res = __salt__['cmd.run_all'](cmd,
stdin=stdin,
runas=_user,
python_shell=False)
if not res['retcode'] == 0:
ret['res'] = False
ret['message'] = res['stderr']
else:
if res['stderr']:
_match = re.findall(r'\d', res['stderr'])
if len(_match) == 2:
ret['fingerprint'] = fingerprint
ret['message'] = 'Changing ownership trust from {0} to {1}.'.format(
INV_NUM_TRUST_DICT[_match[0]],
INV_NUM_TRUST_DICT[_match[1]]
)
else:
ret['fingerprint'] = fingerprint
ret['message'] = 'Setting ownership trust to {0}.'.format(INV_NUM_TRUST_DICT[_match[0]])
else:
ret['message'] = res['stderr']
return ret | python | def trust_key(keyid=None,
fingerprint=None,
trust_level=None,
user=None):
'''
Set the trust level for a key in GPG keychain
keyid
The keyid of the key to set the trust level for.
fingerprint
The fingerprint of the key to set the trust level for.
trust_level
The trust level to set for the specified key, must be one
of the following:
expired, unknown, not_trusted, marginally, fully, ultimately
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.trust_key keyid='3FAD9F1E' trust_level='marginally'
salt '*' gpg.trust_key fingerprint='53C96788253E58416D20BCD352952C84C3252192' trust_level='not_trusted'
salt '*' gpg.trust_key keys=3FAD9F1E trust_level='ultimately' user='username'
'''
ret = {
'res': True,
'message': ''
}
_VALID_TRUST_LEVELS = ['expired', 'unknown',
'not_trusted', 'marginally',
'fully', 'ultimately']
if fingerprint and keyid:
ret['res'] = False
ret['message'] = 'Only specify one argument, fingerprint or keyid'
return ret
if not fingerprint:
if keyid:
key = get_key(keyid, user=user)
if key:
if 'fingerprint' not in key:
ret['res'] = False
ret['message'] = 'Fingerprint not found for keyid {0}'.format(keyid)
return ret
fingerprint = key['fingerprint']
else:
ret['res'] = False
ret['message'] = 'KeyID {0} not in GPG keychain'.format(keyid)
return ret
else:
ret['res'] = False
ret['message'] = 'Required argument, fingerprint or keyid'
return ret
if trust_level not in _VALID_TRUST_LEVELS:
return 'ERROR: Valid trust levels - {0}'.format(','.join(_VALID_TRUST_LEVELS))
stdin = '{0}:{1}\n'.format(fingerprint, NUM_TRUST_DICT[trust_level])
cmd = [_gpg(), '--import-ownertrust']
_user = user
if user == 'salt':
homeDir = os.path.join(__salt__['config.get']('config_dir'), 'gpgkeys')
cmd.extend(['--homedir', homeDir])
_user = 'root'
res = __salt__['cmd.run_all'](cmd,
stdin=stdin,
runas=_user,
python_shell=False)
if not res['retcode'] == 0:
ret['res'] = False
ret['message'] = res['stderr']
else:
if res['stderr']:
_match = re.findall(r'\d', res['stderr'])
if len(_match) == 2:
ret['fingerprint'] = fingerprint
ret['message'] = 'Changing ownership trust from {0} to {1}.'.format(
INV_NUM_TRUST_DICT[_match[0]],
INV_NUM_TRUST_DICT[_match[1]]
)
else:
ret['fingerprint'] = fingerprint
ret['message'] = 'Setting ownership trust to {0}.'.format(INV_NUM_TRUST_DICT[_match[0]])
else:
ret['message'] = res['stderr']
return ret | [
"def",
"trust_key",
"(",
"keyid",
"=",
"None",
",",
"fingerprint",
"=",
"None",
",",
"trust_level",
"=",
"None",
",",
"user",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'res'",
":",
"True",
",",
"'message'",
":",
"''",
"}",
"_VALID_TRUST_LEVELS",
"=",
... | Set the trust level for a key in GPG keychain
keyid
The keyid of the key to set the trust level for.
fingerprint
The fingerprint of the key to set the trust level for.
trust_level
The trust level to set for the specified key, must be one
of the following:
expired, unknown, not_trusted, marginally, fully, ultimately
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
CLI Example:
.. code-block:: bash
salt '*' gpg.trust_key keyid='3FAD9F1E' trust_level='marginally'
salt '*' gpg.trust_key fingerprint='53C96788253E58416D20BCD352952C84C3252192' trust_level='not_trusted'
salt '*' gpg.trust_key keys=3FAD9F1E trust_level='ultimately' user='username' | [
"Set",
"the",
"trust",
"level",
"for",
"a",
"key",
"in",
"GPG",
"keychain"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L854-L951 | train |
saltstack/salt | salt/modules/gpg.py | sign | def sign(user=None,
keyid=None,
text=None,
filename=None,
output=None,
use_passphrase=False,
gnupghome=None):
'''
Sign message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
keyid
The keyid of the key to set the trust level for, defaults to
first key in the secret keyring.
text
The text to sign.
filename
The filename to sign.
output
The filename where the signed file will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.sign text='Hello there. How are you?'
salt '*' gpg.sign filename='/path/to/important.file'
salt '*' gpg.sign filename='/path/to/important.file' use_passphrase=True
'''
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
else:
gpg_passphrase = None
# Check for at least one secret key to sign with
gnupg_version = _LooseVersion(gnupg.__version__)
if text:
if gnupg_version >= '1.3.1':
signed_data = gpg.sign(text, default_key=keyid, passphrase=gpg_passphrase)
else:
signed_data = gpg.sign(text, keyid=keyid, passphrase=gpg_passphrase)
elif filename:
with salt.utils.files.flopen(filename, 'rb') as _fp:
if gnupg_version >= '1.3.1':
signed_data = gpg.sign(text, default_key=keyid, passphrase=gpg_passphrase)
else:
signed_data = gpg.sign_file(_fp, keyid=keyid, passphrase=gpg_passphrase)
if output:
with salt.utils.files.flopen(output, 'w') as fout:
fout.write(signed_data.data)
else:
raise SaltInvocationError('filename or text must be passed.')
return signed_data.data | python | def sign(user=None,
keyid=None,
text=None,
filename=None,
output=None,
use_passphrase=False,
gnupghome=None):
'''
Sign message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
keyid
The keyid of the key to set the trust level for, defaults to
first key in the secret keyring.
text
The text to sign.
filename
The filename to sign.
output
The filename where the signed file will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.sign text='Hello there. How are you?'
salt '*' gpg.sign filename='/path/to/important.file'
salt '*' gpg.sign filename='/path/to/important.file' use_passphrase=True
'''
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
else:
gpg_passphrase = None
# Check for at least one secret key to sign with
gnupg_version = _LooseVersion(gnupg.__version__)
if text:
if gnupg_version >= '1.3.1':
signed_data = gpg.sign(text, default_key=keyid, passphrase=gpg_passphrase)
else:
signed_data = gpg.sign(text, keyid=keyid, passphrase=gpg_passphrase)
elif filename:
with salt.utils.files.flopen(filename, 'rb') as _fp:
if gnupg_version >= '1.3.1':
signed_data = gpg.sign(text, default_key=keyid, passphrase=gpg_passphrase)
else:
signed_data = gpg.sign_file(_fp, keyid=keyid, passphrase=gpg_passphrase)
if output:
with salt.utils.files.flopen(output, 'w') as fout:
fout.write(signed_data.data)
else:
raise SaltInvocationError('filename or text must be passed.')
return signed_data.data | [
"def",
"sign",
"(",
"user",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"text",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"output",
"=",
"None",
",",
"use_passphrase",
"=",
"False",
",",
"gnupghome",
"=",
"None",
")",
":",
"gpg",
"=",
"_crea... | Sign message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
keyid
The keyid of the key to set the trust level for, defaults to
first key in the secret keyring.
text
The text to sign.
filename
The filename to sign.
output
The filename where the signed file will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
CLI Example:
.. code-block:: bash
salt '*' gpg.sign text='Hello there. How are you?'
salt '*' gpg.sign filename='/path/to/important.file'
salt '*' gpg.sign filename='/path/to/important.file' use_passphrase=True | [
"Sign",
"message",
"or",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L954-L1027 | train |
saltstack/salt | salt/modules/gpg.py | verify | def verify(text=None,
user=None,
filename=None,
gnupghome=None,
signature=None,
trustmodel=None):
'''
Verify a message or file
text
The text to verify.
filename
The filename to verify.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
signature
Specify the filename of a detached signature.
.. versionadded:: 2018.3.0
trustmodel
Explicitly define the used trust model. One of:
- pgp
- classic
- tofu
- tofu+pgp
- direct
- always
- auto
.. versionadded:: fluorine
CLI Example:
.. code-block:: bash
salt '*' gpg.verify text='Hello there. How are you?'
salt '*' gpg.verify filename='/path/to/important.file'
salt '*' gpg.verify filename='/path/to/important.file' use_passphrase=True
salt '*' gpg.verify filename='/path/to/important.file' trustmodel=direct
'''
gpg = _create_gpg(user)
trustmodels = ('pgp', 'classic', 'tofu', 'tofu+pgp', 'direct', 'always', 'auto')
if trustmodel and trustmodel not in trustmodels:
msg = 'Invalid trustmodel defined: {}. Use one of: {}'.format(trustmodel, ', '.join(trustmodels))
log.warn(msg)
return {'res': False, 'message': msg}
extra_args = []
if trustmodel:
extra_args.extend(['--trust-model', trustmodel])
if text:
verified = gpg.verify(text, extra_args=extra_args)
elif filename:
if signature:
# need to call with fopen instead of flopen due to:
# https://bitbucket.org/vinay.sajip/python-gnupg/issues/76/verify_file-closes-passed-file-handle
with salt.utils.files.fopen(signature, 'rb') as _fp:
verified = gpg.verify_file(_fp, filename, extra_args=extra_args)
else:
with salt.utils.files.flopen(filename, 'rb') as _fp:
verified = gpg.verify_file(_fp, extra_args=extra_args)
else:
raise SaltInvocationError('filename or text must be passed.')
ret = {}
if verified.trust_level is not None:
ret['res'] = True
ret['username'] = verified.username
ret['key_id'] = verified.key_id
ret['trust_level'] = VERIFY_TRUST_LEVELS[six.text_type(verified.trust_level)]
ret['message'] = 'The signature is verified.'
else:
ret['res'] = False
ret['message'] = 'The signature could not be verified.'
return ret | python | def verify(text=None,
user=None,
filename=None,
gnupghome=None,
signature=None,
trustmodel=None):
'''
Verify a message or file
text
The text to verify.
filename
The filename to verify.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
signature
Specify the filename of a detached signature.
.. versionadded:: 2018.3.0
trustmodel
Explicitly define the used trust model. One of:
- pgp
- classic
- tofu
- tofu+pgp
- direct
- always
- auto
.. versionadded:: fluorine
CLI Example:
.. code-block:: bash
salt '*' gpg.verify text='Hello there. How are you?'
salt '*' gpg.verify filename='/path/to/important.file'
salt '*' gpg.verify filename='/path/to/important.file' use_passphrase=True
salt '*' gpg.verify filename='/path/to/important.file' trustmodel=direct
'''
gpg = _create_gpg(user)
trustmodels = ('pgp', 'classic', 'tofu', 'tofu+pgp', 'direct', 'always', 'auto')
if trustmodel and trustmodel not in trustmodels:
msg = 'Invalid trustmodel defined: {}. Use one of: {}'.format(trustmodel, ', '.join(trustmodels))
log.warn(msg)
return {'res': False, 'message': msg}
extra_args = []
if trustmodel:
extra_args.extend(['--trust-model', trustmodel])
if text:
verified = gpg.verify(text, extra_args=extra_args)
elif filename:
if signature:
# need to call with fopen instead of flopen due to:
# https://bitbucket.org/vinay.sajip/python-gnupg/issues/76/verify_file-closes-passed-file-handle
with salt.utils.files.fopen(signature, 'rb') as _fp:
verified = gpg.verify_file(_fp, filename, extra_args=extra_args)
else:
with salt.utils.files.flopen(filename, 'rb') as _fp:
verified = gpg.verify_file(_fp, extra_args=extra_args)
else:
raise SaltInvocationError('filename or text must be passed.')
ret = {}
if verified.trust_level is not None:
ret['res'] = True
ret['username'] = verified.username
ret['key_id'] = verified.key_id
ret['trust_level'] = VERIFY_TRUST_LEVELS[six.text_type(verified.trust_level)]
ret['message'] = 'The signature is verified.'
else:
ret['res'] = False
ret['message'] = 'The signature could not be verified.'
return ret | [
"def",
"verify",
"(",
"text",
"=",
"None",
",",
"user",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"gnupghome",
"=",
"None",
",",
"signature",
"=",
"None",
",",
"trustmodel",
"=",
"None",
")",
":",
"gpg",
"=",
"_create_gpg",
"(",
"user",
")",
... | Verify a message or file
text
The text to verify.
filename
The filename to verify.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
signature
Specify the filename of a detached signature.
.. versionadded:: 2018.3.0
trustmodel
Explicitly define the used trust model. One of:
- pgp
- classic
- tofu
- tofu+pgp
- direct
- always
- auto
.. versionadded:: fluorine
CLI Example:
.. code-block:: bash
salt '*' gpg.verify text='Hello there. How are you?'
salt '*' gpg.verify filename='/path/to/important.file'
salt '*' gpg.verify filename='/path/to/important.file' use_passphrase=True
salt '*' gpg.verify filename='/path/to/important.file' trustmodel=direct | [
"Verify",
"a",
"message",
"or",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L1030-L1117 | train |
saltstack/salt | salt/modules/gpg.py | encrypt | def encrypt(user=None,
recipients=None,
text=None,
filename=None,
output=None,
sign=None,
use_passphrase=False,
gnupghome=None,
bare=False):
'''
Encrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
recipients
The fingerprints for those recipient whom the data is being encrypted for.
text
The text to encrypt.
filename
The filename to encrypt.
output
The filename where the signed file will be written, default is standard out.
sign
Whether to sign, in addition to encrypt, the data. ``True`` to use
default key or fingerprint to specify a different key to sign with.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) encrypted block as a string without
the standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.encrypt text='Hello there. How are you?'
salt '*' gpg.encrypt filename='/path/to/important.file'
salt '*' gpg.encrypt filename='/path/to/important.file' use_passphrase=True
'''
ret = {
'res': True,
'comment': ''
}
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
gpg_passphrase = gpg_passphrase['gpg_passphrase']
else:
gpg_passphrase = None
if text:
result = gpg.encrypt(text, recipients, passphrase=gpg_passphrase)
elif filename:
if GPG_1_3_1:
# This version does not allow us to encrypt using the
# file stream # have to read in the contents and encrypt.
with salt.utils.files.flopen(filename, 'rb') as _fp:
_contents = _fp.read()
result = gpg.encrypt(_contents, recipients, passphrase=gpg_passphrase, output=output)
else:
# This version allows encrypting the file stream
with salt.utils.files.flopen(filename, 'rb') as _fp:
if output:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, output=output, sign=sign)
else:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, sign=sign)
else:
raise SaltInvocationError('filename or text must be passed.')
if result.ok:
if not bare:
if output:
ret['comment'] = 'Encrypted data has been written to {0}'.format(output)
else:
ret['comment'] = result.data
else:
ret = result.data
else:
if not bare:
ret['res'] = False
ret['comment'] = '{0}.\nPlease check the salt-minion log.'.format(result.status)
else:
ret = False
log.error(result.stderr)
return ret | python | def encrypt(user=None,
recipients=None,
text=None,
filename=None,
output=None,
sign=None,
use_passphrase=False,
gnupghome=None,
bare=False):
'''
Encrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
recipients
The fingerprints for those recipient whom the data is being encrypted for.
text
The text to encrypt.
filename
The filename to encrypt.
output
The filename where the signed file will be written, default is standard out.
sign
Whether to sign, in addition to encrypt, the data. ``True`` to use
default key or fingerprint to specify a different key to sign with.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) encrypted block as a string without
the standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.encrypt text='Hello there. How are you?'
salt '*' gpg.encrypt filename='/path/to/important.file'
salt '*' gpg.encrypt filename='/path/to/important.file' use_passphrase=True
'''
ret = {
'res': True,
'comment': ''
}
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
gpg_passphrase = gpg_passphrase['gpg_passphrase']
else:
gpg_passphrase = None
if text:
result = gpg.encrypt(text, recipients, passphrase=gpg_passphrase)
elif filename:
if GPG_1_3_1:
# This version does not allow us to encrypt using the
# file stream # have to read in the contents and encrypt.
with salt.utils.files.flopen(filename, 'rb') as _fp:
_contents = _fp.read()
result = gpg.encrypt(_contents, recipients, passphrase=gpg_passphrase, output=output)
else:
# This version allows encrypting the file stream
with salt.utils.files.flopen(filename, 'rb') as _fp:
if output:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, output=output, sign=sign)
else:
result = gpg.encrypt_file(_fp, recipients, passphrase=gpg_passphrase, sign=sign)
else:
raise SaltInvocationError('filename or text must be passed.')
if result.ok:
if not bare:
if output:
ret['comment'] = 'Encrypted data has been written to {0}'.format(output)
else:
ret['comment'] = result.data
else:
ret = result.data
else:
if not bare:
ret['res'] = False
ret['comment'] = '{0}.\nPlease check the salt-minion log.'.format(result.status)
else:
ret = False
log.error(result.stderr)
return ret | [
"def",
"encrypt",
"(",
"user",
"=",
"None",
",",
"recipients",
"=",
"None",
",",
"text",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"output",
"=",
"None",
",",
"sign",
"=",
"None",
",",
"use_passphrase",
"=",
"False",
",",
"gnupghome",
"=",
"Non... | Encrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
recipients
The fingerprints for those recipient whom the data is being encrypted for.
text
The text to encrypt.
filename
The filename to encrypt.
output
The filename where the signed file will be written, default is standard out.
sign
Whether to sign, in addition to encrypt, the data. ``True`` to use
default key or fingerprint to specify a different key to sign with.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) encrypted block as a string without
the standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.encrypt text='Hello there. How are you?'
salt '*' gpg.encrypt filename='/path/to/important.file'
salt '*' gpg.encrypt filename='/path/to/important.file' use_passphrase=True | [
"Encrypt",
"a",
"message",
"or",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L1120-L1223 | train |
saltstack/salt | salt/modules/gpg.py | decrypt | def decrypt(user=None,
text=None,
filename=None,
output=None,
use_passphrase=False,
gnupghome=None,
bare=False):
'''
Decrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
text
The encrypted text to decrypt.
filename
The encrypted filename to decrypt.
output
The filename where the decrypted data will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) decrypted block as a string without the
standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.decrypt filename='/path/to/important.file.gpg'
salt '*' gpg.decrypt filename='/path/to/important.file.gpg' use_passphrase=True
'''
ret = {
'res': True,
'comment': ''
}
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
gpg_passphrase = gpg_passphrase['gpg_passphrase']
else:
gpg_passphrase = None
if text:
result = gpg.decrypt(text, passphrase=gpg_passphrase)
elif filename:
with salt.utils.files.flopen(filename, 'rb') as _fp:
if output:
result = gpg.decrypt_file(_fp, passphrase=gpg_passphrase, output=output)
else:
result = gpg.decrypt_file(_fp, passphrase=gpg_passphrase)
else:
raise SaltInvocationError('filename or text must be passed.')
if result.ok:
if not bare:
if output:
ret['comment'] = 'Decrypted data has been written to {0}'.format(output)
else:
ret['comment'] = result.data
else:
ret = result.data
else:
if not bare:
ret['res'] = False
ret['comment'] = '{0}.\nPlease check the salt-minion log.'.format(result.status)
else:
ret = False
log.error(result.stderr)
return ret | python | def decrypt(user=None,
text=None,
filename=None,
output=None,
use_passphrase=False,
gnupghome=None,
bare=False):
'''
Decrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
text
The encrypted text to decrypt.
filename
The encrypted filename to decrypt.
output
The filename where the decrypted data will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) decrypted block as a string without the
standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.decrypt filename='/path/to/important.file.gpg'
salt '*' gpg.decrypt filename='/path/to/important.file.gpg' use_passphrase=True
'''
ret = {
'res': True,
'comment': ''
}
gpg = _create_gpg(user, gnupghome)
if use_passphrase:
gpg_passphrase = __salt__['pillar.get']('gpg_passphrase')
if not gpg_passphrase:
raise SaltInvocationError('gpg_passphrase not available in pillar.')
gpg_passphrase = gpg_passphrase['gpg_passphrase']
else:
gpg_passphrase = None
if text:
result = gpg.decrypt(text, passphrase=gpg_passphrase)
elif filename:
with salt.utils.files.flopen(filename, 'rb') as _fp:
if output:
result = gpg.decrypt_file(_fp, passphrase=gpg_passphrase, output=output)
else:
result = gpg.decrypt_file(_fp, passphrase=gpg_passphrase)
else:
raise SaltInvocationError('filename or text must be passed.')
if result.ok:
if not bare:
if output:
ret['comment'] = 'Decrypted data has been written to {0}'.format(output)
else:
ret['comment'] = result.data
else:
ret = result.data
else:
if not bare:
ret['res'] = False
ret['comment'] = '{0}.\nPlease check the salt-minion log.'.format(result.status)
else:
ret = False
log.error(result.stderr)
return ret | [
"def",
"decrypt",
"(",
"user",
"=",
"None",
",",
"text",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"output",
"=",
"None",
",",
"use_passphrase",
"=",
"False",
",",
"gnupghome",
"=",
"None",
",",
"bare",
"=",
"False",
")",
":",
"ret",
"=",
"{"... | Decrypt a message or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
text
The encrypted text to decrypt.
filename
The encrypted filename to decrypt.
output
The filename where the decrypted data will be written, default is standard out.
use_passphrase
Whether to use a passphrase with the signing key. Passphrase is received
from Pillar.
gnupghome
Specify the location where GPG keyring and related files are stored.
bare
If ``True``, return the (armored) decrypted block as a string without the
standard comment/res dict.
CLI Example:
.. code-block:: bash
salt '*' gpg.decrypt filename='/path/to/important.file.gpg'
salt '*' gpg.decrypt filename='/path/to/important.file.gpg' use_passphrase=True | [
"Decrypt",
"a",
"message",
"or",
"file"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gpg.py#L1226-L1311 | train |
saltstack/salt | salt/utils/msgpack.py | pack | def pack(o, stream, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.pack and ensures that the passed object is unwrapped if it is
a proxy.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
orig_enc_func = kwargs.pop('default', lambda x: x)
def _enc_func(obj):
obj = ThreadLocalProxy.unproxy(obj)
return orig_enc_func(obj)
return msgpack_module.pack(o, stream, default=_enc_func, **kwargs) | python | def pack(o, stream, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.pack and ensures that the passed object is unwrapped if it is
a proxy.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
orig_enc_func = kwargs.pop('default', lambda x: x)
def _enc_func(obj):
obj = ThreadLocalProxy.unproxy(obj)
return orig_enc_func(obj)
return msgpack_module.pack(o, stream, default=_enc_func, **kwargs) | [
"def",
"pack",
"(",
"o",
",",
"stream",
",",
"*",
"*",
"kwargs",
")",
":",
"msgpack_module",
"=",
"kwargs",
".",
"pop",
"(",
"'_msgpack_module'",
",",
"msgpack",
")",
"orig_enc_func",
"=",
"kwargs",
".",
"pop",
"(",
"'default'",
",",
"lambda",
"x",
":"... | .. versionadded:: 2018.3.4
Wraps msgpack.pack and ensures that the passed object is unwrapped if it is
a proxy.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument. | [
"..",
"versionadded",
"::",
"2018",
".",
"3",
".",
"4"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/msgpack.py#L20-L38 | train |
saltstack/salt | salt/utils/msgpack.py | unpack | def unpack(stream, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
return msgpack_module.unpack(stream, **kwargs) | python | def unpack(stream, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
return msgpack_module.unpack(stream, **kwargs) | [
"def",
"unpack",
"(",
"stream",
",",
"*",
"*",
"kwargs",
")",
":",
"msgpack_module",
"=",
"kwargs",
".",
"pop",
"(",
"'_msgpack_module'",
",",
"msgpack",
")",
"return",
"msgpack_module",
".",
"unpack",
"(",
"stream",
",",
"*",
"*",
"kwargs",
")"
] | .. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument. | [
"..",
"versionadded",
"::",
"2018",
".",
"3",
".",
"4"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/msgpack.py#L62-L73 | train |
saltstack/salt | salt/utils/msgpack.py | unpackb | def unpackb(packed, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
return msgpack_module.unpackb(packed, **kwargs) | python | def unpackb(packed, **kwargs):
'''
.. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument.
'''
msgpack_module = kwargs.pop('_msgpack_module', msgpack)
return msgpack_module.unpackb(packed, **kwargs) | [
"def",
"unpackb",
"(",
"packed",
",",
"*",
"*",
"kwargs",
")",
":",
"msgpack_module",
"=",
"kwargs",
".",
"pop",
"(",
"'_msgpack_module'",
",",
"msgpack",
")",
"return",
"msgpack_module",
".",
"unpackb",
"(",
"packed",
",",
"*",
"*",
"kwargs",
")"
] | .. versionadded:: 2018.3.4
Wraps msgpack.unpack.
By default, this function uses the msgpack module and falls back to
msgpack_pure, if the msgpack is not available. You can pass an alternate
msgpack module using the _msgpack_module argument. | [
"..",
"versionadded",
"::",
"2018",
".",
"3",
".",
"4"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/utils/msgpack.py#L76-L87 | train |
saltstack/salt | salt/thorium/key.py | timeout | def timeout(name, delete=0, reject=0):
'''
If any minion's status is older than the timeout value then apply the
given action to the timed out key. This example will remove keys to
minions that have not checked in for 300 seconds (5 minutes)
USAGE:
.. code-block:: yaml
statreg:
status.reg
clean_keys:
key.timeout:
- require:
- status: statreg
- delete: 300
'''
ret = {'name': name,
'changes': {},
'comment': '',
'result': True}
now = time.time()
ktr = 'key_start_tracker'
if ktr not in __context__:
__context__[ktr] = {}
remove = set()
reject_set = set()
keyapi = _get_key_api()
current = keyapi.list_status('acc')
for id_ in current.get('minions', []):
if id_ in __reg__['status']['val']:
# minion is reporting, check timeout and mark for removal
if delete and (now - __reg__['status']['val'][id_]['recv_time']) > delete:
remove.add(id_)
if reject and (now - __reg__['status']['val'][id_]['recv_time']) > reject:
reject_set.add(id_)
else:
# No report from minion recorded, mark for change if thorium has
# been running for longer than the timeout
if id_ not in __context__[ktr]:
__context__[ktr][id_] = now
else:
if delete and (now - __context__[ktr][id_]) > delete:
remove.add(id_)
if reject and (now - __context__[ktr][id_]) > reject:
reject_set.add(id_)
for id_ in remove:
keyapi.delete_key(id_)
__reg__['status']['val'].pop(id_, None)
__context__[ktr].pop(id_, None)
for id_ in reject_set:
keyapi.reject(id_)
__reg__['status']['val'].pop(id_, None)
__context__[ktr].pop(id_, None)
return ret | python | def timeout(name, delete=0, reject=0):
'''
If any minion's status is older than the timeout value then apply the
given action to the timed out key. This example will remove keys to
minions that have not checked in for 300 seconds (5 minutes)
USAGE:
.. code-block:: yaml
statreg:
status.reg
clean_keys:
key.timeout:
- require:
- status: statreg
- delete: 300
'''
ret = {'name': name,
'changes': {},
'comment': '',
'result': True}
now = time.time()
ktr = 'key_start_tracker'
if ktr not in __context__:
__context__[ktr] = {}
remove = set()
reject_set = set()
keyapi = _get_key_api()
current = keyapi.list_status('acc')
for id_ in current.get('minions', []):
if id_ in __reg__['status']['val']:
# minion is reporting, check timeout and mark for removal
if delete and (now - __reg__['status']['val'][id_]['recv_time']) > delete:
remove.add(id_)
if reject and (now - __reg__['status']['val'][id_]['recv_time']) > reject:
reject_set.add(id_)
else:
# No report from minion recorded, mark for change if thorium has
# been running for longer than the timeout
if id_ not in __context__[ktr]:
__context__[ktr][id_] = now
else:
if delete and (now - __context__[ktr][id_]) > delete:
remove.add(id_)
if reject and (now - __context__[ktr][id_]) > reject:
reject_set.add(id_)
for id_ in remove:
keyapi.delete_key(id_)
__reg__['status']['val'].pop(id_, None)
__context__[ktr].pop(id_, None)
for id_ in reject_set:
keyapi.reject(id_)
__reg__['status']['val'].pop(id_, None)
__context__[ktr].pop(id_, None)
return ret | [
"def",
"timeout",
"(",
"name",
",",
"delete",
"=",
"0",
",",
"reject",
"=",
"0",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'comment'",
":",
"''",
",",
"'result'",
":",
"True",
"}",
"now",
"=",
"tim... | If any minion's status is older than the timeout value then apply the
given action to the timed out key. This example will remove keys to
minions that have not checked in for 300 seconds (5 minutes)
USAGE:
.. code-block:: yaml
statreg:
status.reg
clean_keys:
key.timeout:
- require:
- status: statreg
- delete: 300 | [
"If",
"any",
"minion",
"s",
"status",
"is",
"older",
"than",
"the",
"timeout",
"value",
"then",
"apply",
"the",
"given",
"action",
"to",
"the",
"timed",
"out",
"key",
".",
"This",
"example",
"will",
"remove",
"keys",
"to",
"minions",
"that",
"have",
"not... | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/thorium/key.py#L24-L80 | train |
saltstack/salt | salt/beacons/inotify.py | _get_notifier | def _get_notifier(config):
'''
Check the context for the notifier and construct it if not present
'''
if 'inotify.notifier' not in __context__:
__context__['inotify.queue'] = collections.deque()
wm = pyinotify.WatchManager()
__context__['inotify.notifier'] = pyinotify.Notifier(wm, _enqueue)
if ('coalesce' in config and
isinstance(config['coalesce'], bool) and
config['coalesce']):
__context__['inotify.notifier'].coalesce_events()
return __context__['inotify.notifier'] | python | def _get_notifier(config):
'''
Check the context for the notifier and construct it if not present
'''
if 'inotify.notifier' not in __context__:
__context__['inotify.queue'] = collections.deque()
wm = pyinotify.WatchManager()
__context__['inotify.notifier'] = pyinotify.Notifier(wm, _enqueue)
if ('coalesce' in config and
isinstance(config['coalesce'], bool) and
config['coalesce']):
__context__['inotify.notifier'].coalesce_events()
return __context__['inotify.notifier'] | [
"def",
"_get_notifier",
"(",
"config",
")",
":",
"if",
"'inotify.notifier'",
"not",
"in",
"__context__",
":",
"__context__",
"[",
"'inotify.queue'",
"]",
"=",
"collections",
".",
"deque",
"(",
")",
"wm",
"=",
"pyinotify",
".",
"WatchManager",
"(",
")",
"__co... | Check the context for the notifier and construct it if not present | [
"Check",
"the",
"context",
"for",
"the",
"notifier",
"and",
"construct",
"it",
"if",
"not",
"present"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/beacons/inotify.py#L70-L82 | train |
saltstack/salt | salt/beacons/inotify.py | validate | def validate(config):
'''
Validate the beacon configuration
'''
VALID_MASK = [
'access',
'attrib',
'close_nowrite',
'close_write',
'create',
'delete',
'delete_self',
'excl_unlink',
'ignored',
'modify',
'moved_from',
'moved_to',
'move_self',
'oneshot',
'onlydir',
'open',
'unmount'
]
# Configuration for inotify beacon should be a dict of dicts
if not isinstance(config, list):
return False, 'Configuration for inotify beacon must be a list.'
else:
_config = {}
list(map(_config.update, config))
if 'files' not in _config:
return False, 'Configuration for inotify beacon must include files.'
else:
for path in _config.get('files'):
if not isinstance(_config['files'][path], dict):
return False, ('Configuration for inotify beacon must '
'be a list of dictionaries.')
else:
if not any(j in ['mask',
'recurse',
'auto_add'] for j in _config['files'][path]):
return False, ('Configuration for inotify beacon must '
'contain mask, recurse or auto_add items.')
if 'auto_add' in _config['files'][path]:
if not isinstance(_config['files'][path]['auto_add'], bool):
return False, ('Configuration for inotify beacon '
'auto_add must be boolean.')
if 'recurse' in _config['files'][path]:
if not isinstance(_config['files'][path]['recurse'], bool):
return False, ('Configuration for inotify beacon '
'recurse must be boolean.')
if 'mask' in _config['files'][path]:
if not isinstance(_config['files'][path]['mask'], list):
return False, ('Configuration for inotify beacon '
'mask must be list.')
for mask in _config['files'][path]['mask']:
if mask not in VALID_MASK:
return False, ('Configuration for inotify beacon '
'invalid mask option {0}.'.format(mask))
return True, 'Valid beacon configuration' | python | def validate(config):
'''
Validate the beacon configuration
'''
VALID_MASK = [
'access',
'attrib',
'close_nowrite',
'close_write',
'create',
'delete',
'delete_self',
'excl_unlink',
'ignored',
'modify',
'moved_from',
'moved_to',
'move_self',
'oneshot',
'onlydir',
'open',
'unmount'
]
# Configuration for inotify beacon should be a dict of dicts
if not isinstance(config, list):
return False, 'Configuration for inotify beacon must be a list.'
else:
_config = {}
list(map(_config.update, config))
if 'files' not in _config:
return False, 'Configuration for inotify beacon must include files.'
else:
for path in _config.get('files'):
if not isinstance(_config['files'][path], dict):
return False, ('Configuration for inotify beacon must '
'be a list of dictionaries.')
else:
if not any(j in ['mask',
'recurse',
'auto_add'] for j in _config['files'][path]):
return False, ('Configuration for inotify beacon must '
'contain mask, recurse or auto_add items.')
if 'auto_add' in _config['files'][path]:
if not isinstance(_config['files'][path]['auto_add'], bool):
return False, ('Configuration for inotify beacon '
'auto_add must be boolean.')
if 'recurse' in _config['files'][path]:
if not isinstance(_config['files'][path]['recurse'], bool):
return False, ('Configuration for inotify beacon '
'recurse must be boolean.')
if 'mask' in _config['files'][path]:
if not isinstance(_config['files'][path]['mask'], list):
return False, ('Configuration for inotify beacon '
'mask must be list.')
for mask in _config['files'][path]['mask']:
if mask not in VALID_MASK:
return False, ('Configuration for inotify beacon '
'invalid mask option {0}.'.format(mask))
return True, 'Valid beacon configuration' | [
"def",
"validate",
"(",
"config",
")",
":",
"VALID_MASK",
"=",
"[",
"'access'",
",",
"'attrib'",
",",
"'close_nowrite'",
",",
"'close_write'",
",",
"'create'",
",",
"'delete'",
",",
"'delete_self'",
",",
"'excl_unlink'",
",",
"'ignored'",
",",
"'modify'",
",",... | Validate the beacon configuration | [
"Validate",
"the",
"beacon",
"configuration"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/beacons/inotify.py#L85-L150 | train |
saltstack/salt | salt/beacons/inotify.py | beacon | def beacon(config):
'''
Watch the configured files
Example Config
.. code-block:: yaml
beacons:
inotify:
- files:
/path/to/file/or/dir:
mask:
- open
- create
- close_write
recurse: True
auto_add: True
exclude:
- /path/to/file/or/dir/exclude1
- /path/to/file/or/dir/exclude2
- /path/to/file/or/dir/regex[a-m]*$:
regex: True
- coalesce: True
The mask list can contain the following events (the default mask is create,
delete, and modify):
* access - File accessed
* attrib - File metadata changed
* close_nowrite - Unwritable file closed
* close_write - Writable file closed
* create - File created in watched directory
* delete - File deleted from watched directory
* delete_self - Watched file or directory deleted
* modify - File modified
* moved_from - File moved out of watched directory
* moved_to - File moved into watched directory
* move_self - Watched file moved
* open - File opened
The mask can also contain the following options:
* dont_follow - Don't dereference symbolic links
* excl_unlink - Omit events for children after they have been unlinked
* oneshot - Remove watch after one event
* onlydir - Operate only if name is directory
recurse:
Recursively watch files in the directory
auto_add:
Automatically start watching files that are created in the watched directory
exclude:
Exclude directories or files from triggering events in the watched directory.
Can use regex if regex is set to True
coalesce:
If this coalescing option is enabled, events are filtered based on
their unicity, only unique events are enqueued, doublons are discarded.
An event is unique when the combination of its fields (wd, mask,
cookie, name) is unique among events of a same batch. After a batch of
events is processed any events are accepted again.
This option is top-level (at the same level as the path) and therefore
affects all paths that are being watched. This is due to this option
being at the Notifier level in pyinotify.
'''
_config = {}
list(map(_config.update, config))
ret = []
notifier = _get_notifier(_config)
wm = notifier._watch_manager
# Read in existing events
if notifier.check_events(1):
notifier.read_events()
notifier.process_events()
queue = __context__['inotify.queue']
while queue:
event = queue.popleft()
_append = True
# Find the matching path in config
path = event.path
while path != '/':
if path in _config.get('files', {}):
break
path = os.path.dirname(path)
excludes = _config['files'][path].get('exclude', '')
if excludes and isinstance(excludes, list):
for exclude in excludes:
if isinstance(exclude, dict):
_exclude = next(iter(exclude))
if exclude[_exclude].get('regex', False):
try:
if re.search(_exclude, event.pathname):
_append = False
except Exception:
log.warning('Failed to compile regex: %s',
_exclude)
else:
exclude = _exclude
elif '*' in exclude:
if fnmatch.fnmatch(event.pathname, exclude):
_append = False
else:
if event.pathname.startswith(exclude):
_append = False
if _append:
sub = {'tag': event.path,
'path': event.pathname,
'change': event.maskname}
ret.append(sub)
else:
log.info('Excluding %s from event for %s', event.pathname, path)
# Get paths currently being watched
current = set()
for wd in wm.watches:
current.add(wm.watches[wd].path)
# Update existing watches and add new ones
# TODO: make the config handle more options
for path in _config.get('files', ()):
if isinstance(_config['files'][path], dict):
mask = _config['files'][path].get('mask', DEFAULT_MASK)
if isinstance(mask, list):
r_mask = 0
for sub in mask:
r_mask |= _get_mask(sub)
elif isinstance(mask, salt.ext.six.binary_type):
r_mask = _get_mask(mask)
else:
r_mask = mask
mask = r_mask
rec = _config['files'][path].get('recurse', False)
auto_add = _config['files'][path].get('auto_add', False)
else:
mask = DEFAULT_MASK
rec = False
auto_add = False
if path in current:
for wd in wm.watches:
if path == wm.watches[wd].path:
update = False
if wm.watches[wd].mask != mask:
update = True
if wm.watches[wd].auto_add != auto_add:
update = True
if update:
wm.update_watch(wd, mask=mask, rec=rec, auto_add=auto_add)
elif os.path.exists(path):
excludes = _config['files'][path].get('exclude', '')
excl = None
if isinstance(excludes, list):
excl = []
for exclude in excludes:
if isinstance(exclude, dict):
excl.append(list(exclude)[0])
else:
excl.append(exclude)
excl = pyinotify.ExcludeFilter(excl)
wm.add_watch(path, mask, rec=rec, auto_add=auto_add, exclude_filter=excl)
# Return event data
return ret | python | def beacon(config):
'''
Watch the configured files
Example Config
.. code-block:: yaml
beacons:
inotify:
- files:
/path/to/file/or/dir:
mask:
- open
- create
- close_write
recurse: True
auto_add: True
exclude:
- /path/to/file/or/dir/exclude1
- /path/to/file/or/dir/exclude2
- /path/to/file/or/dir/regex[a-m]*$:
regex: True
- coalesce: True
The mask list can contain the following events (the default mask is create,
delete, and modify):
* access - File accessed
* attrib - File metadata changed
* close_nowrite - Unwritable file closed
* close_write - Writable file closed
* create - File created in watched directory
* delete - File deleted from watched directory
* delete_self - Watched file or directory deleted
* modify - File modified
* moved_from - File moved out of watched directory
* moved_to - File moved into watched directory
* move_self - Watched file moved
* open - File opened
The mask can also contain the following options:
* dont_follow - Don't dereference symbolic links
* excl_unlink - Omit events for children after they have been unlinked
* oneshot - Remove watch after one event
* onlydir - Operate only if name is directory
recurse:
Recursively watch files in the directory
auto_add:
Automatically start watching files that are created in the watched directory
exclude:
Exclude directories or files from triggering events in the watched directory.
Can use regex if regex is set to True
coalesce:
If this coalescing option is enabled, events are filtered based on
their unicity, only unique events are enqueued, doublons are discarded.
An event is unique when the combination of its fields (wd, mask,
cookie, name) is unique among events of a same batch. After a batch of
events is processed any events are accepted again.
This option is top-level (at the same level as the path) and therefore
affects all paths that are being watched. This is due to this option
being at the Notifier level in pyinotify.
'''
_config = {}
list(map(_config.update, config))
ret = []
notifier = _get_notifier(_config)
wm = notifier._watch_manager
# Read in existing events
if notifier.check_events(1):
notifier.read_events()
notifier.process_events()
queue = __context__['inotify.queue']
while queue:
event = queue.popleft()
_append = True
# Find the matching path in config
path = event.path
while path != '/':
if path in _config.get('files', {}):
break
path = os.path.dirname(path)
excludes = _config['files'][path].get('exclude', '')
if excludes and isinstance(excludes, list):
for exclude in excludes:
if isinstance(exclude, dict):
_exclude = next(iter(exclude))
if exclude[_exclude].get('regex', False):
try:
if re.search(_exclude, event.pathname):
_append = False
except Exception:
log.warning('Failed to compile regex: %s',
_exclude)
else:
exclude = _exclude
elif '*' in exclude:
if fnmatch.fnmatch(event.pathname, exclude):
_append = False
else:
if event.pathname.startswith(exclude):
_append = False
if _append:
sub = {'tag': event.path,
'path': event.pathname,
'change': event.maskname}
ret.append(sub)
else:
log.info('Excluding %s from event for %s', event.pathname, path)
# Get paths currently being watched
current = set()
for wd in wm.watches:
current.add(wm.watches[wd].path)
# Update existing watches and add new ones
# TODO: make the config handle more options
for path in _config.get('files', ()):
if isinstance(_config['files'][path], dict):
mask = _config['files'][path].get('mask', DEFAULT_MASK)
if isinstance(mask, list):
r_mask = 0
for sub in mask:
r_mask |= _get_mask(sub)
elif isinstance(mask, salt.ext.six.binary_type):
r_mask = _get_mask(mask)
else:
r_mask = mask
mask = r_mask
rec = _config['files'][path].get('recurse', False)
auto_add = _config['files'][path].get('auto_add', False)
else:
mask = DEFAULT_MASK
rec = False
auto_add = False
if path in current:
for wd in wm.watches:
if path == wm.watches[wd].path:
update = False
if wm.watches[wd].mask != mask:
update = True
if wm.watches[wd].auto_add != auto_add:
update = True
if update:
wm.update_watch(wd, mask=mask, rec=rec, auto_add=auto_add)
elif os.path.exists(path):
excludes = _config['files'][path].get('exclude', '')
excl = None
if isinstance(excludes, list):
excl = []
for exclude in excludes:
if isinstance(exclude, dict):
excl.append(list(exclude)[0])
else:
excl.append(exclude)
excl = pyinotify.ExcludeFilter(excl)
wm.add_watch(path, mask, rec=rec, auto_add=auto_add, exclude_filter=excl)
# Return event data
return ret | [
"def",
"beacon",
"(",
"config",
")",
":",
"_config",
"=",
"{",
"}",
"list",
"(",
"map",
"(",
"_config",
".",
"update",
",",
"config",
")",
")",
"ret",
"=",
"[",
"]",
"notifier",
"=",
"_get_notifier",
"(",
"_config",
")",
"wm",
"=",
"notifier",
".",... | Watch the configured files
Example Config
.. code-block:: yaml
beacons:
inotify:
- files:
/path/to/file/or/dir:
mask:
- open
- create
- close_write
recurse: True
auto_add: True
exclude:
- /path/to/file/or/dir/exclude1
- /path/to/file/or/dir/exclude2
- /path/to/file/or/dir/regex[a-m]*$:
regex: True
- coalesce: True
The mask list can contain the following events (the default mask is create,
delete, and modify):
* access - File accessed
* attrib - File metadata changed
* close_nowrite - Unwritable file closed
* close_write - Writable file closed
* create - File created in watched directory
* delete - File deleted from watched directory
* delete_self - Watched file or directory deleted
* modify - File modified
* moved_from - File moved out of watched directory
* moved_to - File moved into watched directory
* move_self - Watched file moved
* open - File opened
The mask can also contain the following options:
* dont_follow - Don't dereference symbolic links
* excl_unlink - Omit events for children after they have been unlinked
* oneshot - Remove watch after one event
* onlydir - Operate only if name is directory
recurse:
Recursively watch files in the directory
auto_add:
Automatically start watching files that are created in the watched directory
exclude:
Exclude directories or files from triggering events in the watched directory.
Can use regex if regex is set to True
coalesce:
If this coalescing option is enabled, events are filtered based on
their unicity, only unique events are enqueued, doublons are discarded.
An event is unique when the combination of its fields (wd, mask,
cookie, name) is unique among events of a same batch. After a batch of
events is processed any events are accepted again.
This option is top-level (at the same level as the path) and therefore
affects all paths that are being watched. This is due to this option
being at the Notifier level in pyinotify. | [
"Watch",
"the",
"configured",
"files"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/beacons/inotify.py#L153-L323 | train |
saltstack/salt | salt/modules/gem.py | _gem | def _gem(command, ruby=None, runas=None, gem_bin=None):
'''
Run the actual gem command. If rvm or rbenv is installed, run the command
using the corresponding module. rbenv is not available on windows, so don't
try.
:param command: string
Command to run
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param gem_bin: string : None
Full path to the ``gem`` binary
:return:
Returns the full standard out including success codes or False if it fails
'''
cmdline = [gem_bin or 'gem'] + command
# If a custom gem is given, use that and don't check for rvm/rbenv. User
# knows best!
if gem_bin is None:
if __salt__['rvm.is_installed'](runas=runas):
return __salt__['rvm.do'](ruby, cmdline, runas=runas)
if not salt.utils.platform.is_windows() \
and __salt__['rbenv.is_installed'](runas=runas):
if ruby is None:
return __salt__['rbenv.do'](cmdline, runas=runas)
else:
return __salt__['rbenv.do_with_ruby'](ruby,
cmdline,
runas=runas)
ret = __salt__['cmd.run_all'](cmdline, runas=runas, python_shell=False)
if ret['retcode'] == 0:
return ret['stdout']
else:
raise CommandExecutionError(ret['stderr']) | python | def _gem(command, ruby=None, runas=None, gem_bin=None):
'''
Run the actual gem command. If rvm or rbenv is installed, run the command
using the corresponding module. rbenv is not available on windows, so don't
try.
:param command: string
Command to run
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param gem_bin: string : None
Full path to the ``gem`` binary
:return:
Returns the full standard out including success codes or False if it fails
'''
cmdline = [gem_bin or 'gem'] + command
# If a custom gem is given, use that and don't check for rvm/rbenv. User
# knows best!
if gem_bin is None:
if __salt__['rvm.is_installed'](runas=runas):
return __salt__['rvm.do'](ruby, cmdline, runas=runas)
if not salt.utils.platform.is_windows() \
and __salt__['rbenv.is_installed'](runas=runas):
if ruby is None:
return __salt__['rbenv.do'](cmdline, runas=runas)
else:
return __salt__['rbenv.do_with_ruby'](ruby,
cmdline,
runas=runas)
ret = __salt__['cmd.run_all'](cmdline, runas=runas, python_shell=False)
if ret['retcode'] == 0:
return ret['stdout']
else:
raise CommandExecutionError(ret['stderr']) | [
"def",
"_gem",
"(",
"command",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"cmdline",
"=",
"[",
"gem_bin",
"or",
"'gem'",
"]",
"+",
"command",
"# If a custom gem is given, use that and don't check for rvm/rbenv. Us... | Run the actual gem command. If rvm or rbenv is installed, run the command
using the corresponding module. rbenv is not available on windows, so don't
try.
:param command: string
Command to run
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param gem_bin: string : None
Full path to the ``gem`` binary
:return:
Returns the full standard out including success codes or False if it fails | [
"Run",
"the",
"actual",
"gem",
"command",
".",
"If",
"rvm",
"or",
"rbenv",
"is",
"installed",
"run",
"the",
"command",
"using",
"the",
"corresponding",
"module",
".",
"rbenv",
"is",
"not",
"available",
"on",
"windows",
"so",
"don",
"t",
"try",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L23-L64 | train |
saltstack/salt | salt/modules/gem.py | install | def install(gems, # pylint: disable=C0103
ruby=None,
gem_bin=None,
runas=None,
version=None,
rdoc=False,
ri=False,
pre_releases=False,
proxy=None,
source=None): # pylint: disable=C0103
'''
Installs one or several gems.
:param gems: string
The gems to install
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param version: string : None
Specify the version to install for the gem.
Doesn't play nice with multiple gems at once
:param rdoc: boolean : False
Generate RDoc documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
ri option will then be ignored
:param ri: boolean : False
Generate RI documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
rdoc option will then be ignored
:param pre_releases: boolean : False
Include pre-releases in the available versions
:param proxy: string : None
Use the specified HTTP proxy server for all outgoing traffic.
Format: http://hostname[:port]
source : None
Use the specified HTTP gem source server to download gem.
Format: http://hostname[:port]
CLI Example:
.. code-block:: bash
salt '*' gem.install vagrant
salt '*' gem.install redphone gem_bin=/opt/sensu/embedded/bin/gem
'''
try:
gems = gems.split()
except AttributeError:
pass
options = []
if version:
options.extend(['--version', version])
if _has_rubygems_3(ruby=ruby, runas=runas, gem_bin=gem_bin):
if not rdoc or not ri:
options.append('--no-document')
if pre_releases:
options.append('--prerelease')
else:
if not rdoc:
options.append('--no-rdoc')
if not ri:
options.append('--no-ri')
if pre_releases:
options.append('--pre')
if proxy:
options.extend(['-p', proxy])
if source:
options.extend(['--source', source])
return _gem(['install'] + gems + options,
ruby,
gem_bin=gem_bin,
runas=runas) | python | def install(gems, # pylint: disable=C0103
ruby=None,
gem_bin=None,
runas=None,
version=None,
rdoc=False,
ri=False,
pre_releases=False,
proxy=None,
source=None): # pylint: disable=C0103
'''
Installs one or several gems.
:param gems: string
The gems to install
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param version: string : None
Specify the version to install for the gem.
Doesn't play nice with multiple gems at once
:param rdoc: boolean : False
Generate RDoc documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
ri option will then be ignored
:param ri: boolean : False
Generate RI documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
rdoc option will then be ignored
:param pre_releases: boolean : False
Include pre-releases in the available versions
:param proxy: string : None
Use the specified HTTP proxy server for all outgoing traffic.
Format: http://hostname[:port]
source : None
Use the specified HTTP gem source server to download gem.
Format: http://hostname[:port]
CLI Example:
.. code-block:: bash
salt '*' gem.install vagrant
salt '*' gem.install redphone gem_bin=/opt/sensu/embedded/bin/gem
'''
try:
gems = gems.split()
except AttributeError:
pass
options = []
if version:
options.extend(['--version', version])
if _has_rubygems_3(ruby=ruby, runas=runas, gem_bin=gem_bin):
if not rdoc or not ri:
options.append('--no-document')
if pre_releases:
options.append('--prerelease')
else:
if not rdoc:
options.append('--no-rdoc')
if not ri:
options.append('--no-ri')
if pre_releases:
options.append('--pre')
if proxy:
options.extend(['-p', proxy])
if source:
options.extend(['--source', source])
return _gem(['install'] + gems + options,
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"install",
"(",
"gems",
",",
"# pylint: disable=C0103",
"ruby",
"=",
"None",
",",
"gem_bin",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"version",
"=",
"None",
",",
"rdoc",
"=",
"False",
",",
"ri",
"=",
"False",
",",
"pre_releases",
"=",
"Fals... | Installs one or several gems.
:param gems: string
The gems to install
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
:param version: string : None
Specify the version to install for the gem.
Doesn't play nice with multiple gems at once
:param rdoc: boolean : False
Generate RDoc documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
ri option will then be ignored
:param ri: boolean : False
Generate RI documentation for the gem(s).
For rubygems > 3 this is interpreted as the --no-document arg and the
rdoc option will then be ignored
:param pre_releases: boolean : False
Include pre-releases in the available versions
:param proxy: string : None
Use the specified HTTP proxy server for all outgoing traffic.
Format: http://hostname[:port]
source : None
Use the specified HTTP gem source server to download gem.
Format: http://hostname[:port]
CLI Example:
.. code-block:: bash
salt '*' gem.install vagrant
salt '*' gem.install redphone gem_bin=/opt/sensu/embedded/bin/gem | [
"Installs",
"one",
"or",
"several",
"gems",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L67-L146 | train |
saltstack/salt | salt/modules/gem.py | uninstall | def uninstall(gems, ruby=None, runas=None, gem_bin=None):
'''
Uninstall one or several gems.
:param gems: string
The gems to uninstall.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.uninstall vagrant
'''
try:
gems = gems.split()
except AttributeError:
pass
return _gem(['uninstall'] + gems + ['-a', '-x'],
ruby,
gem_bin=gem_bin,
runas=runas) | python | def uninstall(gems, ruby=None, runas=None, gem_bin=None):
'''
Uninstall one or several gems.
:param gems: string
The gems to uninstall.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.uninstall vagrant
'''
try:
gems = gems.split()
except AttributeError:
pass
return _gem(['uninstall'] + gems + ['-a', '-x'],
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"uninstall",
"(",
"gems",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"try",
":",
"gems",
"=",
"gems",
".",
"split",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"return",
"_gem",
"(",
"[... | Uninstall one or several gems.
:param gems: string
The gems to uninstall.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.uninstall vagrant | [
"Uninstall",
"one",
"or",
"several",
"gems",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L149-L177 | train |
saltstack/salt | salt/modules/gem.py | update | def update(gems, ruby=None, runas=None, gem_bin=None):
'''
Update one or several gems.
:param gems: string
The gems to update.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update vagrant
'''
try:
gems = gems.split()
except AttributeError:
pass
return _gem(['update'] + gems,
ruby,
gem_bin=gem_bin,
runas=runas) | python | def update(gems, ruby=None, runas=None, gem_bin=None):
'''
Update one or several gems.
:param gems: string
The gems to update.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update vagrant
'''
try:
gems = gems.split()
except AttributeError:
pass
return _gem(['update'] + gems,
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"update",
"(",
"gems",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"try",
":",
"gems",
"=",
"gems",
".",
"split",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"return",
"_gem",
"(",
"[",
... | Update one or several gems.
:param gems: string
The gems to update.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update vagrant | [
"Update",
"one",
"or",
"several",
"gems",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L180-L208 | train |
saltstack/salt | salt/modules/gem.py | update_system | def update_system(version='', ruby=None, runas=None, gem_bin=None):
'''
Update rubygems.
:param version: string : (newest)
The version of rubygems to install.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update_system
'''
return _gem(['update', '--system', version],
ruby,
gem_bin=gem_bin,
runas=runas) | python | def update_system(version='', ruby=None, runas=None, gem_bin=None):
'''
Update rubygems.
:param version: string : (newest)
The version of rubygems to install.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update_system
'''
return _gem(['update', '--system', version],
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"update_system",
"(",
"version",
"=",
"''",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"return",
"_gem",
"(",
"[",
"'update'",
",",
"'--system'",
",",
"version",
"]",
",",
"ruby",
",",
"gem_bin"... | Update rubygems.
:param version: string : (newest)
The version of rubygems to install.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.update_system | [
"Update",
"rubygems",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L211-L234 | train |
saltstack/salt | salt/modules/gem.py | version | def version(ruby=None, runas=None, gem_bin=None):
'''
Print out the version of gem
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.version
'''
cmd = ['--version']
stdout = _gem(cmd,
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(stdout, '\n'):
match = re.match(r'[.0-9]+', line)
if match:
ret = line
break
return ret | python | def version(ruby=None, runas=None, gem_bin=None):
'''
Print out the version of gem
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.version
'''
cmd = ['--version']
stdout = _gem(cmd,
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(stdout, '\n'):
match = re.match(r'[.0-9]+', line)
if match:
ret = line
break
return ret | [
"def",
"version",
"(",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"'--version'",
"]",
"stdout",
"=",
"_gem",
"(",
"cmd",
",",
"ruby",
",",
"gem_bin",
"=",
"gem_bin",
",",
"runas",
"=",
... | Print out the version of gem
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.version | [
"Print",
"out",
"the",
"version",
"of",
"gem"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L237-L266 | train |
saltstack/salt | salt/modules/gem.py | list_ | def list_(prefix='', ruby=None, runas=None, gem_bin=None):
'''
List locally installed gems.
:param prefix: string :
Only list gems when the name matches this prefix.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list
'''
cmd = ['list']
if prefix:
cmd.append(prefix)
stdout = _gem(cmd,
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(stdout, '\n'):
match = re.match(r'^([^ ]+) \((.+)\)', line)
if match:
gem = match.group(1)
versions = match.group(2).split(', ')
ret[gem] = versions
return ret | python | def list_(prefix='', ruby=None, runas=None, gem_bin=None):
'''
List locally installed gems.
:param prefix: string :
Only list gems when the name matches this prefix.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list
'''
cmd = ['list']
if prefix:
cmd.append(prefix)
stdout = _gem(cmd,
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(stdout, '\n'):
match = re.match(r'^([^ ]+) \((.+)\)', line)
if match:
gem = match.group(1)
versions = match.group(2).split(', ')
ret[gem] = versions
return ret | [
"def",
"list_",
"(",
"prefix",
"=",
"''",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"'list'",
"]",
"if",
"prefix",
":",
"cmd",
".",
"append",
"(",
"prefix",
")",
"stdout",
"=",
... | List locally installed gems.
:param prefix: string :
Only list gems when the name matches this prefix.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list | [
"List",
"locally",
"installed",
"gems",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L276-L310 | train |
saltstack/salt | salt/modules/gem.py | list_upgrades | def list_upgrades(ruby=None,
runas=None,
gem_bin=None):
'''
.. versionadded:: 2015.8.0
Check if an upgrade is available for installed gems
gem_bin : None
Full path to ``gem`` binary to use.
ruby : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
runas : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list_upgrades
'''
result = _gem(['outdated'],
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(result, '\n'):
match = re.search(r'(\S+) \(\S+ < (\S+)\)', line)
if match:
name, version = match.groups()
else:
log.error('Can\'t parse line \'%s\'', line)
continue
ret[name] = version
return ret | python | def list_upgrades(ruby=None,
runas=None,
gem_bin=None):
'''
.. versionadded:: 2015.8.0
Check if an upgrade is available for installed gems
gem_bin : None
Full path to ``gem`` binary to use.
ruby : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
runas : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list_upgrades
'''
result = _gem(['outdated'],
ruby,
gem_bin=gem_bin,
runas=runas)
ret = {}
for line in salt.utils.itertools.split(result, '\n'):
match = re.search(r'(\S+) \(\S+ < (\S+)\)', line)
if match:
name, version = match.groups()
else:
log.error('Can\'t parse line \'%s\'', line)
continue
ret[name] = version
return ret | [
"def",
"list_upgrades",
"(",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"result",
"=",
"_gem",
"(",
"[",
"'outdated'",
"]",
",",
"ruby",
",",
"gem_bin",
"=",
"gem_bin",
",",
"runas",
"=",
"runas",
")",
"r... | .. versionadded:: 2015.8.0
Check if an upgrade is available for installed gems
gem_bin : None
Full path to ``gem`` binary to use.
ruby : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
runas : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.list_upgrades | [
"..",
"versionadded",
"::",
"2015",
".",
"8",
".",
"0"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L313-L348 | train |
saltstack/salt | salt/modules/gem.py | sources_add | def sources_add(source_uri, ruby=None, runas=None, gem_bin=None):
'''
Add a gem source.
:param source_uri: string
The source URI to add.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_add http://rubygems.org/
'''
return _gem(['sources', '--add', source_uri],
ruby,
gem_bin=gem_bin,
runas=runas) | python | def sources_add(source_uri, ruby=None, runas=None, gem_bin=None):
'''
Add a gem source.
:param source_uri: string
The source URI to add.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_add http://rubygems.org/
'''
return _gem(['sources', '--add', source_uri],
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"sources_add",
"(",
"source_uri",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"return",
"_gem",
"(",
"[",
"'sources'",
",",
"'--add'",
",",
"source_uri",
"]",
",",
"ruby",
",",
"gem_bin",
"=",
"g... | Add a gem source.
:param source_uri: string
The source URI to add.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_add http://rubygems.org/ | [
"Add",
"a",
"gem",
"source",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L351-L374 | train |
saltstack/salt | salt/modules/gem.py | sources_remove | def sources_remove(source_uri, ruby=None, runas=None, gem_bin=None):
'''
Remove a gem source.
:param source_uri: string
The source URI to remove.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_remove http://rubygems.org/
'''
return _gem(['sources', '--remove', source_uri],
ruby,
gem_bin=gem_bin,
runas=runas) | python | def sources_remove(source_uri, ruby=None, runas=None, gem_bin=None):
'''
Remove a gem source.
:param source_uri: string
The source URI to remove.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_remove http://rubygems.org/
'''
return _gem(['sources', '--remove', source_uri],
ruby,
gem_bin=gem_bin,
runas=runas) | [
"def",
"sources_remove",
"(",
"source_uri",
",",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"return",
"_gem",
"(",
"[",
"'sources'",
",",
"'--remove'",
",",
"source_uri",
"]",
",",
"ruby",
",",
"gem_bin",
"="... | Remove a gem source.
:param source_uri: string
The source URI to remove.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_remove http://rubygems.org/ | [
"Remove",
"a",
"gem",
"source",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L377-L400 | train |
saltstack/salt | salt/modules/gem.py | sources_list | def sources_list(ruby=None, runas=None, gem_bin=None):
'''
List the configured gem sources.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_list
'''
ret = _gem(['sources'], ruby, gem_bin=gem_bin, runas=runas)
return [] if ret is False else ret.splitlines()[2:] | python | def sources_list(ruby=None, runas=None, gem_bin=None):
'''
List the configured gem sources.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_list
'''
ret = _gem(['sources'], ruby, gem_bin=gem_bin, runas=runas)
return [] if ret is False else ret.splitlines()[2:] | [
"def",
"sources_list",
"(",
"ruby",
"=",
"None",
",",
"runas",
"=",
"None",
",",
"gem_bin",
"=",
"None",
")",
":",
"ret",
"=",
"_gem",
"(",
"[",
"'sources'",
"]",
",",
"ruby",
",",
"gem_bin",
"=",
"gem_bin",
",",
"runas",
"=",
"runas",
")",
"return... | List the configured gem sources.
:param gem_bin: string : None
Full path to ``gem`` binary to use.
:param ruby: string : None
If RVM or rbenv are installed, the ruby version and gemset to use.
Ignored if ``gem_bin`` is specified.
:param runas: string : None
The user to run gem as.
CLI Example:
.. code-block:: bash
salt '*' gem.sources_list | [
"List",
"the",
"configured",
"gem",
"sources",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/gem.py#L403-L422 | train |
saltstack/salt | salt/states/icinga2.py | generate_ticket | def generate_ticket(name, output=None, grain=None, key=None, overwrite=True):
'''
Generate an icinga2 ticket on the master.
name
The domain name for which this ticket will be generated
output
grain: output in a grain
other: the file to store results
None: output to the result comment (default)
grain:
grain to store the output (need output=grain)
key:
the specified grain will be treated as a dictionary, the result
of this state will be stored under the specified key.
overwrite:
The file or grain will be overwritten if it already exists (default)
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
# Checking if execution is needed.
if output == 'grain':
if grain and not key:
if not overwrite and grain in __salt__['grains.ls']():
ret['comment'] = 'No execution needed. Grain {0} already set'.format(grain)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in grain: {0}'.format(grain)
return ret
elif grain:
if grain in __salt__['grains.ls']():
grain_value = __salt__['grains.get'](grain)
else:
grain_value = {}
if not overwrite and key in grain_value:
ret['comment'] = 'No execution needed. Grain {0}:{1} already set'.format(grain, key)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in grain: {0}:{1}'.format(grain, key)
return ret
else:
ret['result'] = False
ret['comment'] = "Error: output type 'grain' needs the grain parameter\n"
return ret
elif output:
if not overwrite and os.path.isfile(output):
ret['comment'] = 'No execution needed. File {0} already set'.format(output)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in file: {0}'.format(output)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, not storing result'
return ret
# Executing the command.
ticket_res = __salt__['icinga2.generate_ticket'](name)
ticket = ticket_res['stdout']
if not ticket_res['retcode']:
ret['comment'] = six.text_type(ticket)
if output == 'grain':
if grain and not key:
__salt__['grains.setval'](grain, ticket)
ret['changes']['ticket'] = "Executed. Output into grain: {0}".format(grain)
elif grain:
if grain in __salt__['grains.ls']():
grain_value = __salt__['grains.get'](grain)
else:
grain_value = {}
grain_value[key] = ticket
__salt__['grains.setval'](grain, grain_value)
ret['changes']['ticket'] = "Executed. Output into grain: {0}:{1}".format(grain, key)
elif output:
ret['changes']['ticket'] = "Executed. Output into {0}".format(output)
with salt.utils.files.fopen(output, 'w') as output_file:
output_file.write(salt.utils.stringutils.to_str(ticket))
else:
ret['changes']['ticket'] = "Executed"
return ret | python | def generate_ticket(name, output=None, grain=None, key=None, overwrite=True):
'''
Generate an icinga2 ticket on the master.
name
The domain name for which this ticket will be generated
output
grain: output in a grain
other: the file to store results
None: output to the result comment (default)
grain:
grain to store the output (need output=grain)
key:
the specified grain will be treated as a dictionary, the result
of this state will be stored under the specified key.
overwrite:
The file or grain will be overwritten if it already exists (default)
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
# Checking if execution is needed.
if output == 'grain':
if grain and not key:
if not overwrite and grain in __salt__['grains.ls']():
ret['comment'] = 'No execution needed. Grain {0} already set'.format(grain)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in grain: {0}'.format(grain)
return ret
elif grain:
if grain in __salt__['grains.ls']():
grain_value = __salt__['grains.get'](grain)
else:
grain_value = {}
if not overwrite and key in grain_value:
ret['comment'] = 'No execution needed. Grain {0}:{1} already set'.format(grain, key)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in grain: {0}:{1}'.format(grain, key)
return ret
else:
ret['result'] = False
ret['comment'] = "Error: output type 'grain' needs the grain parameter\n"
return ret
elif output:
if not overwrite and os.path.isfile(output):
ret['comment'] = 'No execution needed. File {0} already set'.format(output)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, storing result in file: {0}'.format(output)
return ret
elif __opts__['test']:
ret['result'] = None
ret['comment'] = 'Ticket generation would be executed, not storing result'
return ret
# Executing the command.
ticket_res = __salt__['icinga2.generate_ticket'](name)
ticket = ticket_res['stdout']
if not ticket_res['retcode']:
ret['comment'] = six.text_type(ticket)
if output == 'grain':
if grain and not key:
__salt__['grains.setval'](grain, ticket)
ret['changes']['ticket'] = "Executed. Output into grain: {0}".format(grain)
elif grain:
if grain in __salt__['grains.ls']():
grain_value = __salt__['grains.get'](grain)
else:
grain_value = {}
grain_value[key] = ticket
__salt__['grains.setval'](grain, grain_value)
ret['changes']['ticket'] = "Executed. Output into grain: {0}:{1}".format(grain, key)
elif output:
ret['changes']['ticket'] = "Executed. Output into {0}".format(output)
with salt.utils.files.fopen(output, 'w') as output_file:
output_file.write(salt.utils.stringutils.to_str(ticket))
else:
ret['changes']['ticket'] = "Executed"
return ret | [
"def",
"generate_ticket",
"(",
"name",
",",
"output",
"=",
"None",
",",
"grain",
"=",
"None",
",",
"key",
"=",
"None",
",",
"overwrite",
"=",
"True",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'"... | Generate an icinga2 ticket on the master.
name
The domain name for which this ticket will be generated
output
grain: output in a grain
other: the file to store results
None: output to the result comment (default)
grain:
grain to store the output (need output=grain)
key:
the specified grain will be treated as a dictionary, the result
of this state will be stored under the specified key.
overwrite:
The file or grain will be overwritten if it already exists (default) | [
"Generate",
"an",
"icinga2",
"ticket",
"on",
"the",
"master",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/icinga2.py#L40-L131 | train |
saltstack/salt | salt/states/icinga2.py | generate_cert | def generate_cert(name):
'''
Generate an icinga2 certificate and key on the client.
name
The domain name for which this certificate and key will be generated
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}{1}.crt".format(get_certs_path(), name)
key = "{0}{1}.key".format(get_certs_path(), name)
# Checking if execution is needed.
if os.path.isfile(cert) and os.path.isfile(key):
ret['comment'] = 'No execution needed. Cert: {0} and key: {1} already generated.'.format(cert, key)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate and key generation would be executed'
return ret
# Executing the command.
cert_save = __salt__['icinga2.generate_cert'](name)
if not cert_save['retcode']:
ret['comment'] = "Certificate and key generated"
ret['changes']['cert'] = "Executed. Certificate saved: {0}".format(cert)
ret['changes']['key'] = "Executed. Key saved: {0}".format(key)
return ret | python | def generate_cert(name):
'''
Generate an icinga2 certificate and key on the client.
name
The domain name for which this certificate and key will be generated
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}{1}.crt".format(get_certs_path(), name)
key = "{0}{1}.key".format(get_certs_path(), name)
# Checking if execution is needed.
if os.path.isfile(cert) and os.path.isfile(key):
ret['comment'] = 'No execution needed. Cert: {0} and key: {1} already generated.'.format(cert, key)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate and key generation would be executed'
return ret
# Executing the command.
cert_save = __salt__['icinga2.generate_cert'](name)
if not cert_save['retcode']:
ret['comment'] = "Certificate and key generated"
ret['changes']['cert'] = "Executed. Certificate saved: {0}".format(cert)
ret['changes']['key'] = "Executed. Key saved: {0}".format(key)
return ret | [
"def",
"generate_cert",
"(",
"name",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"True",
",",
"'comment'",
":",
"''",
"}",
"cert",
"=",
"\"{0}{1}.crt\"",
".",
"format",
"(",
"get_certs_path",... | Generate an icinga2 certificate and key on the client.
name
The domain name for which this certificate and key will be generated | [
"Generate",
"an",
"icinga2",
"certificate",
"and",
"key",
"on",
"the",
"client",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/icinga2.py#L134-L163 | train |
saltstack/salt | salt/states/icinga2.py | save_cert | def save_cert(name, master):
'''
Save the certificate on master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}trusted-master.crt".format(get_certs_path())
# Checking if execution is needed.
if os.path.isfile(cert):
ret['comment'] = 'No execution needed. Cert: {0} already saved.'.format(cert)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate save for icinga2 master would be executed'
return ret
# Executing the command.
cert_save = __salt__['icinga2.save_cert'](name, master)
if not cert_save['retcode']:
ret['comment'] = "Certificate for icinga2 master saved"
ret['changes']['cert'] = "Executed. Certificate saved: {0}".format(cert)
return ret | python | def save_cert(name, master):
'''
Save the certificate on master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}trusted-master.crt".format(get_certs_path())
# Checking if execution is needed.
if os.path.isfile(cert):
ret['comment'] = 'No execution needed. Cert: {0} already saved.'.format(cert)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate save for icinga2 master would be executed'
return ret
# Executing the command.
cert_save = __salt__['icinga2.save_cert'](name, master)
if not cert_save['retcode']:
ret['comment'] = "Certificate for icinga2 master saved"
ret['changes']['cert'] = "Executed. Certificate saved: {0}".format(cert)
return ret | [
"def",
"save_cert",
"(",
"name",
",",
"master",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"True",
",",
"'comment'",
":",
"''",
"}",
"cert",
"=",
"\"{0}trusted-master.crt\"",
".",
"format",
... | Save the certificate on master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved | [
"Save",
"the",
"certificate",
"on",
"master",
"icinga2",
"node",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/icinga2.py#L166-L196 | train |
saltstack/salt | salt/states/icinga2.py | request_cert | def request_cert(name, master, ticket, port="5665"):
'''
Request CA certificate from master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master
port
Icinga2 port, defaults to 5665
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}ca.crt".format(get_certs_path())
# Checking if execution is needed.
if os.path.isfile(cert):
ret['comment'] = 'No execution needed. Cert: {0} already exists.'.format(cert)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate request from icinga2 master would be executed'
return ret
# Executing the command.
cert_request = __salt__['icinga2.request_cert'](name, master, ticket, port)
if not cert_request['retcode']:
ret['comment'] = "Certificate request from icinga2 master executed"
ret['changes']['cert'] = "Executed. Certificate requested: {0}".format(cert)
return ret
ret['comment'] = "FAILED. Certificate requested failed with output: {0}".format(cert_request['stdout'])
ret['result'] = False
return ret | python | def request_cert(name, master, ticket, port="5665"):
'''
Request CA certificate from master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master
port
Icinga2 port, defaults to 5665
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}ca.crt".format(get_certs_path())
# Checking if execution is needed.
if os.path.isfile(cert):
ret['comment'] = 'No execution needed. Cert: {0} already exists.'.format(cert)
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Certificate request from icinga2 master would be executed'
return ret
# Executing the command.
cert_request = __salt__['icinga2.request_cert'](name, master, ticket, port)
if not cert_request['retcode']:
ret['comment'] = "Certificate request from icinga2 master executed"
ret['changes']['cert'] = "Executed. Certificate requested: {0}".format(cert)
return ret
ret['comment'] = "FAILED. Certificate requested failed with output: {0}".format(cert_request['stdout'])
ret['result'] = False
return ret | [
"def",
"request_cert",
"(",
"name",
",",
"master",
",",
"ticket",
",",
"port",
"=",
"\"5665\"",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"True",
",",
"'comment'",
":",
"''",
"}",
"cert... | Request CA certificate from master icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master
port
Icinga2 port, defaults to 5665 | [
"Request",
"CA",
"certificate",
"from",
"master",
"icinga2",
"node",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/icinga2.py#L199-L239 | train |
saltstack/salt | salt/states/icinga2.py | node_setup | def node_setup(name, master, ticket):
'''
Setup the icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}{1}.crt.orig".format(get_certs_path(), name)
key = "{0}{1}.key.orig".format(get_certs_path(), name)
# Checking if execution is needed.
if os.path.isfile(cert) and os.path.isfile(cert):
ret['comment'] = 'No execution needed. Node already configured.'
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Node setup will be executed.'
return ret
# Executing the command.
node_setup = __salt__['icinga2.node_setup'](name, master, ticket)
if not node_setup['retcode']:
ret['comment'] = "Node setup executed."
ret['changes']['cert'] = "Node setup finished successfully."
return ret
ret['comment'] = "FAILED. Node setup failed with outpu: {0}".format(node_setup['stdout'])
ret['result'] = False
return ret | python | def node_setup(name, master, ticket):
'''
Setup the icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
cert = "{0}{1}.crt.orig".format(get_certs_path(), name)
key = "{0}{1}.key.orig".format(get_certs_path(), name)
# Checking if execution is needed.
if os.path.isfile(cert) and os.path.isfile(cert):
ret['comment'] = 'No execution needed. Node already configured.'
return ret
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Node setup will be executed.'
return ret
# Executing the command.
node_setup = __salt__['icinga2.node_setup'](name, master, ticket)
if not node_setup['retcode']:
ret['comment'] = "Node setup executed."
ret['changes']['cert'] = "Node setup finished successfully."
return ret
ret['comment'] = "FAILED. Node setup failed with outpu: {0}".format(node_setup['stdout'])
ret['result'] = False
return ret | [
"def",
"node_setup",
"(",
"name",
",",
"master",
",",
"ticket",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'changes'",
":",
"{",
"}",
",",
"'result'",
":",
"True",
",",
"'comment'",
":",
"''",
"}",
"cert",
"=",
"\"{0}{1}.crt.orig\"",
"."... | Setup the icinga2 node.
name
The domain name for which this certificate will be saved
master
Icinga2 master node for which this certificate will be saved
ticket
Authentication ticket generated on icinga2 master | [
"Setup",
"the",
"icinga2",
"node",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/icinga2.py#L242-L280 | train |
saltstack/salt | salt/cloud/clouds/linode.py | avail_images | def avail_images(call=None):
'''
Return available Linode images.
CLI Example:
.. code-block:: bash
salt-cloud --list-images my-linode-config
salt-cloud -f avail_images my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_images function must be called with -f or --function.'
)
response = _query('avail', 'distributions')
ret = {}
for item in response['DATA']:
name = item['LABEL']
ret[name] = item
return ret | python | def avail_images(call=None):
'''
Return available Linode images.
CLI Example:
.. code-block:: bash
salt-cloud --list-images my-linode-config
salt-cloud -f avail_images my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_images function must be called with -f or --function.'
)
response = _query('avail', 'distributions')
ret = {}
for item in response['DATA']:
name = item['LABEL']
ret[name] = item
return ret | [
"def",
"avail_images",
"(",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The avail_images function must be called with -f or --function.'",
")",
"response",
"=",
"_query",
"(",
"'avail'",
",",
"'distribution... | Return available Linode images.
CLI Example:
.. code-block:: bash
salt-cloud --list-images my-linode-config
salt-cloud -f avail_images my-linode-config | [
"Return",
"available",
"Linode",
"images",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L110-L133 | train |
saltstack/salt | salt/cloud/clouds/linode.py | avail_locations | def avail_locations(call=None):
'''
Return available Linode datacenter locations.
CLI Example:
.. code-block:: bash
salt-cloud --list-locations my-linode-config
salt-cloud -f avail_locations my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_locations function must be called with -f or --function.'
)
response = _query('avail', 'datacenters')
ret = {}
for item in response['DATA']:
name = item['LOCATION']
ret[name] = item
return ret | python | def avail_locations(call=None):
'''
Return available Linode datacenter locations.
CLI Example:
.. code-block:: bash
salt-cloud --list-locations my-linode-config
salt-cloud -f avail_locations my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_locations function must be called with -f or --function.'
)
response = _query('avail', 'datacenters')
ret = {}
for item in response['DATA']:
name = item['LOCATION']
ret[name] = item
return ret | [
"def",
"avail_locations",
"(",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The avail_locations function must be called with -f or --function.'",
")",
"response",
"=",
"_query",
"(",
"'avail'",
",",
"'datace... | Return available Linode datacenter locations.
CLI Example:
.. code-block:: bash
salt-cloud --list-locations my-linode-config
salt-cloud -f avail_locations my-linode-config | [
"Return",
"available",
"Linode",
"datacenter",
"locations",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L136-L159 | train |
saltstack/salt | salt/cloud/clouds/linode.py | avail_sizes | def avail_sizes(call=None):
'''
Return available Linode sizes.
CLI Example:
.. code-block:: bash
salt-cloud --list-sizes my-linode-config
salt-cloud -f avail_sizes my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_locations function must be called with -f or --function.'
)
response = _query('avail', 'LinodePlans')
ret = {}
for item in response['DATA']:
name = item['LABEL']
ret[name] = item
return ret | python | def avail_sizes(call=None):
'''
Return available Linode sizes.
CLI Example:
.. code-block:: bash
salt-cloud --list-sizes my-linode-config
salt-cloud -f avail_sizes my-linode-config
'''
if call == 'action':
raise SaltCloudException(
'The avail_locations function must be called with -f or --function.'
)
response = _query('avail', 'LinodePlans')
ret = {}
for item in response['DATA']:
name = item['LABEL']
ret[name] = item
return ret | [
"def",
"avail_sizes",
"(",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The avail_locations function must be called with -f or --function.'",
")",
"response",
"=",
"_query",
"(",
"'avail'",
",",
"'LinodePlan... | Return available Linode sizes.
CLI Example:
.. code-block:: bash
salt-cloud --list-sizes my-linode-config
salt-cloud -f avail_sizes my-linode-config | [
"Return",
"available",
"Linode",
"sizes",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L162-L185 | train |
saltstack/salt | salt/cloud/clouds/linode.py | boot | def boot(name=None, kwargs=None, call=None):
'''
Boot a Linode.
name
The name of the Linode to boot. Can be used instead of ``linode_id``.
linode_id
The ID of the Linode to boot. If provided, will be used as an
alternative to ``name`` and reduces the number of API calls to
Linode by one. Will be preferred over ``name``.
config_id
The ID of the Config to boot. Required.
check_running
Defaults to True. If set to False, overrides the call to check if
the VM is running before calling the linode.boot API call. Change
``check_running`` to True is useful during the boot call in the
create function, since the new VM will not be running yet.
Can be called as an action (which requires a name):
.. code-block:: bash
salt-cloud -a boot my-instance config_id=10
...or as a function (which requires either a name or linode_id):
.. code-block:: bash
salt-cloud -f boot my-linode-config name=my-instance config_id=10
salt-cloud -f boot my-linode-config linode_id=1225876 config_id=10
'''
if name is None and call == 'action':
raise SaltCloudSystemExit(
'The boot action requires a \'name\'.'
)
if kwargs is None:
kwargs = {}
linode_id = kwargs.get('linode_id', None)
config_id = kwargs.get('config_id', None)
check_running = kwargs.get('check_running', True)
if call == 'function':
name = kwargs.get('name', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The boot function requires either a \'name\' or a \'linode_id\'.'
)
if config_id is None:
raise SaltCloudSystemExit(
'The boot function requires a \'config_id\'.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
linode_item = name
else:
linode_item = linode_id
# Check if Linode is running first
if check_running is True:
status = get_linode(kwargs={'linode_id': linode_id})['STATUS']
if status == '1':
raise SaltCloudSystemExit(
'Cannot boot Linode {0}. '
'Linode {0} is already running.'.format(linode_item)
)
# Boot the VM and get the JobID from Linode
response = _query('linode', 'boot',
args={'LinodeID': linode_id,
'ConfigID': config_id})['DATA']
boot_job_id = response['JobID']
if not _wait_for_job(linode_id, boot_job_id):
log.error('Boot failed for Linode %s.', linode_item)
return False
return True | python | def boot(name=None, kwargs=None, call=None):
'''
Boot a Linode.
name
The name of the Linode to boot. Can be used instead of ``linode_id``.
linode_id
The ID of the Linode to boot. If provided, will be used as an
alternative to ``name`` and reduces the number of API calls to
Linode by one. Will be preferred over ``name``.
config_id
The ID of the Config to boot. Required.
check_running
Defaults to True. If set to False, overrides the call to check if
the VM is running before calling the linode.boot API call. Change
``check_running`` to True is useful during the boot call in the
create function, since the new VM will not be running yet.
Can be called as an action (which requires a name):
.. code-block:: bash
salt-cloud -a boot my-instance config_id=10
...or as a function (which requires either a name or linode_id):
.. code-block:: bash
salt-cloud -f boot my-linode-config name=my-instance config_id=10
salt-cloud -f boot my-linode-config linode_id=1225876 config_id=10
'''
if name is None and call == 'action':
raise SaltCloudSystemExit(
'The boot action requires a \'name\'.'
)
if kwargs is None:
kwargs = {}
linode_id = kwargs.get('linode_id', None)
config_id = kwargs.get('config_id', None)
check_running = kwargs.get('check_running', True)
if call == 'function':
name = kwargs.get('name', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The boot function requires either a \'name\' or a \'linode_id\'.'
)
if config_id is None:
raise SaltCloudSystemExit(
'The boot function requires a \'config_id\'.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
linode_item = name
else:
linode_item = linode_id
# Check if Linode is running first
if check_running is True:
status = get_linode(kwargs={'linode_id': linode_id})['STATUS']
if status == '1':
raise SaltCloudSystemExit(
'Cannot boot Linode {0}. '
'Linode {0} is already running.'.format(linode_item)
)
# Boot the VM and get the JobID from Linode
response = _query('linode', 'boot',
args={'LinodeID': linode_id,
'ConfigID': config_id})['DATA']
boot_job_id = response['JobID']
if not _wait_for_job(linode_id, boot_job_id):
log.error('Boot failed for Linode %s.', linode_item)
return False
return True | [
"def",
"boot",
"(",
"name",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
"and",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The boot action requires a \\'name\\'.'",
")",
... | Boot a Linode.
name
The name of the Linode to boot. Can be used instead of ``linode_id``.
linode_id
The ID of the Linode to boot. If provided, will be used as an
alternative to ``name`` and reduces the number of API calls to
Linode by one. Will be preferred over ``name``.
config_id
The ID of the Config to boot. Required.
check_running
Defaults to True. If set to False, overrides the call to check if
the VM is running before calling the linode.boot API call. Change
``check_running`` to True is useful during the boot call in the
create function, since the new VM will not be running yet.
Can be called as an action (which requires a name):
.. code-block:: bash
salt-cloud -a boot my-instance config_id=10
...or as a function (which requires either a name or linode_id):
.. code-block:: bash
salt-cloud -f boot my-linode-config name=my-instance config_id=10
salt-cloud -f boot my-linode-config linode_id=1225876 config_id=10 | [
"Boot",
"a",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L188-L272 | train |
saltstack/salt | salt/cloud/clouds/linode.py | clone | def clone(kwargs=None, call=None):
'''
Clone a Linode.
linode_id
The ID of the Linode to clone. Required.
datacenter_id
The ID of the Datacenter where the Linode will be placed. Required.
plan_id
The ID of the plan (size) of the Linode. Required.
CLI Example:
.. code-block:: bash
salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5
'''
if call == 'action':
raise SaltCloudSystemExit(
'The clone function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
linode_id = kwargs.get('linode_id', None)
datacenter_id = kwargs.get('datacenter_id', None)
plan_id = kwargs.get('plan_id', None)
required_params = [linode_id, datacenter_id, plan_id]
for item in required_params:
if item is None:
raise SaltCloudSystemExit(
'The clone function requires a \'linode_id\', \'datacenter_id\', '
'and \'plan_id\' to be provided.'
)
clone_args = {
'LinodeID': linode_id,
'DatacenterID': datacenter_id,
'PlanID': plan_id
}
return _query('linode', 'clone', args=clone_args) | python | def clone(kwargs=None, call=None):
'''
Clone a Linode.
linode_id
The ID of the Linode to clone. Required.
datacenter_id
The ID of the Datacenter where the Linode will be placed. Required.
plan_id
The ID of the plan (size) of the Linode. Required.
CLI Example:
.. code-block:: bash
salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5
'''
if call == 'action':
raise SaltCloudSystemExit(
'The clone function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
linode_id = kwargs.get('linode_id', None)
datacenter_id = kwargs.get('datacenter_id', None)
plan_id = kwargs.get('plan_id', None)
required_params = [linode_id, datacenter_id, plan_id]
for item in required_params:
if item is None:
raise SaltCloudSystemExit(
'The clone function requires a \'linode_id\', \'datacenter_id\', '
'and \'plan_id\' to be provided.'
)
clone_args = {
'LinodeID': linode_id,
'DatacenterID': datacenter_id,
'PlanID': plan_id
}
return _query('linode', 'clone', args=clone_args) | [
"def",
"clone",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The clone function must be called with -f or --function.'",
")",
"if",
"kwargs",
"is",
"None",
":",
"kwarg... | Clone a Linode.
linode_id
The ID of the Linode to clone. Required.
datacenter_id
The ID of the Datacenter where the Linode will be placed. Required.
plan_id
The ID of the plan (size) of the Linode. Required.
CLI Example:
.. code-block:: bash
salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5 | [
"Clone",
"a",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L275-L320 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create | def create(vm_):
'''
Create a single Linode VM.
'''
name = vm_['name']
try:
# Check for required profile parameters before sending any API calls.
if vm_['profile'] and config.is_profile_configured(__opts__,
__active_provider_name__ or 'linode',
vm_['profile'],
vm_=vm_) is False:
return False
except AttributeError:
pass
if _validate_name(name) is False:
return False
__utils__['cloud.fire_event'](
'event',
'starting create',
'salt/cloud/{0}/creating'.format(name),
args=__utils__['cloud.filter_event']('creating', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
log.info('Creating Cloud VM %s', name)
data = {}
kwargs = {'name': name}
plan_id = None
size = vm_.get('size')
if size:
kwargs['size'] = size
plan_id = get_plan_id(kwargs={'label': size})
datacenter_id = None
location = vm_.get('location')
if location:
try:
datacenter_id = get_datacenter_id(location)
except KeyError:
# Linode's default datacenter is Dallas, but we still have to set one to
# use the create function from Linode's API. Dallas's datacenter id is 2.
datacenter_id = 2
clonefrom_name = vm_.get('clonefrom')
cloning = True if clonefrom_name else False
if cloning:
linode_id = get_linode_id_from_name(clonefrom_name)
clone_source = get_linode(kwargs={'linode_id': linode_id})
kwargs = {
'clonefrom': clonefrom_name,
'image': 'Clone of {0}'.format(clonefrom_name),
}
if size is None:
size = clone_source['TOTALRAM']
kwargs['size'] = size
plan_id = clone_source['PLANID']
if location is None:
datacenter_id = clone_source['DATACENTERID']
# Create new Linode from cloned Linode
try:
result = clone(kwargs={'linode_id': linode_id,
'datacenter_id': datacenter_id,
'plan_id': plan_id})
except Exception as err:
log.error(
'Error cloning \'%s\' on Linode.\n\n'
'The following exception was thrown by Linode when trying to '
'clone the specified machine:\n%s',
clonefrom_name, err, exc_info_on_loglevel=logging.DEBUG
)
return False
else:
kwargs['image'] = vm_['image']
# Create Linode
try:
result = _query('linode', 'create', args={
'PLANID': plan_id,
'DATACENTERID': datacenter_id
})
except Exception as err:
log.error(
'Error creating %s on Linode\n\n'
'The following exception was thrown by Linode when trying to '
'run the initial deployment:\n%s',
name, err, exc_info_on_loglevel=logging.DEBUG
)
return False
if 'ERRORARRAY' in result:
for error_data in result['ERRORARRAY']:
log.error(
'Error creating %s on Linode\n\n'
'The Linode API returned the following: %s\n',
name, error_data['ERRORMESSAGE']
)
return False
__utils__['cloud.fire_event'](
'event',
'requesting instance',
'salt/cloud/{0}/requesting'.format(name),
args=__utils__['cloud.filter_event']('requesting', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
node_id = _clean_data(result)['LinodeID']
data['id'] = node_id
if not _wait_for_status(node_id, status=(_get_status_id_by_name('brand_new'))):
log.error(
'Error creating %s on LINODE\n\n'
'while waiting for initial ready status',
name, exc_info_on_loglevel=logging.DEBUG
)
# Update the Linode's Label to reflect the given VM name
update_linode(node_id, update_args={'Label': name})
log.debug('Set name for %s - was linode%s.', name, node_id)
# Add private IP address if requested
private_ip_assignment = get_private_ip(vm_)
if private_ip_assignment:
create_private_ip(node_id)
# Define which ssh_interface to use
ssh_interface = _get_ssh_interface(vm_)
# If ssh_interface is set to use private_ips, but assign_private_ip
# wasn't set to True, let's help out and create a private ip.
if ssh_interface == 'private_ips' and private_ip_assignment is False:
create_private_ip(node_id)
private_ip_assignment = True
if cloning:
config_id = get_config_id(kwargs={'linode_id': node_id})['config_id']
else:
# Create disks and get ids
log.debug('Creating disks for %s', name)
root_disk_id = create_disk_from_distro(vm_, node_id)['DiskID']
swap_disk_id = create_swap_disk(vm_, node_id)['DiskID']
# Create a ConfigID using disk ids
config_id = create_config(kwargs={'name': name,
'linode_id': node_id,
'root_disk_id': root_disk_id,
'swap_disk_id': swap_disk_id})['ConfigID']
# Boot the Linode
boot(kwargs={'linode_id': node_id,
'config_id': config_id,
'check_running': False})
node_data = get_linode(kwargs={'linode_id': node_id})
ips = get_ips(node_id)
state = int(node_data['STATUS'])
data['image'] = kwargs['image']
data['name'] = name
data['size'] = size
data['state'] = _get_status_descr_by_id(state)
data['private_ips'] = ips['private_ips']
data['public_ips'] = ips['public_ips']
# Pass the correct IP address to the bootstrap ssh_host key
if ssh_interface == 'private_ips':
vm_['ssh_host'] = data['private_ips'][0]
else:
vm_['ssh_host'] = data['public_ips'][0]
# If a password wasn't supplied in the profile or provider config, set it now.
vm_['password'] = get_password(vm_)
# Make public_ips and private_ips available to the bootstrap script.
vm_['public_ips'] = ips['public_ips']
vm_['private_ips'] = ips['private_ips']
# Send event that the instance has booted.
__utils__['cloud.fire_event'](
'event',
'waiting for ssh',
'salt/cloud/{0}/waiting_for_ssh'.format(name),
sock_dir=__opts__['sock_dir'],
args={'ip_address': vm_['ssh_host']},
transport=__opts__['transport']
)
# Bootstrap!
ret = __utils__['cloud.bootstrap'](vm_, __opts__)
ret.update(data)
log.info('Created Cloud VM \'%s\'', name)
log.debug('\'%s\' VM creation details:\n%s', name, pprint.pformat(data))
__utils__['cloud.fire_event'](
'event',
'created instance',
'salt/cloud/{0}/created'.format(name),
args=__utils__['cloud.filter_event']('created', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
return ret | python | def create(vm_):
'''
Create a single Linode VM.
'''
name = vm_['name']
try:
# Check for required profile parameters before sending any API calls.
if vm_['profile'] and config.is_profile_configured(__opts__,
__active_provider_name__ or 'linode',
vm_['profile'],
vm_=vm_) is False:
return False
except AttributeError:
pass
if _validate_name(name) is False:
return False
__utils__['cloud.fire_event'](
'event',
'starting create',
'salt/cloud/{0}/creating'.format(name),
args=__utils__['cloud.filter_event']('creating', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
log.info('Creating Cloud VM %s', name)
data = {}
kwargs = {'name': name}
plan_id = None
size = vm_.get('size')
if size:
kwargs['size'] = size
plan_id = get_plan_id(kwargs={'label': size})
datacenter_id = None
location = vm_.get('location')
if location:
try:
datacenter_id = get_datacenter_id(location)
except KeyError:
# Linode's default datacenter is Dallas, but we still have to set one to
# use the create function from Linode's API. Dallas's datacenter id is 2.
datacenter_id = 2
clonefrom_name = vm_.get('clonefrom')
cloning = True if clonefrom_name else False
if cloning:
linode_id = get_linode_id_from_name(clonefrom_name)
clone_source = get_linode(kwargs={'linode_id': linode_id})
kwargs = {
'clonefrom': clonefrom_name,
'image': 'Clone of {0}'.format(clonefrom_name),
}
if size is None:
size = clone_source['TOTALRAM']
kwargs['size'] = size
plan_id = clone_source['PLANID']
if location is None:
datacenter_id = clone_source['DATACENTERID']
# Create new Linode from cloned Linode
try:
result = clone(kwargs={'linode_id': linode_id,
'datacenter_id': datacenter_id,
'plan_id': plan_id})
except Exception as err:
log.error(
'Error cloning \'%s\' on Linode.\n\n'
'The following exception was thrown by Linode when trying to '
'clone the specified machine:\n%s',
clonefrom_name, err, exc_info_on_loglevel=logging.DEBUG
)
return False
else:
kwargs['image'] = vm_['image']
# Create Linode
try:
result = _query('linode', 'create', args={
'PLANID': plan_id,
'DATACENTERID': datacenter_id
})
except Exception as err:
log.error(
'Error creating %s on Linode\n\n'
'The following exception was thrown by Linode when trying to '
'run the initial deployment:\n%s',
name, err, exc_info_on_loglevel=logging.DEBUG
)
return False
if 'ERRORARRAY' in result:
for error_data in result['ERRORARRAY']:
log.error(
'Error creating %s on Linode\n\n'
'The Linode API returned the following: %s\n',
name, error_data['ERRORMESSAGE']
)
return False
__utils__['cloud.fire_event'](
'event',
'requesting instance',
'salt/cloud/{0}/requesting'.format(name),
args=__utils__['cloud.filter_event']('requesting', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
node_id = _clean_data(result)['LinodeID']
data['id'] = node_id
if not _wait_for_status(node_id, status=(_get_status_id_by_name('brand_new'))):
log.error(
'Error creating %s on LINODE\n\n'
'while waiting for initial ready status',
name, exc_info_on_loglevel=logging.DEBUG
)
# Update the Linode's Label to reflect the given VM name
update_linode(node_id, update_args={'Label': name})
log.debug('Set name for %s - was linode%s.', name, node_id)
# Add private IP address if requested
private_ip_assignment = get_private_ip(vm_)
if private_ip_assignment:
create_private_ip(node_id)
# Define which ssh_interface to use
ssh_interface = _get_ssh_interface(vm_)
# If ssh_interface is set to use private_ips, but assign_private_ip
# wasn't set to True, let's help out and create a private ip.
if ssh_interface == 'private_ips' and private_ip_assignment is False:
create_private_ip(node_id)
private_ip_assignment = True
if cloning:
config_id = get_config_id(kwargs={'linode_id': node_id})['config_id']
else:
# Create disks and get ids
log.debug('Creating disks for %s', name)
root_disk_id = create_disk_from_distro(vm_, node_id)['DiskID']
swap_disk_id = create_swap_disk(vm_, node_id)['DiskID']
# Create a ConfigID using disk ids
config_id = create_config(kwargs={'name': name,
'linode_id': node_id,
'root_disk_id': root_disk_id,
'swap_disk_id': swap_disk_id})['ConfigID']
# Boot the Linode
boot(kwargs={'linode_id': node_id,
'config_id': config_id,
'check_running': False})
node_data = get_linode(kwargs={'linode_id': node_id})
ips = get_ips(node_id)
state = int(node_data['STATUS'])
data['image'] = kwargs['image']
data['name'] = name
data['size'] = size
data['state'] = _get_status_descr_by_id(state)
data['private_ips'] = ips['private_ips']
data['public_ips'] = ips['public_ips']
# Pass the correct IP address to the bootstrap ssh_host key
if ssh_interface == 'private_ips':
vm_['ssh_host'] = data['private_ips'][0]
else:
vm_['ssh_host'] = data['public_ips'][0]
# If a password wasn't supplied in the profile or provider config, set it now.
vm_['password'] = get_password(vm_)
# Make public_ips and private_ips available to the bootstrap script.
vm_['public_ips'] = ips['public_ips']
vm_['private_ips'] = ips['private_ips']
# Send event that the instance has booted.
__utils__['cloud.fire_event'](
'event',
'waiting for ssh',
'salt/cloud/{0}/waiting_for_ssh'.format(name),
sock_dir=__opts__['sock_dir'],
args={'ip_address': vm_['ssh_host']},
transport=__opts__['transport']
)
# Bootstrap!
ret = __utils__['cloud.bootstrap'](vm_, __opts__)
ret.update(data)
log.info('Created Cloud VM \'%s\'', name)
log.debug('\'%s\' VM creation details:\n%s', name, pprint.pformat(data))
__utils__['cloud.fire_event'](
'event',
'created instance',
'salt/cloud/{0}/created'.format(name),
args=__utils__['cloud.filter_event']('created', vm_, ['name', 'profile', 'provider', 'driver']),
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
return ret | [
"def",
"create",
"(",
"vm_",
")",
":",
"name",
"=",
"vm_",
"[",
"'name'",
"]",
"try",
":",
"# Check for required profile parameters before sending any API calls.",
"if",
"vm_",
"[",
"'profile'",
"]",
"and",
"config",
".",
"is_profile_configured",
"(",
"__opts__",
... | Create a single Linode VM. | [
"Create",
"a",
"single",
"Linode",
"VM",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L323-L537 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create_config | def create_config(kwargs=None, call=None):
'''
Creates a Linode Configuration Profile.
name
The name of the VM to create the config for.
linode_id
The ID of the Linode to create the configuration for.
root_disk_id
The Root Disk ID to be used for this config.
swap_disk_id
The Swap Disk ID to be used for this config.
data_disk_id
The Data Disk ID to be used for this config.
.. versionadded:: 2016.3.0
kernel_id
The ID of the kernel to use for this configuration profile.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The create_config function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
root_disk_id = kwargs.get('root_disk_id', None)
swap_disk_id = kwargs.get('swap_disk_id', None)
data_disk_id = kwargs.get('data_disk_id', None)
kernel_id = kwargs.get('kernel_id', None)
if kernel_id is None:
# 138 appears to always be the latest 64-bit kernel for Linux
kernel_id = 138
required_params = [name, linode_id, root_disk_id, swap_disk_id]
for item in required_params:
if item is None:
raise SaltCloudSystemExit(
'The create_config functions requires a \'name\', \'linode_id\', '
'\'root_disk_id\', and \'swap_disk_id\'.'
)
disklist = '{0},{1}'.format(root_disk_id, swap_disk_id)
if data_disk_id is not None:
disklist = '{0},{1},{2}'.format(root_disk_id, swap_disk_id, data_disk_id)
config_args = {'LinodeID': linode_id,
'KernelID': kernel_id,
'Label': name,
'DiskList': disklist
}
result = _query('linode', 'config.create', args=config_args)
return _clean_data(result) | python | def create_config(kwargs=None, call=None):
'''
Creates a Linode Configuration Profile.
name
The name of the VM to create the config for.
linode_id
The ID of the Linode to create the configuration for.
root_disk_id
The Root Disk ID to be used for this config.
swap_disk_id
The Swap Disk ID to be used for this config.
data_disk_id
The Data Disk ID to be used for this config.
.. versionadded:: 2016.3.0
kernel_id
The ID of the kernel to use for this configuration profile.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The create_config function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
root_disk_id = kwargs.get('root_disk_id', None)
swap_disk_id = kwargs.get('swap_disk_id', None)
data_disk_id = kwargs.get('data_disk_id', None)
kernel_id = kwargs.get('kernel_id', None)
if kernel_id is None:
# 138 appears to always be the latest 64-bit kernel for Linux
kernel_id = 138
required_params = [name, linode_id, root_disk_id, swap_disk_id]
for item in required_params:
if item is None:
raise SaltCloudSystemExit(
'The create_config functions requires a \'name\', \'linode_id\', '
'\'root_disk_id\', and \'swap_disk_id\'.'
)
disklist = '{0},{1}'.format(root_disk_id, swap_disk_id)
if data_disk_id is not None:
disklist = '{0},{1},{2}'.format(root_disk_id, swap_disk_id, data_disk_id)
config_args = {'LinodeID': linode_id,
'KernelID': kernel_id,
'Label': name,
'DiskList': disklist
}
result = _query('linode', 'config.create', args=config_args)
return _clean_data(result) | [
"def",
"create_config",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The create_config function must be called with -f or --function.'",
")",
"if",
"kwargs",
"is",
"None",... | Creates a Linode Configuration Profile.
name
The name of the VM to create the config for.
linode_id
The ID of the Linode to create the configuration for.
root_disk_id
The Root Disk ID to be used for this config.
swap_disk_id
The Swap Disk ID to be used for this config.
data_disk_id
The Data Disk ID to be used for this config.
.. versionadded:: 2016.3.0
kernel_id
The ID of the kernel to use for this configuration profile. | [
"Creates",
"a",
"Linode",
"Configuration",
"Profile",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L540-L603 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create_disk_from_distro | def create_disk_from_distro(vm_, linode_id, swap_size=None):
r'''
Creates the disk for the Linode from the distribution.
vm\_
The VM profile to create the disk for.
linode_id
The ID of the Linode to create the distribution disk for. Required.
swap_size
The size of the disk, in MB.
'''
kwargs = {}
if swap_size is None:
swap_size = get_swap_size(vm_)
pub_key = get_pub_key(vm_)
root_password = get_password(vm_)
if pub_key:
kwargs.update({'rootSSHKey': pub_key})
if root_password:
kwargs.update({'rootPass': root_password})
else:
raise SaltCloudConfigError(
'The Linode driver requires a password.'
)
kwargs.update({'LinodeID': linode_id,
'DistributionID': get_distribution_id(vm_),
'Label': vm_['name'],
'Size': get_disk_size(vm_, swap_size, linode_id)})
result = _query('linode', 'disk.createfromdistribution', args=kwargs)
return _clean_data(result) | python | def create_disk_from_distro(vm_, linode_id, swap_size=None):
r'''
Creates the disk for the Linode from the distribution.
vm\_
The VM profile to create the disk for.
linode_id
The ID of the Linode to create the distribution disk for. Required.
swap_size
The size of the disk, in MB.
'''
kwargs = {}
if swap_size is None:
swap_size = get_swap_size(vm_)
pub_key = get_pub_key(vm_)
root_password = get_password(vm_)
if pub_key:
kwargs.update({'rootSSHKey': pub_key})
if root_password:
kwargs.update({'rootPass': root_password})
else:
raise SaltCloudConfigError(
'The Linode driver requires a password.'
)
kwargs.update({'LinodeID': linode_id,
'DistributionID': get_distribution_id(vm_),
'Label': vm_['name'],
'Size': get_disk_size(vm_, swap_size, linode_id)})
result = _query('linode', 'disk.createfromdistribution', args=kwargs)
return _clean_data(result) | [
"def",
"create_disk_from_distro",
"(",
"vm_",
",",
"linode_id",
",",
"swap_size",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"}",
"if",
"swap_size",
"is",
"None",
":",
"swap_size",
"=",
"get_swap_size",
"(",
"vm_",
")",
"pub_key",
"=",
"get_pub_key",
"(",
... | r'''
Creates the disk for the Linode from the distribution.
vm\_
The VM profile to create the disk for.
linode_id
The ID of the Linode to create the distribution disk for. Required.
swap_size
The size of the disk, in MB. | [
"r",
"Creates",
"the",
"disk",
"for",
"the",
"Linode",
"from",
"the",
"distribution",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L606-L644 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create_swap_disk | def create_swap_disk(vm_, linode_id, swap_size=None):
r'''
Creates the disk for the specified Linode.
vm\_
The VM profile to create the swap disk for.
linode_id
The ID of the Linode to create the swap disk for.
swap_size
The size of the disk, in MB.
'''
kwargs = {}
if not swap_size:
swap_size = get_swap_size(vm_)
kwargs.update({'LinodeID': linode_id,
'Label': vm_['name'],
'Type': 'swap',
'Size': swap_size
})
result = _query('linode', 'disk.create', args=kwargs)
return _clean_data(result) | python | def create_swap_disk(vm_, linode_id, swap_size=None):
r'''
Creates the disk for the specified Linode.
vm\_
The VM profile to create the swap disk for.
linode_id
The ID of the Linode to create the swap disk for.
swap_size
The size of the disk, in MB.
'''
kwargs = {}
if not swap_size:
swap_size = get_swap_size(vm_)
kwargs.update({'LinodeID': linode_id,
'Label': vm_['name'],
'Type': 'swap',
'Size': swap_size
})
result = _query('linode', 'disk.create', args=kwargs)
return _clean_data(result) | [
"def",
"create_swap_disk",
"(",
"vm_",
",",
"linode_id",
",",
"swap_size",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"}",
"if",
"not",
"swap_size",
":",
"swap_size",
"=",
"get_swap_size",
"(",
"vm_",
")",
"kwargs",
".",
"update",
"(",
"{",
"'LinodeID'",... | r'''
Creates the disk for the specified Linode.
vm\_
The VM profile to create the swap disk for.
linode_id
The ID of the Linode to create the swap disk for.
swap_size
The size of the disk, in MB. | [
"r",
"Creates",
"the",
"disk",
"for",
"the",
"specified",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L647-L673 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create_data_disk | def create_data_disk(vm_=None, linode_id=None, data_size=None):
r'''
Create a data disk for the linode (type is hardcoded to ext4 at the moment)
.. versionadded:: 2016.3.0
vm\_
The VM profile to create the data disk for.
linode_id
The ID of the Linode to create the data disk for.
data_size
The size of the disk, in MB.
'''
kwargs = {}
kwargs.update({'LinodeID': linode_id,
'Label': vm_['name']+"_data",
'Type': 'ext4',
'Size': data_size
})
result = _query('linode', 'disk.create', args=kwargs)
return _clean_data(result) | python | def create_data_disk(vm_=None, linode_id=None, data_size=None):
r'''
Create a data disk for the linode (type is hardcoded to ext4 at the moment)
.. versionadded:: 2016.3.0
vm\_
The VM profile to create the data disk for.
linode_id
The ID of the Linode to create the data disk for.
data_size
The size of the disk, in MB.
'''
kwargs = {}
kwargs.update({'LinodeID': linode_id,
'Label': vm_['name']+"_data",
'Type': 'ext4',
'Size': data_size
})
result = _query('linode', 'disk.create', args=kwargs)
return _clean_data(result) | [
"def",
"create_data_disk",
"(",
"vm_",
"=",
"None",
",",
"linode_id",
"=",
"None",
",",
"data_size",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"}",
"kwargs",
".",
"update",
"(",
"{",
"'LinodeID'",
":",
"linode_id",
",",
"'Label'",
":",
"vm_",
"[",
"... | r'''
Create a data disk for the linode (type is hardcoded to ext4 at the moment)
.. versionadded:: 2016.3.0
vm\_
The VM profile to create the data disk for.
linode_id
The ID of the Linode to create the data disk for.
data_size
The size of the disk, in MB. | [
"r",
"Create",
"a",
"data",
"disk",
"for",
"the",
"linode",
"(",
"type",
"is",
"hardcoded",
"to",
"ext4",
"at",
"the",
"moment",
")"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L676-L701 | train |
saltstack/salt | salt/cloud/clouds/linode.py | create_private_ip | def create_private_ip(linode_id):
r'''
Creates a private IP for the specified Linode.
linode_id
The ID of the Linode to create the IP address for.
'''
kwargs = {'LinodeID': linode_id}
result = _query('linode', 'ip.addprivate', args=kwargs)
return _clean_data(result) | python | def create_private_ip(linode_id):
r'''
Creates a private IP for the specified Linode.
linode_id
The ID of the Linode to create the IP address for.
'''
kwargs = {'LinodeID': linode_id}
result = _query('linode', 'ip.addprivate', args=kwargs)
return _clean_data(result) | [
"def",
"create_private_ip",
"(",
"linode_id",
")",
":",
"kwargs",
"=",
"{",
"'LinodeID'",
":",
"linode_id",
"}",
"result",
"=",
"_query",
"(",
"'linode'",
",",
"'ip.addprivate'",
",",
"args",
"=",
"kwargs",
")",
"return",
"_clean_data",
"(",
"result",
")"
] | r'''
Creates a private IP for the specified Linode.
linode_id
The ID of the Linode to create the IP address for. | [
"r",
"Creates",
"a",
"private",
"IP",
"for",
"the",
"specified",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L704-L714 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_config_id | def get_config_id(kwargs=None, call=None):
'''
Returns a config_id for a given linode.
.. versionadded:: 2015.8.0
name
The name of the Linode for which to get the config_id. Can be used instead
of ``linode_id``.h
linode_id
The ID of the Linode for which to get the config_id. Can be used instead
of ``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_config_id my-linode-config name=my-linode
salt-cloud -f get_config_id my-linode-config linode_id=1234567
'''
if call == 'action':
raise SaltCloudException(
'The get_config_id function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The get_config_id function requires either a \'name\' or a \'linode_id\' '
'to be provided.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
response = _query('linode', 'config.list', args={'LinodeID': linode_id})['DATA']
config_id = {'config_id': response[0]['ConfigID']}
return config_id | python | def get_config_id(kwargs=None, call=None):
'''
Returns a config_id for a given linode.
.. versionadded:: 2015.8.0
name
The name of the Linode for which to get the config_id. Can be used instead
of ``linode_id``.h
linode_id
The ID of the Linode for which to get the config_id. Can be used instead
of ``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_config_id my-linode-config name=my-linode
salt-cloud -f get_config_id my-linode-config linode_id=1234567
'''
if call == 'action':
raise SaltCloudException(
'The get_config_id function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The get_config_id function requires either a \'name\' or a \'linode_id\' '
'to be provided.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
response = _query('linode', 'config.list', args={'LinodeID': linode_id})['DATA']
config_id = {'config_id': response[0]['ConfigID']}
return config_id | [
"def",
"get_config_id",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The get_config_id function must be called with -f or --function.'",
")",
"if",
"kwargs",
"is",
"None",
... | Returns a config_id for a given linode.
.. versionadded:: 2015.8.0
name
The name of the Linode for which to get the config_id. Can be used instead
of ``linode_id``.h
linode_id
The ID of the Linode for which to get the config_id. Can be used instead
of ``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_config_id my-linode-config name=my-linode
salt-cloud -f get_config_id my-linode-config linode_id=1234567 | [
"Returns",
"a",
"config_id",
"for",
"a",
"given",
"linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L764-L806 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_disk_size | def get_disk_size(vm_, swap, linode_id):
r'''
Returns the size of of the root disk in MB.
vm\_
The VM to get the disk size for.
'''
disk_size = get_linode(kwargs={'linode_id': linode_id})['TOTALHD']
return config.get_cloud_config_value(
'disk_size', vm_, __opts__, default=disk_size - swap
) | python | def get_disk_size(vm_, swap, linode_id):
r'''
Returns the size of of the root disk in MB.
vm\_
The VM to get the disk size for.
'''
disk_size = get_linode(kwargs={'linode_id': linode_id})['TOTALHD']
return config.get_cloud_config_value(
'disk_size', vm_, __opts__, default=disk_size - swap
) | [
"def",
"get_disk_size",
"(",
"vm_",
",",
"swap",
",",
"linode_id",
")",
":",
"disk_size",
"=",
"get_linode",
"(",
"kwargs",
"=",
"{",
"'linode_id'",
":",
"linode_id",
"}",
")",
"[",
"'TOTALHD'",
"]",
"return",
"config",
".",
"get_cloud_config_value",
"(",
... | r'''
Returns the size of of the root disk in MB.
vm\_
The VM to get the disk size for. | [
"r",
"Returns",
"the",
"size",
"of",
"of",
"the",
"root",
"disk",
"in",
"MB",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L820-L830 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_data_disk_size | def get_data_disk_size(vm_, swap, linode_id):
'''
Return the size of of the data disk in MB
.. versionadded:: 2016.3.0
'''
disk_size = get_linode(kwargs={'linode_id': linode_id})['TOTALHD']
root_disk_size = config.get_cloud_config_value(
'disk_size', vm_, __opts__, default=disk_size - swap
)
return disk_size - root_disk_size - swap | python | def get_data_disk_size(vm_, swap, linode_id):
'''
Return the size of of the data disk in MB
.. versionadded:: 2016.3.0
'''
disk_size = get_linode(kwargs={'linode_id': linode_id})['TOTALHD']
root_disk_size = config.get_cloud_config_value(
'disk_size', vm_, __opts__, default=disk_size - swap
)
return disk_size - root_disk_size - swap | [
"def",
"get_data_disk_size",
"(",
"vm_",
",",
"swap",
",",
"linode_id",
")",
":",
"disk_size",
"=",
"get_linode",
"(",
"kwargs",
"=",
"{",
"'linode_id'",
":",
"linode_id",
"}",
")",
"[",
"'TOTALHD'",
"]",
"root_disk_size",
"=",
"config",
".",
"get_cloud_conf... | Return the size of of the data disk in MB
.. versionadded:: 2016.3.0 | [
"Return",
"the",
"size",
"of",
"of",
"the",
"data",
"disk",
"in",
"MB"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L833-L843 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_distribution_id | def get_distribution_id(vm_):
r'''
Returns the distribution ID for a VM
vm\_
The VM to get the distribution ID for
'''
distributions = _query('avail', 'distributions')['DATA']
vm_image_name = config.get_cloud_config_value('image', vm_, __opts__)
distro_id = ''
for distro in distributions:
if vm_image_name == distro['LABEL']:
distro_id = distro['DISTRIBUTIONID']
return distro_id
if not distro_id:
raise SaltCloudNotFound(
'The DistributionID for the \'{0}\' profile could not be found.\n'
'The \'{1}\' instance could not be provisioned. The following distributions '
'are available:\n{2}'.format(
vm_image_name,
vm_['name'],
pprint.pprint(sorted([distro['LABEL'].encode(__salt_system_encoding__) for distro in distributions]))
)
) | python | def get_distribution_id(vm_):
r'''
Returns the distribution ID for a VM
vm\_
The VM to get the distribution ID for
'''
distributions = _query('avail', 'distributions')['DATA']
vm_image_name = config.get_cloud_config_value('image', vm_, __opts__)
distro_id = ''
for distro in distributions:
if vm_image_name == distro['LABEL']:
distro_id = distro['DISTRIBUTIONID']
return distro_id
if not distro_id:
raise SaltCloudNotFound(
'The DistributionID for the \'{0}\' profile could not be found.\n'
'The \'{1}\' instance could not be provisioned. The following distributions '
'are available:\n{2}'.format(
vm_image_name,
vm_['name'],
pprint.pprint(sorted([distro['LABEL'].encode(__salt_system_encoding__) for distro in distributions]))
)
) | [
"def",
"get_distribution_id",
"(",
"vm_",
")",
":",
"distributions",
"=",
"_query",
"(",
"'avail'",
",",
"'distributions'",
")",
"[",
"'DATA'",
"]",
"vm_image_name",
"=",
"config",
".",
"get_cloud_config_value",
"(",
"'image'",
",",
"vm_",
",",
"__opts__",
")"... | r'''
Returns the distribution ID for a VM
vm\_
The VM to get the distribution ID for | [
"r",
"Returns",
"the",
"distribution",
"ID",
"for",
"a",
"VM"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L846-L872 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_ips | def get_ips(linode_id=None):
'''
Returns public and private IP addresses.
linode_id
Limits the IP addresses returned to the specified Linode ID.
'''
if linode_id:
ips = _query('linode', 'ip.list', args={'LinodeID': linode_id})
else:
ips = _query('linode', 'ip.list')
ips = ips['DATA']
ret = {}
for item in ips:
node_id = six.text_type(item['LINODEID'])
if item['ISPUBLIC'] == 1:
key = 'public_ips'
else:
key = 'private_ips'
if ret.get(node_id) is None:
ret.update({node_id: {'public_ips': [], 'private_ips': []}})
ret[node_id][key].append(item['IPADDRESS'])
# If linode_id was specified, only return the ips, and not the
# dictionary based on the linode ID as a key.
if linode_id:
_all_ips = {'public_ips': [], 'private_ips': []}
matching_id = ret.get(six.text_type(linode_id))
if matching_id:
_all_ips['private_ips'] = matching_id['private_ips']
_all_ips['public_ips'] = matching_id['public_ips']
ret = _all_ips
return ret | python | def get_ips(linode_id=None):
'''
Returns public and private IP addresses.
linode_id
Limits the IP addresses returned to the specified Linode ID.
'''
if linode_id:
ips = _query('linode', 'ip.list', args={'LinodeID': linode_id})
else:
ips = _query('linode', 'ip.list')
ips = ips['DATA']
ret = {}
for item in ips:
node_id = six.text_type(item['LINODEID'])
if item['ISPUBLIC'] == 1:
key = 'public_ips'
else:
key = 'private_ips'
if ret.get(node_id) is None:
ret.update({node_id: {'public_ips': [], 'private_ips': []}})
ret[node_id][key].append(item['IPADDRESS'])
# If linode_id was specified, only return the ips, and not the
# dictionary based on the linode ID as a key.
if linode_id:
_all_ips = {'public_ips': [], 'private_ips': []}
matching_id = ret.get(six.text_type(linode_id))
if matching_id:
_all_ips['private_ips'] = matching_id['private_ips']
_all_ips['public_ips'] = matching_id['public_ips']
ret = _all_ips
return ret | [
"def",
"get_ips",
"(",
"linode_id",
"=",
"None",
")",
":",
"if",
"linode_id",
":",
"ips",
"=",
"_query",
"(",
"'linode'",
",",
"'ip.list'",
",",
"args",
"=",
"{",
"'LinodeID'",
":",
"linode_id",
"}",
")",
"else",
":",
"ips",
"=",
"_query",
"(",
"'lin... | Returns public and private IP addresses.
linode_id
Limits the IP addresses returned to the specified Linode ID. | [
"Returns",
"public",
"and",
"private",
"IP",
"addresses",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L875-L912 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_linode | def get_linode(kwargs=None, call=None):
'''
Returns data for a single named Linode.
name
The name of the Linode for which to get data. Can be used instead
``linode_id``. Note this will induce an additional API call
compared to using ``linode_id``.
linode_id
The ID of the Linode for which to get data. Can be used instead of
``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_linode my-linode-config name=my-instance
salt-cloud -f get_linode my-linode-config linode_id=1234567
'''
if call == 'action':
raise SaltCloudSystemExit(
'The get_linode function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The get_linode function requires either a \'name\' or a \'linode_id\'.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
result = _query('linode', 'list', args={'LinodeID': linode_id})
return result['DATA'][0] | python | def get_linode(kwargs=None, call=None):
'''
Returns data for a single named Linode.
name
The name of the Linode for which to get data. Can be used instead
``linode_id``. Note this will induce an additional API call
compared to using ``linode_id``.
linode_id
The ID of the Linode for which to get data. Can be used instead of
``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_linode my-linode-config name=my-instance
salt-cloud -f get_linode my-linode-config linode_id=1234567
'''
if call == 'action':
raise SaltCloudSystemExit(
'The get_linode function must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
name = kwargs.get('name', None)
linode_id = kwargs.get('linode_id', None)
if name is None and linode_id is None:
raise SaltCloudSystemExit(
'The get_linode function requires either a \'name\' or a \'linode_id\'.'
)
if linode_id is None:
linode_id = get_linode_id_from_name(name)
result = _query('linode', 'list', args={'LinodeID': linode_id})
return result['DATA'][0] | [
"def",
"get_linode",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The get_linode function must be called with -f or --function.'",
")",
"if",
"kwargs",
"is",
"None",
":"... | Returns data for a single named Linode.
name
The name of the Linode for which to get data. Can be used instead
``linode_id``. Note this will induce an additional API call
compared to using ``linode_id``.
linode_id
The ID of the Linode for which to get data. Can be used instead of
``name``.
CLI Example:
.. code-block:: bash
salt-cloud -f get_linode my-linode-config name=my-instance
salt-cloud -f get_linode my-linode-config linode_id=1234567 | [
"Returns",
"data",
"for",
"a",
"single",
"named",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L915-L955 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_linode_id_from_name | def get_linode_id_from_name(name):
'''
Returns the Linode ID for a VM from the provided name.
name
The name of the Linode from which to get the Linode ID. Required.
'''
nodes = _query('linode', 'list')['DATA']
linode_id = ''
for node in nodes:
if name == node['LABEL']:
linode_id = node['LINODEID']
return linode_id
if not linode_id:
raise SaltCloudNotFound(
'The specified name, {0}, could not be found.'.format(name)
) | python | def get_linode_id_from_name(name):
'''
Returns the Linode ID for a VM from the provided name.
name
The name of the Linode from which to get the Linode ID. Required.
'''
nodes = _query('linode', 'list')['DATA']
linode_id = ''
for node in nodes:
if name == node['LABEL']:
linode_id = node['LINODEID']
return linode_id
if not linode_id:
raise SaltCloudNotFound(
'The specified name, {0}, could not be found.'.format(name)
) | [
"def",
"get_linode_id_from_name",
"(",
"name",
")",
":",
"nodes",
"=",
"_query",
"(",
"'linode'",
",",
"'list'",
")",
"[",
"'DATA'",
"]",
"linode_id",
"=",
"''",
"for",
"node",
"in",
"nodes",
":",
"if",
"name",
"==",
"node",
"[",
"'LABEL'",
"]",
":",
... | Returns the Linode ID for a VM from the provided name.
name
The name of the Linode from which to get the Linode ID. Required. | [
"Returns",
"the",
"Linode",
"ID",
"for",
"a",
"VM",
"from",
"the",
"provided",
"name",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L958-L976 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_password | def get_password(vm_):
r'''
Return the password to use for a VM.
vm\_
The configuration to obtain the password from.
'''
return config.get_cloud_config_value(
'password', vm_, __opts__,
default=config.get_cloud_config_value(
'passwd', vm_, __opts__,
search_global=False
),
search_global=False
) | python | def get_password(vm_):
r'''
Return the password to use for a VM.
vm\_
The configuration to obtain the password from.
'''
return config.get_cloud_config_value(
'password', vm_, __opts__,
default=config.get_cloud_config_value(
'passwd', vm_, __opts__,
search_global=False
),
search_global=False
) | [
"def",
"get_password",
"(",
"vm_",
")",
":",
"return",
"config",
".",
"get_cloud_config_value",
"(",
"'password'",
",",
"vm_",
",",
"__opts__",
",",
"default",
"=",
"config",
".",
"get_cloud_config_value",
"(",
"'passwd'",
",",
"vm_",
",",
"__opts__",
",",
"... | r'''
Return the password to use for a VM.
vm\_
The configuration to obtain the password from. | [
"r",
"Return",
"the",
"password",
"to",
"use",
"for",
"a",
"VM",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L979-L993 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _decode_linode_plan_label | def _decode_linode_plan_label(label):
'''
Attempts to decode a user-supplied Linode plan label
into the format in Linode API output
label
The label, or name, of the plan to decode.
Example:
`Linode 2048` will decode to `Linode 2GB`
'''
sizes = avail_sizes()
if label not in sizes:
if 'GB' in label:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(label)
)
else:
plan = label.split()
if len(plan) != 2:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(label)
)
plan_type = plan[0]
try:
plan_size = int(plan[1])
except TypeError:
plan_size = 0
log.debug('Failed to decode Linode plan label in Cloud Profile: %s', label)
if plan_type == 'Linode' and plan_size == 1024:
plan_type = 'Nanode'
plan_size = plan_size/1024
new_label = "{} {}GB".format(plan_type, plan_size)
if new_label not in sizes:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(new_label)
)
log.warning(
'An outdated Linode plan label was detected in your Cloud '
'Profile (%s). Please update the profile to use the new '
'label format (%s) for the requested Linode plan size.',
label, new_label
)
label = new_label
return sizes[label]['PLANID'] | python | def _decode_linode_plan_label(label):
'''
Attempts to decode a user-supplied Linode plan label
into the format in Linode API output
label
The label, or name, of the plan to decode.
Example:
`Linode 2048` will decode to `Linode 2GB`
'''
sizes = avail_sizes()
if label not in sizes:
if 'GB' in label:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(label)
)
else:
plan = label.split()
if len(plan) != 2:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(label)
)
plan_type = plan[0]
try:
plan_size = int(plan[1])
except TypeError:
plan_size = 0
log.debug('Failed to decode Linode plan label in Cloud Profile: %s', label)
if plan_type == 'Linode' and plan_size == 1024:
plan_type = 'Nanode'
plan_size = plan_size/1024
new_label = "{} {}GB".format(plan_type, plan_size)
if new_label not in sizes:
raise SaltCloudException(
'Invalid Linode plan ({}) specified - call avail_sizes() for all available options'.format(new_label)
)
log.warning(
'An outdated Linode plan label was detected in your Cloud '
'Profile (%s). Please update the profile to use the new '
'label format (%s) for the requested Linode plan size.',
label, new_label
)
label = new_label
return sizes[label]['PLANID'] | [
"def",
"_decode_linode_plan_label",
"(",
"label",
")",
":",
"sizes",
"=",
"avail_sizes",
"(",
")",
"if",
"label",
"not",
"in",
"sizes",
":",
"if",
"'GB'",
"in",
"label",
":",
"raise",
"SaltCloudException",
"(",
"'Invalid Linode plan ({}) specified - call avail_sizes... | Attempts to decode a user-supplied Linode plan label
into the format in Linode API output
label
The label, or name, of the plan to decode.
Example:
`Linode 2048` will decode to `Linode 2GB` | [
"Attempts",
"to",
"decode",
"a",
"user",
"-",
"supplied",
"Linode",
"plan",
"label",
"into",
"the",
"format",
"in",
"Linode",
"API",
"output"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L996-L1049 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_plan_id | def get_plan_id(kwargs=None, call=None):
'''
Returns the Linode Plan ID.
label
The label, or name, of the plan to get the ID from.
CLI Example:
.. code-block:: bash
salt-cloud -f get_plan_id linode label="Linode 1024"
'''
if call == 'action':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
label = kwargs.get('label', None)
if label is None:
raise SaltCloudException(
'The get_plan_id function requires a \'label\'.'
)
label = _decode_linode_plan_label(label)
return label | python | def get_plan_id(kwargs=None, call=None):
'''
Returns the Linode Plan ID.
label
The label, or name, of the plan to get the ID from.
CLI Example:
.. code-block:: bash
salt-cloud -f get_plan_id linode label="Linode 1024"
'''
if call == 'action':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
label = kwargs.get('label', None)
if label is None:
raise SaltCloudException(
'The get_plan_id function requires a \'label\'.'
)
label = _decode_linode_plan_label(label)
return label | [
"def",
"get_plan_id",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The show_instance action must be called with -f or --function.'",
")",
"if",
"kwargs",
"is",
"None",
":... | Returns the Linode Plan ID.
label
The label, or name, of the plan to get the ID from.
CLI Example:
.. code-block:: bash
salt-cloud -f get_plan_id linode label="Linode 1024" | [
"Returns",
"the",
"Linode",
"Plan",
"ID",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1052-L1081 | train |
saltstack/salt | salt/cloud/clouds/linode.py | get_vm_size | def get_vm_size(vm_):
r'''
Returns the VM's size.
vm\_
The VM to get the size for.
'''
vm_size = config.get_cloud_config_value('size', vm_, __opts__)
ram = avail_sizes()[vm_size]['RAM']
if vm_size.startswith('Linode'):
vm_size = vm_size.replace('Linode ', '')
if ram == int(vm_size):
return ram
else:
raise SaltCloudNotFound(
'The specified size, {0}, could not be found.'.format(vm_size)
) | python | def get_vm_size(vm_):
r'''
Returns the VM's size.
vm\_
The VM to get the size for.
'''
vm_size = config.get_cloud_config_value('size', vm_, __opts__)
ram = avail_sizes()[vm_size]['RAM']
if vm_size.startswith('Linode'):
vm_size = vm_size.replace('Linode ', '')
if ram == int(vm_size):
return ram
else:
raise SaltCloudNotFound(
'The specified size, {0}, could not be found.'.format(vm_size)
) | [
"def",
"get_vm_size",
"(",
"vm_",
")",
":",
"vm_size",
"=",
"config",
".",
"get_cloud_config_value",
"(",
"'size'",
",",
"vm_",
",",
"__opts__",
")",
"ram",
"=",
"avail_sizes",
"(",
")",
"[",
"vm_size",
"]",
"[",
"'RAM'",
"]",
"if",
"vm_size",
".",
"st... | r'''
Returns the VM's size.
vm\_
The VM to get the size for. | [
"r",
"Returns",
"the",
"VM",
"s",
"size",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1128-L1146 | train |
saltstack/salt | salt/cloud/clouds/linode.py | list_nodes_min | def list_nodes_min(call=None):
'''
Return a list of the VMs that are on the provider. Only a list of VM names and
their state is returned. This is the minimum amount of information needed to
check for existing VMs.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f list_nodes_min my-linode-config
salt-cloud --function list_nodes_min my-linode-config
'''
if call == 'action':
raise SaltCloudSystemExit(
'The list_nodes_min function must be called with -f or --function.'
)
ret = {}
nodes = _query('linode', 'list')['DATA']
for node in nodes:
name = node['LABEL']
this_node = {
'id': six.text_type(node['LINODEID']),
'state': _get_status_descr_by_id(int(node['STATUS']))
}
ret[name] = this_node
return ret | python | def list_nodes_min(call=None):
'''
Return a list of the VMs that are on the provider. Only a list of VM names and
their state is returned. This is the minimum amount of information needed to
check for existing VMs.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f list_nodes_min my-linode-config
salt-cloud --function list_nodes_min my-linode-config
'''
if call == 'action':
raise SaltCloudSystemExit(
'The list_nodes_min function must be called with -f or --function.'
)
ret = {}
nodes = _query('linode', 'list')['DATA']
for node in nodes:
name = node['LABEL']
this_node = {
'id': six.text_type(node['LINODEID']),
'state': _get_status_descr_by_id(int(node['STATUS']))
}
ret[name] = this_node
return ret | [
"def",
"list_nodes_min",
"(",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The list_nodes_min function must be called with -f or --function.'",
")",
"ret",
"=",
"{",
"}",
"nodes",
"=",
"_query",
"(",
"'... | Return a list of the VMs that are on the provider. Only a list of VM names and
their state is returned. This is the minimum amount of information needed to
check for existing VMs.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f list_nodes_min my-linode-config
salt-cloud --function list_nodes_min my-linode-config | [
"Return",
"a",
"list",
"of",
"the",
"VMs",
"that",
"are",
"on",
"the",
"provider",
".",
"Only",
"a",
"list",
"of",
"VM",
"names",
"and",
"their",
"state",
"is",
"returned",
".",
"This",
"is",
"the",
"minimum",
"amount",
"of",
"information",
"needed",
"... | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1199-L1231 | train |
saltstack/salt | salt/cloud/clouds/linode.py | reboot | def reboot(name, call=None):
'''
Reboot a linode.
.. versionadded:: 2015.8.0
name
The name of the VM to reboot.
CLI Example:
.. code-block:: bash
salt-cloud -a reboot vm_name
'''
if call != 'action':
raise SaltCloudException(
'The show_instance action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
response = _query('linode', 'reboot', args={'LinodeID': node_id})
data = _clean_data(response)
reboot_jid = data['JobID']
if not _wait_for_job(node_id, reboot_jid):
log.error('Reboot failed for %s.', name)
return False
return data | python | def reboot(name, call=None):
'''
Reboot a linode.
.. versionadded:: 2015.8.0
name
The name of the VM to reboot.
CLI Example:
.. code-block:: bash
salt-cloud -a reboot vm_name
'''
if call != 'action':
raise SaltCloudException(
'The show_instance action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
response = _query('linode', 'reboot', args={'LinodeID': node_id})
data = _clean_data(response)
reboot_jid = data['JobID']
if not _wait_for_job(node_id, reboot_jid):
log.error('Reboot failed for %s.', name)
return False
return data | [
"def",
"reboot",
"(",
"name",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"!=",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The show_instance action must be called with -a or --action.'",
")",
"node_id",
"=",
"get_linode_id_from_name",
"(",
"name",
... | Reboot a linode.
.. versionadded:: 2015.8.0
name
The name of the VM to reboot.
CLI Example:
.. code-block:: bash
salt-cloud -a reboot vm_name | [
"Reboot",
"a",
"linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1243-L1272 | train |
saltstack/salt | salt/cloud/clouds/linode.py | show_instance | def show_instance(name, call=None):
'''
Displays details about a particular Linode VM. Either a name or a linode_id must
be provided.
.. versionadded:: 2015.8.0
name
The name of the VM for which to display details.
CLI Example:
.. code-block:: bash
salt-cloud -a show_instance vm_name
.. note::
The ``image`` label only displays information about the VM's distribution vendor,
such as "Debian" or "RHEL" and does not display the actual image name. This is
due to a limitation of the Linode API.
'''
if call != 'action':
raise SaltCloudException(
'The show_instance action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
node_data = get_linode(kwargs={'linode_id': node_id})
ips = get_ips(node_id)
state = int(node_data['STATUS'])
ret = {'id': node_data['LINODEID'],
'image': node_data['DISTRIBUTIONVENDOR'],
'name': node_data['LABEL'],
'size': node_data['TOTALRAM'],
'state': _get_status_descr_by_id(state),
'private_ips': ips['private_ips'],
'public_ips': ips['public_ips']}
return ret | python | def show_instance(name, call=None):
'''
Displays details about a particular Linode VM. Either a name or a linode_id must
be provided.
.. versionadded:: 2015.8.0
name
The name of the VM for which to display details.
CLI Example:
.. code-block:: bash
salt-cloud -a show_instance vm_name
.. note::
The ``image`` label only displays information about the VM's distribution vendor,
such as "Debian" or "RHEL" and does not display the actual image name. This is
due to a limitation of the Linode API.
'''
if call != 'action':
raise SaltCloudException(
'The show_instance action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
node_data = get_linode(kwargs={'linode_id': node_id})
ips = get_ips(node_id)
state = int(node_data['STATUS'])
ret = {'id': node_data['LINODEID'],
'image': node_data['DISTRIBUTIONVENDOR'],
'name': node_data['LABEL'],
'size': node_data['TOTALRAM'],
'state': _get_status_descr_by_id(state),
'private_ips': ips['private_ips'],
'public_ips': ips['public_ips']}
return ret | [
"def",
"show_instance",
"(",
"name",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"!=",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The show_instance action must be called with -a or --action.'",
")",
"node_id",
"=",
"get_linode_id_from_name",
"(",
"na... | Displays details about a particular Linode VM. Either a name or a linode_id must
be provided.
.. versionadded:: 2015.8.0
name
The name of the VM for which to display details.
CLI Example:
.. code-block:: bash
salt-cloud -a show_instance vm_name
.. note::
The ``image`` label only displays information about the VM's distribution vendor,
such as "Debian" or "RHEL" and does not display the actual image name. This is
due to a limitation of the Linode API. | [
"Displays",
"details",
"about",
"a",
"particular",
"Linode",
"VM",
".",
"Either",
"a",
"name",
"or",
"a",
"linode_id",
"must",
"be",
"provided",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1275-L1315 | train |
saltstack/salt | salt/cloud/clouds/linode.py | show_pricing | def show_pricing(kwargs=None, call=None):
'''
Show pricing for a particular profile. This is only an estimate, based on
unofficial pricing sources.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f show_pricing my-linode-config profile=my-linode-profile
'''
if call != 'function':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
profile = __opts__['profiles'].get(kwargs['profile'], {})
if not profile:
raise SaltCloudNotFound(
'The requested profile was not found.'
)
# Make sure the profile belongs to Linode
provider = profile.get('provider', '0:0')
comps = provider.split(':')
if len(comps) < 2 or comps[1] != 'linode':
raise SaltCloudException(
'The requested profile does not belong to Linode.'
)
plan_id = get_plan_id(kwargs={'label': profile['size']})
response = _query('avail', 'linodeplans', args={'PlanID': plan_id})['DATA'][0]
ret = {}
ret['per_hour'] = response['HOURLY']
ret['per_day'] = ret['per_hour'] * 24
ret['per_week'] = ret['per_day'] * 7
ret['per_month'] = response['PRICE']
ret['per_year'] = ret['per_month'] * 12
return {profile['profile']: ret} | python | def show_pricing(kwargs=None, call=None):
'''
Show pricing for a particular profile. This is only an estimate, based on
unofficial pricing sources.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f show_pricing my-linode-config profile=my-linode-profile
'''
if call != 'function':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
profile = __opts__['profiles'].get(kwargs['profile'], {})
if not profile:
raise SaltCloudNotFound(
'The requested profile was not found.'
)
# Make sure the profile belongs to Linode
provider = profile.get('provider', '0:0')
comps = provider.split(':')
if len(comps) < 2 or comps[1] != 'linode':
raise SaltCloudException(
'The requested profile does not belong to Linode.'
)
plan_id = get_plan_id(kwargs={'label': profile['size']})
response = _query('avail', 'linodeplans', args={'PlanID': plan_id})['DATA'][0]
ret = {}
ret['per_hour'] = response['HOURLY']
ret['per_day'] = ret['per_hour'] * 24
ret['per_week'] = ret['per_day'] * 7
ret['per_month'] = response['PRICE']
ret['per_year'] = ret['per_month'] * 12
return {profile['profile']: ret} | [
"def",
"show_pricing",
"(",
"kwargs",
"=",
"None",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"!=",
"'function'",
":",
"raise",
"SaltCloudException",
"(",
"'The show_instance action must be called with -f or --function.'",
")",
"profile",
"=",
"__opts__",
"["... | Show pricing for a particular profile. This is only an estimate, based on
unofficial pricing sources.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f show_pricing my-linode-config profile=my-linode-profile | [
"Show",
"pricing",
"for",
"a",
"particular",
"profile",
".",
"This",
"is",
"only",
"an",
"estimate",
"based",
"on",
"unofficial",
"pricing",
"sources",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1318-L1360 | train |
saltstack/salt | salt/cloud/clouds/linode.py | start | def start(name, call=None):
'''
Start a VM in Linode.
name
The name of the VM to start.
CLI Example:
.. code-block:: bash
salt-cloud -a stop vm_name
'''
if call != 'action':
raise SaltCloudException(
'The start action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
node = get_linode(kwargs={'linode_id': node_id})
if node['STATUS'] == 1:
return {'success': True,
'action': 'start',
'state': 'Running',
'msg': 'Machine already running'}
response = _query('linode', 'boot', args={'LinodeID': node_id})['DATA']
if _wait_for_job(node_id, response['JobID']):
return {'state': 'Running',
'action': 'start',
'success': True}
else:
return {'action': 'start',
'success': False} | python | def start(name, call=None):
'''
Start a VM in Linode.
name
The name of the VM to start.
CLI Example:
.. code-block:: bash
salt-cloud -a stop vm_name
'''
if call != 'action':
raise SaltCloudException(
'The start action must be called with -a or --action.'
)
node_id = get_linode_id_from_name(name)
node = get_linode(kwargs={'linode_id': node_id})
if node['STATUS'] == 1:
return {'success': True,
'action': 'start',
'state': 'Running',
'msg': 'Machine already running'}
response = _query('linode', 'boot', args={'LinodeID': node_id})['DATA']
if _wait_for_job(node_id, response['JobID']):
return {'state': 'Running',
'action': 'start',
'success': True}
else:
return {'action': 'start',
'success': False} | [
"def",
"start",
"(",
"name",
",",
"call",
"=",
"None",
")",
":",
"if",
"call",
"!=",
"'action'",
":",
"raise",
"SaltCloudException",
"(",
"'The start action must be called with -a or --action.'",
")",
"node_id",
"=",
"get_linode_id_from_name",
"(",
"name",
")",
"n... | Start a VM in Linode.
name
The name of the VM to start.
CLI Example:
.. code-block:: bash
salt-cloud -a stop vm_name | [
"Start",
"a",
"VM",
"in",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1363-L1398 | train |
saltstack/salt | salt/cloud/clouds/linode.py | update_linode | def update_linode(linode_id, update_args=None):
'''
Updates a Linode's properties.
linode_id
The ID of the Linode to shutdown. Required.
update_args
The args to update the Linode with. Must be in dictionary form.
'''
update_args.update({'LinodeID': linode_id})
result = _query('linode', 'update', args=update_args)
return _clean_data(result) | python | def update_linode(linode_id, update_args=None):
'''
Updates a Linode's properties.
linode_id
The ID of the Linode to shutdown. Required.
update_args
The args to update the Linode with. Must be in dictionary form.
'''
update_args.update({'LinodeID': linode_id})
result = _query('linode', 'update', args=update_args)
return _clean_data(result) | [
"def",
"update_linode",
"(",
"linode_id",
",",
"update_args",
"=",
"None",
")",
":",
"update_args",
".",
"update",
"(",
"{",
"'LinodeID'",
":",
"linode_id",
"}",
")",
"result",
"=",
"_query",
"(",
"'linode'",
",",
"'update'",
",",
"args",
"=",
"update_args... | Updates a Linode's properties.
linode_id
The ID of the Linode to shutdown. Required.
update_args
The args to update the Linode with. Must be in dictionary form. | [
"Updates",
"a",
"Linode",
"s",
"properties",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1438-L1452 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _clean_data | def _clean_data(api_response):
'''
Returns the DATA response from a Linode API query as a single pre-formatted dictionary
api_response
The query to be cleaned.
'''
data = {}
data.update(api_response['DATA'])
if not data:
response_data = api_response['DATA']
data.update(response_data)
return data | python | def _clean_data(api_response):
'''
Returns the DATA response from a Linode API query as a single pre-formatted dictionary
api_response
The query to be cleaned.
'''
data = {}
data.update(api_response['DATA'])
if not data:
response_data = api_response['DATA']
data.update(response_data)
return data | [
"def",
"_clean_data",
"(",
"api_response",
")",
":",
"data",
"=",
"{",
"}",
"data",
".",
"update",
"(",
"api_response",
"[",
"'DATA'",
"]",
")",
"if",
"not",
"data",
":",
"response_data",
"=",
"api_response",
"[",
"'DATA'",
"]",
"data",
".",
"update",
... | Returns the DATA response from a Linode API query as a single pre-formatted dictionary
api_response
The query to be cleaned. | [
"Returns",
"the",
"DATA",
"response",
"from",
"a",
"Linode",
"API",
"query",
"as",
"a",
"single",
"pre",
"-",
"formatted",
"dictionary"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1455-L1469 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _list_linodes | def _list_linodes(full=False):
'''
Helper function to format and parse linode data
'''
nodes = _query('linode', 'list')['DATA']
ips = get_ips()
ret = {}
for node in nodes:
this_node = {}
linode_id = six.text_type(node['LINODEID'])
this_node['id'] = linode_id
this_node['image'] = node['DISTRIBUTIONVENDOR']
this_node['name'] = node['LABEL']
this_node['size'] = node['TOTALRAM']
state = int(node['STATUS'])
this_node['state'] = _get_status_descr_by_id(state)
for key, val in six.iteritems(ips):
if key == linode_id:
this_node['private_ips'] = val['private_ips']
this_node['public_ips'] = val['public_ips']
if full:
this_node['extra'] = node
ret[node['LABEL']] = this_node
return ret | python | def _list_linodes(full=False):
'''
Helper function to format and parse linode data
'''
nodes = _query('linode', 'list')['DATA']
ips = get_ips()
ret = {}
for node in nodes:
this_node = {}
linode_id = six.text_type(node['LINODEID'])
this_node['id'] = linode_id
this_node['image'] = node['DISTRIBUTIONVENDOR']
this_node['name'] = node['LABEL']
this_node['size'] = node['TOTALRAM']
state = int(node['STATUS'])
this_node['state'] = _get_status_descr_by_id(state)
for key, val in six.iteritems(ips):
if key == linode_id:
this_node['private_ips'] = val['private_ips']
this_node['public_ips'] = val['public_ips']
if full:
this_node['extra'] = node
ret[node['LABEL']] = this_node
return ret | [
"def",
"_list_linodes",
"(",
"full",
"=",
"False",
")",
":",
"nodes",
"=",
"_query",
"(",
"'linode'",
",",
"'list'",
")",
"[",
"'DATA'",
"]",
"ips",
"=",
"get_ips",
"(",
")",
"ret",
"=",
"{",
"}",
"for",
"node",
"in",
"nodes",
":",
"this_node",
"="... | Helper function to format and parse linode data | [
"Helper",
"function",
"to",
"format",
"and",
"parse",
"linode",
"data"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1472-L1502 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _query | def _query(action=None,
command=None,
args=None,
method='GET',
header_dict=None,
data=None,
url='https://api.linode.com/'):
'''
Make a web call to the Linode API.
'''
global LASTCALL
vm_ = get_configured_provider()
ratelimit_sleep = config.get_cloud_config_value(
'ratelimit_sleep', vm_, __opts__, search_global=False, default=0,
)
apikey = config.get_cloud_config_value(
'apikey', vm_, __opts__, search_global=False
)
if not isinstance(args, dict):
args = {}
if 'api_key' not in args.keys():
args['api_key'] = apikey
if action and 'api_action' not in args.keys():
args['api_action'] = '{0}.{1}'.format(action, command)
if header_dict is None:
header_dict = {}
if method != 'POST':
header_dict['Accept'] = 'application/json'
decode = True
if method == 'DELETE':
decode = False
now = int(time.mktime(datetime.datetime.now().timetuple()))
if LASTCALL >= now:
time.sleep(ratelimit_sleep)
result = __utils__['http.query'](
url,
method,
params=args,
data=data,
header_dict=header_dict,
decode=decode,
decode_type='json',
text=True,
status=True,
hide_fields=['api_key', 'rootPass'],
opts=__opts__,
)
if 'ERRORARRAY' in result['dict']:
if result['dict']['ERRORARRAY']:
error_list = []
for error in result['dict']['ERRORARRAY']:
msg = error['ERRORMESSAGE']
if msg == "Authentication failed":
raise SaltCloudSystemExit(
'Linode API Key is expired or invalid'
)
else:
error_list.append(msg)
raise SaltCloudException(
'Linode API reported error(s): {}'.format(", ".join(error_list))
)
LASTCALL = int(time.mktime(datetime.datetime.now().timetuple()))
log.debug('Linode Response Status Code: %s', result['status'])
return result['dict'] | python | def _query(action=None,
command=None,
args=None,
method='GET',
header_dict=None,
data=None,
url='https://api.linode.com/'):
'''
Make a web call to the Linode API.
'''
global LASTCALL
vm_ = get_configured_provider()
ratelimit_sleep = config.get_cloud_config_value(
'ratelimit_sleep', vm_, __opts__, search_global=False, default=0,
)
apikey = config.get_cloud_config_value(
'apikey', vm_, __opts__, search_global=False
)
if not isinstance(args, dict):
args = {}
if 'api_key' not in args.keys():
args['api_key'] = apikey
if action and 'api_action' not in args.keys():
args['api_action'] = '{0}.{1}'.format(action, command)
if header_dict is None:
header_dict = {}
if method != 'POST':
header_dict['Accept'] = 'application/json'
decode = True
if method == 'DELETE':
decode = False
now = int(time.mktime(datetime.datetime.now().timetuple()))
if LASTCALL >= now:
time.sleep(ratelimit_sleep)
result = __utils__['http.query'](
url,
method,
params=args,
data=data,
header_dict=header_dict,
decode=decode,
decode_type='json',
text=True,
status=True,
hide_fields=['api_key', 'rootPass'],
opts=__opts__,
)
if 'ERRORARRAY' in result['dict']:
if result['dict']['ERRORARRAY']:
error_list = []
for error in result['dict']['ERRORARRAY']:
msg = error['ERRORMESSAGE']
if msg == "Authentication failed":
raise SaltCloudSystemExit(
'Linode API Key is expired or invalid'
)
else:
error_list.append(msg)
raise SaltCloudException(
'Linode API reported error(s): {}'.format(", ".join(error_list))
)
LASTCALL = int(time.mktime(datetime.datetime.now().timetuple()))
log.debug('Linode Response Status Code: %s', result['status'])
return result['dict'] | [
"def",
"_query",
"(",
"action",
"=",
"None",
",",
"command",
"=",
"None",
",",
"args",
"=",
"None",
",",
"method",
"=",
"'GET'",
",",
"header_dict",
"=",
"None",
",",
"data",
"=",
"None",
",",
"url",
"=",
"'https://api.linode.com/'",
")",
":",
"global"... | Make a web call to the Linode API. | [
"Make",
"a",
"web",
"call",
"to",
"the",
"Linode",
"API",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1505-L1582 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _wait_for_job | def _wait_for_job(linode_id, job_id, timeout=300, quiet=True):
'''
Wait for a Job to return.
linode_id
The ID of the Linode to wait on. Required.
job_id
The ID of the job to wait for.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when True. Otherwise, logs to info.
'''
interval = 5
iterations = int(timeout / interval)
for i in range(0, iterations):
jobs_result = _query('linode',
'job.list',
args={'LinodeID': linode_id})['DATA']
if jobs_result[0]['JOBID'] == job_id and jobs_result[0]['HOST_SUCCESS'] == 1:
return True
time.sleep(interval)
log.log(
logging.INFO if not quiet else logging.DEBUG,
'Still waiting on Job %s for Linode %s.', job_id, linode_id
)
return False | python | def _wait_for_job(linode_id, job_id, timeout=300, quiet=True):
'''
Wait for a Job to return.
linode_id
The ID of the Linode to wait on. Required.
job_id
The ID of the job to wait for.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when True. Otherwise, logs to info.
'''
interval = 5
iterations = int(timeout / interval)
for i in range(0, iterations):
jobs_result = _query('linode',
'job.list',
args={'LinodeID': linode_id})['DATA']
if jobs_result[0]['JOBID'] == job_id and jobs_result[0]['HOST_SUCCESS'] == 1:
return True
time.sleep(interval)
log.log(
logging.INFO if not quiet else logging.DEBUG,
'Still waiting on Job %s for Linode %s.', job_id, linode_id
)
return False | [
"def",
"_wait_for_job",
"(",
"linode_id",
",",
"job_id",
",",
"timeout",
"=",
"300",
",",
"quiet",
"=",
"True",
")",
":",
"interval",
"=",
"5",
"iterations",
"=",
"int",
"(",
"timeout",
"/",
"interval",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
... | Wait for a Job to return.
linode_id
The ID of the Linode to wait on. Required.
job_id
The ID of the job to wait for.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when True. Otherwise, logs to info. | [
"Wait",
"for",
"a",
"Job",
"to",
"return",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1585-L1616 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _wait_for_status | def _wait_for_status(linode_id, status=None, timeout=300, quiet=True):
'''
Wait for a certain status from Linode.
linode_id
The ID of the Linode to wait on. Required.
status
The status to look for to update.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when False. Otherwise, logs to info.
'''
if status is None:
status = _get_status_id_by_name('brand_new')
status_desc_waiting = _get_status_descr_by_id(status)
interval = 5
iterations = int(timeout / interval)
for i in range(0, iterations):
result = get_linode(kwargs={'linode_id': linode_id})
if result['STATUS'] == status:
return True
status_desc_result = _get_status_descr_by_id(result['STATUS'])
time.sleep(interval)
log.log(
logging.INFO if not quiet else logging.DEBUG,
'Status for Linode %s is \'%s\', waiting for \'%s\'.',
linode_id, status_desc_result, status_desc_waiting
)
return False | python | def _wait_for_status(linode_id, status=None, timeout=300, quiet=True):
'''
Wait for a certain status from Linode.
linode_id
The ID of the Linode to wait on. Required.
status
The status to look for to update.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when False. Otherwise, logs to info.
'''
if status is None:
status = _get_status_id_by_name('brand_new')
status_desc_waiting = _get_status_descr_by_id(status)
interval = 5
iterations = int(timeout / interval)
for i in range(0, iterations):
result = get_linode(kwargs={'linode_id': linode_id})
if result['STATUS'] == status:
return True
status_desc_result = _get_status_descr_by_id(result['STATUS'])
time.sleep(interval)
log.log(
logging.INFO if not quiet else logging.DEBUG,
'Status for Linode %s is \'%s\', waiting for \'%s\'.',
linode_id, status_desc_result, status_desc_waiting
)
return False | [
"def",
"_wait_for_status",
"(",
"linode_id",
",",
"status",
"=",
"None",
",",
"timeout",
"=",
"300",
",",
"quiet",
"=",
"True",
")",
":",
"if",
"status",
"is",
"None",
":",
"status",
"=",
"_get_status_id_by_name",
"(",
"'brand_new'",
")",
"status_desc_waitin... | Wait for a certain status from Linode.
linode_id
The ID of the Linode to wait on. Required.
status
The status to look for to update.
timeout
The amount of time to wait for a status to update.
quiet
Log status updates to debug logs when False. Otherwise, logs to info. | [
"Wait",
"for",
"a",
"certain",
"status",
"from",
"Linode",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1619-L1658 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _get_status_descr_by_id | def _get_status_descr_by_id(status_id):
'''
Return linode status by ID
status_id
linode VM status ID
'''
for status_name, status_data in six.iteritems(LINODE_STATUS):
if status_data['code'] == int(status_id):
return status_data['descr']
return LINODE_STATUS.get(status_id, None) | python | def _get_status_descr_by_id(status_id):
'''
Return linode status by ID
status_id
linode VM status ID
'''
for status_name, status_data in six.iteritems(LINODE_STATUS):
if status_data['code'] == int(status_id):
return status_data['descr']
return LINODE_STATUS.get(status_id, None) | [
"def",
"_get_status_descr_by_id",
"(",
"status_id",
")",
":",
"for",
"status_name",
",",
"status_data",
"in",
"six",
".",
"iteritems",
"(",
"LINODE_STATUS",
")",
":",
"if",
"status_data",
"[",
"'code'",
"]",
"==",
"int",
"(",
"status_id",
")",
":",
"return",... | Return linode status by ID
status_id
linode VM status ID | [
"Return",
"linode",
"status",
"by",
"ID"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1661-L1671 | train |
saltstack/salt | salt/cloud/clouds/linode.py | _validate_name | def _validate_name(name):
'''
Checks if the provided name fits Linode's labeling parameters.
.. versionadded:: 2015.5.6
name
The VM name to validate
'''
name = six.text_type(name)
name_length = len(name)
regex = re.compile(r'^[a-zA-Z0-9][A-Za-z0-9_-]*[a-zA-Z0-9]$')
if name_length < 3 or name_length > 48:
ret = False
elif not re.match(regex, name):
ret = False
else:
ret = True
if ret is False:
log.warning(
'A Linode label may only contain ASCII letters or numbers, dashes, and '
'underscores, must begin and end with letters or numbers, and be at least '
'three characters in length.'
)
return ret | python | def _validate_name(name):
'''
Checks if the provided name fits Linode's labeling parameters.
.. versionadded:: 2015.5.6
name
The VM name to validate
'''
name = six.text_type(name)
name_length = len(name)
regex = re.compile(r'^[a-zA-Z0-9][A-Za-z0-9_-]*[a-zA-Z0-9]$')
if name_length < 3 or name_length > 48:
ret = False
elif not re.match(regex, name):
ret = False
else:
ret = True
if ret is False:
log.warning(
'A Linode label may only contain ASCII letters or numbers, dashes, and '
'underscores, must begin and end with letters or numbers, and be at least '
'three characters in length.'
)
return ret | [
"def",
"_validate_name",
"(",
"name",
")",
":",
"name",
"=",
"six",
".",
"text_type",
"(",
"name",
")",
"name_length",
"=",
"len",
"(",
"name",
")",
"regex",
"=",
"re",
".",
"compile",
"(",
"r'^[a-zA-Z0-9][A-Za-z0-9_-]*[a-zA-Z0-9]$'",
")",
"if",
"name_length... | Checks if the provided name fits Linode's labeling parameters.
.. versionadded:: 2015.5.6
name
The VM name to validate | [
"Checks",
"if",
"the",
"provided",
"name",
"fits",
"Linode",
"s",
"labeling",
"parameters",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/cloud/clouds/linode.py#L1684-L1711 | train |
saltstack/salt | salt/modules/napalm_netacl.py | _get_capirca_platform | def _get_capirca_platform(): # pylint: disable=too-many-return-statements
'''
Given the following NAPALM grains, we can determine the Capirca platform name:
- vendor
- device model
- operating system
Not the most optimal.
'''
vendor = __grains__['vendor'].lower()
os_ = __grains__['os'].lower()
model = __grains__['model'].lower()
if vendor == 'juniper' and 'srx' in model:
return 'junipersrx'
elif vendor == 'cisco' and os_ == 'ios':
return 'cisco'
elif vendor == 'cisco' and os_ == 'iosxr':
return 'ciscoxr'
elif vendor == 'cisco' and os_ == 'asa':
return 'ciscoasa'
elif os_ == 'linux':
return 'iptables'
elif vendor == 'palo alto networks':
return 'paloaltofw'
# anything else will point to the vendor
# i.e.: some of the Capirca platforms are named by the device vendor
# e.g.: eOS => arista, junos => juniper, etc.
return vendor | python | def _get_capirca_platform(): # pylint: disable=too-many-return-statements
'''
Given the following NAPALM grains, we can determine the Capirca platform name:
- vendor
- device model
- operating system
Not the most optimal.
'''
vendor = __grains__['vendor'].lower()
os_ = __grains__['os'].lower()
model = __grains__['model'].lower()
if vendor == 'juniper' and 'srx' in model:
return 'junipersrx'
elif vendor == 'cisco' and os_ == 'ios':
return 'cisco'
elif vendor == 'cisco' and os_ == 'iosxr':
return 'ciscoxr'
elif vendor == 'cisco' and os_ == 'asa':
return 'ciscoasa'
elif os_ == 'linux':
return 'iptables'
elif vendor == 'palo alto networks':
return 'paloaltofw'
# anything else will point to the vendor
# i.e.: some of the Capirca platforms are named by the device vendor
# e.g.: eOS => arista, junos => juniper, etc.
return vendor | [
"def",
"_get_capirca_platform",
"(",
")",
":",
"# pylint: disable=too-many-return-statements",
"vendor",
"=",
"__grains__",
"[",
"'vendor'",
"]",
".",
"lower",
"(",
")",
"os_",
"=",
"__grains__",
"[",
"'os'",
"]",
".",
"lower",
"(",
")",
"model",
"=",
"__grain... | Given the following NAPALM grains, we can determine the Capirca platform name:
- vendor
- device model
- operating system
Not the most optimal. | [
"Given",
"the",
"following",
"NAPALM",
"grains",
"we",
"can",
"determine",
"the",
"Capirca",
"platform",
"name",
":"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L80-L108 | train |
saltstack/salt | salt/modules/napalm_netacl.py | load_term_config | def load_term_config(filter_name,
term_name,
filter_options=None,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
source_service=None,
destination_service=None,
**term_fields):
'''
Generate and load the configuration of a policy term.
filter_name
The name of the policy filter.
term_name
The name of the term.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
If the pillar contains the following structure:
.. code-block:: yaml
firewall:
- my-filter:
terms:
- my-term:
source_port: 1234
source_address:
- 1.2.3.4/32
- 5.6.7.8/32
The ``pillar_key`` field would be specified as ``firewall``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The properties specified through the CLI have higher priority than the pillar.
revision_id
Add a comment in the term config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the term configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
source_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a source_port and protocol.
As this module is available on Unix platforms only,
it reads the IANA_ port assignment from /etc/services.
If the user requires additional shortcuts to be referenced, they can add entries under /etc/services,
which can be managed using the :mod:`file state <salt.states.file>`.
.. _IANA: http://www.iana.org/assignments/port-numbers
destination_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a destination_port and protocol.
Allows the same options as ``source_service``.
term_fields
Term attributes. To see what fields are supported, please consult the
list of supported keywords_. Some platforms have a few other optional_
keywords.
.. _keywords: https://github.com/google/capirca/wiki/Policy-format#keywords
.. _optional: https://github.com/google/capirca/wiki/Policy-format#optionally-supported-keywords
.. note::
The following fields are accepted (some being platform-specific):
- action
- address
- address_exclude
- comment
- counter
- expiration
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- log_name
- loss_priority
- option
- policer
- port
- precedence
- principals
- protocol
- protocol_except
- qos
- pan_application
- routing_instance
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- packet_length
- fragment_offset
- hop_limit
- icmp_type
- ether_type
- traffic_class_count
- traffic_type
- translated
- dscp_set
- dscp_match
- dscp_except
- next_ip
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- vpn
- source_tag
- destination_tag
- source_interface
- destination_interface
- flattened
- flattened_addr
- flattened_saddr
- flattened_daddr
- priority
.. note::
The following fields can be also a single value and a list of values:
- action
- address
- address_exclude
- comment
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- option
- port
- precedence
- principals
- protocol
- protocol_except
- pan_application
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- icmp_type
- ether_type
- traffic_type
- dscp_match
- dscp_except
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- source_tag
- destination_tag
- source_service
- destination_service
Example: ``destination_address`` can be either defined as:
.. code-block:: yaml
destination_address: 172.17.17.1/24
or as a list of destination IP addresses:
.. code-block:: yaml
destination_address:
- 172.17.17.1/24
- 172.17.19.1/24
or a list of services to be matched:
.. code-block:: yaml
source_service:
- ntp
- snmp
- ldap
- bgpd
.. note::
The port fields ``source_port`` and ``destination_port`` can be used as above to select either
a single value, either a list of values, but also they can select port ranges. Example:
.. code-block:: yaml
source_port:
- - 1000
- 2000
- - 3000
- 4000
With the configuration above, the user is able to select the 1000-2000 and 3000-4000 source port ranges.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_term_config filter-name term-name source_address=1.2.3.4 destination_address=5.6.7.8 action=accept test=True debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
Configuration discarded.
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter filter-name {
+ interface-specific;
+ term term-name {
+ from {
+ source-address {
+ 1.2.3.4/32;
+ }
+ destination-address {
+ 5.6.7.8/32;
+ }
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter filter-name {
interface-specific;
term term-name {
from {
source-address {
1.2.3.4/32;
}
destination-address {
5.6.7.8/32;
}
}
then accept;
}
}
}
}
result:
True
'''
if not filter_options:
filter_options = []
platform = _get_capirca_platform()
term_config = __salt__['capirca.get_term_config'](platform,
filter_name,
term_name,
filter_options=filter_options,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format,
source_service=source_service,
destination_service=destination_service,
**term_fields)
return __salt__['net.load_config'](text=term_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | python | def load_term_config(filter_name,
term_name,
filter_options=None,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
source_service=None,
destination_service=None,
**term_fields):
'''
Generate and load the configuration of a policy term.
filter_name
The name of the policy filter.
term_name
The name of the term.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
If the pillar contains the following structure:
.. code-block:: yaml
firewall:
- my-filter:
terms:
- my-term:
source_port: 1234
source_address:
- 1.2.3.4/32
- 5.6.7.8/32
The ``pillar_key`` field would be specified as ``firewall``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The properties specified through the CLI have higher priority than the pillar.
revision_id
Add a comment in the term config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the term configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
source_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a source_port and protocol.
As this module is available on Unix platforms only,
it reads the IANA_ port assignment from /etc/services.
If the user requires additional shortcuts to be referenced, they can add entries under /etc/services,
which can be managed using the :mod:`file state <salt.states.file>`.
.. _IANA: http://www.iana.org/assignments/port-numbers
destination_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a destination_port and protocol.
Allows the same options as ``source_service``.
term_fields
Term attributes. To see what fields are supported, please consult the
list of supported keywords_. Some platforms have a few other optional_
keywords.
.. _keywords: https://github.com/google/capirca/wiki/Policy-format#keywords
.. _optional: https://github.com/google/capirca/wiki/Policy-format#optionally-supported-keywords
.. note::
The following fields are accepted (some being platform-specific):
- action
- address
- address_exclude
- comment
- counter
- expiration
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- log_name
- loss_priority
- option
- policer
- port
- precedence
- principals
- protocol
- protocol_except
- qos
- pan_application
- routing_instance
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- packet_length
- fragment_offset
- hop_limit
- icmp_type
- ether_type
- traffic_class_count
- traffic_type
- translated
- dscp_set
- dscp_match
- dscp_except
- next_ip
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- vpn
- source_tag
- destination_tag
- source_interface
- destination_interface
- flattened
- flattened_addr
- flattened_saddr
- flattened_daddr
- priority
.. note::
The following fields can be also a single value and a list of values:
- action
- address
- address_exclude
- comment
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- option
- port
- precedence
- principals
- protocol
- protocol_except
- pan_application
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- icmp_type
- ether_type
- traffic_type
- dscp_match
- dscp_except
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- source_tag
- destination_tag
- source_service
- destination_service
Example: ``destination_address`` can be either defined as:
.. code-block:: yaml
destination_address: 172.17.17.1/24
or as a list of destination IP addresses:
.. code-block:: yaml
destination_address:
- 172.17.17.1/24
- 172.17.19.1/24
or a list of services to be matched:
.. code-block:: yaml
source_service:
- ntp
- snmp
- ldap
- bgpd
.. note::
The port fields ``source_port`` and ``destination_port`` can be used as above to select either
a single value, either a list of values, but also they can select port ranges. Example:
.. code-block:: yaml
source_port:
- - 1000
- 2000
- - 3000
- 4000
With the configuration above, the user is able to select the 1000-2000 and 3000-4000 source port ranges.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_term_config filter-name term-name source_address=1.2.3.4 destination_address=5.6.7.8 action=accept test=True debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
Configuration discarded.
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter filter-name {
+ interface-specific;
+ term term-name {
+ from {
+ source-address {
+ 1.2.3.4/32;
+ }
+ destination-address {
+ 5.6.7.8/32;
+ }
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter filter-name {
interface-specific;
term term-name {
from {
source-address {
1.2.3.4/32;
}
destination-address {
5.6.7.8/32;
}
}
then accept;
}
}
}
}
result:
True
'''
if not filter_options:
filter_options = []
platform = _get_capirca_platform()
term_config = __salt__['capirca.get_term_config'](platform,
filter_name,
term_name,
filter_options=filter_options,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format,
source_service=source_service,
destination_service=destination_service,
**term_fields)
return __salt__['net.load_config'](text=term_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | [
"def",
"load_term_config",
"(",
"filter_name",
",",
"term_name",
",",
"filter_options",
"=",
"None",
",",
"pillar_key",
"=",
"'acl'",
",",
"pillarenv",
"=",
"None",
",",
"saltenv",
"=",
"None",
",",
"merge_pillar",
"=",
"True",
",",
"revision_id",
"=",
"None... | Generate and load the configuration of a policy term.
filter_name
The name of the policy filter.
term_name
The name of the term.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
If the pillar contains the following structure:
.. code-block:: yaml
firewall:
- my-filter:
terms:
- my-term:
source_port: 1234
source_address:
- 1.2.3.4/32
- 5.6.7.8/32
The ``pillar_key`` field would be specified as ``firewall``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The properties specified through the CLI have higher priority than the pillar.
revision_id
Add a comment in the term config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the term configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
source_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a source_port and protocol.
As this module is available on Unix platforms only,
it reads the IANA_ port assignment from /etc/services.
If the user requires additional shortcuts to be referenced, they can add entries under /etc/services,
which can be managed using the :mod:`file state <salt.states.file>`.
.. _IANA: http://www.iana.org/assignments/port-numbers
destination_service
A special service to choose from. This is a helper so the user is able to
select a source just using the name, instead of specifying a destination_port and protocol.
Allows the same options as ``source_service``.
term_fields
Term attributes. To see what fields are supported, please consult the
list of supported keywords_. Some platforms have a few other optional_
keywords.
.. _keywords: https://github.com/google/capirca/wiki/Policy-format#keywords
.. _optional: https://github.com/google/capirca/wiki/Policy-format#optionally-supported-keywords
.. note::
The following fields are accepted (some being platform-specific):
- action
- address
- address_exclude
- comment
- counter
- expiration
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- log_name
- loss_priority
- option
- policer
- port
- precedence
- principals
- protocol
- protocol_except
- qos
- pan_application
- routing_instance
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- packet_length
- fragment_offset
- hop_limit
- icmp_type
- ether_type
- traffic_class_count
- traffic_type
- translated
- dscp_set
- dscp_match
- dscp_except
- next_ip
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- vpn
- source_tag
- destination_tag
- source_interface
- destination_interface
- flattened
- flattened_addr
- flattened_saddr
- flattened_daddr
- priority
.. note::
The following fields can be also a single value and a list of values:
- action
- address
- address_exclude
- comment
- destination_address
- destination_address_exclude
- destination_port
- destination_prefix
- forwarding_class
- forwarding_class_except
- logging
- option
- port
- precedence
- principals
- protocol
- protocol_except
- pan_application
- source_address
- source_address_exclude
- source_port
- source_prefix
- verbatim
- icmp_type
- ether_type
- traffic_type
- dscp_match
- dscp_except
- flexible_match_range
- source_prefix_except
- destination_prefix_except
- source_tag
- destination_tag
- source_service
- destination_service
Example: ``destination_address`` can be either defined as:
.. code-block:: yaml
destination_address: 172.17.17.1/24
or as a list of destination IP addresses:
.. code-block:: yaml
destination_address:
- 172.17.17.1/24
- 172.17.19.1/24
or a list of services to be matched:
.. code-block:: yaml
source_service:
- ntp
- snmp
- ldap
- bgpd
.. note::
The port fields ``source_port`` and ``destination_port`` can be used as above to select either
a single value, either a list of values, but also they can select port ranges. Example:
.. code-block:: yaml
source_port:
- - 1000
- 2000
- - 3000
- 4000
With the configuration above, the user is able to select the 1000-2000 and 3000-4000 source port ranges.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_term_config filter-name term-name source_address=1.2.3.4 destination_address=5.6.7.8 action=accept test=True debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
Configuration discarded.
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter filter-name {
+ interface-specific;
+ term term-name {
+ from {
+ source-address {
+ 1.2.3.4/32;
+ }
+ destination-address {
+ 5.6.7.8/32;
+ }
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter filter-name {
interface-specific;
term term-name {
from {
source-address {
1.2.3.4/32;
}
destination-address {
5.6.7.8/32;
}
}
then accept;
}
}
}
}
result:
True | [
"Generate",
"and",
"load",
"the",
"configuration",
"of",
"a",
"policy",
"term",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L116-L451 | train |
saltstack/salt | salt/modules/napalm_netacl.py | load_filter_config | def load_filter_config(filter_name,
filter_options=None,
terms=None,
prepend=True,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
only_lower_merge=False,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
**kwargs): # pylint: disable=unused-argument
'''
Generate and load the configuration of a policy filter.
.. note::
The order of the terms is very important. The configuration loaded
on the device respects the order defined in the ``terms`` and/or
inside the pillar.
When merging the ``terms`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filter_name
The name of the policy filter.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
terms
List of terms for this policy filter.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of terms generated by merging
the terms from ``terms`` with those defined in the pillar (if any): new terms are prepended
at the beginning, while existing ones will preserve the position. To add the new terms
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the terms fields. Otherwise it will try
to merge also filters fields. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the filter config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the filter configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_filter_config my-filter pillar_key=netacl debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter my-filter {
+ interface-specific;
+ term my-term {
+ from {
+ source-port [ 1234 1235 ];
+ }
+ then {
+ reject;
+ }
+ }
+ term my-other-term {
+ from {
+ protocol tcp;
+ source-port 5678-5680;
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter my-filter {
interface-specific;
term my-term {
from {
source-port [ 1234 1235 ];
}
then {
reject;
}
}
term my-other-term {
from {
protocol tcp;
source-port 5678-5680;
}
then accept;
}
}
}
}
result:
True
The filter configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
netacl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
action: reject
- my-other-term:
source_port:
- - 5678
- 5680
protocol: tcp
action: accept
'''
if not filter_options:
filter_options = []
if not terms:
terms = []
platform = _get_capirca_platform()
filter_config = __salt__['capirca.get_filter_config'](platform,
filter_name,
terms=terms,
prepend=prepend,
filter_options=filter_options,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
only_lower_merge=only_lower_merge,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format)
return __salt__['net.load_config'](text=filter_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | python | def load_filter_config(filter_name,
filter_options=None,
terms=None,
prepend=True,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
only_lower_merge=False,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
**kwargs): # pylint: disable=unused-argument
'''
Generate and load the configuration of a policy filter.
.. note::
The order of the terms is very important. The configuration loaded
on the device respects the order defined in the ``terms`` and/or
inside the pillar.
When merging the ``terms`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filter_name
The name of the policy filter.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
terms
List of terms for this policy filter.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of terms generated by merging
the terms from ``terms`` with those defined in the pillar (if any): new terms are prepended
at the beginning, while existing ones will preserve the position. To add the new terms
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the terms fields. Otherwise it will try
to merge also filters fields. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the filter config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the filter configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_filter_config my-filter pillar_key=netacl debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter my-filter {
+ interface-specific;
+ term my-term {
+ from {
+ source-port [ 1234 1235 ];
+ }
+ then {
+ reject;
+ }
+ }
+ term my-other-term {
+ from {
+ protocol tcp;
+ source-port 5678-5680;
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter my-filter {
interface-specific;
term my-term {
from {
source-port [ 1234 1235 ];
}
then {
reject;
}
}
term my-other-term {
from {
protocol tcp;
source-port 5678-5680;
}
then accept;
}
}
}
}
result:
True
The filter configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
netacl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
action: reject
- my-other-term:
source_port:
- - 5678
- 5680
protocol: tcp
action: accept
'''
if not filter_options:
filter_options = []
if not terms:
terms = []
platform = _get_capirca_platform()
filter_config = __salt__['capirca.get_filter_config'](platform,
filter_name,
terms=terms,
prepend=prepend,
filter_options=filter_options,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
only_lower_merge=only_lower_merge,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format)
return __salt__['net.load_config'](text=filter_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | [
"def",
"load_filter_config",
"(",
"filter_name",
",",
"filter_options",
"=",
"None",
",",
"terms",
"=",
"None",
",",
"prepend",
"=",
"True",
",",
"pillar_key",
"=",
"'acl'",
",",
"pillarenv",
"=",
"None",
",",
"saltenv",
"=",
"None",
",",
"merge_pillar",
"... | Generate and load the configuration of a policy filter.
.. note::
The order of the terms is very important. The configuration loaded
on the device respects the order defined in the ``terms`` and/or
inside the pillar.
When merging the ``terms`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filter_name
The name of the policy filter.
filter_options
Additional filter options. These options are platform-specific.
See the complete list of options_.
.. _options: https://github.com/google/capirca/wiki/Policy-format#header-section
terms
List of terms for this policy filter.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of terms generated by merging
the terms from ``terms`` with those defined in the pillar (if any): new terms are prepended
at the beginning, while existing ones will preserve the position. To add the new terms
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the terms fields. Otherwise it will try
to merge also filters fields. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the filter config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the filter configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.bjm01' netacl.load_filter_config my-filter pillar_key=netacl debug=True
Output Example:
.. code-block:: jinja
edge01.bjm01:
----------
already_configured:
False
comment:
diff:
[edit firewall]
+ family inet {
+ /*
+ ** $Date: 2017/03/22 $
+ **
+ */
+ filter my-filter {
+ interface-specific;
+ term my-term {
+ from {
+ source-port [ 1234 1235 ];
+ }
+ then {
+ reject;
+ }
+ }
+ term my-other-term {
+ from {
+ protocol tcp;
+ source-port 5678-5680;
+ }
+ then accept;
+ }
+ }
+ }
loaded_config:
firewall {
family inet {
replace:
/*
** $Date: 2017/03/22 $
**
*/
filter my-filter {
interface-specific;
term my-term {
from {
source-port [ 1234 1235 ];
}
then {
reject;
}
}
term my-other-term {
from {
protocol tcp;
source-port 5678-5680;
}
then accept;
}
}
}
}
result:
True
The filter configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
netacl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
action: reject
- my-other-term:
source_port:
- - 5678
- 5680
protocol: tcp
action: accept | [
"Generate",
"and",
"load",
"the",
"configuration",
"of",
"a",
"policy",
"filter",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L455-L665 | train |
saltstack/salt | salt/modules/napalm_netacl.py | load_policy_config | def load_policy_config(filters=None,
prepend=True,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
only_lower_merge=False,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
**kwargs): # pylint: disable=unused-argument
'''
Generate and load the configuration of the whole policy.
.. note::
The order of the filters and their terms is very important.
The configuration loaded on the device respects the order
defined in the ``filters`` and/or inside the pillar.
When merging the ``filters`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filters
List of filters for this policy.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of filters generated by merging
the filters from ``filters`` with those defined in the pillar (if any): new filters are prepended
at the beginning, while existing ones will preserve the position. To add the new filters
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the filters and terms fields. Otherwise it will try
to merge everything at the policy level. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the policy config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the policy configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.flw01' netacl.load_policy_config debug=True
Output Example:
.. code-block:: text
edge01.flw01:
----------
already_configured:
False
comment:
diff:
---
+++
@@ -1228,9 +1228,24 @@
!
+ipv4 access-list my-filter
+ 10 remark my-term
+ 20 deny tcp host 1.2.3.4 eq 1234 any
+ 30 deny udp host 1.2.3.4 eq 1234 any
+ 40 deny tcp host 1.2.3.4 eq 1235 any
+ 50 deny udp host 1.2.3.4 eq 1235 any
+ 60 remark my-other-term
+ 70 permit tcp any range 5678 5680 any
+!
+!
+ipv4 access-list block-icmp
+ 10 remark first-term
+ 20 deny icmp any any
!
loaded_config:
! $Date: 2017/03/22 $
no ipv4 access-list my-filter
ipv4 access-list my-filter
remark my-term
deny tcp host 1.2.3.4 eq 1234 any
deny udp host 1.2.3.4 eq 1234 any
deny tcp host 1.2.3.4 eq 1235 any
deny udp host 1.2.3.4 eq 1235 any
remark my-other-term
permit tcp any range 5678 5680 any
exit
no ipv4 access-list block-icmp
ipv4 access-list block-icmp
remark first-term
deny icmp any any
exit
result:
True
The policy configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
acl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
protocol:
- tcp
- udp
source_address: 1.2.3.4
action: reject
- my-other-term:
source_port:
- [5678, 5680]
protocol: tcp
action: accept
- block-icmp:
terms:
- first-term:
protocol:
- icmp
action: reject
'''
if not filters:
filters = []
platform = _get_capirca_platform()
policy_config = __salt__['capirca.get_policy_config'](platform,
filters=filters,
prepend=prepend,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
only_lower_merge=only_lower_merge,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format)
return __salt__['net.load_config'](text=policy_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | python | def load_policy_config(filters=None,
prepend=True,
pillar_key='acl',
pillarenv=None,
saltenv=None,
merge_pillar=True,
only_lower_merge=False,
revision_id=None,
revision_no=None,
revision_date=True,
revision_date_format='%Y/%m/%d',
test=False,
commit=True,
debug=False,
**kwargs): # pylint: disable=unused-argument
'''
Generate and load the configuration of the whole policy.
.. note::
The order of the filters and their terms is very important.
The configuration loaded on the device respects the order
defined in the ``filters`` and/or inside the pillar.
When merging the ``filters`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filters
List of filters for this policy.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of filters generated by merging
the filters from ``filters`` with those defined in the pillar (if any): new filters are prepended
at the beginning, while existing ones will preserve the position. To add the new filters
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the filters and terms fields. Otherwise it will try
to merge everything at the policy level. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the policy config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the policy configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.flw01' netacl.load_policy_config debug=True
Output Example:
.. code-block:: text
edge01.flw01:
----------
already_configured:
False
comment:
diff:
---
+++
@@ -1228,9 +1228,24 @@
!
+ipv4 access-list my-filter
+ 10 remark my-term
+ 20 deny tcp host 1.2.3.4 eq 1234 any
+ 30 deny udp host 1.2.3.4 eq 1234 any
+ 40 deny tcp host 1.2.3.4 eq 1235 any
+ 50 deny udp host 1.2.3.4 eq 1235 any
+ 60 remark my-other-term
+ 70 permit tcp any range 5678 5680 any
+!
+!
+ipv4 access-list block-icmp
+ 10 remark first-term
+ 20 deny icmp any any
!
loaded_config:
! $Date: 2017/03/22 $
no ipv4 access-list my-filter
ipv4 access-list my-filter
remark my-term
deny tcp host 1.2.3.4 eq 1234 any
deny udp host 1.2.3.4 eq 1234 any
deny tcp host 1.2.3.4 eq 1235 any
deny udp host 1.2.3.4 eq 1235 any
remark my-other-term
permit tcp any range 5678 5680 any
exit
no ipv4 access-list block-icmp
ipv4 access-list block-icmp
remark first-term
deny icmp any any
exit
result:
True
The policy configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
acl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
protocol:
- tcp
- udp
source_address: 1.2.3.4
action: reject
- my-other-term:
source_port:
- [5678, 5680]
protocol: tcp
action: accept
- block-icmp:
terms:
- first-term:
protocol:
- icmp
action: reject
'''
if not filters:
filters = []
platform = _get_capirca_platform()
policy_config = __salt__['capirca.get_policy_config'](platform,
filters=filters,
prepend=prepend,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv,
merge_pillar=merge_pillar,
only_lower_merge=only_lower_merge,
revision_id=revision_id,
revision_no=revision_no,
revision_date=revision_date,
revision_date_format=revision_date_format)
return __salt__['net.load_config'](text=policy_config,
test=test,
commit=commit,
debug=debug,
inherit_napalm_device=napalm_device) | [
"def",
"load_policy_config",
"(",
"filters",
"=",
"None",
",",
"prepend",
"=",
"True",
",",
"pillar_key",
"=",
"'acl'",
",",
"pillarenv",
"=",
"None",
",",
"saltenv",
"=",
"None",
",",
"merge_pillar",
"=",
"True",
",",
"only_lower_merge",
"=",
"False",
","... | Generate and load the configuration of the whole policy.
.. note::
The order of the filters and their terms is very important.
The configuration loaded on the device respects the order
defined in the ``filters`` and/or inside the pillar.
When merging the ``filters`` with the pillar data, consider the
``prepend`` argument to make sure the order is correct!
filters
List of filters for this policy.
If not specified or empty, will try to load the configuration from the pillar,
unless ``merge_pillar`` is set as ``False``.
prepend: ``True``
When ``merge_pillar`` is set as ``True``, the final list of filters generated by merging
the filters from ``filters`` with those defined in the pillar (if any): new filters are prepended
at the beginning, while existing ones will preserve the position. To add the new filters
at the end of the list, set this argument to ``False``.
pillar_key: ``acl``
The key in the pillar containing the default attributes values. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
merge_pillar: ``True``
Merge the CLI variables with the pillar. Default: ``True``.
The merge logic depends on the ``prepend`` argument and
the CLI has higher priority than the pillar.
only_lower_merge: ``False``
Specify if it should merge only the filters and terms fields. Otherwise it will try
to merge everything at the policy level. Default: ``False``.
This option requires ``merge_pillar``, otherwise it is ignored.
revision_id
Add a comment in the policy config having the description for the changes applied.
revision_no
The revision count.
revision_date: ``True``
Boolean flag: display the date when the policy configuration was generated. Default: ``True``.
revision_date_format: ``%Y/%m/%d``
The date format to be used when generating the perforce data. Default: ``%Y/%m/%d`` (<year>/<month>/<day>).
test: ``False``
Dry run? If set as ``True``, will apply the config, discard and return the changes.
Default: ``False`` and will commit the changes on the device.
commit: ``True``
Commit? Default: ``True``.
debug: ``False``
Debug mode. Will insert a new key under the output dictionary,
as ``loaded_config`` containing the raw configuration loaded on the device.
The output is a dictionary having the same form as :mod:`net.load_config <salt.modules.napalm_network.load_config>`.
CLI Example:
.. code-block:: bash
salt 'edge01.flw01' netacl.load_policy_config debug=True
Output Example:
.. code-block:: text
edge01.flw01:
----------
already_configured:
False
comment:
diff:
---
+++
@@ -1228,9 +1228,24 @@
!
+ipv4 access-list my-filter
+ 10 remark my-term
+ 20 deny tcp host 1.2.3.4 eq 1234 any
+ 30 deny udp host 1.2.3.4 eq 1234 any
+ 40 deny tcp host 1.2.3.4 eq 1235 any
+ 50 deny udp host 1.2.3.4 eq 1235 any
+ 60 remark my-other-term
+ 70 permit tcp any range 5678 5680 any
+!
+!
+ipv4 access-list block-icmp
+ 10 remark first-term
+ 20 deny icmp any any
!
loaded_config:
! $Date: 2017/03/22 $
no ipv4 access-list my-filter
ipv4 access-list my-filter
remark my-term
deny tcp host 1.2.3.4 eq 1234 any
deny udp host 1.2.3.4 eq 1234 any
deny tcp host 1.2.3.4 eq 1235 any
deny udp host 1.2.3.4 eq 1235 any
remark my-other-term
permit tcp any range 5678 5680 any
exit
no ipv4 access-list block-icmp
ipv4 access-list block-icmp
remark first-term
deny icmp any any
exit
result:
True
The policy configuration has been loaded from the pillar, having the following structure:
.. code-block:: yaml
acl:
- my-filter:
terms:
- my-term:
source_port:
- 1234
- 1235
protocol:
- tcp
- udp
source_address: 1.2.3.4
action: reject
- my-other-term:
source_port:
- [5678, 5680]
protocol: tcp
action: accept
- block-icmp:
terms:
- first-term:
protocol:
- icmp
action: reject | [
"Generate",
"and",
"load",
"the",
"configuration",
"of",
"the",
"whole",
"policy",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L669-L855 | train |
saltstack/salt | salt/modules/napalm_netacl.py | get_filter_pillar | def get_filter_pillar(filter_name,
pillar_key='acl',
pillarenv=None,
saltenv=None):
'''
Helper that can be used inside a state SLS,
in order to get the filter configuration given its name.
filter_name
The name of the filter.
pillar_key
The root key of the whole policy config.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
'''
return __salt__['capirca.get_filter_pillar'](filter_name,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv) | python | def get_filter_pillar(filter_name,
pillar_key='acl',
pillarenv=None,
saltenv=None):
'''
Helper that can be used inside a state SLS,
in order to get the filter configuration given its name.
filter_name
The name of the filter.
pillar_key
The root key of the whole policy config.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
'''
return __salt__['capirca.get_filter_pillar'](filter_name,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv) | [
"def",
"get_filter_pillar",
"(",
"filter_name",
",",
"pillar_key",
"=",
"'acl'",
",",
"pillarenv",
"=",
"None",
",",
"saltenv",
"=",
"None",
")",
":",
"return",
"__salt__",
"[",
"'capirca.get_filter_pillar'",
"]",
"(",
"filter_name",
",",
"pillar_key",
"=",
"p... | Helper that can be used inside a state SLS,
in order to get the filter configuration given its name.
filter_name
The name of the filter.
pillar_key
The root key of the whole policy config.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored. | [
"Helper",
"that",
"can",
"be",
"used",
"inside",
"a",
"state",
"SLS",
"in",
"order",
"to",
"get",
"the",
"filter",
"configuration",
"given",
"its",
"name",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L858-L883 | train |
saltstack/salt | salt/modules/napalm_netacl.py | get_term_pillar | def get_term_pillar(filter_name,
term_name,
pillar_key='acl',
pillarenv=None,
saltenv=None):
'''
Helper that can be used inside a state SLS,
in order to get the term configuration given its name,
under a certain filter uniquely identified by its name.
filter_name
The name of the filter.
term_name
The name of the term.
pillar_key: ``acl``
The root key of the whole policy config. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
'''
return __salt__['capirca.get_term_pillar'](filter_name,
term_name,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv) | python | def get_term_pillar(filter_name,
term_name,
pillar_key='acl',
pillarenv=None,
saltenv=None):
'''
Helper that can be used inside a state SLS,
in order to get the term configuration given its name,
under a certain filter uniquely identified by its name.
filter_name
The name of the filter.
term_name
The name of the term.
pillar_key: ``acl``
The root key of the whole policy config. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.
'''
return __salt__['capirca.get_term_pillar'](filter_name,
term_name,
pillar_key=pillar_key,
pillarenv=pillarenv,
saltenv=saltenv) | [
"def",
"get_term_pillar",
"(",
"filter_name",
",",
"term_name",
",",
"pillar_key",
"=",
"'acl'",
",",
"pillarenv",
"=",
"None",
",",
"saltenv",
"=",
"None",
")",
":",
"return",
"__salt__",
"[",
"'capirca.get_term_pillar'",
"]",
"(",
"filter_name",
",",
"term_n... | Helper that can be used inside a state SLS,
in order to get the term configuration given its name,
under a certain filter uniquely identified by its name.
filter_name
The name of the filter.
term_name
The name of the term.
pillar_key: ``acl``
The root key of the whole policy config. Default: ``acl``.
pillarenv
Query the master to generate fresh pillar data on the fly,
specifically from the requested pillar environment.
saltenv
Included only for compatibility with
:conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored. | [
"Helper",
"that",
"can",
"be",
"used",
"inside",
"a",
"state",
"SLS",
"in",
"order",
"to",
"get",
"the",
"term",
"configuration",
"given",
"its",
"name",
"under",
"a",
"certain",
"filter",
"uniquely",
"identified",
"by",
"its",
"name",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_netacl.py#L886-L917 | train |
saltstack/salt | salt/modules/purefb.py | _get_blade | def _get_blade():
'''
Get Pure Storage FlasBlade configuration
1) From the minion config
pure_tags:
fb:
san_ip: management vip or hostname for the FlashBlade
api_token: A valid api token for the FlashBlade being managed
2) From environment (PUREFB_IP and PUREFB_API)
3) From the pillar (PUREFB_IP and PUREFB_API)
'''
try:
blade_name = __opts__['pure_tags']['fb'].get('san_ip')
api_token = __opts__['pure_tags']['fb'].get('api_token')
if blade_name and api:
blade = PurityFb(blade_name)
blade.disable_verify_ssl()
except (KeyError, NameError, TypeError):
try:
blade_name = os.environ.get('PUREFB_IP')
api_token = os.environ.get('PUREFB_API')
if blade_name:
blade = PurityFb(blade_name)
blade.disable_verify_ssl()
except (ValueError, KeyError, NameError):
try:
api_token = __pillar__['PUREFB_API']
blade = PurityFb(__pillar__['PUREFB_IP'])
blade.disable_verify_ssl()
except (KeyError, NameError):
raise CommandExecutionError('No Pure Storage FlashBlade credentials found.')
try:
blade.login(api_token)
except Exception:
raise CommandExecutionError('Pure Storage FlashBlade authentication failed.')
return blade | python | def _get_blade():
'''
Get Pure Storage FlasBlade configuration
1) From the minion config
pure_tags:
fb:
san_ip: management vip or hostname for the FlashBlade
api_token: A valid api token for the FlashBlade being managed
2) From environment (PUREFB_IP and PUREFB_API)
3) From the pillar (PUREFB_IP and PUREFB_API)
'''
try:
blade_name = __opts__['pure_tags']['fb'].get('san_ip')
api_token = __opts__['pure_tags']['fb'].get('api_token')
if blade_name and api:
blade = PurityFb(blade_name)
blade.disable_verify_ssl()
except (KeyError, NameError, TypeError):
try:
blade_name = os.environ.get('PUREFB_IP')
api_token = os.environ.get('PUREFB_API')
if blade_name:
blade = PurityFb(blade_name)
blade.disable_verify_ssl()
except (ValueError, KeyError, NameError):
try:
api_token = __pillar__['PUREFB_API']
blade = PurityFb(__pillar__['PUREFB_IP'])
blade.disable_verify_ssl()
except (KeyError, NameError):
raise CommandExecutionError('No Pure Storage FlashBlade credentials found.')
try:
blade.login(api_token)
except Exception:
raise CommandExecutionError('Pure Storage FlashBlade authentication failed.')
return blade | [
"def",
"_get_blade",
"(",
")",
":",
"try",
":",
"blade_name",
"=",
"__opts__",
"[",
"'pure_tags'",
"]",
"[",
"'fb'",
"]",
".",
"get",
"(",
"'san_ip'",
")",
"api_token",
"=",
"__opts__",
"[",
"'pure_tags'",
"]",
"[",
"'fb'",
"]",
".",
"get",
"(",
"'ap... | Get Pure Storage FlasBlade configuration
1) From the minion config
pure_tags:
fb:
san_ip: management vip or hostname for the FlashBlade
api_token: A valid api token for the FlashBlade being managed
2) From environment (PUREFB_IP and PUREFB_API)
3) From the pillar (PUREFB_IP and PUREFB_API) | [
"Get",
"Pure",
"Storage",
"FlasBlade",
"configuration"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/purefb.py#L85-L123 | train |
saltstack/salt | salt/modules/purefb.py | _get_fs | def _get_fs(name, blade):
'''
Private function to
check for existance of a filesystem
'''
_fs = []
_fs.append(name)
try:
res = blade.file_systems.list_file_systems(names=_fs)
return res.items[0]
except rest.ApiException:
return None | python | def _get_fs(name, blade):
'''
Private function to
check for existance of a filesystem
'''
_fs = []
_fs.append(name)
try:
res = blade.file_systems.list_file_systems(names=_fs)
return res.items[0]
except rest.ApiException:
return None | [
"def",
"_get_fs",
"(",
"name",
",",
"blade",
")",
":",
"_fs",
"=",
"[",
"]",
"_fs",
".",
"append",
"(",
"name",
")",
"try",
":",
"res",
"=",
"blade",
".",
"file_systems",
".",
"list_file_systems",
"(",
"names",
"=",
"_fs",
")",
"return",
"res",
"."... | Private function to
check for existance of a filesystem | [
"Private",
"function",
"to",
"check",
"for",
"existance",
"of",
"a",
"filesystem"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/purefb.py#L126-L137 | train |
saltstack/salt | salt/modules/purefb.py | _get_snapshot | def _get_snapshot(name, suffix, blade):
'''
Return name of Snapshot
or None
'''
try:
filt = 'source=\'{}\' and suffix=\'{}\''.format(name, suffix)
res = blade.file_system_snapshots.list_file_system_snapshots(filter=filt)
return res.items[0]
except rest.ApiException:
return None | python | def _get_snapshot(name, suffix, blade):
'''
Return name of Snapshot
or None
'''
try:
filt = 'source=\'{}\' and suffix=\'{}\''.format(name, suffix)
res = blade.file_system_snapshots.list_file_system_snapshots(filter=filt)
return res.items[0]
except rest.ApiException:
return None | [
"def",
"_get_snapshot",
"(",
"name",
",",
"suffix",
",",
"blade",
")",
":",
"try",
":",
"filt",
"=",
"'source=\\'{}\\' and suffix=\\'{}\\''",
".",
"format",
"(",
"name",
",",
"suffix",
")",
"res",
"=",
"blade",
".",
"file_system_snapshots",
".",
"list_file_sys... | Return name of Snapshot
or None | [
"Return",
"name",
"of",
"Snapshot",
"or",
"None"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/purefb.py#L140-L150 | train |
saltstack/salt | salt/modules/purefb.py | _get_deleted_fs | def _get_deleted_fs(name, blade):
'''
Private function to check
if a file systeem has already been deleted
'''
try:
_fs = _get_fs(name, blade)
if _fs and _fs.destroyed:
return _fs
except rest.ApiException:
return None | python | def _get_deleted_fs(name, blade):
'''
Private function to check
if a file systeem has already been deleted
'''
try:
_fs = _get_fs(name, blade)
if _fs and _fs.destroyed:
return _fs
except rest.ApiException:
return None | [
"def",
"_get_deleted_fs",
"(",
"name",
",",
"blade",
")",
":",
"try",
":",
"_fs",
"=",
"_get_fs",
"(",
"name",
",",
"blade",
")",
"if",
"_fs",
"and",
"_fs",
".",
"destroyed",
":",
"return",
"_fs",
"except",
"rest",
".",
"ApiException",
":",
"return",
... | Private function to check
if a file systeem has already been deleted | [
"Private",
"function",
"to",
"check",
"if",
"a",
"file",
"systeem",
"has",
"already",
"been",
"deleted"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/purefb.py#L153-L163 | train |
saltstack/salt | salt/states/syslog_ng.py | started | def started(name=None,
user=None,
group=None,
chroot=None,
caps=None,
no_caps=False,
pidfile=None,
enable_core=False,
fd_limit=None,
verbose=False,
debug=False,
trace=False,
yydebug=False,
persist_file=None,
control=None,
worker_threads=None,
*args,
**kwargs):
'''
Ensures, that syslog-ng is started via the given parameters.
Users shouldn't use this function, if the service module is available on
their system.
'''
return __salt__['syslog_ng.start'](name=name,
user=user,
group=group,
chroot=chroot,
caps=caps,
no_caps=no_caps,
pidfile=pidfile,
enable_core=enable_core,
fd_limit=fd_limit,
verbose=verbose,
debug=debug,
trace=trace,
yydebug=yydebug,
persist_file=persist_file,
control=control,
worker_threads=worker_threads) | python | def started(name=None,
user=None,
group=None,
chroot=None,
caps=None,
no_caps=False,
pidfile=None,
enable_core=False,
fd_limit=None,
verbose=False,
debug=False,
trace=False,
yydebug=False,
persist_file=None,
control=None,
worker_threads=None,
*args,
**kwargs):
'''
Ensures, that syslog-ng is started via the given parameters.
Users shouldn't use this function, if the service module is available on
their system.
'''
return __salt__['syslog_ng.start'](name=name,
user=user,
group=group,
chroot=chroot,
caps=caps,
no_caps=no_caps,
pidfile=pidfile,
enable_core=enable_core,
fd_limit=fd_limit,
verbose=verbose,
debug=debug,
trace=trace,
yydebug=yydebug,
persist_file=persist_file,
control=control,
worker_threads=worker_threads) | [
"def",
"started",
"(",
"name",
"=",
"None",
",",
"user",
"=",
"None",
",",
"group",
"=",
"None",
",",
"chroot",
"=",
"None",
",",
"caps",
"=",
"None",
",",
"no_caps",
"=",
"False",
",",
"pidfile",
"=",
"None",
",",
"enable_core",
"=",
"False",
",",... | Ensures, that syslog-ng is started via the given parameters.
Users shouldn't use this function, if the service module is available on
their system. | [
"Ensures",
"that",
"syslog",
"-",
"ng",
"is",
"started",
"via",
"the",
"given",
"parameters",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/syslog_ng.py#L76-L115 | train |
saltstack/salt | salt/client/ssh/client.py | SSHClient._prep_ssh | def _prep_ssh(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
kwarg=None,
**kwargs):
'''
Prepare the arguments
'''
opts = copy.deepcopy(self.opts)
opts.update(kwargs)
if timeout:
opts['timeout'] = timeout
arg = salt.utils.args.condition_input(arg, kwarg)
opts['argv'] = [fun] + arg
opts['selected_target_option'] = tgt_type
opts['tgt'] = tgt
opts['arg'] = arg
return salt.client.ssh.SSH(opts) | python | def _prep_ssh(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
kwarg=None,
**kwargs):
'''
Prepare the arguments
'''
opts = copy.deepcopy(self.opts)
opts.update(kwargs)
if timeout:
opts['timeout'] = timeout
arg = salt.utils.args.condition_input(arg, kwarg)
opts['argv'] = [fun] + arg
opts['selected_target_option'] = tgt_type
opts['tgt'] = tgt
opts['arg'] = arg
return salt.client.ssh.SSH(opts) | [
"def",
"_prep_ssh",
"(",
"self",
",",
"tgt",
",",
"fun",
",",
"arg",
"=",
"(",
")",
",",
"timeout",
"=",
"None",
",",
"tgt_type",
"=",
"'glob'",
",",
"kwarg",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"opts",
"=",
"copy",
".",
"deepcopy",
... | Prepare the arguments | [
"Prepare",
"the",
"arguments"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/client/ssh/client.py#L43-L64 | train |
saltstack/salt | salt/client/ssh/client.py | SSHClient.cmd_iter | def cmd_iter(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
ret='',
kwarg=None,
**kwargs):
'''
Execute a single command via the salt-ssh subsystem and return a
generator
.. versionadded:: 2015.5.0
'''
ssh = self._prep_ssh(
tgt,
fun,
arg,
timeout,
tgt_type,
kwarg,
**kwargs)
for ret in ssh.run_iter(jid=kwargs.get('jid', None)):
yield ret | python | def cmd_iter(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
ret='',
kwarg=None,
**kwargs):
'''
Execute a single command via the salt-ssh subsystem and return a
generator
.. versionadded:: 2015.5.0
'''
ssh = self._prep_ssh(
tgt,
fun,
arg,
timeout,
tgt_type,
kwarg,
**kwargs)
for ret in ssh.run_iter(jid=kwargs.get('jid', None)):
yield ret | [
"def",
"cmd_iter",
"(",
"self",
",",
"tgt",
",",
"fun",
",",
"arg",
"=",
"(",
")",
",",
"timeout",
"=",
"None",
",",
"tgt_type",
"=",
"'glob'",
",",
"ret",
"=",
"''",
",",
"kwarg",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"ssh",
"=",
"... | Execute a single command via the salt-ssh subsystem and return a
generator
.. versionadded:: 2015.5.0 | [
"Execute",
"a",
"single",
"command",
"via",
"the",
"salt",
"-",
"ssh",
"subsystem",
"and",
"return",
"a",
"generator"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/client/ssh/client.py#L66-L91 | train |
saltstack/salt | salt/client/ssh/client.py | SSHClient.cmd | def cmd(self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
kwarg=None,
**kwargs):
'''
Execute a single command via the salt-ssh subsystem and return all
routines at once
.. versionadded:: 2015.5.0
'''
ssh = self._prep_ssh(
tgt,
fun,
arg,
timeout,
tgt_type,
kwarg,
**kwargs)
final = {}
for ret in ssh.run_iter(jid=kwargs.get('jid', None)):
final.update(ret)
return final | python | def cmd(self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
kwarg=None,
**kwargs):
'''
Execute a single command via the salt-ssh subsystem and return all
routines at once
.. versionadded:: 2015.5.0
'''
ssh = self._prep_ssh(
tgt,
fun,
arg,
timeout,
tgt_type,
kwarg,
**kwargs)
final = {}
for ret in ssh.run_iter(jid=kwargs.get('jid', None)):
final.update(ret)
return final | [
"def",
"cmd",
"(",
"self",
",",
"tgt",
",",
"fun",
",",
"arg",
"=",
"(",
")",
",",
"timeout",
"=",
"None",
",",
"tgt_type",
"=",
"'glob'",
",",
"kwarg",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"ssh",
"=",
"self",
".",
"_prep_ssh",
"(",
... | Execute a single command via the salt-ssh subsystem and return all
routines at once
.. versionadded:: 2015.5.0 | [
"Execute",
"a",
"single",
"command",
"via",
"the",
"salt",
"-",
"ssh",
"subsystem",
"and",
"return",
"all",
"routines",
"at",
"once"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/client/ssh/client.py#L93-L118 | train |
saltstack/salt | salt/client/ssh/client.py | SSHClient.cmd_sync | def cmd_sync(self, low):
'''
Execute a salt-ssh call synchronously.
.. versionadded:: 2015.5.0
WARNING: Eauth is **NOT** respected
.. code-block:: python
client.cmd_sync({
'tgt': 'silver',
'fun': 'test.ping',
'arg': (),
'tgt_type'='glob',
'kwarg'={}
})
{'silver': {'fun_args': [], 'jid': '20141202152721523072', 'return': True, 'retcode': 0, 'success': True, 'fun': 'test.ping', 'id': 'silver'}}
'''
kwargs = copy.deepcopy(low)
for ignore in ['tgt', 'fun', 'arg', 'timeout', 'tgt_type', 'kwarg']:
if ignore in kwargs:
del kwargs[ignore]
return self.cmd(low['tgt'],
low['fun'],
low.get('arg', []),
low.get('timeout'),
low.get('tgt_type'),
low.get('kwarg'),
**kwargs) | python | def cmd_sync(self, low):
'''
Execute a salt-ssh call synchronously.
.. versionadded:: 2015.5.0
WARNING: Eauth is **NOT** respected
.. code-block:: python
client.cmd_sync({
'tgt': 'silver',
'fun': 'test.ping',
'arg': (),
'tgt_type'='glob',
'kwarg'={}
})
{'silver': {'fun_args': [], 'jid': '20141202152721523072', 'return': True, 'retcode': 0, 'success': True, 'fun': 'test.ping', 'id': 'silver'}}
'''
kwargs = copy.deepcopy(low)
for ignore in ['tgt', 'fun', 'arg', 'timeout', 'tgt_type', 'kwarg']:
if ignore in kwargs:
del kwargs[ignore]
return self.cmd(low['tgt'],
low['fun'],
low.get('arg', []),
low.get('timeout'),
low.get('tgt_type'),
low.get('kwarg'),
**kwargs) | [
"def",
"cmd_sync",
"(",
"self",
",",
"low",
")",
":",
"kwargs",
"=",
"copy",
".",
"deepcopy",
"(",
"low",
")",
"for",
"ignore",
"in",
"[",
"'tgt'",
",",
"'fun'",
",",
"'arg'",
",",
"'timeout'",
",",
"'tgt_type'",
",",
"'kwarg'",
"]",
":",
"if",
"ig... | Execute a salt-ssh call synchronously.
.. versionadded:: 2015.5.0
WARNING: Eauth is **NOT** respected
.. code-block:: python
client.cmd_sync({
'tgt': 'silver',
'fun': 'test.ping',
'arg': (),
'tgt_type'='glob',
'kwarg'={}
})
{'silver': {'fun_args': [], 'jid': '20141202152721523072', 'return': True, 'retcode': 0, 'success': True, 'fun': 'test.ping', 'id': 'silver'}} | [
"Execute",
"a",
"salt",
"-",
"ssh",
"call",
"synchronously",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/client/ssh/client.py#L120-L152 | train |
saltstack/salt | salt/client/ssh/client.py | SSHClient.cmd_subset | def cmd_subset(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
ret='',
kwarg=None,
sub=3,
**kwargs):
'''
Execute a command on a random subset of the targeted systems
The function signature is the same as :py:meth:`cmd` with the
following exceptions.
:param sub: The number of systems to execute on
.. code-block:: python
>>> import salt.client.ssh.client
>>> sshclient= salt.client.ssh.client.SSHClient()
>>> sshclient.cmd_subset('*', 'test.ping', sub=1)
{'jerry': True}
.. versionadded:: 2017.7.0
'''
minion_ret = self.cmd(tgt,
'sys.list_functions',
tgt_type=tgt_type,
**kwargs)
minions = list(minion_ret)
random.shuffle(minions)
f_tgt = []
for minion in minions:
if fun in minion_ret[minion]['return']:
f_tgt.append(minion)
if len(f_tgt) >= sub:
break
return self.cmd_iter(f_tgt, fun, arg, timeout, tgt_type='list', ret=ret, kwarg=kwarg, **kwargs) | python | def cmd_subset(
self,
tgt,
fun,
arg=(),
timeout=None,
tgt_type='glob',
ret='',
kwarg=None,
sub=3,
**kwargs):
'''
Execute a command on a random subset of the targeted systems
The function signature is the same as :py:meth:`cmd` with the
following exceptions.
:param sub: The number of systems to execute on
.. code-block:: python
>>> import salt.client.ssh.client
>>> sshclient= salt.client.ssh.client.SSHClient()
>>> sshclient.cmd_subset('*', 'test.ping', sub=1)
{'jerry': True}
.. versionadded:: 2017.7.0
'''
minion_ret = self.cmd(tgt,
'sys.list_functions',
tgt_type=tgt_type,
**kwargs)
minions = list(minion_ret)
random.shuffle(minions)
f_tgt = []
for minion in minions:
if fun in minion_ret[minion]['return']:
f_tgt.append(minion)
if len(f_tgt) >= sub:
break
return self.cmd_iter(f_tgt, fun, arg, timeout, tgt_type='list', ret=ret, kwarg=kwarg, **kwargs) | [
"def",
"cmd_subset",
"(",
"self",
",",
"tgt",
",",
"fun",
",",
"arg",
"=",
"(",
")",
",",
"timeout",
"=",
"None",
",",
"tgt_type",
"=",
"'glob'",
",",
"ret",
"=",
"''",
",",
"kwarg",
"=",
"None",
",",
"sub",
"=",
"3",
",",
"*",
"*",
"kwargs",
... | Execute a command on a random subset of the targeted systems
The function signature is the same as :py:meth:`cmd` with the
following exceptions.
:param sub: The number of systems to execute on
.. code-block:: python
>>> import salt.client.ssh.client
>>> sshclient= salt.client.ssh.client.SSHClient()
>>> sshclient.cmd_subset('*', 'test.ping', sub=1)
{'jerry': True}
.. versionadded:: 2017.7.0 | [
"Execute",
"a",
"command",
"on",
"a",
"random",
"subset",
"of",
"the",
"targeted",
"systems"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/client/ssh/client.py#L174-L214 | train |
saltstack/salt | salt/states/eselect.py | set_ | def set_(name, target, module_parameter=None, action_parameter=None):
'''
Verify that the given module is set to the given target
name
The name of the module
target
The target to be set for this module
module_parameter
additional params passed to the defined module
action_parameter
additional params passed to the defined action
.. code-block:: yaml
profile:
eselect.set:
- target: hardened/linux/amd64
'''
ret = {'changes': {},
'comment': '',
'name': name,
'result': True}
old_target = __salt__['eselect.get_current_target'](name, module_parameter=module_parameter, action_parameter=action_parameter)
if target == old_target:
ret['comment'] = 'Target \'{0}\' is already set on \'{1}\' module.'.format(
target, name
)
elif target not in __salt__['eselect.get_target_list'](name, action_parameter=action_parameter):
ret['comment'] = (
'Target \'{0}\' is not available for \'{1}\' module.'.format(
target, name
)
)
ret['result'] = False
elif __opts__['test']:
ret['comment'] = 'Target \'{0}\' will be set on \'{1}\' module.'.format(
target, name
)
ret['result'] = None
else:
result = __salt__['eselect.set_target'](name, target, module_parameter=module_parameter, action_parameter=action_parameter)
if result:
ret['changes'][name] = {'old': old_target, 'new': target}
ret['comment'] = 'Target \'{0}\' set on \'{1}\' module.'.format(
target, name
)
else:
ret['comment'] = (
'Target \'{0}\' failed to be set on \'{1}\' module.'.format(
target, name
)
)
ret['result'] = False
return ret | python | def set_(name, target, module_parameter=None, action_parameter=None):
'''
Verify that the given module is set to the given target
name
The name of the module
target
The target to be set for this module
module_parameter
additional params passed to the defined module
action_parameter
additional params passed to the defined action
.. code-block:: yaml
profile:
eselect.set:
- target: hardened/linux/amd64
'''
ret = {'changes': {},
'comment': '',
'name': name,
'result': True}
old_target = __salt__['eselect.get_current_target'](name, module_parameter=module_parameter, action_parameter=action_parameter)
if target == old_target:
ret['comment'] = 'Target \'{0}\' is already set on \'{1}\' module.'.format(
target, name
)
elif target not in __salt__['eselect.get_target_list'](name, action_parameter=action_parameter):
ret['comment'] = (
'Target \'{0}\' is not available for \'{1}\' module.'.format(
target, name
)
)
ret['result'] = False
elif __opts__['test']:
ret['comment'] = 'Target \'{0}\' will be set on \'{1}\' module.'.format(
target, name
)
ret['result'] = None
else:
result = __salt__['eselect.set_target'](name, target, module_parameter=module_parameter, action_parameter=action_parameter)
if result:
ret['changes'][name] = {'old': old_target, 'new': target}
ret['comment'] = 'Target \'{0}\' set on \'{1}\' module.'.format(
target, name
)
else:
ret['comment'] = (
'Target \'{0}\' failed to be set on \'{1}\' module.'.format(
target, name
)
)
ret['result'] = False
return ret | [
"def",
"set_",
"(",
"name",
",",
"target",
",",
"module_parameter",
"=",
"None",
",",
"action_parameter",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"'changes'",
":",
"{",
"}",
",",
"'comment'",
":",
"''",
",",
"'name'",
":",
"name",
",",
"'result'",
":... | Verify that the given module is set to the given target
name
The name of the module
target
The target to be set for this module
module_parameter
additional params passed to the defined module
action_parameter
additional params passed to the defined action
.. code-block:: yaml
profile:
eselect.set:
- target: hardened/linux/amd64 | [
"Verify",
"that",
"the",
"given",
"module",
"is",
"set",
"to",
"the",
"given",
"target"
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/states/eselect.py#L26-L85 | train |
saltstack/salt | salt/modules/napalm_network.py | _filter_list | def _filter_list(input_list, search_key, search_value):
'''
Filters a list of dictionary by a set of key-value pair.
:param input_list: is a list of dictionaries
:param search_key: is the key we are looking for
:param search_value: is the value we are looking for the key specified in search_key
:return: filered list of dictionaries
'''
output_list = list()
for dictionary in input_list:
if dictionary.get(search_key) == search_value:
output_list.append(dictionary)
return output_list | python | def _filter_list(input_list, search_key, search_value):
'''
Filters a list of dictionary by a set of key-value pair.
:param input_list: is a list of dictionaries
:param search_key: is the key we are looking for
:param search_value: is the value we are looking for the key specified in search_key
:return: filered list of dictionaries
'''
output_list = list()
for dictionary in input_list:
if dictionary.get(search_key) == search_value:
output_list.append(dictionary)
return output_list | [
"def",
"_filter_list",
"(",
"input_list",
",",
"search_key",
",",
"search_value",
")",
":",
"output_list",
"=",
"list",
"(",
")",
"for",
"dictionary",
"in",
"input_list",
":",
"if",
"dictionary",
".",
"get",
"(",
"search_key",
")",
"==",
"search_value",
":",... | Filters a list of dictionary by a set of key-value pair.
:param input_list: is a list of dictionaries
:param search_key: is the key we are looking for
:param search_value: is the value we are looking for the key specified in search_key
:return: filered list of dictionaries | [
"Filters",
"a",
"list",
"of",
"dictionary",
"by",
"a",
"set",
"of",
"key",
"-",
"value",
"pair",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_network.py#L70-L87 | train |
saltstack/salt | salt/modules/napalm_network.py | _filter_dict | def _filter_dict(input_dict, search_key, search_value):
'''
Filters a dictionary of dictionaries by a key-value pair.
:param input_dict: is a dictionary whose values are lists of dictionaries
:param search_key: is the key in the leaf dictionaries
:param search_values: is the value in the leaf dictionaries
:return: filtered dictionary
'''
output_dict = dict()
for key, key_list in six.iteritems(input_dict):
key_list_filtered = _filter_list(key_list, search_key, search_value)
if key_list_filtered:
output_dict[key] = key_list_filtered
return output_dict | python | def _filter_dict(input_dict, search_key, search_value):
'''
Filters a dictionary of dictionaries by a key-value pair.
:param input_dict: is a dictionary whose values are lists of dictionaries
:param search_key: is the key in the leaf dictionaries
:param search_values: is the value in the leaf dictionaries
:return: filtered dictionary
'''
output_dict = dict()
for key, key_list in six.iteritems(input_dict):
key_list_filtered = _filter_list(key_list, search_key, search_value)
if key_list_filtered:
output_dict[key] = key_list_filtered
return output_dict | [
"def",
"_filter_dict",
"(",
"input_dict",
",",
"search_key",
",",
"search_value",
")",
":",
"output_dict",
"=",
"dict",
"(",
")",
"for",
"key",
",",
"key_list",
"in",
"six",
".",
"iteritems",
"(",
"input_dict",
")",
":",
"key_list_filtered",
"=",
"_filter_li... | Filters a dictionary of dictionaries by a key-value pair.
:param input_dict: is a dictionary whose values are lists of dictionaries
:param search_key: is the key in the leaf dictionaries
:param search_values: is the value in the leaf dictionaries
:return: filtered dictionary | [
"Filters",
"a",
"dictionary",
"of",
"dictionaries",
"by",
"a",
"key",
"-",
"value",
"pair",
"."
] | e8541fd6e744ab0df786c0f76102e41631f45d46 | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_network.py#L90-L108 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.