Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
TFS
controller
Compare revisions
6958674bf5af23810e1e318981c979450683069c...c2179dd845b717806fb0acc522f80e70581e0a37
Commits (2)
refactoring: port lookup done sequentially in device protobuf instead of global regex search
· 27b2104d
Shayan Hajipour
authored
Jan 26, 2024
27b2104d
bug fix: Showing service info error in webui when service is created by BWM resolved.
· c2179dd8
Shayan Hajipour
authored
Jan 26, 2024
c2179dd8
Hide whitespace changes
Inline
Side-by-side
src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Tools.py
View file @
c2179dd8
...
...
@@ -27,9 +27,8 @@ from common.tools.object_factory.Service import json_service_id
LOGGER
=
logging
.
getLogger
(
__name__
)
RE_PORT_AND_IP_MATCH
=
r
'resource_key: \"\/interface\[(.*)\]\/subinterface\[.*\]\"[.|\n]*.*\\\"address_ip\\\": \\\"{}\\\"'
RE_ENDPOINT_UUID_PORT_MATCH
=
r
'\s*\n?\s*endpoint_uuid .\s*\n?\s*uuid: \"(.*)\"\n?\s*.\n?\s*.\n?\s*name: \"{}\"'
RE_DEVICE_UUID_MATCH
=
r
'\n?\s*device_uuid \{\s*\n?\s*uuid: \"(.*)\"\n?\s*\}\n?\s*\}'
RE_CONFIG_RULE_IF_SUBIF
=
re
.
compile
(
r
'^\/interface\[([^\]]+)\]\/subinterface\[([^\]]+)\]$'
)
RE_CONFIG_RULE_ADDRESS_IP
=
re
.
compile
(
r
'\\\"address_ip\\\": \\\"((?:[0-9]{1,3}\.){3}[0-9]{1,3})\\\"'
)
def
service_2_bwInfo
(
service
:
Service
)
->
dict
:
response
=
{}
...
...
@@ -79,20 +78,20 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service:
a_ip
=
bwInfo
[
'sessionFilter'
][
0
][
'sourceIp'
]
z_ip
=
bwInfo
[
'sessionFilter'
][
0
][
'dstAddress'
]
devices
=
(
str
(
device
)
for
device
in
client
.
ListDevices
(
Empty
()).
devices
)
devices
=
client
.
ListDevices
(
Empty
()).
devices
for
device
in
devices
:
for
ep_id
in
(
a_ip
,
z_ip
):
if
look_up
:
=
re
.
search
(
RE_PORT_AND_IP_MATCH
.
format
(
ep_id
),
device
)
:
physical_port
=
look_up
.
groups
(
0
)[
0
]
# 'PORT-' is added as a prefix
port
=
'PORT-'
+
physical_port
port_uuid
=
re
.
search
(
RE_ENDPOINT_UUID_PORT_MATCH
.
format
(
port
),
device
)
.
group
(
0
)[
0
]
device_uuid
=
re
.
search
(
RE_DEVICE_UUID_MATCH
,
device
).
group
(
0
)[
0
]
ep_id
=
EndPointId
()
ep_id
.
e
nd
p
oint
_uuid
.
uuid
=
port_uuid
ep_id
.
device_id
.
device
_uuid
.
uuid
=
device_
uuid
service
.
service_endpoint_ids
.
append
(
ep_
id
)
device_endpoint_uuids
=
{
ep
.
name
:
ep
.
endpoint_id
.
endpoint_uuid
for
ep
in
device
.
device_endpoints
}
for
cr
in
device
.
device_config
.
config_rules
:
if
cr
.
WhichOneof
(
'config_rule'
)
==
'custom'
:
match_subif
=
RE_CONFIG_RULE_IF_SUBIF
.
match
(
cr
.
custom
.
resource_key
)
match_ip
=
RE_CONFIG_RULE_ADDRESS_IP
.
match
(
cr
.
custom
.
resource_value
)
if
match_subif
and
match_ip
and
match_ip
.
group
s
(
0
)[
0
]
in
[
a_ip
,
z_ip
]:
# `PORT-` added as prefix
port_name
=
'PORT-'
+
match_subif
.
groups
(
0
)[
0
]
ep_id
=
E
nd
P
oint
Id
()
ep_id
.
endpoint
_uuid
.
uuid
=
device_
endpoint_uuids
[
port_name
]
ep_id
.
device_id
.
device_uuid
.
uuid
=
device
.
device_id
.
device_uu
id
service
.
service_endpoint_ids
.
append
(
ep_id
)
service
.
service_type
=
ServiceTypeEnum
.
SERVICETYPE_L3NM
if
'appInsId'
in
bwInfo
:
...
...
src/webui/service/__init__.py
View file @
c2179dd8
...
...
@@ -48,7 +48,7 @@ def json_to_list(json_str : str) -> List[Union[str, Tuple[str, str]]]:
if
isinstance
(
data
,
dict
):
return
[(
'kv'
,
(
key
,
value
))
for
key
,
value
in
data
.
items
()]
elif
isinstance
(
data
,
list
):
elif
isinstance
(
data
,
list
)
and
not
isinstance
(
data
[
0
],
dict
)
:
return
[(
'item'
,
', '
.
join
(
data
))]
else
:
return
[(
'item'
,
str
(
data
))]
...
...