diff --git a/src/allclients.py b/src/allclients.py index 073af18d073a5201f04291eea77cac25475b3e9e..241de5b59b46db80f26eb5dac8c85ccff444a109 100644 --- a/src/allclients.py +++ b/src/allclients.py @@ -38,7 +38,11 @@ if __name__ == '__main__': optParser.add_option("-g", "--group", action="append", default=[], metavar="GROUP", - help="apply actions only to GROUP") + help="apply actions to GROUP") + optParser.add_option("-m", "--machine", + action="append", default=[], + metavar="MACHINE", + help="apply actions to MACHINE") optParser.add_option("-o", "--ordered", action="store_true", default=False, help="order result by hostname") @@ -65,7 +69,7 @@ if __name__ == '__main__': if options.ipv4 and options.ipv6: raise Exception('Only one --ipv4 or --ipv6 may be specified') - if not options.group: + if not options.group and not options.machine: options.group = [ '__all__' ] pass exclude = set() @@ -73,21 +77,29 @@ if __name__ == '__main__': exclude.update(local_interfaces()) pass hosts = set() - for n in map(netgroup.getgroup, options.group): - for h,_,_ in n: - try: - for _,_,_,_,a in socket.getaddrinfo(h, 0, - socket.AF_UNSPEC, - socket.SOCK_STREAM): - if not a[0] in exclude: - hosts.add(h) - pass + def add_host(name): + try: + for _,_,_,_,a in socket.getaddrinfo(name, 0, + socket.AF_UNSPEC, + socket.SOCK_STREAM): + if not a[0] in exclude: + hosts.add(name) pass pass - except socket.gaierror: - # Silently skip non-existing machines + pass + except socket.gaierror: + if not options.quiet: + print('%s has no address' % name) pass pass + return + for n in map(netgroup.getgroup, options.group): + for h,_,_ in n: + add_host(h) + pass + pass + for h in options.machine: + add_host(h) pass if hosts: def status(msg, done, failed, total):