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
4894ecfa
Commit
4894ecfa
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
extra functionality
parent
eb0eb0fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
circuit_tree.py
+41
-22
41 additions, 22 deletions
circuit_tree.py
with
41 additions
and
22 deletions
circuit_tree.py
+
41
−
22
View file @
4894ecfa
...
@@ -4,12 +4,13 @@ from operator import itemgetter
...
@@ -4,12 +4,13 @@ from operator import itemgetter
import
click
import
click
import
redis
import
redis
from
click
import
BadParameter
from
tree_format
import
format_tree
from
tree_format
import
format_tree
from
inventory_provider.db.ims
import
IMS
,
CIRCUIT_PROPERTIES
,
InventoryStatus
from
inventory_provider.db.ims
import
IMS
,
CIRCUIT_PROPERTIES
,
InventoryStatus
username
=
'
TEST05
'
username
=
'
TEST05
'
password
=
''
password
=
'
robert_Testing250
'
bt
=
os
.
getenv
(
'
IMS_BT
'
)
bt
=
os
.
getenv
(
'
IMS_BT
'
)
ds
=
IMS
(
'
http://83.97.94.128:2080/api
'
,
username
,
password
,
bt
)
ds
=
IMS
(
'
http://83.97.94.128:2080/api
'
,
username
,
password
,
bt
)
...
@@ -23,8 +24,11 @@ NAV_PROPS = [
...
@@ -23,8 +24,11 @@ NAV_PROPS = [
@click.command
()
@click.command
()
@click.option
(
'
-c
'
,
'
carriers
'
,
is_flag
=
True
)
@click.option
(
'
-c
'
,
'
carriers
'
,
is_flag
=
True
)
@click.option
(
'
-l
'
,
'
local
'
,
is_flag
=
True
)
@click.option
(
'
-l
'
,
'
local
'
,
is_flag
=
True
)
@click.argument
(
'
root_circuit_identifier
'
,
type
=
click
.
STRING
,
required
=
True
)
@click.option
(
'
-i
'
,
'
interface_
'
,
is_flag
=
True
)
def
cli
(
carriers
,
local
,
root_circuit_identifier
):
@click.argument
(
'
root_identifier
'
,
type
=
click
.
STRING
,
required
=
True
)
def
cli
(
carriers
,
local
,
interface_
,
root_identifier
):
if
interface_
and
not
local
:
raise
BadParameter
(
'
-i flag only works with -l flag
'
)
if
local
:
if
local
:
if
carriers
:
if
carriers
:
children_prop
=
'
carrier-circuits
'
children_prop
=
'
carrier-circuits
'
...
@@ -41,12 +45,12 @@ def cli(carriers, local, root_circuit_identifier):
...
@@ -41,12 +45,12 @@ def cli(carriers, local, root_circuit_identifier):
NAV_PROPS
.
append
(
CIRCUIT_PROPERTIES
[
'
SubCircuits
'
])
NAV_PROPS
.
append
(
CIRCUIT_PROPERTIES
[
'
SubCircuits
'
])
if
local
:
if
local
:
r
=
redis
.
StrictRedis
(
r
=
redis
.
StrictRedis
(
host
=
'
localhost
'
,
db
=
0
,
decode_responses
=
True
,
host
=
'
localhost
'
,
db
=
0
,
decode_responses
=
True
,
encoding
=
'
utf-8
'
)
encoding
=
'
utf-8
'
)
def
_get_childcircuit_tree_local
(
circuit_id
):
def
_get_childcircuit_tree_local
(
circuit_id
):
circuit
=
r
.
get
(
f
'
ims:circuit_hierarchy:
{
circuit_id
}
'
)
circuit
=
r
.
get
(
f
'
ims:circuit_hierarchy:
{
circuit_id
}
'
)
if
not
circuit
:
if
not
circuit
:
return
None
return
None
...
@@ -70,22 +74,37 @@ def cli(carriers, local, root_circuit_identifier):
...
@@ -70,22 +74,37 @@ def cli(carriers, local, root_circuit_identifier):
_tree
.
append
([])
_tree
.
append
([])
return
_tree
return
_tree
try
:
if
interface_
:
root_circuit_identifier
=
int
(
root_circuit_identifier
)
except
ValueError
:
if_services
=
r
.
get
(
f
'
ims:interface_services:
{
root_identifier
}
'
)
for
k
in
r
.
scan_iter
(
'
ims:circuit_hierarchy:*
'
,
count
=
2000
):
if
if_services
:
ch
=
r
.
get
(
k
)
root_identifiers
=
[
s
[
'
id
'
]
for
s
in
json
.
loads
(
if_services
)]
details
=
json
.
loads
(
ch
)[
0
]
children
=
[]
if
root_circuit_identifier
.
lower
()
==
details
[
'
name
'
].
lower
():
for
id_
in
root_identifiers
:
root_circuit_identifier
=
details
[
'
id
'
]
children
.
append
(
_get_childcircuit_tree_local
(
id_
))
break
tree
=
[
root_identifier
,
children
]
else
:
else
:
print
(
f
'
No circuit found for:
{
root_
circuit_
identifier
}
'
)
print
(
f
'
No circuit found for:
{
root_identifier
}
'
)
exit
(
0
)
exit
(
0
)
tree
=
_get_childcircuit_tree_local
(
root_circuit_identifier
)
else
:
try
:
root_identifier
=
int
(
root_identifier
)
except
ValueError
:
for
k
in
r
.
scan_iter
(
'
ims:circuit_hierarchy:*
'
,
count
=
2000
):
ch
=
r
.
get
(
k
)
details
=
json
.
loads
(
ch
)[
0
]
if
root_identifier
.
lower
()
==
details
[
'
name
'
].
lower
():
root_identifier
=
details
[
'
id
'
]
break
else
:
print
(
f
'
No circuit found for:
{
root_identifier
}
'
)
exit
(
0
)
tree
=
_get_childcircuit_tree_local
(
root_identifier
)
else
:
else
:
def
_get_childcircuit_tree
(
circuit_id
):
def
_get_childcircuit_tree
_remote
(
circuit_id
):
circuit
=
ds
.
get_entity_by_id
(
circuit
=
ds
.
get_entity_by_id
(
'
circuit
'
,
circuit_id
,
navigation_properties
=
NAV_PROPS
)
'
circuit
'
,
circuit_id
,
navigation_properties
=
NAV_PROPS
)
_tree
=
[
_tree
=
[
...
@@ -99,7 +118,7 @@ def cli(carriers, local, root_circuit_identifier):
...
@@ -99,7 +118,7 @@ def cli(carriers, local, root_circuit_identifier):
children
=
[]
children
=
[]
for
child_circuit
in
circuit
[
children_prop
]:
for
child_circuit
in
circuit
[
children_prop
]:
children
.
append
(
_get_childcircuit_tree
(
children
.
append
(
_get_childcircuit_tree
_remote
(
child_circuit
[
childid
]
child_circuit
[
childid
]
))
))
_tree
.
append
(
children
)
_tree
.
append
(
children
)
...
@@ -108,17 +127,17 @@ def cli(carriers, local, root_circuit_identifier):
...
@@ -108,17 +127,17 @@ def cli(carriers, local, root_circuit_identifier):
return
_tree
return
_tree
try
:
try
:
root_
circuit_
identifier
=
int
(
root_
circuit_
identifier
)
root_identifier
=
int
(
root_identifier
)
except
ValueError
:
except
ValueError
:
root_circuit
=
\
root_circuit
=
\
ds
.
get_entity_by_name
(
'
circuit
'
,
root_
circuit_
identifier
)
ds
.
get_entity_by_name
(
'
circuit
'
,
root_identifier
)
if
root_circuit
:
if
root_circuit
:
root_
circuit_
identifier
=
root_circuit
[
'
id
'
]
root_identifier
=
root_circuit
[
'
id
'
]
else
:
else
:
print
(
f
'
No circuit found for:
{
root_
circuit_
identifier
}
'
)
print
(
f
'
No circuit found for:
{
root_identifier
}
'
)
exit
(
0
)
exit
(
0
)
tree
=
_get_childcircuit_tree
(
root_circui
t_identifier
)
tree
=
_get_childcircuit_tree
_remote
(
roo
t_identifier
)
print
(
format_tree
(
print
(
format_tree
(
tree
,
format_node
=
itemgetter
(
0
),
get_children
=
itemgetter
(
1
))
tree
,
format_node
=
itemgetter
(
0
),
get_children
=
itemgetter
(
1
))
)
)
...
...
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