rq.yaml: cmds -> scripts

added implementation to launch commands from rq.yaml
This commit is contained in:
adobdin 2016-05-11 11:09:04 +00:00
parent 7c3a1eafbb
commit e865055ca8
2 changed files with 34 additions and 2 deletions

12
rq.yaml
View File

@ -9,7 +9,7 @@ files:
by_os_platform:
centos: [yum]
ubuntu: [etc-apt]
cmds:
scripts:
by_release:
'4.1.1':
by_roles:
@ -55,3 +55,13 @@ cmds:
centos: [dmesg-centos, packages-centos]
__default:
[ip-ne, iptables, ipnetns, ss, ipa, iptables-nat, df-m, services-status, cpuinfo, df-i, ipro]
# cmds:
# __default:
# test:
# 'echo "test" | head -n 1'
# test2:
# 'echo "test2" | less'
# by_roles:
# compute:
# t3: 'echo t3'
# t4: 'echo t4'

View File

@ -166,7 +166,29 @@ class Node(object):
ddir = os.path.join(odir, ckey, cl, sn)
tools.mdir(ddir)
for c in self.cmds:
f = os.path.join(self.rqdir, 'cmds', c)
for cmd in c:
if not fake:
outs, errs, code = tools.ssh_node(ip=self.ip,
command=c[cmd],
ssh_opts=self.ssh_opts,
env_vars=self.env_vars,
timeout=self.timeout)
if code not in ok_codes:
logging.warning("node: %s, ip: %s, cmdfile: %s,"
" code: %s, error message: %s" %
(self.id, self.ip, c, code, errs))
dfile = os.path.join(ddir, 'node-%s-%s-%s' %
(self.id, self.ip, cmd))
logging.info('outfile: %s' % dfile)
self.mapcmds['cmd-'+cmd] = dfile
if not fake:
try:
with open(dfile, 'w') as df:
df.write(outs)
except:
logging.error("exec_cmd: can't write to file %s" % dfile)
for scr in self.scripts:
f = os.path.join(self.rqdir, 'scripts', scr)
logging.info('node:%s(%s), exec: %s' % (self.id, self.ip, f))
if not fake:
outs, errs, code = tools.ssh_node(ip=self.ip,