-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg-server-power
executable file
·57 lines (41 loc) · 1.16 KB
/
gg-server-power
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
#!/usr/bin/env python
"""
Tool to power server. Typical usage would be:
./gg-server-power -i 123 cycle
or:
./gg-server-power -n my_server on
"""
import sys
import getopt
from GoGridManager import GoGridManager
valid_actions = ["on", "off", "cycle"]
def usage():
print "%s [-i id|-n name] [ -p profile ] [%s]" % (sys.argv[0], "|".join(valid_actions))
if __name__ == "__main__":
account = "default"
id = name = None
try:
opts, args = getopt.getopt(sys.argv[1:], "i:n:p:")
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
for o, a in opts:
if o == "-i":
id = a
elif o == "-n":
name = a
elif o == "-p":
account = a
if (name is None and id is None):
print "You should specifiy either id or name!"
sys.exit(1)
manager = GoGridManager(account=account)
if len(args) != 1:
usage()
sys.exit(2)
action = args[0]
if action not in valid_actions:
usage()
sys.exit(2)
server = manager.power_server(id=id, name=name, action=action)
print "%s %s" % (server.name, server.ip.ip)