-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg-server-add
executable file
·59 lines (46 loc) · 1.42 KB
/
gg-server-add
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
#!/usr/bin/env python
"""A script to add a new server
Example:
./gg-server-add -n somename -i centos51_64_apache -r 512MB -a som.e.add.r
You can omit IP address of the machine (i.e. don't specify -a) and it will pick
on of the available public IPs in state Unassigned.
"""
import sys
import getopt
from random import choice
from GoGridManager import GoGridManager
def usage():
print "%s -n name -i image -r ram -a ip_addr [ -d descr ] [ -s ]" % sys.argv[0]
print
if __name__ == "__main__":
account = "default"
name = image = ram = ip = descr = None
sandbox = False
try:
opts, args = getopt.getopt(sys.argv[1:], "n:i:p:r:sa:d:")
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
for o, a in opts:
if o == "-p":
account = a
elif o == "-n":
name = a
elif o == "-i":
image = a
elif o == "-r":
ram = a
elif o == "-s":
sandbox = True
elif o == "-a":
ip = a
elif o == "-d":
descr = a
manager = GoGridManager(account=account)
if ip is None:
ip = choice(manager.get_ips(type='Public', state='Unassigned')).ip
if (name and image and ram and ip) is None:
usage()
sys.exit(2)
server = manager.add_server(name, image, ram, ip, descr, sandbox=sandbox)
print "%s %s" % (server.name, server.ip.ip)