Ejemplo n.º 1
0
    else:
        return parameter

cluster = raw_input(Fore.CYAN + "Enter cluster name [all] : ") or "all" if not args["machine_cluster"] else args["machine_cluster"]
command = raw_input(Fore.CYAN + "Enter command name to execute [login] : ") or False if not args["command"] else args["command"]

if command and command != "login":
    command = "hostname; " + command

if cluster == "all":
    public_ips = ConfigReader.get_all_common_parameters("public_ip")
# returning  m/c's after applying filter
elif args['filter']:
    args['filter'][1] = convert_to_boolean(args['filter'][1])
    public_ips = ConfigReader.get_parameter_for_cluster_after_applying_filters( cluster = args["machine_cluster"], parameter = "public_ip",filter_parameter = args['filter'][0], filter_value = args['filter'][1])
else:
    public_ips = ConfigReader.get_parameter_for_cluster(cluster = cluster, parameter = "public_ip")

public_ips = (ip for ip in public_ips if ip)
public_ips = set(public_ips)
for ip in public_ips:
    if command == "login":
        cmd = 'ssh root@' + ip
        os.system(cmd)
        continue
    cmd = 'ssh root@' + ip + " " + shellquote(command) if command else 'ssh root@' + ip
    print(Fore.RED + cmd)
    if command:
        output = commands.getoutput(cmd)
        print(Fore.YELLOW + output)