Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scc-net
netvs
netvs-core
Commits
412562fb
Commit
412562fb
authored
Oct 15, 2021
by
janis.streib
🦉
Browse files
ADD: (unstable): macfinder redis based
parent
1f3c3219
Changes
2
Hide whitespace changes
Inline
Side-by-side
middleware/net_suite/modules/macfinder/views.py
View file @
412562fb
...
...
@@ -6,6 +6,7 @@ import requests
from
flask
import
request
,
jsonify
,
abort
import
re
from
.
import
OUI_DB
import
redis
class
MacFinderJob
(
DBObject
):
...
...
@@ -26,10 +27,6 @@ class MacFinderJob(DBObject):
verify
=
app
.
config
.
get
(
'MACFINDER_CA'
)).
json
()
self
.
finished
=
self
.
status
[
'status'
]
==
'finished'
self
.
failed
=
self
.
status
[
'status'
]
==
'failed'
if
self
.
finished
:
for
d
in
self
.
status
[
'result'
]:
d
.
update
({
'nd_p_port'
:
NDPPort
.
get_nd_p_port_by_dev_fqdn_and_port_name
(
db
=
db
,
connection
=
connection
,
fqdn
=
d
[
'host'
],
port
=
d
[
'port'
])})
return
self
.
status
...
...
@@ -52,22 +49,37 @@ def create_job():
return
jsonify
({
'success'
:
False
,
'error'
:
'invalid_vlan'
}),
404
created_jobs
=
[]
for
vlan
in
vlans
:
resp
=
requests
.
post
(
app
.
config
.
get
(
'MACFINDER_SERVER_URL'
)
+
'/new_task'
,
cert
=
(
app
.
config
.
get
(
'MACFINDER_CERT'
),
app
.
config
.
get
(
'MACFINDER_KEY'
)),
verify
=
app
.
config
.
get
(
'MACFINDER_CA'
),
data
=
{
'mac'
:
request
.
json
[
'mac'
],
'vlan'
:
vlan
.
id
,
'net_instnc'
:
vlan
.
net_instnc
,
'tag_check'
:
'y'
})
if
not
resp
.
ok
:
return
jsonify
({
'success'
:
False
,
'error'
:
'internal_error'
}),
500
job_id
=
resp
.
json
()[
'job_id'
]
created_jobs
.
append
(
job_id
)
with
redis
.
Redis
(
db
=
int
(
app
.
config
.
get
(
'REDIS_DB_INDEX'
)))
as
r
:
resp
=
requests
.
post
(
app
.
config
.
get
(
'MACFINDER_SERVER_URL'
)
+
'/new_task'
,
cert
=
(
app
.
config
.
get
(
'MACFINDER_CERT'
),
app
.
config
.
get
(
'MACFINDER_KEY'
)),
verify
=
app
.
config
.
get
(
'MACFINDER_CA'
),
data
=
{
'mac'
:
request
.
json
[
'mac'
],
'vlan'
:
vlan
.
id
,
'net_instnc'
:
vlan
.
net_instnc
,
'tag_check'
:
'y'
})
if
not
resp
.
ok
:
return
jsonify
({
'success'
:
False
,
'error'
:
'internal_error'
}),
500
job_id
=
resp
.
json
()[
'job_id'
]
created_jobs
.
append
(
job_id
)
pipe
=
r
.
pipeline
()
pipe
.
multi
()
pipe
.
set
(
job_id
,
MacFinderJob
(
job_id
=
job_id
,
vlan
=
vlan
,
bcd
=
vlan
.
bcd
))
pipe
.
expire
(
job_id
,
60
*
60
*
12
)
pipe
.
execute
()
return
jsonify
({
'success'
:
True
,
'job_ids'
:
created_jobs
})
@
macfinder
.
route
(
'/job/<job_id>'
)
@
api_netdb_required
def
poll
(
job_id
):
session
=
requests
.
session
()
return
jsonify
(
MacFinderJob
(
job_id
=
job_id
).
poll
(
session
,
db
,
get_db_conn
()))
with
redis
.
Redis
(
db
=
int
(
app
.
config
.
get
(
'REDIS_DB_INDEX'
)))
as
r
:
job
=
r
.
get
(
job_id
)
session
=
requests
.
session
()
job
.
poll
(
session
,
db
,
get_db_conn
())
pipe
=
r
.
pipeline
()
pipe
.
multi
()
pipe
.
set
(
job_id
,
job
)
pipe
.
expire
(
job_id
,
60
*
60
*
12
)
pipe
.
execute
()
return
jsonify
(
job
)
@
macfinder
.
route
(
'/oui_lookup'
)
...
...
middleware/requirements.txt
View file @
412562fb
...
...
@@ -19,10 +19,12 @@ psycopg2>=2.9.1
psycopg2-binary>=2.9.1
psycopg2-pool>=1.1
py-postgresql>=1.2.2
py-redis>=1.1.0
pycparser>=2.20
pycryptodomex>=3.11.0
pyjwkest>=1.4.2
-e git+ssh://git@git.scc.kit.edu/scc-net/net-suite/python3.x-packages.git@d1686cf04a9013d8af7de7770429228c434e247c#egg=python3.x_packages.pgsql
redis>=3.5.3
requests>=2.26.0
six>=1.16.0
typing-extensions>=3.10.0.2
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment