Esempio n. 1
0
 def connect(self):
     """ Create a kombu AMQP connection and channel. """
     direction = self.direction
     config = self._config[direction]["broker"]
     params = common.parse_amqp_uri(config["uri"])
     cred = config.get("auth")
     if cred is None:
         cred = credential.new(scheme="none")
     if cred.scheme == "x509":
         ssl_options = dict()
         cred_dict = cred.dict()
         for key, keyval in {
                 "cert": "certfile",
                 "key": "keyfile",
                 "ca": "ca_certs"
         }.items():
             if key in cred_dict:
                 ssl_options[keyval] = cred_dict[key]
         ssl_options["cert_reqs"] = ssl.CERT_REQUIRED
         ssl_options["ssl_version"] = ssl.PROTOCOL_SSLv3
         extra = {
             "ssl": ssl_options,
             "transport_options": {
                 "login_method": "EXTERNAL"
             }
         }
     elif cred.scheme == "plain":
         extra = {
             "userid": cred['name'],
             "password": cred['pass'],
         }
     else:
         # none
         extra = dict()
     # if self._config.get("heartbeat") is not None:
     #    extra["heartbeat"] = self._config["heartbeat"]
     parameters = {
         "hostname": params["host"],
         "port": int(params["port"]),
         "transport": "amqplib",
         "virtual_host": params.get("virtual_host", "rabbitmq")
     }
     timeout_connect = self._config.get("timeout-connect")
     if timeout_connect is not None:
         parameters["connect_timeout"] = timeout_connect
     parameters.update(extra)
     self._connection = connection = self._kombu.BrokerConnection(
         **parameters)
     self._channel = connection.channel()
     LOGGER.debug("%s broker %s:%s: %s" % (
         direction,
         params['host'],
         params['port'],
         self.server_type(),
     ))
     if self._config.get("%s-broker-type" % direction) is None:
         self._config["%s-broker-type" % direction] = self.server_type()
     return True
Esempio n. 2
0
 def connect(self):
     """ Create a pika AMQP connection and channel. """
     direction = self.direction
     config = self._config[direction]["broker"]
     params = common.parse_amqp_uri(config["uri"])
     cred = config.get("auth")
     if cred is None:
         cred = credential.new(scheme="none")
     if cred.scheme == "x509":
         if self._pika.__version__ < "0.9.6":
             raise AmqpcltError(
                 "x509 authentication not supported in pika %s" %
                 self._pika.__version__)
         ssl_options = dict()
         for key, keyval in {
                 "cert": "certfile",
                 "key": "keyfile",
                 "ca": "ca_certs"
         }.items():
             if key in cred:
                 ssl_options[keyval] = cred[key]
         ssl_options["cert_reqs"] = ssl.CERT_REQUIRED
         ssl_options["ssl_version"] = ssl.PROTOCOL_SSLv3
         extra = {
             "ssl": True,
             "ssl_options": ssl_options,
             "credentials": self._pika.credentials.ExternalCredentials()
         }
     elif cred.scheme == "plain":
         extra = {
             "credentials":
             self._pika.credentials.PlainCredentials(
                 cred['name'], cred['pass']),
         }
     else:
         # none
         extra = dict()
     # if self._config.get("heartbeat") is not None:
     #    extra["heartbeat"] = self._config["heartbeat"]
     parameters = self._pika.connection.ConnectionParameters(
         params['host'].encode(), int(params['port']),
         params.get('virtual_host', "rabbitmq").encode(), **extra)
     self._connection = self._pika.BlockingConnection(parameters)
     self._channel = self._connection.channel()
     self._server_properties = self._connection._impl.server_properties
     LOGGER.debug("%s broker %s:%s: %s %s" %
                  (direction, params['host'], params['port'],
                   self.server_type(), self.server_version()))
     if self._config.get("%s-broker-type" % direction) is None:
         self._config["%s-broker-type" % direction] = self.server_type()
     return True
Esempio n. 3
0
 def connect(self):
     """ Create a pika AMQP connection and channel. """
     direction = self.direction
     config = self._config[direction]["broker"]
     params = common.parse_amqp_uri(config["uri"])
     cred = config.get("auth")
     if cred is None:
         cred = credential.new(scheme="none")
     if cred.scheme == "x509":
         if self._pika.__version__ < "0.9.6":
             raise AmqpcltError(
                 "x509 authentication not supported in pika %s" %
                 self._pika.__version__)
         ssl_options = dict()
         for key, keyval in {"cert": "certfile",
                             "key": "keyfile", "ca": "ca_certs"}.items():
             if key in cred:
                 ssl_options[keyval] = cred[key]
         ssl_options["cert_reqs"] = ssl.CERT_REQUIRED
         ssl_options["ssl_version"] = ssl.PROTOCOL_SSLv3
         extra = {
             "ssl": True,
             "ssl_options": ssl_options,
             "credentials": self._pika.credentials.ExternalCredentials()}
     elif cred.scheme == "plain":
         extra = {
             "credentials": self._pika.credentials.PlainCredentials(
                 cred['name'], cred['pass']), }
     else:
         # none
         extra = dict()
     #if self._config.get("heartbeat") is not None:
     #    extra["heartbeat"] = self._config["heartbeat"]
     parameters = self._pika.connection.ConnectionParameters(
         params['host'].encode(),
         int(params['port']),
         params.get('virtual_host', "rabbitmq").encode(), **extra)
     self._connection = connection = self._pika.BlockingConnection(
         parameters)
     self._channel = connection.channel()
     LOGGER.debug(
         "%s broker %s:%s: %s %s" %
         (direction, params['host'], params['port'], self.amqp_type(),
          connection.server_properties.get("version", "UNKNOWN"),))
     if self._config.get("%s-broker-type" % direction) is None:
         self._config["%s-broker-type" % direction] = self.amqp_type()
     return True
Esempio n. 4
0
 def connect(self):
     """ Create a kombu AMQP connection and channel. """
     direction = self.direction
     config = self._config[direction]["broker"]
     params = common.parse_amqp_uri(config["uri"])
     cred = config.get("auth")
     if cred is None:
         cred = credential.new(scheme="none")
     if cred.scheme == "x509":
         ssl_options = dict()
         cred_dict = cred.dict()
         for key, keyval in {"cert": "certfile",
                             "key": "keyfile", "ca": "ca_certs"}.items():
             if key in cred_dict:
                 ssl_options[keyval] = cred_dict[key]
         ssl_options["cert_reqs"] = ssl.CERT_REQUIRED
         ssl_options["ssl_version"] = ssl.PROTOCOL_SSLv3
         extra = {"ssl": ssl_options,
                  "transport_options": {"login_method": "EXTERNAL"}}
     elif cred.scheme == "plain":
         extra = {
             "userid": cred['name'],
             "password": cred['pass'], }
     else:
         # none
         extra = dict()
     #if self._config.get("heartbeat") is not None:
     #    extra["heartbeat"] = self._config["heartbeat"]
     parameters = {
         "hostname": params["host"],
         "port": int(params["port"]),
         "transport": "amqplib",
         "virtual_host": params.get("virtual_host", "rabbitmq")
     }
     timeout_connect = self._config.get("timeout-connect")
     if timeout_connect is not None:
         parameters["connect_timeout"] = timeout_connect
     parameters.update(extra)
     self._connection = connection = self._kombu.BrokerConnection(
         **parameters)
     self._channel = connection.channel()
     LOGGER.debug(
         "%s broker %s:%s: %s" %
         (direction, params['host'], params['port'], self.amqp_type(),))
     if self._config.get("%s-broker-type" % direction) is None:
         self._config["%s-broker-type" % direction] = self.amqp_type()
     return True