Debian Codegraph @

script/ecaccess-gateway-list

raw
1 #!/usr/bin/perl -w
2 #
3 # ecaccess-gateway-list: List the ECaccess Gateways
4 #
5 # [email protected] - 2010-10-15
6
7 use ECMWF::ECaccess;
8 use Getopt::Long;
9 use Pod::Usage;
10 use Term::ReadKey;
11
12 my %opt = ( version => 0, help => 0, manual => 0, debug => 0 );
13
14 pod2usage( -noperldoc => 1, -exit => 1, retry => 0, verbose => 1 ) if !GetOptions(
15 \%opt,
16 qw(
17 version
18 help|?
19 manual
20 retry=i
21 debug
22 )
23 );
24
25 # Display version if requested
26 die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} );
27
28 my $gatewayName = $ARGV[0];
29
30 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} );
31 pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} );
32
33 # Create the ECaccess Controler
34 my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug});
35
36 # Get the Token (using the Certificate in $HOME)
37 my $token = $ecaccess->getToken();
38
39 # Get the Control Channel
40 my $controlChannel = $ecaccess->getControlChannel();
41
42 if ( not($gatewayName) ) {
43
44 # Get the list of Gateways
45 my $gateways = $controlChannel->getGatewayList($token);
46
47 # Display the information for each Gateway
48 foreach $gateway ( $gateways->valueof('//getGatewayListResponse/return') ) {
49 printf "%-16s %-12s %s", $gateway->{version}, $gateway->{lastReport}, $gateway->{name};
50 print " (off)" if not( $gateway->{active} eq 'true' );
51 print "\n";
52 }
53 }
54 else {
55
56 # Get the detail for the specified Gateway
57 my $gateway = $controlChannel->getGateway( $token, $gatewayName )->valueof('//getGatewayResponse/return');
58 print " Name: " . $gateway->{name} . "\n";
59 print " Version: " . $gateway->{version} . "\n";
60 print " OS/JDK: " . $gateway->{comment} . "\n";
61 print "Connected: " . ( $gateway->{active} eq 'true' ? 'yes' : 'no' ) . " (since " . $gateway->{lastReport} . ")\n";
62 }
63
64 # Logout
65 END {
66 $ecaccess->releaseToken($token) if ($token);
67 }
68
69 __END__
70
71 =head1 NAME
72
73 ecaccess-gateway-list - List the ECaccess Gateways
74
75 =head1 SYNOPSIS
76
77 B<ecaccess-gateway-list -version|-help|-manual>
78
79 B<ecaccess-gateway-list [-debug]> B<[>I<gateway-name>B<]>
80
81 =head1 DESCRIPTION
82
83 List all the ECaccess Gateways. When a I<gateway-name> is specified
84 then the details for this Gateway are displayed.
85
86 =head1 ARGUMENTS
87
88 =over 8
89
90 =item I<gateway-name> (optional)
91
92 The name of the ECaccess Gateway to retrieve the details.
93
94 =back
95
96 =head1 OPTIONS
97
98 =over 8
99
100 =item B<-version>
101
102 Display version number and exits.
103
104 =item B<-help>
105
106 Print a brief help message and exits.
107
108 =item B<-manual>
109
110 Prints the manual page and exits.
111
112 =item B<-retry> I<count>
113
114 Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the
115 initial SSL connection initiated by the command to the ECMWF server. It does not
116 apply to all the subsequent requests made afteward as it is mainly targeting errors
117 that can happen from time to time during the SSL handshake. Default is no retry.
118
119 =item B<-debug>
120
121 Display the SOAP and SSL messages exchanged.
122
123 =back
124
125 =head1 EXAMPLES
126
127 B<ecaccess-gateway-list>
128
129 List all the ECaccess Gateways.
130
131 B<ecaccess-gateway-list> I<boaccess.ecmwf.int>
132
133 List the details for the ECaccess Gateway I<boaccess.ecmwf.int>.
134
135 =head1 SEE ALSO
136
137 B<ecaccess-gateway-name>, B<ecaccess-gateway-connected>, B<ecaccess>.
138
139 =cut