forked from MFALHI/netplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupProxy.py
More file actions
executable file
·90 lines (76 loc) · 2.32 KB
/
Copy pathsetupProxy.py
File metadata and controls
executable file
·90 lines (76 loc) · 2.32 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
# sanity tests
import time
import sys
import os
import urllib
import urllib2
import json
# Wrapper for HTTP get
def httpGet(url):
try:
retData = urllib2.urlopen(url)
return retData.read()
except urllib2.HTTPError, err:
if err.code == 404:
print "Page not found!"
elif err.code == 403:
print "Access denied!"
else:
print "HTTP Error! Error code", err.code
return "Error"
except urllib2.URLError, err:
print "URL error:", err.reason
return "Error"
# Function to setup proxy
def setupProxy():
print "Setting up proxy"
cfg = """{
"Tenants" : [ {
"Name" : "default",
"Networks" : [
{
"Name" : "private",
"Endpoints" : [ {
"Container" : "proxyPort",
"Host" : "netplugin-node1"
}]
} ]
} ]
}
"""
# Write the config file
print "Writing config file.."
cfgFile = "/tmp/proxy-endpoint.cfg"
f = open(cfgFile,'w')
f.write(cfg)
f.close()
# Add the config to Netmaster
print 'netdcli -add-cfg ' + cfgFile
print os.popen('netdcli -add-cfg ' + cfgFile).read()
print "Adding ovs interface"
# get the endpoints
for iter in range(5):
resp = httpGet('http://netmaster:9999/endpoints')
if resp != "Error":
# Read the json response
epList = json.loads(resp)
# Look for pro
for ep in epList:
if ep['id'] == "private.default-proxyPort":
# Config ip and bringup interface
print "Found the proxy endpoint, bringing up the ovs interface"
print "sudo ifconfig " + ep['portName'] + " " + ep['ipAddress'] + " up"
print os.popen("sudo ifconfig " + ep['portName'] + " " + ep['ipAddress'] + " up").read()
return
print "Failed to find proxy endpoint. Retrying.."
else:
print "HTTP error reading endpoints. Retrying.."
# Retry after 1 sec
time.sleep(1)
# Failed to create endpoint
print "ERROR: Error finding proxy endpoint. Exiting"
os._exit(1)
if __name__ == "__main__":
# Call it
setupProxy()