Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
arthur-zzz
noc
Commits
adef51e7
Commit
adef51e7
authored
Nov 22, 2021
by
Andrey Vertiprahov
Browse files
Merge branch 'issue-1713-mib' into 'master'
Switch service mib from tornado to FastAPI See merge request
noc/noc!5878
parents
c95b7fc7
5da834ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/service/models/__init__.py
0 → 100644
View file @
adef51e7
core/service/models/jsonrpc.py
0 → 100644
View file @
adef51e7
# ----------------------------------------------------------------------
# Models for JSON-RPC API
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from
typing
import
Any
,
List
# Third-party modules
from
pydantic
import
BaseModel
class
JSONRemoteProcedureCall
(
BaseModel
):
method
:
str
params
:
List
[
Any
]
id
:
int
services/mib/paths/jsonrpc_mib.py
0 → 100644
View file @
adef51e7
# ----------------------------------------------------------------------
# mib JSON-RPC API endpoint
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Third-party modules
from
fastapi
import
APIRouter
# NOC modules
from
noc.core.debug
import
error_report
from
noc.core.error
import
NOCError
from
noc.core.service.loader
import
get_service
from
noc.core.service.models.jsonrpc
import
JSONRemoteProcedureCall
from
noc.services.mib.api.mib
import
MIBAPI
router
=
APIRouter
()
@
router
.
post
(
"/api/mib/"
)
@
router
.
post
(
"/api/mib"
)
def
api_mib
(
req
:
JSONRemoteProcedureCall
):
if
req
.
method
not
in
MIBAPI
.
get_methods
():
return
{
"error"
:
f
"Invalid method: '
{
req
.
method
}
'"
,
"id"
:
req
.
id
}
service
=
get_service
()
api
=
MIBAPI
(
service
,
None
,
None
)
api_method
=
getattr
(
api
,
req
.
method
)
result
=
None
error
=
None
try
:
result
=
api_method
(
*
req
.
params
)
except
NOCError
as
e
:
error
=
f
"Failed:
{
e
}
"
except
Exception
as
e
:
error_report
()
error
=
f
"Failed:
{
e
}
"
return
{
"result"
:
result
,
"error"
:
error
,
"id"
:
req
.
id
}
services/mib/service.py
View file @
adef51e7
...
...
@@ -7,13 +7,12 @@
# ----------------------------------------------------------------------
# NOC modules
from
noc.core.service.
tornado
import
Tornado
Service
from
noc.core.service.
fastapi
import
FastAPI
Service
from
noc.services.mib.api.mib
import
MIBAPI
class
MIBService
(
Tornado
Service
):
class
MIBService
(
FastAPI
Service
):
name
=
"mib"
api
=
[
MIBAPI
]
use_mongo
=
True
...
...
Write
Preview
Markdown
is supported
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