-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_server.py
44 lines (32 loc) · 1.15 KB
/
deploy_server.py
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
import requests, sys
from optparse import OptionParser
from bs4 import BeautifulSoup
usage = "usage: %prog username password orgid netid imageid name password"
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
if len(args) < 7:
print "Not enough arguments: "
print usage
sys.exit()
username = args[0]
password = args[1]
orgid = args[2]
netid = args[3]
imageid = args[4]
name = args[5]
admin_password = args[6]
payload = """<Server xmlns='http://oec.api.opsource.net/schemas/server'>
<name>""" + name + """</name>
<description>test description</description>
<vlanResourcePath>/oec/""" + orgid + """/network/""" + netid + """</vlanResourcePath>
<imageResourcePath>/oec/base/image/""" + imageid + """</imageResourcePath>
<administratorPassword>""" + admin_password + """</administratorPassword>
<isStarted>true</isStarted>
</Server>"""
r = requests.post("https://api-eu.dimensiondata.com/oec/0.9/" + orgid + "/server", data=payload, auth=(username,password))
if r.status_code != 200:
print "error: " + str(r.status_code)
print r.text
sys.exit()
soup = BeautifulSoup(r.text).html.body
print r.text