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
f82c5fa1
Commit
f82c5fa1
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
added decorator to help with node names in IMS
parent
9323bd3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/common.py
+32
-0
32 additions, 0 deletions
inventory_provider/routes/common.py
with
32 additions
and
0 deletions
inventory_provider/routes/common.py
+
32
−
0
View file @
f82c5fa1
import
functools
import
logging
from
collections
import
OrderedDict
import
requests
from
flask
import
request
,
Response
,
current_app
,
g
from
inventory_provider.tasks
import
common
as
tasks_common
logger
=
logging
.
getLogger
(
__name__
)
def
ims_hostname_decorator
(
field
):
"""
Decorator to convert host names to various formats to try to match what is
found in IMS before executing the decorated function.
:param field: name of the field containing hostname
:return: result of decorated function
"""
suffix
=
'
.geant.net
'
def
wrapper
(
func
):
def
inner
(
*
args
,
**
kwargs
):
orig_val
=
kwargs
[
field
]
values_to_try
=
[]
if
orig_val
.
endswith
(
suffix
):
values_to_try
.
append
(
orig_val
[:
-
len
(
suffix
)].
upper
())
values_to_try
.
append
(
orig_val
.
upper
())
values_to_try
.
append
(
orig_val
)
values_to_try
.
append
(
orig_val
.
lower
())
for
val
in
list
(
OrderedDict
.
fromkeys
(
values_to_try
)):
kwargs
[
field
]
=
val
res
=
func
(
*
args
,
**
kwargs
)
if
res
.
status_code
!=
requests
.
codes
.
not_found
:
return
res
return
res
return
inner
return
wrapper
def
get_current_redis
():
if
'
current_redis_db
'
in
g
:
latch
=
tasks_common
.
get_latch
(
g
.
current_redis_db
)
...
...
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