Skip to content
Snippets Groups Projects
Commit f4c24e96 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Add possibilty to specify machines

parent 3c390154
Branches
No related tags found
No related merge requests found
......@@ -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:
def add_host(name):
try:
for _,_,_,_,a in socket.getaddrinfo(h, 0,
for _,_,_,_,a in socket.getaddrinfo(name, 0,
socket.AF_UNSPEC,
socket.SOCK_STREAM):
if not a[0] in exclude:
hosts.add(h)
hosts.add(name)
pass
pass
pass
except socket.gaierror:
# Silently skip non-existing machines
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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment