crans_ticket/client.py
2014-08-31 16:54:46 +02:00

37 lines
952 B
Python
Executable file

# -*- coding: utf-8 -*-
from __future__ import print_function
import pika
import json
import config
rabbit_c = pika.BlockingConnection(config.PARAMS)
ch = rabbit_c.channel()
ch.queue_declare('CransTicket')
class Ticket(object):
data = []
def add_entry(self, x):
self.data.append(x)
def add_account(self, login, mdp):
self.add_entry({'login': login, 'pass': mdp})
def add_machine(self, machine):
todo = {
'host': machine['host'][0].split('.', 1)[0],
'macAddress': machine['macAddress'][0].value,
'type': 'fil',
}
if machine.has_key('ipsec'):
todo['secret'] = machine['ipsec'][0].value
todo['type'] = 'wifi'
self.add_entry(todo)
def print(self):
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(self.data))
print("Un nouveau ticket est en cours d'impression ...")