-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg-server-list
executable file
·60 lines (46 loc) · 1.4 KB
/
gg-server-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""A tool to list currently available servers.
Example:
./gg-server-list <-- shows a list of servers
./gg-server-list -H <-- shows a list of servers and appends header to the output
Yeah, that's simple"""
import sys
import getopt
from GoGridManager import GoGridManager
from GoGridClient import Error403
if __name__ == "__main__":
account = "default"
show_headers = False
show_description = False
try:
opts, args = getopt.getopt(sys.argv[1:], "p:Hd")
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
for o, a in opts:
if o == "-p":
account = a
elif o == "-H":
show_headers = True
elif o == "-d":
show_description = True
manager = GoGridManager(account=account)
try:
servers = manager.get_servers()
except (Error403,), e:
print e
sys.exit(2)
if show_headers:
if show_description:
desc_hdr = 'description'
else:
desc_hdr = ''
print "%6s %12s %20s %10s %s" % ("id", "name", "ip", "state", desc_hdr)
for server in servers:
if server.isSandbox:
server.name += '<'
if show_description:
desc = server.descr
else:
desc = ''
print "%6s %12s %20s %10s %s" % (server.id, server.name, server.ip.ip, server.state, desc)