Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Merge requests
!139
Fixes on OpenConfig and ACLs
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fixes on OpenConfig and ACLs
fix/tid-openconfig-acls
into
develop
Overview
0
Commits
9
Pipelines
0
Changes
1
Merged
Lluis Gifre Renom
requested to merge
fix/tid-openconfig-acls
into
develop
1 year ago
Overview
0
Commits
9
Pipelines
0
Changes
1
Expand
Fixes on OpenConfig and ACLs
0
0
Merge request reports
Viewing commit
f0de9596
Prev
Next
Show latest version
1 file
+
57
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
f0de9596
Update ComposeConfigRules.py
· f0de9596
Lluis Gifre Renom
authored
1 year ago
src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py
+
57
−
21
Options
@@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
itertools
,
json
,
re
import
itertools
,
json
,
logging
,
re
from
typing
import
Dict
,
List
,
Optional
,
Tuple
from
common.proto.context_pb2
import
ConfigRule
from
common.tools.grpc.Tools
import
grpc_message_to_json_string
from
common.tools.object_factory.ConfigRule
import
json_config_rule_set
LOGGER
=
logging
.
getLogger
(
__name__
)
SETTINGS_RULE_NAME
=
'
/settings
'
DEVICE_SETTINGS
=
re
.
compile
(
r
'
\/device\[([^\]]+)\]\/settings
'
)
@@ -76,6 +79,7 @@ def compose_device_config_rules(
config_rules
:
List
,
subservice_config_rules
:
List
,
path_hops
:
List
,
device_name_mapping
:
Dict
[
str
,
str
],
endpoint_name_mapping
:
Dict
[
Tuple
[
str
,
str
],
str
]
)
->
None
:
LOGGER
.
warning
(
'
[compose_device_config_rules] begin
'
)
devices_traversed
=
set
()
endpoints_traversed
=
set
()
@@ -85,29 +89,61 @@ def compose_device_config_rules(
endpoints_traversed
.
add
((
device_uuid_or_name
,
path_hop
[
'
ingress_ep
'
]))
endpoints_traversed
.
add
((
device_uuid_or_name
,
path_hop
[
'
egress_ep
'
]))
LOGGER
.
warning
(
'
[compose_device_config_rules] devices_traversed={:s}
'
.
format
(
str
(
devices_traversed
)))
LOGGER
.
warning
(
'
[compose_device_config_rules] endpoints_traversed={:s}
'
.
format
(
str
(
endpoints_traversed
)))
for
config_rule
in
config_rules
:
if
config_rule
.
WhichOneof
(
'
config_rule
'
)
!=
'
custom
'
:
continue
LOGGER
.
warning
(
'
[compose_device_config_rules] processing config_rule: {:s}
'
.
format
(
grpc_message_to_json_string
(
config_rule
)))
if
config_rule
.
WhichOneof
(
'
config_rule
'
)
==
'
acl
'
:
LOGGER
.
warning
(
'
[compose_device_config_rules] is acl
'
)
acl_endpoint_id
=
config_rule
.
acl
.
endpoint_id
acl_device_uuid
=
acl_endpoint_id
.
device_id
.
device_uuid
.
uuid
LOGGER
.
warning
(
'
[compose_device_config_rules] acl_device_uuid={:s}
'
.
format
(
str
(
acl_device_uuid
)))
if
acl_device_uuid
not
in
devices_traversed
:
continue
acl_endpoint_uuid
=
acl_endpoint_id
.
endpoint_uuid
.
uuid
LOGGER
.
warning
(
'
[compose_device_config_rules] initial acl_endpoint_uuid={:s}
'
.
format
(
str
(
acl_endpoint_uuid
)))
# given endpoint uuids link 'eth-1/0/20.533', remove last part after the '.'
acl_endpoint_uuid_reversed
=
acl_endpoint_uuid
[::
-
1
]
acl_endpoint_uuid_reversed_parts
=
acl_endpoint_uuid_reversed
.
split
(
'
.
'
,
maxsplit
=
1
)
acl_endpoint_uuid_reversed_last_part
=
acl_endpoint_uuid_reversed_parts
[
-
1
]
acl_endpoint_uuid
=
acl_endpoint_uuid_reversed_last_part
[::
-
1
]
LOGGER
.
warning
(
'
[compose_device_config_rules] corrected acl_endpoint_uuid={:s}
'
.
format
(
str
(
acl_endpoint_uuid
)))
if
acl_endpoint_uuid
not
in
endpoints_traversed
:
continue
LOGGER
.
warning
(
'
[compose_device_config_rules] adding acl config rule
'
)
subservice_config_rules
.
append
(
config_rule
)
match
=
DEVICE_SETTINGS
.
match
(
config_rule
.
custom
.
resource_key
)
if
match
is
not
None
:
device_uuid_or_name
=
match
.
group
(
1
)
device_name_or_uuid
=
device_name_mapping
[
device_uuid_or_name
]
device_keys
=
{
device_uuid_or_name
,
device_name_or_uuid
}
elif
config_rule
.
WhichOneof
(
'
config_rule
'
)
==
'
custom
'
:
LOGGER
.
warning
(
'
[compose_device_config_rules] is custom
'
)
if
len
(
device_keys
.
intersection
(
devices_traversed
))
==
0
:
continue
subservice_config_rules
.
append
(
config_rule
)
match
=
DEVICE_SETTINGS
.
match
(
config_rule
.
custom
.
resource_key
)
if
match
is
not
None
:
device_uuid_or_name
=
match
.
group
(
1
)
device_name_or_uuid
=
device_name_mapping
[
device_uuid_or_name
]
device_keys
=
{
device_uuid_or_name
,
device_name_or_uuid
}
match
=
ENDPOINT_SETTINGS
.
match
(
config_rule
.
custom
.
resource_key
)
if
match
is
not
None
:
device_uuid_or_name
=
match
.
group
(
1
)
device_name_or_uuid
=
device_name_mapping
[
device_uuid_or_name
]
device_keys
=
{
device_uuid_or_name
,
device_name_or_uuid
}
if
len
(
device_keys
.
intersection
(
devices_traversed
))
==
0
:
continue
subservice_config_rules
.
append
(
config_rule
)
endpoint_uuid_or_name
=
match
.
group
(
2
)
endpoint_name_or_uuid_1
=
endpoint_name_mapping
[(
device_uuid_or_name
,
endpoint_uuid_or_name
)]
endpoint_name_or_uuid_2
=
endpoint_name_mapping
[(
device_name_or_uuid
,
endpoint_uuid_or_name
)]
endpoint_keys
=
{
endpoint_uuid_or_name
,
endpoint_name_or_uuid_1
,
endpoint_name_or_uuid_2
}
match
=
ENDPOINT_SETTINGS
.
match
(
config_rule
.
custom
.
resource_key
)
if
match
is
not
None
:
device_uuid_or_name
=
match
.
group
(
1
)
device_name_or_uuid
=
device_name_mapping
[
device_uuid_or_name
]
device_keys
=
{
device_uuid_or_name
,
device_name_or_uuid
}
device_endpoint_keys
=
set
(
itertools
.
product
(
device_keys
,
endpoint_keys
))
if
len
(
device_endpoint_keys
.
intersection
(
endpoints_traversed
))
==
0
:
continue
subservice_config_rules
.
append
(
config_rule
)
endpoint_uuid_or_name
=
match
.
group
(
2
)
endpoint_name_or_uuid_1
=
endpoint_name_mapping
[(
device_uuid_or_name
,
endpoint_uuid_or_name
)]
endpoint_name_or_uuid_2
=
endpoint_name_mapping
[(
device_name_or_uuid
,
endpoint_uuid_or_name
)]
endpoint_keys
=
{
endpoint_uuid_or_name
,
endpoint_name_or_uuid_1
,
endpoint_name_or_uuid_2
}
device_endpoint_keys
=
set
(
itertools
.
product
(
device_keys
,
endpoint_keys
))
if
len
(
device_endpoint_keys
.
intersection
(
endpoints_traversed
))
==
0
:
continue
subservice_config_rules
.
append
(
config_rule
)
else
:
continue
LOGGER
.
warning
(
'
[compose_device_config_rules] end
'
)
Loading