reset mdp

This commit is contained in:
Daniel STAN 2014-08-30 17:51:07 +02:00
parent d76ed2febb
commit d627da4e47
3 changed files with 93 additions and 24 deletions

View file

@ -1,5 +1,7 @@
#!/bin/bash /usr/scripts/python.sh
from __future__ import print_function
import pika
import json
import sys
@ -7,25 +9,21 @@ import sys
from lc_ldap.shortcuts import lc_ldap_readonly
from affich_tools import prompt
import lc_ldap.filter2 as filter
import config
rabbit_c = pika.BlockingConnection(config.PARAMS)
ch = rabbit_c.channel()
ch.queue_declare('CransTicket')
from client import Ticket
ldap = lc_ldap_readonly()
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
adh = ldap.search(f)
if len(adh) > 1:
print "More than one result"
res = ldap.search(f)
if len(res) > 1:
print("More than one result")
exit()
elif not adh:
print "Nobody"
elif not res:
print("Nobody found")
else:
adh = adh[0]
adh.display()
item = res[0]
item.display()
while True:
c = prompt("[O/N]").lower()
if c == 'n':
@ -33,16 +31,11 @@ else:
elif c == 'o':
break
m = adh.machines()
ticket = Ticket()
if hasattr(item, 'machines'):
for m in item.machines():
ticket.add_machine(m)
else:
ticket.add_machine(item)
ticket.print()
to_print = []
for machine in m:
if u'<automatique>' in machine['macAddress']:
continue
login = machine['host'][0].split('.', 1)[0]
todo = {'login': login, 'macAddress': machine['macAddress'][0].value}
if machine.has_key('ipsec'):
todo['secret'] = machine['ipsec'][0].value
to_print.append(todo)
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(to_print))