Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gepetto Utils
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
Container Registry
Model registry
Operate
Environments
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
Gepetto
Gepetto Utils
Commits
0e70853c
Commit
0e70853c
authored
1 year ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
machines: find issues with users DB
parent
c9bb6649
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
scripts/machines.py
+37
-7
37 additions, 7 deletions
scripts/machines.py
with
37 additions
and
7 deletions
scripts/machines.py
+
37
−
7
View file @
0e70853c
...
...
@@ -8,6 +8,7 @@ import pandas as pd
from
ldap3
import
Connection
from
tabulate
import
tabulate
CONN
=
Connection
(
"
ldap.laas.fr
"
,
auto_bind
=
True
)
ATTRIBUTES
=
[
"
cn
"
,
"
laas-date-install
"
,
...
...
@@ -57,8 +58,7 @@ def machines_ldap(utilisateur="", responsable="", room="", **kwargs):
if
room
:
filters
[
"
roomNumber
"
]
=
room
conn
=
Connection
(
"
ldap.laas.fr
"
,
auto_bind
=
True
)
conn
.
search
(
CONN
.
search
(
"
ou=machines,dc=laas,dc=fr
"
,
f
"
(&
{
filter
(
**
filters
)
}
)
"
,
attributes
=
ATTRIBUTES
,
...
...
@@ -68,12 +68,26 @@ def machines_ldap(utilisateur="", responsable="", room="", **kwargs):
str
(
entry
.
cn
):
{
short
(
k
):
parse
(
k
,
v
)
for
k
,
v
in
entry
.
entry_attributes_as_dict
.
items
()
}
for
entry
in
conn
.
entries
for
entry
in
CONN
.
entries
}
def
display
(
data
,
sort_by
=
"
datePeremption
"
):
"""
Pandas & Tabulate magic to display data.
"""
def
users_ldap
():
"""
Get a dict of Gepettists with their room and st
"""
CONN
.
search
(
"
ou=users,dc=laas,dc=fr
"
,
"
(o=gepetto)
"
,
attributes
=
[
"
uid
"
,
"
st
"
,
"
roomNumber
"
]
)
return
{
str
(
entry
.
uid
):
{
short
(
k
):
parse
(
k
,
v
)
for
k
,
v
in
entry
.
entry_attributes_as_dict
.
items
()
}
for
entry
in
CONN
.
entries
}
def
machines_display
(
data
,
sort_by
=
"
datePeremption
"
):
"""
Pandas & Tabulate magic to display machines data.
"""
df
=
pd
.
DataFrame
(
data
).
T
.
sort_values
(
by
=
sort_by
)
print
(
tabulate
(
df
.
drop
(
"
cn
"
,
axis
=
1
),
headers
=
"
keys
"
))
...
...
@@ -100,5 +114,21 @@ def get_parser() -> ArgumentParser:
if
__name__
==
"
__main__
"
:
args
=
get_parser
().
parse_args
()
data
=
machines_ldap
(
**
vars
(
args
))
display
(
data
,
args
.
sort_by
)
machines_data
=
machines_ldap
(
**
vars
(
args
))
machines_display
(
machines_data
,
args
.
sort_by
)
print
()
users_data
=
users_ldap
()
for
k
,
v
in
machines_data
.
items
():
if
not
v
[
"
utilisateur
"
]
or
v
[
"
utilisateur
"
]
not
in
users_data
:
print
(
f
"
{
k
}
: wrong user
{
v
[
'
utilisateur
'
]
}
"
)
continue
user
=
users_data
[
v
[
"
utilisateur
"
]]
if
user
[
"
st
"
]
in
[
"
JAMAIS
"
,
"
NON-PERTINENT
"
]:
continue
d
,
m
,
y
=
(
int
(
i
)
for
i
in
user
[
"
st
"
].
split
(
"
/
"
))
st
=
date
(
y
,
m
,
d
)
if
v
[
"
datePeremption
"
]
>
st
:
print
(
f
"
{
k
}
: wrong peremption for
{
user
[
'
uid
'
]
}
:
"
f
"
{
v
[
'
datePeremption
'
]
:
%
d
/%
m
/%
Y
}
>
{
st
:
%
d
/%
m
/%
Y
}
"
)
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