def run(self, params, args): restart, = self.fillParams([('restart', 'yes')]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) me = self.db.getHostname('localhost') threads = [] for host in hosts: # # get the attributes for the host # attrs = self.db.getHostAttrs(host) if self.str2bool(attrs.get('firewall')) != True: continue cmd = '/opt/stack/bin/stack report host firewall ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if me != host: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) if restartit: threads = [] for host in hosts: cmd = '/sbin/service iptables restart ' cmd += '> /dev/null 2>&1' if me != host: cmd = 'ssh -T -x %s "%s"' % (host, cmd) p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) self.runPlugins(hosts)
def run(self, params, args): sys.stdout = open('/dev/null') sys.stderr = open('/dev/null') hosts = self.getHostnames(args, managed_only=1) me = self.db.getHostname('localhost') threads = [] for host in hosts: attrs = {} for row in self.call('list.host.attr', [host]): attrs[row['attr']] = row['value'] cmd = '/opt/stack/bin/stack report host yum %s | ' % host cmd += '/opt/stack/bin/stack report script | ' if me != host: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' try: p = Parallel(cmd) p.start() threads.append(p) except: pass # # collect the threads # for thread in threads: thread.join(timeout)
def run(self, params, args): prms = self._params if prms: pkeys = list(prms.keys())[0] pvalues = list(prms.values())[0] self.notify('Sync Host Ansible Inventory') hosts = self.getHostnames(args, managed_only=0) run_hosts = self.getRunHosts(hosts) me = self.db.getHostname('localhost') # Only shutdown stdout/stderr if we not local for host in hosts: if host != me: sys.stdout = open('/dev/null') sys.stderr = open('/dev/null') break threads = [] ha = self.call('list.host.attr', hosts) g = lambda x: (x['attr'], x['value']) host_attrs = {} for host in hosts: if host not in host_attrs: host_attrs[host] = {} f = lambda x: x['host'] == host tmp_f = list(filter(f, ha)) host_attrs[host] = dict(list(map(g, tmp_f))) for h in run_hosts: host = h['host'] hostname = h['name'] if prms: cmd = '/opt/stack/bin/stack report ansible %s ' % host cmd += '%s=%s | ' % (pkeys, pvalues) else: cmd = '/opt/stack/bin/stack report ansible %s | ' % host cmd += '/opt/stack/bin/stack report script | ' if me != host: cmd += 'ssh -T -x %s ' % hostname cmd += 'bash > /dev/null 2>&1 ' try: p = Parallel(cmd) p.start() threads.append(p) except: pass # # collect the threads # for thread in threads: thread.join(timeout)
def run(self, params, args): src,dest,svc = self.fillParams([ ('src', None), ('dest', None), ('service', None) ]) recurse = False hosts = self.getHostnames(args, managed_only=1) me = self.db.getHostname('localhost') if not src: raise ParamError(self,'src', "- no source is given.") if not os.path.isfile(src): if os.path.isdir(src): recurse = True else: raise CommandError(self, '%s is not a file or a directory' % src) if not dest: raise ParamError(self,'dest', "- no destination is given.") threads = [] for host in hosts: if me != host: if recurse: cmd = 'scp -r %s %s:%s ' % (src,host,dest) else: cmd = 'scp %s %s:%s ' % (src,host,dest) try: p = Parallel(cmd) p.start() threads.append(p) except: pass # # collect the threads # for thread in threads: thread.join(timeout) if svc: cmd = 'systemctl daemon-reload' cmd += 'systemctl restart %s' % svc api.Call('run.host',[hosts, cmd])
def run(self, params, args): self.notify('Sync Host Time') hosts = self.getHostnames(args, managed_only=1) run_hosts = self.getRunHosts(hosts) me = self.db.getHostname('localhost') # Only shutdown stdout/stderr if we not local for host in hosts: if host != me: sys.stdout = open('/dev/null') sys.stderr = open('/dev/null') break threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] cmd = '/opt/stack/bin/stack report host time %s | ' % host cmd += '/opt/stack/bin/stack report script | ' if me != host: cmd += 'ssh -T -x %s ' % hostname cmd += 'bash > /dev/null 2>&1 ' try: p = Parallel(cmd) p.start() threads.append(p) except: pass # # collect the threads # for thread in threads: thread.join(timeout)
def run(self, params, args): restart, = self.fillParams([ ('restart', 'yes') ]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) run_hosts = self.getRunHosts(hosts) me = self.db.getHostname('localhost') threads = [] out = {} host_output = {} ha = self.call('list.host.attr', hosts) g = lambda x: (x['attr'], x['value']) host_attrs = {} for host in hosts: if host not in host_attrs: host_attrs[host] = {} f = lambda x : x['host'] == host tmp_f = list(filter(f, ha)) host_attrs[host] = dict(list(map(g, tmp_f))) for h in run_hosts: host = h['host'] hostname = h['name'] host_output[host] = {"output": "", "error": "", "rc": 0} out[host] = "" attrs = host_attrs[host] if self.str2bool(attrs.get('firewall')) is not True: continue cmd = '/opt/stack/bin/stack report host firewall ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if me != host: cmd += 'ssh -T -x %s ' % hostname cmd += 'bash > /dev/null 2>&1 ' p = Parallel(cmd, host_output[host]) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) for host in host_output: if host_output[host]["rc"]: out[host] += host_output[host]['output'] if restartit: threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] if stack.release in [ 'redhat7' ]: cmd = 'systemctl restart iptables' elif stack.release in [ 'sles12' ]: cmd = 'systemctl restart stacki-iptables' else: cmd = '/sbin/service iptables restart' if me != host: cmd = 'ssh -T -x %s "%s"' % (hostname, cmd) host_output[host] = {"output": "", "error": "", "rc": 0} p = Parallel(cmd, host_output[host]) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) for host in host_output: if host_output[host]["rc"]: if isinstance((host_output[host]['output']), bytes): out[host] += host_output[host]['output'].decode() else: out[host] += str(host_output[host]['output']) self.beginOutput() for host in out: if len(out[host]): self.addOutput(host, out[host]) self.runPlugins(hosts) self.endOutput(header=['host', 'output'])
def run(self, args): hosts, subnet = args self.owner.fields = ["host", "to", "mbits/sec"] if not subnet: subnet = 'private' # # first, start iperf on all nodes # # remove the bye if it's there if 'bye' in hosts: hosts.remove('bye') cmd = 'systemctl start iperf3.service' res = self.owner.command('run.host', hosts + ['command=' + "%s" % cmd]) threads = [] file = open('/tmp/nettest.debug', 'w') for homes, aways in self.tournament(hosts, subnet): file.write('home %s\n' % homes) file.write('away %s\n' % aways) for home in homes: for away in aways: iperf_cmd = '/opt/stack/sbin/iperf3.py ' iperf_cmd += '%s %s' % (home, away) cmd = 'ssh -T -x %s "%s"' % (home, iperf_cmd) p = Parallel(cmd) threads.append(p) p.start() for thread in threads: thread.join(timeout) out = p.out['output'] file.write('%s\n' % out) for host in out: if type(out) != type({}) or not \ out.has_key(host) or \ type(out[host]) != type({}) or not \ out[host].has_key('away') or not \ out[host].has_key('sent') or not \ out[host].has_key('recv'): continue tohost = out[host]['away'] fromhost = self.owner.db.getHostname(host, subnet) if subnet == 'private': # # just output the short name, that is, # don't append the private domain # (e.g., ".local") # tohost = self.owner.db.getHostname(tohost) fromhost = self.owner.db.getHostname(fromhost) sent = float(out[host]['sent']) / (1000 * 1000) recv = float(out[host]['recv']) / (1000 * 1000) self.owner.addOutput(fromhost, (tohost, '%.2f' % sent)) self.owner.addOutput(tohost, (fromhost, '%.2f' % recv)) file.close() # remove the bye if it's there if 'bye' in hosts: hosts.remove('bye') cmd = 'systemctl stop iperf3.service' res = self.owner.command('run.host', hosts + ['command=' + "%s" % cmd])
def run(self, params, args): restart, = self.fillParams([ ('restart', 'yes') ]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) me = self.db.getHostname('localhost') threads = [] out = {} host_output = {} for host in hosts: host_output[host] = {"output": "", "error": "", "rc": 0} out[host] = "" attrs = {} for row in self.call('list.host.attr', [ host ]): attrs[row['attr']] = row['value'] if self.str2bool(attrs.get('firewall')) is not True: continue cmd = '/opt/stack/bin/stack report host firewall ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if me != host: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' p = Parallel(cmd, host_output[host]) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) for host in host_output: if host_output[host]["rc"]: out[host] += host_output[host]['output'] if restartit: threads = [] for host in hosts: if stack.release in [ 'redhat7', 'sles12' ]: cmd = 'systemctl restart iptables' else: cmd = '/sbin/service iptables restart' if me != host: cmd = 'ssh -T -x %s "%s"' % (host, cmd) host_output[host] = {"output": "", "error": "", "rc": 0} p = Parallel(cmd, host_output[host]) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) for host in host_output: if host_output[host]["rc"]: out[host] += host_output[host]['output'] self.beginOutput() for host in out: if len(out[host]): self.addOutput(host, out[host]) self.runPlugins(hosts) self.endOutput(header=['host', 'output'])
def run(self, params, args): restart, = self.fillParams([('restart', 'yes')]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) me = self.db.getHostname('localhost') threads = [] for host in hosts: attrs = {} for row in self.call('list.host.attr', [host]): attrs[row['attr']] = row['value'] cmd = '/opt/stack/bin/stack report host interface ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if host != me: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' cmd += '; /opt/stack/bin/stack report host network ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if host != me: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' cmd += '; /opt/stack/bin/stack report host route ' cmd += '%s | ' % host cmd += '/opt/stack/bin/stack report script ' cmd += 'attrs="%s" | ' % attrs if host != me: cmd += 'ssh -T -x %s ' % host cmd += 'bash > /dev/null 2>&1 ' p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) self.command('sync.host.firewall', ['restart=%s' % restart] + hosts) self.runPlugins(hosts) if restartit: # # after all the configuration files have been rewritten, # restart the network # threads = [] for host in hosts: cmd = '/sbin/service network restart ' cmd += '> /dev/null 2>&1 ; ' cmd += '/sbin/service ipmi restart > ' cmd += '/dev/null 2>&1' if host != me: cmd = 'ssh %s "%s"' % (host, cmd) p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) # # if IP addresses change, we'll need to sync the config (e.g., # update /etc/hosts, /etc/dhcpd.conf, etc.). # self.command('sync.config') # # hack for ganglia on the frontend # if me in hosts and os.path.exists('/etc/ganglia/gmond.conf'): os.system('service gmond restart > /dev/null 2>&1')
def run(self, params, args): restart, = self.fillParams([('restart', 'yes')]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) run_hosts = self.getRunHosts(hosts) host_attrs = self.getHostAttrDict(hosts) me = self.db.getHostname('localhost') threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] if host == me: self.cleanup() # Attributes for /etc/hosts management # # sync.hosts : write /etc/hosts during installation # (what it used to mean before we starting syncing in # this command as well). # # manage.hostsfile : write /etc/hosts during # installation. # # sync.hostsfile : write /etc/hosts during # sync.host.network IFF manage.hostsfile is also true. manage_hostsfile = self.str2bool(host_attrs[host].get( 'manage.hostsfile', False)) sync_hostsfile = self.str2bool(host_attrs[host].get( 'sync.hostsfile', False)) cmd = '( /opt/stack/bin/stack report host interface %s && ' % host cmd += '/opt/stack/bin/stack report host network %s && ' % host if manage_hostsfile and sync_hostsfile: # we only conditionally sync /etc/hosts cmd += '/opt/stack/bin/stack report host && ' cmd += '/opt/stack/bin/stack report host resolv %s && ' % host cmd += '/opt/stack/bin/stack report host route %s ) | ' % host cmd += '/opt/stack/bin/stack report script | ' if host != me: cmd += 'ssh -T -x %s ' % hostname cmd += 'bash > /dev/null 2>&1' p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) self.command('sync.host.firewall', ['restart=%s' % restart] + hosts) self.runPlugins(hosts) if restartit: # # after all the configuration files have been rewritten, # restart the network # threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] cmd = '/sbin/service network restart ' cmd += '> /dev/null 2>&1 ; ' cmd += '/sbin/service ipmi restart > ' cmd += '/dev/null 2>&1' if host != me: cmd = 'ssh %s "%s"' % (hostname, cmd) p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) # if IP addresses change, we'll need to sync the config (e.g., # update /etc/hosts, /etc/dhcpd.conf, etc.). # A note on /etc/hosts, since there's some commands that overlap # in management for the FE # # • `sync host` will always overwrite /etc/hosts on the FE # • `sync config` will always call `sync host` # • `sync host network` will respect the `sync.hosts` attr and # conditionally re-write /etc/hosts on backends. # • `sync host network` always calls `sync config` # • `sync host network localhost` therefore does not respect # the attribute for the FE # note: 'sync.hosts' implicitly defaults to `False`, meaning # don't rewrite /etc/hosts on backends # # The net effect is that we always want to rewrite the hostfile # for the FE (FE needs to know how to get ahold of hosts), but # only do the backends if we're explicitly asked to do so. self.command('sync.config')
def run(self, params, args): restart, = self.fillParams([('restart', 'yes')]) restartit = self.str2bool(restart) hosts = self.getHostnames(args, managed_only=1) run_hosts = self.getRunHosts(hosts) me = self.db.getHostname('localhost') threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] if host == me: self.cleanup() # Sometimes these return None, in that case, make them an empty string c = str(self.command('report.host.interface',[host]) or '') + \ str(self.command('report.host.network',[host]) or '') + \ str(self.command('report.host.route',[host]) or '') s = subprocess.Popen(['/opt/stack/bin/stack', 'report', 'script'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) o, e = s.communicate(input=c.encode()) cmd = '( /opt/stack/bin/stack report host interface %s && ' % host cmd += '/opt/stack/bin/stack report host network %s && ' % host cmd += '/opt/stack/bin/stack report host route %s ) | ' % host cmd += '/opt/stack/bin/stack report script | ' if host != me: cmd += 'ssh -T -x %s ' % hostname cmd += 'bash > /dev/null 2>&1' p = Parallel(cmd, stdin=o.decode()) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) self.command('sync.host.firewall', ['restart=%s' % restart] + hosts) self.runPlugins(hosts) if restartit: # # after all the configuration files have been rewritten, # restart the network # threads = [] for h in run_hosts: host = h['host'] hostname = h['name'] cmd = '/sbin/service network restart ' cmd += '> /dev/null 2>&1 ; ' cmd += '/sbin/service ipmi restart > ' cmd += '/dev/null 2>&1' if host != me: cmd = 'ssh %s "%s"' % (hostname, cmd) p = Parallel(cmd) threads.append(p) p.start() # # collect the threads # for thread in threads: thread.join(timeout) # # if IP addresses change, we'll need to sync the config (e.g., # update /etc/hosts, /etc/dhcpd.conf, etc.). # self.command('sync.config') # # hack for ganglia on the frontend # if me in hosts and os.path.exists('/etc/ganglia/gmond.conf'): os.system('service gmond restart > /dev/null 2>&1')