Module: OneviewSDK::SCMB

Defined in:
lib/oneview-sdk/scmb.rb

Overview

State Schange Message Bus (SCMB) helper

Constant Summary collapse

DEFAULT_ROUTING_KEY =
'scmb.#'.freeze

Class Method Summary collapse

Class Method Details

.get_or_create_keypair(client) ⇒ Hash

Retrieve or create the default RabbitMQ keypair



53
54
55
56
57
58
59
60
61
# File 'lib/oneview-sdk/scmb.rb', line 53

def self.get_or_create_keypair(client)
  client.response_handler(client.rest_get('/rest/certificates/client/rabbitmq/keypair/default'))
rescue OneviewSDK::NotFound # Create the keypair if it doesn't exist
  client.logger.info('RabbitMQ default keypair not found. Creating it now.')
  opts = { commonName: 'default', type: 'RabbitMqClientCertV2' }
  client.response_handler(client.rest_post('/rest/certificates/client/rabbitmq', body: opts))
  # Retrieve the created key
  client.response_handler(client.rest_get('/rest/certificates/client/rabbitmq/keypair/default'))
end

.new_connection(client, opts = {}) ⇒ Bunny::Session

Create a new connection to the message bus

See http://rubybunny.info/articles/connecting.html for more details & options


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/oneview-sdk/scmb.rb', line 32

def self.new_connection(client, opts = {})
  con_opts = {
    port: 5671,
    auth_mechanism: 'EXTERNAL',
    tls: true,
    verify_peer: client.ssl_enabled,
    logger: client.logger
  }
  con_opts.merge!(opts)
  con_opts[:host] = URI.parse(client.url).host
  unless con_opts[:tls_cert] && con_opts[:tls_key]
    kp = get_or_create_keypair(client)
    con_opts[:tls_cert] = kp['base64SSLCertData']
    con_opts[:tls_key] = kp['base64SSLKeyData']
  end
  Bunny.new(con_opts).start
end

.new_queue(connection, routing_key = DEFAULT_ROUTING_KEY) ⇒ Bunny::Queue



65
66
67
68
69
# File 'lib/oneview-sdk/scmb.rb', line 65

def self.new_queue(connection, routing_key = DEFAULT_ROUTING_KEY)
  ch = connection.create_channel
  q = ch.queue('')
  q.bind('scmb', routing_key: routing_key)
end