forked from mehdiBezahaf/intent-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_deployer.py
111 lines (99 loc) · 2.9 KB
/
upgrade_deployer.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from osmclient import client
import json
import os, time
# pip3 install git+http://osm.etsi.org/gerrit/osm/IM.git
# pip3 install git+http://osm.etsi.org/gerrit/osm/osmclient.git
# pip3 install pyaml pycurl jinja2 python-magic packaging requests verboselogs
def post_json(url, reroute_JSON):
try:
r = requests.post(url, data=reroute_JSON)
print(r.status_code)
except IOError as e:
print(e)
return
sess = client.Client(host="10.30.64.15", sol005=True)
# resp = sess.ns.create("routerProxy-ns", "test", "admin", wait=True)
# print(resp)
reroute_JSON = {
"api_key": "test-key",
"routes": [
{
"key": "00:00:00:00:00:06/None00:00:00:00:00:09/None",
"route": [
"00:00:00:00:00:06/None",
"of:0000000000000006",
"of:000000000000000b",
"of:000000000000000e",
"00:00:00:00:00:09/None",
],
}
],
}
print(post_json("http://localhost:5000/api/push_intent", json.dumps(reroute_JSON)))
print("Reroute done. Press Enter to continue...")
resp = sess.ns.exec_op(
"test",
op_name="action",
op_data={"primitive": "upgrade", "primitive_params": {}, "member_vnf_index": "1"},
wait=True,
)
print(resp)
# resp = sess.ns.exec_op("test", "downgrade", wait=True)
# print(resp)
input("Interface upgrade. Press Enter to continue...")
try:
resp = sess.ns.exec_op(
"test",
op_name="action",
op_data={
"primitive": "test",
"primitive_params": {"host": "10.10.0.6"},
"member_vnf_index": "1",
},
wait=True,
)
print(resp)
input("Testin results. Press Enter to continue...")
except:
os.system("ifconfig tap2 up")
time.sleep(30)
resp = sess.ns.exec_op(
"test",
op_name="action",
op_data={
"primitive": "test",
"primitive_params": {"host": "10.10.0.6"},
"member_vnf_index": "1",
},
wait=True,
)
print(resp)
input("Interface connectivity restored. Press Enter to continue...")
reroute_JSON = {
"api_key": "test-key",
"routes": [
{
"key": "00:00:00:00:00:06/None00:00:00:00:00:09/None",
"route": [
"00:00:00:00:00:06/None",
"of:0000000000000006",
"of:0000000000000011",
"of:000000000000000e",
"00:00:00:00:00:09/None",
],
}
],
}
print(post_json("http://localhost:5000/api/push_intent", json.dumps(reroute_JSON)))
input("Restore routing. Press Enter to continue...")
resp = sess.ns.exec_op("test", "downgrade", wait=True)
resp = sess.ns.exec_op(
"test",
op_name="action",
op_data={"primitive": "downgrade", "primitive_params": {}, "member_vnf_index": "1"},
wait=True,
)
print(resp)
os.system("ifconfig tap2 down")
input("Reroute done. Press Enter to continue...")
# resp = sess.ns.delete("test")