Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
geant-swd
dashboardv3
inventory-provider
Commits
b11787ac
Commit
b11787ac
authored
9 months ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
moved asn_to_int function into tasks.common
parent
aa1dafa6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/juniper.py
+2
-30
2 additions, 30 deletions
inventory_provider/juniper.py
inventory_provider/tasks/common.py
+30
-0
30 additions, 0 deletions
inventory_provider/tasks/common.py
with
32 additions
and
30 deletions
inventory_provider/juniper.py
+
2
−
30
View file @
b11787ac
...
...
@@ -11,6 +11,8 @@ from jnpr.junos import exception as EzErrors
from
lxml
import
etree
import
netifaces
from
inventory_provider.tasks.common
import
asn_to_int
CONFIG_SCHEMA
=
"""
<?xml version=
"
1.1
"
encoding=
"
UTF-8
"
?>
<xs:schema xmlns:xs=
"
http://www.w3.org/2001/XMLSchema
"
>
...
...
@@ -280,36 +282,6 @@ def list_interfaces(netconf_config):
yield
u
def
asn_to_int
(
asn_string
:
str
)
->
int
:
"""
Convert a possibly dotted ASN to an integer.
Args:
asn_string (str): ASN to be converted, can be in dot notation or not.
Returns:
int: ASN in integer format.
Raises:
ValueError: If the ASN string is not in the expected format or exceeds valid range.
"""
dotted_asn_pattern
=
re
.
compile
(
r
'
^(\d+)\.(\d+)$
'
)
match
=
dotted_asn_pattern
.
match
(
asn_string
)
if
match
:
high_order
,
low_order
=
map
(
int
,
match
.
groups
())
if
high_order
>
0xffff
or
low_order
>
0xffff
:
raise
ValueError
(
f
'
Invalid ASN format:
{
asn_string
}
. Both components must be <= 0xffff.
'
)
return
(
high_order
<<
16
)
|
low_order
elif
asn_string
.
isdigit
():
return
int
(
asn_string
)
else
:
raise
ValueError
(
f
'
Unable to parse ASN string:
{
asn_string
}
. Expected either a pure integer or a dot notation.
'
)
def
_system_bgp_peers
(
system_node
):
def
_peering_params
(
neighbor_node
):
address
=
neighbor_node
.
find
(
'
name
'
).
text
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/common.py
+
30
−
0
View file @
b11787ac
...
...
@@ -255,3 +255,33 @@ def ims_sorted_service_type_key(service_type):
# prettification ... e.g. no trailing _ for 'MD-VPN (NATIVE)'
service_type
=
re
.
sub
(
'
_+$
'
,
''
,
service_type
)
return
re
.
sub
(
'
^_+
'
,
''
,
service_type
)
def
asn_to_int
(
asn_string
:
str
)
->
int
:
"""
Convert a possibly dotted ASN to an integer.
Args:
asn_string (str): ASN to be converted, can be in dot notation or not.
Returns:
int: ASN in integer format.
Raises:
ValueError: If the ASN string is not in the expected format or exceeds valid range.
"""
dotted_asn_pattern
=
re
.
compile
(
r
'
^(\d+)\.(\d+)$
'
)
match
=
dotted_asn_pattern
.
match
(
asn_string
)
if
match
:
high_order
,
low_order
=
map
(
int
,
match
.
groups
())
if
high_order
>
0xffff
or
low_order
>
0xffff
:
raise
ValueError
(
f
'
Invalid ASN format:
{
asn_string
}
. Both components must be <= 0xffff.
'
)
return
(
high_order
<<
16
)
|
low_order
elif
asn_string
.
isdigit
():
return
int
(
asn_string
)
else
:
raise
ValueError
(
f
'
Unable to parse ASN string:
{
asn_string
}
. Expected either a pure integer or a dot notation.
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment