Skip to content

Commit

Permalink
Make 'pscheduler ping' default to the local host. #1453
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeit-internet2 committed Jul 2, 2024
1 parent afa0cab commit 5d6b764
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pscheduler-core/pscheduler-core/ping
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class VerbatimParser(optparse.OptionParser):
return self.epilog

opt_parser = VerbatimParser(
usage="Usage: %prog host",
usage="Usage: %prog [ HOST ]",
epilog=
"""
Example:
ping
Check on the local host
ping perfsonar6.example.org
Check on the host at perfsonar6.example.org
"""
Expand All @@ -47,19 +50,24 @@ opt_parser.add_option("--timeout", "-W",

(options, remaining_args) = opt_parser.parse_args()

if len(remaining_args) != 1:
if len(remaining_args) > 1:
opt_parser.print_usage()
pscheduler.fail()

if options.timeout <= 0:
pscheduler.fail("Timeout must be >= 0")

host = remaining_args[0]
try:
host = remaining_args[0]
host_display = host
except IndexError:
host = None
host_display = pscheduler.api_local_host()

up, reason = pscheduler.api_ping(host, timeout=options.timeout,
bind=options.bind)

message = "%s: %s" % (host, reason)
message = "%s: %s" % (host_display, reason)

if up:
pscheduler.succeed(message)
Expand Down

0 comments on commit 5d6b764

Please sign in to comment.