-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
107 lines (66 loc) · 2.5 KB
/
app.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
from flask import Flask, request, render_template, make_response
import requests
from connConfigDto import ConnConfigDto
from VmDto import VmDto
app = Flask(__name__)
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
@app.route("/connections", methods=['GET', 'POST'])
def connections():
if request.method == 'POST':
spider_url = request.form.get('spider_url')
connections = get_connections(spider_url)
resp = make_response(render_template("connection.html", connections=connections))
resp.set_cookie('spider_url', spider_url)
return resp
else:
return render_template("connection.html")
@app.route("/connections/<string:connectionName>", methods=['GET', 'POST'])
def connection_vm_list(connectionName):
if request.method == 'GET':
only_csp_list = get_vm_list(connectionName)
return render_template("vmlist.html", only_csp_list=only_csp_list, connectionName=connectionName)
else: # vm 등록
vm_id = request.form.get("name_id")
vm_system_id = request.form.get("system_id")
# cb-spider에 vm 정보 get request
spider_url = request.cookies.get("spider_url")
#cb-spider에 vm등록하는 함수
def regist_vm():
reg_vpc()
reg_subnet()
reg_security_group()
reg_keypair()
def reg_vpc():
pass
def reg_subnet():
pass
def reg_security_group():
pass
def reg_keypair():
pass
def get_connections(spider_url):
response = requests.get(f"http://{spider_url}/spider/connectionconfig")
row = response.json()
connections = []
for connection in row['connectionconfig']:
connConfigDto = ConnConfigDto(connection["ConfigName"])
connections.append(connConfigDto)
return connections
# AllList / OnlySpiderList / OnlyCSPList => 여기에 있는 것들은 등록 안 된 것들..
# allvpc, allsequritygroup, allkeypair, allvm body{"ConnectionName : "~~~"}
def get_vm_list(connection_name):
spider_url = request.cookies.get('spider_url')
params ={"ConnectionName": connection_name}
response = requests.get(f"http://{spider_url}/spider/allvm", params=params).json()
not_registered_list = response["AllList"]["OnlyCSPList"]
only_csp_list = []
for vm in not_registered_list:
name_id = vm["NameId"]
system_id = vm["SystemId"]
vm_dto = VmDto(name_id, system_id)
only_csp_list.append(vm_dto)
return only_csp_list
if __name__ == '__main__':
app.run(debug=True)