Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Benjamin Graillot
scripts
Commits
248d1998
Commit
248d1998
authored
Nov 20, 2013
by
Valentin Samir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ressuscite_lc] Un ressucite pour lc_ldap gerant les exceptions
parent
05cb8fc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
11 deletions
+59
-11
gestion/ressuscite_lc.py
gestion/ressuscite_lc.py
+58
-10
respbats/ressuscite_lc
respbats/ressuscite_lc
+1
-1
No files found.
gestion/ressuscite_lc.py
View file @
248d1998
#!/
usr/bin/env
python
#!/
bin/bash /usr/scripts/
python
.sh
# -*- mode: python; coding: utf-8 -*-
################# ATTENTION #####################
# À ne pas laisser executable par n'importe qui,#
# permet de récupérer un shell vers lc_ldap #
#################################################
import
sys
sys
.
path
.
append
(
'/usr/scripts/'
)
import
pprint
from
affich_tools
import
coul
,
prompt
from
IPython.frontend.terminal.embed
import
InteractiveShellEmbed
import
lc_ldap.shortcuts
import
lc_ldap.attributs
import
lc_ldap.crans_utils
import
lc_ldap.printing
def
reset_ip
(
machine
):
machine
[
'rid'
]
=
unicode
(
conn
.
_find_id
(
'rid'
,
lc_ldap
.
crans_utils
.
find_rid_plage
(
machine
[
'rid'
][
0
].
value
)[
0
]))
machine
[
'ipHostNumber'
]
=
lc_ldap
.
attributs
.
ipHostNumber
.
default
machine
[
'ip6HostNumber'
]
=
lc_ldap
.
attributs
.
ip6HostNumber
.
default
def
reset_mid
(
machine
,
proprio
=
None
):
machine
[
'mid'
]
=
unicode
(
conn
.
_find_id
(
'mid'
))
if
proprio
:
machine
.
dn
=
"mid=%s,aid=%s,%s"
%
(
machine
[
'mid'
][
0
],
proprio
[
'aid'
][
0
],
machine
.
dn
.
split
(
','
,
2
)[
2
])
else
:
print
coul
(
"Pas de proprio de fourni, on suppose que l'aid du dn %s est valide"
%
machine
.
dn
.
split
(
','
,
2
)[
1
],
"jaune"
)
machine
.
dn
=
"mid=%s,%s"
%
(
machine
[
'mid'
][
0
],
machine
.
dn
.
split
(
','
,
1
)[
1
])
class
Edit
(
Exception
):
pass
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>
=
2
:
if
len
(
sys
.
argv
)
>
2
:
conn
=
lc_ldap
.
shortcuts
.
lc_ldap_admin
()
for
file
in
sys
.
argv
[
1
:]:
try
:
conn
.
ressuscite
(
file
)
except
lc_ldap
.
attributs
.
UniquenessError
as
e
:
sys
.
stderr
.
write
(
"%s
\n
"
%
e
)
try
:
coffins
=
conn
.
gravedig
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
if
not
coffins
:
print
"Nothing to do"
elif
len
(
coffins
)
==
1
:
print
lc_ldap
.
printing
.
sprint
(
coffins
[
0
])
ret
=
prompt
(
"Ressuciter ?[y,n,e]"
,
"N"
)
if
ret
.
lower
()
==
'y'
:
coffins
[
0
].
create
()
if
ret
.
lower
()
==
'e'
:
raise
Edit
(
"Édition manuelle"
)
else
:
raise
lc_ldap
.
attributs
.
UniquenessError
(
"Plus d'un objet machtant %s"
%
sys
.
argv
[
2
])
except
(
lc_ldap
.
attributs
.
UniquenessError
,
Edit
)
as
error
:
msg
=
coul
(
"%s, démarrage d'un shell."
%
error
,
'rouge'
)
msg
+=
"""
Les objets ressucitables sont dans la variable `coffins`.
Une connexion admin à la base ldap dans la variable `conn`.
Pour ressuciter les machines, il y a en plus les fonctions :
* reset_mid(machine, proprio=None)
* reset_ip(machine)
"""
ipshell
=
InteractiveShellEmbed
.
instance
(
banner1
=
unicode
(
msg
,
'utf-8'
))
ipshell
()
sys
.
exit
(
0
)
except
ValueError
as
error
:
print
coul
(
"%s"
%
error
,
"rouge"
)
else
:
sys
.
stderr
.
write
(
"Usage: %s
[fichier_du_cimetière]*
\n
Le cimetière est dans /home/cimetiere_lc/
\n
"
%
sys
.
argv
[
0
])
sys
.
stderr
.
write
(
"Usage: %s
{cimetière} {filtre}
\n
Le cimetière est dans /home/cimetiere_lc/
\n
"
%
sys
.
argv
[
0
])
respbats/ressuscite_lc
View file @
248d1998
#! /bin/sh
LANG
=
fr_FR.UTF-8
sudo
-u
respbats
/usr/scripts/gestion/ressuscite_lc.py
$*
LANG
=
fr_FR.UTF-8 /usr/scripts/gestion/ressuscite_lc.py
$*
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment