Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _do(name, fun):
'''
Invoke a function in the lxc module with no args
'''
host = find_guest(name, quiet=True)
if not host:
return False
client = salt.client.LocalClient(__opts__['conf_file'])
cmd_ret = client.cmd_iter(
host,
'lxc.{0}'.format(fun),
[name],
timeout=60)
data = next(cmd_ret)
data = data.get(host, {}).get('ret', None)
if data:
data = {host: data}
return data
def EnableMonitoringPlugin(nodes, pluginName, ctxt=""):
failed_minions = {}
source_file = monitoring_disabled_root_path + pluginName + '.conf'
destination = monitoring_root_path
local = salt.client.LocalClient()
out = local.cmd(
nodes, "cmd.run", [
"mv " + source_file + " " + destination], expr_form='list')
for nodeName, message in out.iteritems():
if out.get(nodeName) != '':
log.error(
'%s-Failed to enable collectd plugin %s because %s on %s' %
(ctxt, pluginName, out.get(nodeName), nodeName))
failed_minions[nodeName] = out.get(nodeName)
if failed_minions:
return failed_minions
out = local.cmd(nodes, 'service.restart', ['collectd'], expr_form='list')
for node, restartStatus in out.iteritems():
if not restartStatus:
log.error("%s-Failed to restart collectd on node %s after enabling the plugin %s" %(ctxt, node, pluginName))
failed_minions[node] = "Failed to restart collectd"
@memoize
def _salt_client():
return salt.client.LocalClient()
def need_restart_lsof(role=None, cluster='ceph'):
"""
Complement Runner call to cephprocesses.need_restart_lsof
"""
assert role
_stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
local = salt.client.LocalClient()
role_search = "I@cluster:{} and I@roles:{}".format(cluster, role)
restart = local.cmd(role_search,
'cephprocesses.need_restart_lsof',
["role={}".format(role)],
tgt_type="compound")
sys.stdout = _stdout
for need_rs in six.itervalues(restart):
if need_rs:
return True
return False
def __init__(self, debug=False):
self.debug = debug
self.log = logging.getLogger("Main.VpsHerder")
try:
self.local = salt.client.LocalClient()
except ImportError:
print("No local salt.client.LocalClient. Running without, may cause errors!")
except salt.exceptions.SaltClientError:
print("Cannot load salt master configuration!")
except IOError:
print("Cannot load salt master configuration!")
self.cc = salt.cloud.CloudClient('/etc/salt/cloud')
self.mon_con = statsd.StatsClient(
host = settings.GRAPHITE_DB_IP,
port = 8125,
prefix = 'ReadableWebProxy.VpsHerder',
)
def __init__(self, search):
"""
Set search criteria
"""
self.search = search
self.passed = OrderedDict()
self.warnings = OrderedDict()
self.local = salt.client.LocalClient()
def _ganesha_configurations(self):
"""
Use the custom names for ganesha configurations specified. Otherwise,
default to 'ganesha'.
"""
local = salt.client.LocalClient()
_ganeshas = local.cmd(self.search, 'pillar.get',
['ganesha_configurations'], tgt_type="compound")
for node in _ganeshas:
# Check the first one
if _ganeshas[node]:
return _ganeshas[node]
else:
return ['ganesha']
print(" os: {}".format(next(iter(os_codename.values()))))
print("")
return True
# We've got different versions of base OS, or ceph, or both, so we need:
# - all the roles, to provide advice on what next to upgrade
# - the OS and ceph versions in an easily comparable form, to figure out
# what's newest
down_nodes = [node for node in os_codename if os_codename[node].startswith("Unknown")]
search = "I@cluster:ceph"
if down_nodes:
search += " and not ( {} )".format("or ".join(down_nodes))
local = salt.client.LocalClient()
roles = local.cmd(search, 'pillar.get', ['roles'], tgt_type="compound")
os_release = local.cmd(search, 'grains.get', ['osrelease'], tgt_type="compound")
for node in os_release:
os_release[node] = version.parse(os_release[node])
ceph_release = {}
for node in ceph_version:
match = re.match(r'ceph version ([^\s]+)', ceph_version[node])
if match:
ceph_release[node] = version.parse(match.group(1))
else:
# If ceph_version is "Unknown" or "Not installed", this still gives
# a comparable version object, which sorts before actual versions
ceph_release[node] = version.parse(ceph_version[node])
def _process(hostname, device_name, led, status):
"""
Turn on/off the specified LED of the disk on the given host.
"""
assert not device_name.startswith('/dev/')
assert led in ['ident', 'fault']
local_client = salt.client.LocalClient()
device_file = '/dev/{}'.format(device_name)
status = 'on' if status in [True, 'on'] else 'off'
# Get the configuration of the command to turn on/off the ident
# or fault LED on the target host.
result = local_client.cmd(
hostname, 'pillar.get', ['disk_led:cmd'], tgt_type='compound')
if not result or hostname not in result.keys():
raise RuntimeError(
'Failed to get "disk_led:cmd" configuration from pillar')
cmd_cfg = result[hostname]
if not isinstance(cmd_cfg, dict):
raise RuntimeError('Invalid "disk_led:cmd" configuration')
print('Turning {} the {} LED of disk "{}" on host "{}" ...'.format(
status, led, device_file, hostname))
def _list_nodes(call=None):
'''
List the nodes, ask all 'vagrant' minions, return dict of grains.
'''
local = salt.client.LocalClient()
ret = local.cmd('salt-cloud:driver:vagrant', 'grains.items', '', tgt_type='grain')
return ret