def delete_rule(table, chain, rule_text): command = 'iptables -t %s -D %s %s' % (table, chain, rule_text) LOGGER.info('delete rule: %s' % command) try: shell.check_call(shlex.split(command)) except: LOGGER.exception('failed to delete rule: %s' % command)
def emacs(path, cluster_id): try: instance = aws.ec2._ls([master_instance_id(cluster_id)])[0] shell.check_call( "nohup emacsclient /hadoop@{}:{} > /dev/null &".format( instance.public_dns_name, path)) except: sys.exit(1)
def emacs(path, name): _ip = list(ip(name))[0] logging.info(_ip) try: shell.check_call( "nohup emacsclient /ubuntu@{}:{} > /dev/null &".format(_ip, path)) except: sys.exit(1)
def insert_rule(optional, table, chain, rule_text): command = 'iptables -t %s -I %s %s' % (table, chain, rule_text) LOGGER.info('insert %s rule: %s' % ('optional' if optional else 'mandatory', command)) try: shell.check_call(shlex.split(command)) except: if optional: LOGGER.exception('skip optional iptables rule') else: raise
def insert_rule(optional, table, chain, rule_text): command = "iptables -t %s -I %s %s" % (table, chain, rule_text) LOGGER.info("insert %s rule: %s" % ("optional" if optional else "mandatory", command)) try: shell.check_call(shlex.split(command)) except: if optional: LOGGER.exception("skip optional iptables rule") else: raise
def pull(src, dst, name, filter=None, yes=False): _ip = list(ip(name))[0] logging.info('targeting:\n %s', _ip) script = _tar_script(src, filter, echo_only=True) cmd = ('cat %(script)s |ssh' + ssh_args + 'ubuntu@%(_ip)s bash -s') % locals() logging.info('going to pull:') logging.info(util.strings.indent(shell.check_output(cmd), 1)) shell.check_call('rm -rf', os.path.dirname(script)) if is_cli and not yes: logging.info('\nwould you like to proceed? y/n\n') assert pager.getch() == 'y', 'abort' script = _tar_script(src, filter) cmd = ('cd %(dst)s && cat %(script)s | ssh' + ssh_args + 'ubuntu@%(_ip)s bash -s | tar xf -') % locals() try: shell.check_call(cmd) except: logging.info('failure for: %s', _ip) sys.exit(1) finally: shell.check_call('rm -rf', os.path.dirname(script))
def emacs(path, cluster_id): try: instance = aws.ec2._ls([master_instance_id(cluster_id)])[0] shell.check_call("nohup emacsclient /hadoop@{}:{} > /dev/null &".format(instance.public_dns_name, path)) except: sys.exit(1)
def push(src, dst, name=None, group=None, filter=None, yes=False, max_threads=0, user='******'): if name: _ips = list(ip(name)) else: _ips = list(ips(group)) logging.info('targeting:') for _ip in _ips: logging.info(' %s', _ip) logging.info( 'going to push:\n%s', util.strings.indent( shell.run('bash', _tar_script(src, filter, echo_only=True)), 1)) if is_cli and not yes: logging.info('\nwould you like to proceed? y/n\n') assert pager.getch() == 'y', 'abort' script = _tar_script(src, filter) failures = [] successes = [] justify = max(len(_ip) for _ip in _ips) def run(_ip, color): if color: color = getattr(util.colors, color) else: color = lambda x: x _name = (_ip + ': ').ljust(justify + 2) def fn(): try: shell.run( 'bash', script, '|ssh', ssh_args, user + '@' + _ip, '"mkdir -p', dst, '&& cd', dst, '&& tar xf -"', callback=lambda x: print(color(_name + x), flush=True)) except: failures.append(util.colors.red('failure: ') + _ip) else: successes.append(util.colors.green('success: ') + _ip) return fn pool.thread.wait(*map( run, _ips, itertools.cycle(util.colors._colors) if len(_ips) > 1 else [False]), max_threads=max_threads) shell.check_call('rm -rf', os.path.dirname(script)) logging.info('\nresults:') for msg in successes + failures: logging.info(' ' + msg) if failures: sys.exit(1)