Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
524aef91f9 | |||
84834a228f | |||
f081522e1e | |||
441fbd22d2 | |||
0f3c332923 | |||
4b11e407be | |||
32bfaa523f | |||
244cc1a716 | |||
1a63a81555 | |||
ebcb30f0ba | |||
db53a99881 | |||
bc53733bf7 | |||
d6e8801684 | |||
dc8d71a574 | |||
39c0895538 | |||
89b75f0147 | |||
a2f7313cc5 | |||
401a4f9ef4 | |||
27bdbf5e4f | |||
7b4414b137 | |||
e7903ded1b | |||
c13d90045e | |||
50cc20307d | |||
d79fd7be7a | |||
4c409112d8 | |||
93fd0536f1 |
@ -10,35 +10,36 @@ from collections import OrderedDict
|
||||
|
||||
def display_help():
|
||||
print("Modification de la valeur d'une variable d'un serveur")
|
||||
print("{} [--var nom_variable --value valeur]".format(sys.argv[0]))
|
||||
print("{} [--d domain --integration --save --no-save]".format(sys.argv[0]))
|
||||
|
||||
|
||||
def argparser():
|
||||
# récupère l'ID du groupe
|
||||
arglen = len(sys.argv)
|
||||
save = None
|
||||
integration = None
|
||||
if "--save" in sys.argv:
|
||||
save = True
|
||||
if "--no-save" in sys.argv:
|
||||
save = False
|
||||
if "--integration" in sys.argv:
|
||||
integration = True
|
||||
if arglen == 1:
|
||||
return None, None
|
||||
return None, save
|
||||
if sys.argv[1] in ['-h', '--help']:
|
||||
display_help()
|
||||
sys.exit(0)
|
||||
|
||||
if sys.argv[1] in ['-r', '--realm']:
|
||||
realm = sys.argv[2]
|
||||
return realm, None
|
||||
if sys.argv[1] in ['-d', '--domain']:
|
||||
domain = sys.argv[2]
|
||||
return domain, save, integration
|
||||
|
||||
if sys.argv[3] in ['-d', '--domain']:
|
||||
domain = sys.argv[4]
|
||||
return realm, domain
|
||||
|
||||
return None, None
|
||||
return None, save, integration
|
||||
|
||||
|
||||
def main():
|
||||
# import des fonctions communes de Zéphir client
|
||||
realm, domain = argparser()
|
||||
|
||||
if realm is None :
|
||||
realm = raw_input("Realm AD : ")
|
||||
domain, save, integration = argparser()
|
||||
|
||||
if domain is None :
|
||||
domain = raw_input("Domaine AD : ")
|
||||
@ -46,24 +47,45 @@ def main():
|
||||
fh = open("/etc/eole/config.eol", 'r')
|
||||
store = cjson.decode(fh.read(), all_unicode=True)
|
||||
fh.close
|
||||
if "ad_realm" in store:
|
||||
store["ad_realm"]['val'] = realm
|
||||
if "ad_domain" in store:
|
||||
store["ad_domain"]['val'] = domain
|
||||
if "nom_domaine_local" in store:
|
||||
store["nom_domaine_local"]['val'] = domain
|
||||
|
||||
fh = open("/etc/eole/config.eol", 'w')
|
||||
fh.write(cjson.encode(store))
|
||||
fh.close()
|
||||
|
||||
cmd="""CreoleCat samba4-vars.conf"""
|
||||
cmd="""CreoleCat -t samba4-vars.conf"""
|
||||
output = os.popen(cmd)
|
||||
res = output.read().strip()
|
||||
output.close()
|
||||
|
||||
cmd="""/usr/share/eole/posttemplate/25-manage-samba instance"""
|
||||
if not integration :
|
||||
to_integrate = raw_input("Souhaitez vous intégrer le serveur au domaine ad ? (O/N) ")
|
||||
if to_integrate == "O":
|
||||
integration = True
|
||||
|
||||
if integration:
|
||||
cmd="""rm -f /var/lib/samba/.instance_ok; rm -f *.tdb"""
|
||||
output = os.popen(cmd)
|
||||
res = output.read().strip()
|
||||
output.close()
|
||||
cmd="""/usr/share/eole/postservice/25-manage-samba instance"""
|
||||
output = os.popen(cmd)
|
||||
res = output.read().strip()
|
||||
output.close()
|
||||
|
||||
to_save = ""
|
||||
if save if None:
|
||||
to_save = raw_input("Souhaitez vous sauvegarder la configuration sur Zephir ? (O/N) ")
|
||||
if to_save == "O":
|
||||
save = True
|
||||
print("Sauvegarde de la configuration sur zephir")
|
||||
else:
|
||||
print("La configuration ne sera pas sauvegardé sur le zephir")
|
||||
if save:
|
||||
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
|
||||
output = os.popen(cmd)
|
||||
output.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from zephir.lib_zephir import *
|
||||
import os, shutil
|
||||
from creole.config import eoledirs, distrib_dir, dicos_dir
|
||||
@ -39,7 +41,7 @@ if eole_module != 'zephir':
|
||||
try:
|
||||
os.unlink("%s/zephir_conf/zephir_conf.py" % zephir_path)
|
||||
except:
|
||||
print("\n !! le fichier %s/zephir_conf/zephir_conf.py n'a pas pu être supprimé !!\n" % zephir_d_path)
|
||||
print("\n !! le fichier %s/zephir_conf/zephir_conf.py n'a pas pu être supprimé !!\n" % zephir_path)
|
||||
try:
|
||||
os.unlink("%s/zephir_conf/zephir_conf.pyc" % zephir_path)
|
||||
try:
|
@ -1,60 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys, getpass, socket, cjson
|
||||
from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def display_help():
|
||||
print("Modification de la valeur d'une variable d'un serveur")
|
||||
print("{} [--var nom_variable --value valeur]".format(sys.argv[0]))
|
||||
|
||||
|
||||
def argparser():
|
||||
# récupère l'ID du groupe
|
||||
arglen = len(sys.argv)
|
||||
if arglen == 1:
|
||||
return None, None
|
||||
if sys.argv[1] in ['-h', '--help']:
|
||||
display_help()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if sys.argv[1] in ['-v', '--var']:
|
||||
varc = sys.argv[2]
|
||||
return varc, None
|
||||
|
||||
if sys.argv[3] in ['-l', '--value']:
|
||||
valvar = sys.argv[4]
|
||||
return varc, valvar
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
def main():
|
||||
# import des fonctions communes de Zéphir client
|
||||
varc, valvar = argparser()
|
||||
|
||||
|
||||
if varc is None :
|
||||
varc = raw_input("Variable à modifier : ")
|
||||
|
||||
if valvar is None :
|
||||
valvar = raw_input("Valeur de la variable : ")
|
||||
|
||||
fh = open("/etc/eole/config.eol", 'r')
|
||||
store = cjson.decode(fh.read(), all_unicode=True)
|
||||
fh.close
|
||||
if varc in store:
|
||||
store[varc]['val'] = valvar
|
||||
|
||||
fh = open("/etc/eole/config.eol", 'w')
|
||||
fh.write(cjson.encode(store))
|
||||
fh.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
85
scripts/module/set_var.zephir
Normal file
85
scripts/module/set_var.zephir
Normal file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys, getpass, socket, cjson, os
|
||||
from pyeole.ihm import print_line, question_ouinon
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def display_help():
|
||||
print("Modification de la valeur d'une variable d'un serveur")
|
||||
print("{} [--var nom_variable --value valeur --save --no-save]".format(sys.argv[0]))
|
||||
|
||||
|
||||
def argparser():
|
||||
# récupère l'ID du groupe
|
||||
arglen = len(sys.argv)
|
||||
save = None
|
||||
if "--save" in sys.argv:
|
||||
save = True
|
||||
if "--no-save" in sys.argv:
|
||||
save = False
|
||||
if arglen == 1:
|
||||
return None, None, save
|
||||
|
||||
if sys.argv[1] in ['-h', '--help']:
|
||||
display_help()
|
||||
sys.exit(0)
|
||||
|
||||
if sys.argv[1] in ['-v', '--var']:
|
||||
varc = sys.argv[2]
|
||||
if sys.argv[3] in ['-l', '--value']:
|
||||
valvar = sys.argv[4]
|
||||
return varc, valvar, save
|
||||
else:
|
||||
return varc, None, save
|
||||
|
||||
return None, None, save
|
||||
|
||||
|
||||
def main():
|
||||
# import des fonctions communes de Zéphir client
|
||||
varc, valvar, save = argparser()
|
||||
|
||||
fh = open("/etc/eole/config.eol", 'r')
|
||||
store = cjson.decode(fh.read(), all_unicode=True)
|
||||
fh.close
|
||||
|
||||
if varc is None :
|
||||
print
|
||||
print('Liste des variables modifiables :')
|
||||
for var in store:
|
||||
print(' - ' + var)
|
||||
varc = raw_input("Variable à modifier : ")
|
||||
|
||||
if valvar is None :
|
||||
valvar = raw_input("Valeur de la variable : ")
|
||||
|
||||
if varc in store:
|
||||
if "|" in valvar:
|
||||
valvar = valvar.split("|")
|
||||
store[varc]['val'] = valvar
|
||||
|
||||
fh = open("/etc/eole/config.eol", 'w')
|
||||
fh.write(cjson.encode(store))
|
||||
fh.close()
|
||||
|
||||
if save is None :
|
||||
if question_ouinon("Souhaitez vous sauvegarder la configuration sur Zephir ?", default='non') == 'oui':
|
||||
print("Sauvegarde de la configuration sur zephir")
|
||||
save=True
|
||||
else:
|
||||
print("La configuration ne sera pas sauvegardé sur zephir")
|
||||
|
||||
if save:
|
||||
cmd="""/usr/share/zephir/scripts/zephir_client save_files"""
|
||||
output = os.popen(cmd)
|
||||
output.close()
|
||||
else:
|
||||
print_orange('Erreur : variable {} inconnue'.format(varc))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -6,6 +6,7 @@ from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
|
||||
try:
|
||||
@ -24,7 +25,6 @@ def display_help():
|
||||
print("Autorise une connexion ssh d'un utilisateur sur un groupe de serveur")
|
||||
print("{} [numero du groupe] [--user utilisateur]".format(sys.argv[0]))
|
||||
|
||||
|
||||
def argparser():
|
||||
# récupère l'ID du groupe
|
||||
arglen = len(sys.argv)
|
||||
@ -40,9 +40,9 @@ def argparser():
|
||||
display_help()
|
||||
sys.exit(1)
|
||||
|
||||
if sys.argv[2] in ['-v', '--var']:
|
||||
varc = sys.argv[3]
|
||||
return server_id, user
|
||||
if sys.argv[2] in ['-u', '--user']:
|
||||
user = sys.argv[3]
|
||||
return group_id, user
|
||||
|
||||
return group_id, None
|
||||
|
||||
@ -68,8 +68,13 @@ def main():
|
||||
print('Liste des groupes :')
|
||||
for grp_id, group_infos in groups.items():
|
||||
print(' - ' + str(grp_id) + ' : ' + group_infos[0])
|
||||
print( ' - N : Créer un nouveau groupe')
|
||||
while group_id is None:
|
||||
tmp_group_id = flushed_input("Numéro du groupe : ")
|
||||
if tmp_group_id == 'N':
|
||||
group_id = 'N'
|
||||
liste_serveurs = make_group()
|
||||
else:
|
||||
try:
|
||||
group_id = int(tmp_group_id)
|
||||
except Exception as err:
|
||||
@ -78,23 +83,74 @@ def main():
|
||||
if not group_id in groups:
|
||||
print_red('Groupe inconnu')
|
||||
group_id = None
|
||||
elif not group_id in groups:
|
||||
print_red('Le groupe "{}" est inconnu'.format(group_id))
|
||||
sys.exit(1)
|
||||
liste_serveurs = groups[group_id][1]
|
||||
else:
|
||||
liste_serveurs = groups[group_id][1]
|
||||
|
||||
if user is None:
|
||||
user = flushed_input("Utilisateur : ")
|
||||
|
||||
liste_serveurs = groups[group_id][1]
|
||||
|
||||
ret = proxy.serveurs.authorize_user(user,liste_serveurs)
|
||||
# on affiche les erreurs si nécessaire
|
||||
if ret[1]:
|
||||
print_orange('Erreur : ' + str(ret[1]))
|
||||
|
||||
print('Utilisateur {} autorisé à accéder en ssh aux serveurs {}'.format(user, liste_serveurs))
|
||||
print("Excecuter le script exec_script_group [id_group] -s call pour pour envoyer la configuration aux serveurs")
|
||||
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
print("Liste des serveurs : ")
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append(server[0])
|
||||
return server_infos
|
||||
|
||||
def get_pwd(addr, port):
|
||||
"""lecture d'un login/passwd pour l'application zephir
|
||||
|
@ -2,11 +2,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys, getpass, socket
|
||||
from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
try:
|
||||
from zephir.zephir_conf.zephir_conf import adresse_zephir
|
||||
@ -64,8 +61,13 @@ def main():
|
||||
print('Liste des groupes :')
|
||||
for grp_id, group_infos in groups.items():
|
||||
print(' - ' + str(grp_id) + ' : ' + group_infos[0])
|
||||
print( ' - N : Créer un nouveau groupe')
|
||||
while group_id is None:
|
||||
tmp_group_id = flushed_input("Numéro du groupe : ")
|
||||
if tmp_group_id == 'N':
|
||||
group_id = 'N'
|
||||
liste_serveurs = make_group()
|
||||
else:
|
||||
try:
|
||||
group_id = int(tmp_group_id)
|
||||
except Exception as err:
|
||||
@ -74,19 +76,73 @@ def main():
|
||||
if not group_id in groups:
|
||||
print_red('Groupe inconnu')
|
||||
group_id = None
|
||||
elif not group_id in groups:
|
||||
print_red('Le groupe "{}" est inconnu'.format(group_id))
|
||||
sys.exit(1)
|
||||
liste_serveurs = groups[group_id][1]
|
||||
else:
|
||||
liste_serveurs = groups[group_id][1]
|
||||
for id_serv in liste_serveurs :
|
||||
ret = proxy.serveurs.del_serveur(id_serv)
|
||||
if ret[1]:
|
||||
if ret[1] == "ok":
|
||||
print('Les serveurs {} ont été supprimés'.format(liste_serveurs))
|
||||
else:
|
||||
print_orange('Erreur : ' + str(ret[1]))
|
||||
sys.exit(1)
|
||||
|
||||
print('Les serveurs {} ont été supprimés'.format(liste_serveurs))
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
print("Liste des serveurs : ")
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append(server[0])
|
||||
return server_infos
|
||||
|
||||
def get_pwd(addr, port):
|
||||
"""lecture d'un login/passwd pour l'application zephir
|
||||
|
@ -6,6 +6,8 @@ from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
|
||||
|
||||
try:
|
||||
@ -44,7 +46,7 @@ def argparser():
|
||||
script = sys.argv[3]
|
||||
return group_id, script, None
|
||||
|
||||
if sys.argv[4] in ['-p', '--params']:
|
||||
if sys.argv[4] in ['-a', '--args']:
|
||||
varc = sys.argv[5]
|
||||
return group_id, script, params
|
||||
|
||||
@ -72,8 +74,13 @@ def main():
|
||||
print('Liste des groupes :')
|
||||
for grp_id, group_infos in groups.items():
|
||||
print(' - ' + str(grp_id) + ' : ' + group_infos[0])
|
||||
print( ' - N : Créer un nouveau groupe')
|
||||
while group_id is None:
|
||||
tmp_group_id = flushed_input("Numéro du groupe : ")
|
||||
if tmp_group_id == 'N':
|
||||
group_id = 'N'
|
||||
liste_serveurs = make_group()
|
||||
else:
|
||||
try:
|
||||
group_id = int(tmp_group_id)
|
||||
except Exception as err:
|
||||
@ -82,18 +89,18 @@ def main():
|
||||
if not group_id in groups:
|
||||
print_red('Groupe inconnu')
|
||||
group_id = None
|
||||
elif not group_id in groups:
|
||||
print_red('Le groupe "{}" est inconnu'.format(group_id))
|
||||
sys.exit(1)
|
||||
|
||||
liste_serveurs = groups[group_id][1]
|
||||
else:
|
||||
liste_serveurs = groups[group_id][1]
|
||||
if script is None:
|
||||
script = flushed_input("Script à executer : ")
|
||||
if params is None:
|
||||
params = flushed_input("Paramètres : ")
|
||||
|
||||
liste_serveurs = groups[group_id][1]
|
||||
|
||||
ret = proxy.uucp.exec_script(serveurs, script, params))
|
||||
if params is None: params = ""
|
||||
ret = proxy.uucp.exec_script(liste_serveurs, script, params)
|
||||
|
||||
# on affiche les erreurs si nécessaire
|
||||
if ret[1]:
|
||||
@ -101,6 +108,60 @@ def main():
|
||||
|
||||
print('Script {} {} exécuté sur les serveurs {}'.format(script, params, liste_serveurs))
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
print("Liste des serveurs : ")
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append(server[0])
|
||||
return server_infos
|
||||
|
||||
|
||||
def get_pwd(addr, port):
|
||||
|
58
scripts/zephir/groups.py
Normal file
58
scripts/zephir/groups.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
print("Liste des serveurs : ")
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append((server[0], server[1], server[2], server[3]))
|
||||
return server_infos
|
@ -6,6 +6,7 @@ from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
|
||||
try:
|
||||
@ -69,8 +70,13 @@ def main():
|
||||
print('Liste des groupes :')
|
||||
for grp_id, group_infos in groups.items():
|
||||
print(' - ' + str(grp_id) + ' : ' + group_infos[0])
|
||||
print( ' - N : Créer un nouveau groupe')
|
||||
while group_id is None:
|
||||
tmp_group_id = flushed_input("Numéro du groupe : ")
|
||||
if tmp_group_id == 'N':
|
||||
group_id = 'N'
|
||||
liste_serveurs = make_group()
|
||||
else:
|
||||
try:
|
||||
group_id = int(tmp_group_id)
|
||||
except Exception as err:
|
||||
@ -79,10 +85,10 @@ def main():
|
||||
if not group_id in groups:
|
||||
print_red('Groupe inconnu')
|
||||
group_id = None
|
||||
elif not group_id in groups:
|
||||
print_red('Le groupe "{}" est inconnu'.format(group_id))
|
||||
sys.exit(1)
|
||||
liste_serveurs = groups[group_id][1]
|
||||
else:
|
||||
liste_serveurs = groups[group_id][1]
|
||||
|
||||
if polling is None :
|
||||
polling = flushed_input("Durée du polling (en min) : ")
|
||||
@ -90,8 +96,65 @@ def main():
|
||||
ret = proxy.serveurs.groupe_params(liste_serveurs,{'timeout': str(int(polling)*60)})
|
||||
# on affiche les erreurs si nécessaire
|
||||
if ret[1]:
|
||||
if ret[1] != "OK":
|
||||
print_orange('Erreur : ' + str(ret[1]))
|
||||
sys.exit(1)
|
||||
print('Polling mis à jour sur les serveurs {}'.format(liste_serveurs))
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
print("Liste des serveurs : ")
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append(server[0])
|
||||
return server_infos
|
||||
|
||||
def get_pwd(addr, port):
|
||||
"""lecture d'un login/passwd pour l'application zephir
|
||||
|
@ -62,6 +62,7 @@ def main():
|
||||
keyssh = f.read()
|
||||
|
||||
clef_ssh = base64.encodestring(keyssh).decode()
|
||||
os.chdir("/etc/postgresql/")
|
||||
cmd="""sudo -u postgres psql -c "update users set cle='{}' where login='{}';" zephir""".format(clef_ssh,user)
|
||||
output = os.popen(cmd)
|
||||
res = output.read().strip()
|
||||
@ -71,6 +72,7 @@ def main():
|
||||
|
||||
if res == "UPDATE 1":
|
||||
print("OK")
|
||||
print("Excecuter le script authorize_user_group pour authoriser l'accès de l'utilisateur aux serveurs")
|
||||
else:
|
||||
print("Erreur : ", str(res))
|
||||
|
||||
|
204
scripts/zephir/set_var.py
Normal file
204
scripts/zephir/set_var.py
Normal file
@ -0,0 +1,204 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import sys, getpass, socket
|
||||
from pyeole.ihm import print_line
|
||||
from pyeole.ansiprint import print_orange, print_red
|
||||
from creole.client import CreoleClient
|
||||
from collections import OrderedDict
|
||||
from zephir.backend.lib_backend import CxPool
|
||||
|
||||
|
||||
try:
|
||||
from zephir.zephir_conf.zephir_conf import adresse_zephir
|
||||
except:
|
||||
client = CreoleClient()
|
||||
adresse_zephir = client.get_creole('nom_domaine_machine')
|
||||
from zephir.lib_zephir import convert
|
||||
from zephir.lib_zephir import xmlrpclib
|
||||
from zephir.lib_zephir import EoleProxy
|
||||
from zephir.lib_zephir import TransportEole
|
||||
from zephir.lib_zephir import flushed_input
|
||||
|
||||
def display_help():
|
||||
print("Modification de la valeur d'une variable d'un serveur")
|
||||
print("{} [numero du groupe] [--var nom_variable --value valeur --save]".format(sys.argv[0]))
|
||||
|
||||
|
||||
def argparser():
|
||||
# récupère l'ID du groupe
|
||||
arglen = len(sys.argv)
|
||||
|
||||
if arglen == 1:
|
||||
return None, None, None
|
||||
if sys.argv[1] in ['-h', '--help']:
|
||||
display_help()
|
||||
sys.exit(0)
|
||||
|
||||
try:
|
||||
group_id = int(sys.argv[1])
|
||||
except:
|
||||
print_red("\"{}\" n'est pas un ID de groupe valide".format(sys.argv[1]))
|
||||
display_help()
|
||||
sys.exit(1)
|
||||
|
||||
if sys.argv[2] in ['-v', '--var']:
|
||||
varc = sys.argv[3]
|
||||
if sys.argv[4] in ['-l', '--value']:
|
||||
valvar = sys.argv[5]
|
||||
return group_id, varc, valvar
|
||||
else:
|
||||
return group_id, varc, None,
|
||||
|
||||
return None, None, None
|
||||
|
||||
|
||||
def main():
|
||||
# import des fonctions communes de Zéphir client
|
||||
group_id, varc, valvar = argparser()
|
||||
|
||||
authentified, proxy = get_pwd(adresse_zephir, 7080)
|
||||
if authentified == False:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# on récupère la liste des groupes
|
||||
try:
|
||||
groups = {grp_id: (group_name, liste_serveurs) for grp_id, group_name, liste_serveurs in convert(proxy.serveurs.get_groups())[1]}
|
||||
except xmlrpclib.ProtocolError:
|
||||
print_red("""Erreur de permissions ou Zéphir non disponible""")
|
||||
sys.exit(1)
|
||||
except socket.error, e:
|
||||
print_red("""Erreur de connexion au serveur Zéphir (%s)""" % str(e))
|
||||
sys.exit(1)
|
||||
# on récupère l'ID du groupe concerné
|
||||
if group_id is None:
|
||||
print('Liste des groupes :')
|
||||
for grp_id, group_infos in groups.items():
|
||||
print(' - ' + str(grp_id) + ' : ' + group_infos[0])
|
||||
print( ' - N : Créer un nouveau groupe')
|
||||
while group_id is None:
|
||||
tmp_group_id = flushed_input("Numéro du groupe : ")
|
||||
if tmp_group_id == 'N':
|
||||
group_id = 'N'
|
||||
liste_serveurs = make_group()
|
||||
else:
|
||||
try:
|
||||
group_id = int(tmp_group_id)
|
||||
except Exception as err:
|
||||
print(err)
|
||||
continue
|
||||
if not group_id in groups:
|
||||
print_red('Groupe inconnu')
|
||||
group_id = None
|
||||
sys.exit(1)
|
||||
liste_serveurs = groups[group_id][1]
|
||||
else:
|
||||
liste_serveurs = groups[group_id][1]
|
||||
# on récupère toutes les master/slaves du groupe de serveurs
|
||||
params = convert(proxy.serveurs.get_groupe_vars(liste_serveurs, True))
|
||||
|
||||
|
||||
if varc is None :
|
||||
print
|
||||
print('Liste des variables dans un groupe :')
|
||||
list_vars = params[1][3]
|
||||
for var in list_vars:
|
||||
print(' - ' + var)
|
||||
varc = flushed_input("Variable à modifier : ")
|
||||
|
||||
if valvar is None :
|
||||
valvar = flushed_input("Valeur de la variable (séparateur |): ")
|
||||
ret = proxy.serveurs.set_groupe_var(liste_serveurs, varc, valvar, False)
|
||||
# on affiche les erreurs si nécessaire
|
||||
if ret[1]:
|
||||
if ret[1] != "OK":
|
||||
print_orange('Erreur : ' + str(ret[1]))
|
||||
sys.exit(1)
|
||||
print('Variable {} mis à jour sur les serveurs {}'.format(varc, liste_serveurs))
|
||||
|
||||
def make_group():
|
||||
cx_pool = CxPool()
|
||||
cu = cx_pool.create()
|
||||
cu.execute("""select libelle,id from modules""")
|
||||
infos = {}
|
||||
variante_infos = {}
|
||||
filename = 'exportation'
|
||||
server_infos = []
|
||||
for module_name in cu.fetchall():
|
||||
module, version = module_name[0].rsplit('-', 1)
|
||||
infos.setdefault(version, {})[module] = module_name[1]
|
||||
|
||||
versions = infos.keys()
|
||||
versions.sort()
|
||||
print('Choix de la version :')
|
||||
for idx, version in enumerate(versions):
|
||||
print('{}: {}'.format(idx, version))
|
||||
idx = input('> ')
|
||||
version = versions[int(idx)]
|
||||
filename += '-' + version
|
||||
print
|
||||
print('Choix du module :')
|
||||
modules = infos[version].keys()
|
||||
modules.sort()
|
||||
for idx, module in enumerate(modules):
|
||||
print('{}: {}'.format(idx, module))
|
||||
idx = input('> ')
|
||||
module = modules[int(idx)]
|
||||
filename += '-' + module
|
||||
print
|
||||
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
|
||||
for variante_obj in cu.fetchall():
|
||||
variante_infos[variante_obj[0]] = variante_obj[1]
|
||||
print('Choix de la variante :')
|
||||
variantes = variante_infos.keys()
|
||||
variantes.sort()
|
||||
for idx, variante in enumerate(variantes):
|
||||
print('{}: {}'.format(idx, variante))
|
||||
idx_all = idx + 1
|
||||
print('{}: toutes les variantes'.format(idx_all))
|
||||
idx = input('> ')
|
||||
if idx == idx_all:
|
||||
variantes = variante_infos.values()
|
||||
else:
|
||||
filename += '-' + variantes[idx]
|
||||
variantes = [variante_infos[variantes[idx]]]
|
||||
print
|
||||
for variante in variantes:
|
||||
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
|
||||
print("Liste des serveurs : ")
|
||||
for server in cu.fetchall():
|
||||
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
|
||||
server_infos.append(server[0])
|
||||
return server_infos
|
||||
|
||||
def get_pwd(addr, port):
|
||||
"""lecture d'un login/passwd pour l'application zephir
|
||||
"""
|
||||
login_ok = 0
|
||||
user = "toto"
|
||||
while login_ok == 0 and user != "":
|
||||
try:
|
||||
# flush de l'entrée standard au cas où l'utilisateur aurait
|
||||
# tapé <entrée> pendant l'Upgrade
|
||||
termios.tcflush(sys.stdin, termios.TCIOFLUSH)
|
||||
except:
|
||||
pass
|
||||
user = flushed_input("Entrez votre login zephir (rien pour sortir) : ")
|
||||
if user != "":
|
||||
passwd = getpass.getpass("Mot de passe zephir pour %s : " % user)
|
||||
# création du proxy avec zephir
|
||||
proxy = EoleProxy("https://%s:%s@%s:%s" % (user, passwd, addr, port), transport=TransportEole())
|
||||
login_ok = 1
|
||||
try:
|
||||
res = convert(proxy.get_permissions(user))
|
||||
except xmlrpclib.ProtocolError:
|
||||
login_ok = 0
|
||||
print_line("\n Erreur d'authentification \n")
|
||||
else:
|
||||
return False, "! Abandon de la procédure !"
|
||||
return True, proxy
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user