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
Commits
90bb0d50
Commit
90bb0d50
authored
7 months ago
by
Pablo Armingol
Browse files
Options
Downloads
Patches
Plain Diff
pre merge code cleanup
parent
e47151d6
No related branches found
No related tags found
2 merge requests
!294
Release TeraFlowSDN 4.0
,
!251
Resolve "(TID) Add inventory NBI to WebUI"
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py
+4
-21
4 additions, 21 deletions
...vice/rest_server/nbi_plugins/ietf_hardware/YangHandler.py
src/nbi/service/rest_server/nbi_plugins/tfs_api/__init__.py
+1
-2
1 addition, 2 deletions
src/nbi/service/rest_server/nbi_plugins/tfs_api/__init__.py
with
5 additions
and
23 deletions
src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py
+
4
−
21
View file @
90bb0d50
...
...
@@ -46,60 +46,45 @@ class YangHandler:
dnode
.
free
()
return
message
@staticmethod
def
convert_to_iso_date
(
date_str
:
str
)
->
Optional
[
str
]:
date_str
=
date_str
.
strip
(
'"'
)
# Define the regex pattern for ISO 8601 date format
pattern
=
r
"
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-]\d{2}:\d{2})
"
# Check if the input date string matches the pattern
if
re
.
match
(
pattern
,
date_str
):
return
date_str
# Already in ISO format
return
date_str
else
:
try
:
# Parse the input date string as a datetime object
datetime_obj
=
datetime
.
datetime
.
strptime
(
date_str
,
"
%Y-%m-%d
"
)
# Convert to ISO format
iso_date
=
datetime_obj
.
isoformat
()
+
"
Z
"
return
iso_date
except
ValueError
:
return
None
# Invalid date format
return
None
def
compose
(
self
,
device
:
Device
)
->
Dict
:
hardware
=
self
.
_yang_context
.
create_data_path
(
'
/ietf-network-hardware-inventory:network-hardware-inventory
'
)
network_elements
=
hardware
.
create_path
(
'
network-elements
'
)
network_element
=
network_elements
.
create_path
(
'
network-element[uuid=
"
{:s}
"
]
'
.
format
(
device
.
device_id
.
device_uuid
.
uuid
))
network_element
.
create_path
(
'
uuid
'
,
device
.
device_id
.
device_uuid
.
uuid
)
network_element
.
create_path
(
'
name
'
,
device
.
name
)
components
=
network_element
.
create_path
(
'
components
'
)
physical_index
=
1
for
component
in
device
.
components
:
attributes
=
component
.
attributes
component_new
=
components
.
create_path
(
'
component[uuid=
"
{:s}
"
]
'
.
format
(
component
.
component_uuid
.
uuid
))
component_new
.
create_path
(
'
name
'
,
component
.
name
)
#Cambiar las clases especiales, su formato y añadir isfru
component_type
=
component
.
type
if
component_type
==
"
TRANSCEIVER
"
:
component_type
=
"
module
"
if
component_type
==
"
FRU
"
:
component_type
=
"
slack
"
component_type
=
component_type
.
replace
(
"
_
"
,
"
-
"
).
lower
()
component_type
=
'
iana-hardware:
'
+
component_type
component_new
.
create_path
(
'
class
'
,
component_type
)
#Añadir resto de atributos en IETF
physical_index
+=
1
component_new
.
create_path
(
'
description
'
,
attributes
[
"
description
"
].
replace
(
'
/
"'
,
""
))
if
"
CHASSIS
"
not
in
component
.
type
:
parent_component_references
=
component_new
.
create_path
(
'
parent-component-references
'
)
parent
=
parent_component_references
.
create_path
(
'
component-reference[index=
"
{:d}
"
]
'
.
format
(
physical_index
))
...
...
@@ -107,7 +92,6 @@ class YangHandler:
if
component
.
parent
==
component_parent
.
name
:
parent
.
create_path
(
'
uuid
'
,
component_parent
.
component_uuid
.
uuid
)
break
if
attributes
[
"
mfg-date
"
]
!=
""
:
mfg_date
=
self
.
convert_to_iso_date
(
attributes
[
"
mfg-date
"
])
component_new
.
create_path
(
'
mfg-date
'
,
mfg_date
)
...
...
@@ -137,7 +121,6 @@ class YangHandler:
component_new
.
create_path
(
'
uri
'
,
component
.
name
)
component_new
.
create_path
(
'
uuid
'
,
component
.
component_uuid
.
uuid
)
for
child
in
device
.
components
:
if
component
.
name
==
child
.
parent
:
component_new
.
create_path
(
'
contained-child
'
,
child
.
component_uuid
.
uuid
)
...
...
This diff is collapsed.
Click to expand it.
src/nbi/service/rest_server/nbi_plugins/tfs_api/__init__.py
+
1
−
2
View file @
90bb0d50
...
...
@@ -13,7 +13,6 @@
# limitations under the License.
from
nbi.service.rest_server.RestServer
import
RestServer
from
nbi.service.rest_server.nbi_plugins.ietf_hardware
import
Hardware
,
HardwareMultipleDevices
from
.Resources
import
(
Connection
,
ConnectionIds
,
Connections
,
Context
,
ContextIds
,
Contexts
,
...
...
@@ -51,7 +50,7 @@ RESOURCES = [
(
'
api.device_ids
'
,
DeviceIds
,
'
/device_ids
'
),
(
'
api.devices
'
,
Devices
,
'
/devices
'
),
(
'
api.device
'
,
Device
,
'
/device/<path:device_uuid>
'
),
(
'
api.link_ids
'
,
LinkIds
,
'
/link_ids
'
),
(
'
api.links
'
,
Links
,
'
/links
'
),
(
'
api.link
'
,
Link
,
'
/link/<path:link_uuid>
'
),
...
...
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