Commit dd657362 authored by Francesco Pace's avatar Francesco Pace
Browse files

Add port to plugin channel


Signed-off-by: default avatarFrancesco Pace <pace.francesco.g@gmail.com>
parent 5005f9ab
......@@ -198,7 +198,7 @@ def _storage_plugin_check(data):
def _channel_check(data):
required_keys = ['protocol', 'host', 'username', 'password']
required_keys = ['protocol', 'host', 'port', 'username', 'password']
for k in required_keys:
if k not in data:
raise InvalidApplicationDescription(msg="Missing required key: %s" % k)
......
......@@ -20,16 +20,18 @@ log = logging.getLogger(__name__)
class RabbitMQ:
def __init__(self, username, password, host):
def __init__(self, username, password, host, port=None):
self.username = username
self.password = password
self.host = host
self.port = port
self.channel = None
def open_connection(self):
log.debug("Opening connection to RabbitMQ: {}".format(self.host))
credentials = pika.PlainCredentials(self.username, self.password)
connection = pika.BlockingConnection(pika.ConnectionParameters(self.host, credentials=credentials))
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=self.host, port=self.port, credentials=credentials))
self.channel = connection.channel()
def send_message(self, exchange, queue, message):
......
......@@ -27,7 +27,7 @@ class Crystal:
message = "{}:{}".format(tenant, policy)
if self.channel['protocol'] == 'rabbitmq':
log.debug("Transmitting policy to Crystal via RabbitMQ")
rmq = RabbitMQ(self.channel['username'], self.channel['password'], self.channel['host'])
rmq = RabbitMQ(self.channel['username'], self.channel['password'], self.channel['host'], self.channel['port'])
rmq.open_connection()
rmq.send_message(self.channel['exchange'], self.channel['queue'], message)
rmq.close_connection()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment