-
Notifications
You must be signed in to change notification settings - Fork 1
/
appc.py.original
executable file
·100 lines (76 loc) · 3.79 KB
/
appc.py.original
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
#!/usr/bin/python
import json
import requests
import time
import subprocess
import os
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def action_gora():
url = 'http://10.254.185.17:8183/restconf/config/stream-count:stream-count/streams'
payload = '{"streams": {"active-streams": 6}}'
headers = {"Authorization": "Basic YWRtaW46YWRtaW4=", "Content-Type": "application/json", "Cache-Control": "no-cache", "Postman-Token": "9005870c-900b-2e2e-0902-ef2009bb0ff7"}
r = requests.put(url, data=payload, headers=headers)
return r.status_code
def action_dol():
url = 'http://10.254.185.17:8183/restconf/config/stream-count:stream-count/streams'
payload = '{"streams": {"active-streams": 4}}'
headers = {"Authorization": "Basic YWRtaW46YWRtaW4=", "Content-Type": "application/json", "Cache-Control": "no-cache", "Postman-Token": "9005870c-900b-2e2e-0902-ef2009bb0ff7"}
r = requests.put(url, data=payload, headers=headers)
return r.status_code
url = 'https://portal.api.simpledemo.onap.org:30226/events/APPC-CL/g1/c3?timeout=5000'
headers = {'accept': 'application/json', 'cache-control': 'no-cache', 'postman-token': '61210824-faf0-d843-218d-28337bab5d87'}
requestID = None
requestID_old = None
#testing DB
direc=4 #starting with smaller size
direction = 0
while True:
# time.sleep(5)
# r = requests.get(url, headers=headers, verify=False)
# event_json = r.json()
# print(event_json)
# direction = 0
# #event_json='["{\\"CommonHeader\\":{\\"TimeStamp\\":1608547151210,\\"APIver\\":\\"1.01\\",\\"RequestID\\":\\"08dd8ebc-00ff-43c5-bfbe-ecf5cf60beec\\",\\"SubRequestID\\":\\"ab23127d-fe65-4ae0-afe6-034dd0769afb\\",\\"RequestTrack\\":[],\\"Flags\\":[]},\\"Action\\":\\"ModifyConfig\\",\\"Payload\\":{\\"streams\\":{\\"active-streams\\":6},\\"generic-vnf.vnf-id\\":\\"bd6af5c1-fc85-446d-bb59-553b0404075b\\"}}"]'
# try:
# event_dict = json.loads(event_json[0])
# except:
# continue
# requestID_old = requestID
# try:
# requestID = event_dict["CommonHeader"]["RequestID"]
# if requestID == requestID_old:
# continue
# action = event_dict["Action"]
# vnf_id = event_dict["Payload"]["generic-vnf.vnf-id"]
# direction = event_dict["Payload"]["streams"]["active-streams"]
# except:
# None
#testing fragment DB - looping with direc 4-6-4-6...
print("direction APPC=", direction)
if direc == 6:
direc=4
else:
direc=6
direction=direc
#end testing fragment
if direction == 6:
print ("Action: resize up", direction)
#r = action_gora() #this is for packet generator in vFW use case
#print ("Action response", r)
shellCommand = "./test-resize.sh" + " " + "test-resizevm-db" + " " + "m2.large"
print("starting: " + shellCommand)
# proc = subprocess.Popen( ['/home/ubuntu/clamp/test-resize.sh', 'test-resizevm-db', 'm2.large'], stdout=subprocess.PIPE, shell=True)
# proc = subprocess.call( ['/home/ubuntu/clamp/test-resize.sh', 'test-resizevm-db', 'm2.large'], shell=True)
os.system("/bin/bash /home/ubuntu/clamp/test-resize.sh test-resizevm-db m2.large")
print("completed")
if direction == 4:
print ("Action: resize down", direction)
#r= action_dol() #this is for packet generator in vFW use case
#print ("Action response", r)
shellCommand = "./test-resize.sh" + " " + "test-resizevm-db" + " " + "m1.large"
print("starting: " + shellCommand)
# proc = subprocess.call( ['/home/ubuntu/clamp/test-resize.sh', 'test-resizevm-db', 'm2.large'], shell=True)
os.system("/bin/bash /home/ubuntu/clamp/test-resize.sh test-resizevm-db m1.large")
print("completed")
time.sleep(120)