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
2e026d68
Commit
2e026d68
authored
5 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
updated OTRS exports
parent
d04c9e85
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/db/ims_data.py
+86
-77
86 additions, 77 deletions
inventory_provider/db/ims_data.py
with
86 additions
and
77 deletions
inventory_provider/db/ims_data.py
+
86
−
77
View file @
2e026d68
...
...
@@ -115,40 +115,30 @@ def get_interface_info(ds):
def
otrs_get_customer_company_rows
(
ds
):
yield
[
'
customer_id
'
,
'
name
'
,
'
street
'
,
'
zip
'
,
'
city
'
,
'
country
'
,
'
url
'
,
'
comments
'
]
all_cus_comps
=
set
()
for
customer
in
ds
.
get_all_entities
(
'
Customer
'
):
yield
[
customer
[
'
Name
'
],
customer
[
'
FullName
'
],
''
,
''
,
''
,
''
,
''
,
''
]
all_cus_comps
.
add
(
customer
[
'
Name
'
])
yield
[
customer
[
'
Name
'
].
replace
(
'
'
,
''
),
customer
[
'
Name
'
],
''
,
''
,
''
,
''
,
''
,
''
]
for
vendor
in
ds
.
get_all_entities
(
'
Vendor
'
):
if
vendor
[
'
Name
'
]
not
in
all_cus_comps
:
all_cus_comps
.
add
(
vendor
[
'
Name
'
])
yield
[
vendor
[
'
Name
'
].
replace
(
'
'
,
''
),
vendor
[
'
Name
'
],
''
,
''
,
''
,
''
,
''
,
''
]
def
otrs_get_customer_users_rows
(
ds
):
yield
[
'
email
'
,
'
username
'
,
'
customer_id
'
,
'
customer_id_2
'
,
'
title
'
,
'
firstname
'
,
'
lastname
'
,
'
phone
'
,
'
fax
'
,
'
mobile
'
,
'
street
'
,
'
zip
'
,
'
city
'
,
'
country
'
,
'
comments
'
]
type_priority
=
{
RelateType
.
SITE
:
1
,
RelateType
.
GROUP
:
2
,
RelateType
.
CONTRACT
:
3
,
RelateType
.
VENDOR
:
4
,
RelateType
.
CONTACT
:
5
,
RelateType
.
CUSTOMER
:
6
,
}
# TODO - check the rules for prioritisation once model has been confirmed
def
_choose_customer_user
(
cu_1
,
cu_2
):
if
not
cu_2
or
type_priority
.
get
(
cu_1
[
'
type
'
],
0
)
>
type_priority
.
get
(
cu_2
[
'
type
'
],
0
):
return
cu_1
return
cu_2
# TODO - check the rules for validation once model has been confirmed
def
_is_valid_customer
(
cus
):
if
not
cus
[
'
email
'
]:
return
False
return
True
# TODO - check the rules for validation once model has been confirmed
def
_is_valid_customer
(
cus
):
if
not
cus
[
'
email
'
]:
return
False
return
True
def
otrs_get_customer_contacts
(
ds
):
# TODO - check this rule for getting the customer_id2 once model has been confirmed # noqa
def
_get_customer_id2
(
cus
):
if
cus
[
'
CustomerType
'
]
and
cus
[
'
CustomerType
'
][
'
Name
'
]
==
'
NREN NOC
'
:
return
True
def
_get_customer_id2
(
t
):
if
t
[
'
Id
'
]
==
3
or
t
[
'
Name
'
]
==
'
EU NREN
'
:
return
'
OTRS-GEANT-NREN
'
return
''
for
customer
in
ds
.
get_all_entities
(
...
...
@@ -157,52 +147,16 @@ def otrs_get_customer_users_rows(ds):
ims
.
CUSTOMER_PROPERTIES
[
'
CustomerRelatedContacts
'
],
ims
.
CUSTOMER_PROPERTIES
[
'
CustomerType
'
]
]):
# # Org as User
# org_customer = OrderedDict({
# 'type': customer['CustomerType']['Name'] if customer[
# 'CustomerType'] else '',
# 'email': customer['AccountEmail'],
# 'username': customer['AccountEmail'],
# 'customer_id': customer['Name'],
# 'customer_id_2': _get_customer_id2(customer),
# 'title': '',
# 'firstname': customer['Name'],
# 'lastname': '-',
# 'phone': '',
# 'fax': '',
# 'mobile': '',
# 'street': '',
# 'zip': '',
# 'city': '',
# 'country': '',
# 'comments': 'Organisation imported as a user'
# })
# if _is_valid_customer(org_customer):
# del org_customer['type']
#
# # todo - remove from here after testing
# # dummy_email = f'dumy_{dummy_counter}@geant.org'
# # org_customer['email'] = dummy_email
# # org_customer['username'] = dummy_email
# # dummy_counter += 1
# # todo - remove up to here after testing
#
# yield list(org_customer.values())
# # end of Org as User
# Contacts as Users
if
customer
[
'
CustomerRelatedContacts
'
]:
customer_user
=
None
for
contact
in
customer
[
'
CustomerRelatedContacts
'
]:
# could just do this as an array, but this makes it easier to
# keep track of the fields
t_customer_user
=
OrderedDict
({
'
type
'
:
ims
.
RelateType
(
contact
[
'
MainTypeId
'
]),
'
email
'
:
contact
[
'
Contact
'
][
'
Mail
'
],
'
username
'
:
contact
[
'
Contact
'
][
'
Mail
'
],
# TODO if tal_id is going to be present use that # noqa
'
customer_id
'
:
customer
[
'
Name
'
],
'
customer_id_2
'
:
_get_customer_id2
(
customer
),
'
customer_id
'
:
customer
[
'
Name
'
].
replace
(
'
'
,
''
),
'
customer_id_2
'
:
_get_customer_id2
(
customer
[
'
CustomerType
'
]),
'
title
'
:
''
,
'
firstname
'
:
contact
[
'
Contact
'
][
'
Name
'
],
'
lastname
'
:
...
...
@@ -217,7 +171,9 @@ def otrs_get_customer_users_rows(ds):
'
zip
'
:
''
,
'
city
'
:
''
,
'
country
'
:
''
,
'
comments
'
:
''
'
comments
'
:
''
,
# 'type_0': 'customer',
# 'type': customer['CustomerType']['Name']
})
if
not
_is_valid_customer
(
t_customer_user
):
continue
...
...
@@ -225,12 +181,65 @@ def otrs_get_customer_users_rows(ds):
t_customer_user
[
'
comments
'
]
=
\
'
Organisation imported as a user
'
del
t_customer_user
[
'
type
'
]
yield
list
(
t_customer_user
.
values
())
# if customer_user:
# del customer_user['type']
# yield list(customer_user.values())
# end of Contact as User
yield
t_customer_user
def
otrs_get_vendor_contacts
(
ds
):
for
vrc
in
ds
.
get_all_entities
(
'
VendorRelatedContact
'
,
[
ims
.
VENDOR_RELATED_CONTACT_PROPERTIES
[
'
Vendor
'
],
ims
.
VENDOR_RELATED_CONTACT_PROPERTIES
[
'
Contact
'
]
]):
t_customer_user
=
OrderedDict
({
'
email
'
:
vrc
[
'
Contact
'
][
'
Mail
'
],
'
username
'
:
vrc
[
'
Contact
'
][
'
Mail
'
],
# TODO if tal_id is going to be present use that # noqa
'
customer_id
'
:
vrc
[
'
Vendor
'
][
'
Name
'
].
replace
(
'
'
,
''
),
'
customer_id_2
'
:
''
,
'
title
'
:
''
,
'
firstname
'
:
vrc
[
'
Contact
'
][
'
Name
'
],
'
lastname
'
:
'
'
.
join
(
filter
(
None
,
[
vrc
[
'
Contact
'
][
'
InFix
'
],
vrc
[
'
Contact
'
][
'
LastName
'
]
])),
'
phone
'
:
''
,
'
fax
'
:
''
,
'
mobile
'
:
''
,
'
street
'
:
''
,
'
zip
'
:
''
,
'
city
'
:
''
,
'
country
'
:
''
,
'
comments
'
:
''
,
# 'type_0': 'vendor',
# 'type': ''
})
if
not
_is_valid_customer
(
t_customer_user
):
continue
if
vrc
[
'
Contact
'
][
'
IsGroup
'
]:
t_customer_user
[
'
comments
'
]
=
\
'
Organisation imported as a user
'
yield
t_customer_user
def
otrs_get_customer_users_rows
(
ds
):
yield
[
'
email
'
,
'
username
'
,
'
customer_id
'
,
'
customer_id_2
'
,
'
title
'
,
'
firstname
'
,
'
lastname
'
,
'
phone
'
,
'
fax
'
,
'
mobile
'
,
'
street
'
,
'
zip
'
,
'
city
'
,
'
country
'
,
'
comments
'
]
# yield ['email', 'username', 'customer_id', 'customer_id_2', 'title',
# 'firstname', 'lastname', 'phone', 'fax', 'mobile', 'street', 'zip',
# 'city', 'country', 'comments', 'type', 'type_2']
def
get_all_cus_user_rows
():
yield
from
otrs_get_customer_contacts
(
ds
)
yield
from
otrs_get_vendor_contacts
(
ds
)
sorted_cus
=
sorted
(
get_all_cus_user_rows
(),
key
=
lambda
x
:
x
[
'
email
'
])
# this will be used to prioritisation
for
cu
in
sorted_cus
:
yield
list
(
cu
.
values
())
if
__name__
==
'
__main__
'
:
...
...
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