2 pika – HP OneView User Manual

Page 222

Advertising
background image

a.

Download and install the setuptools (Python setup.py install) at

https://pypi.python.org/

pypi/setuptools#downloads

.

b.

Install the pika tools.

When you install the pika or amqp libraries, run the same python setup.py install
command from the downloaded pika or amqp directory.

2.

Create the certificate.

POST /rest/certificates/client/rabbitmq

Request body: {"type":"RabbitMqClientCertV2","commonName":"default"}

3.

Download the client certificate and private key.

GET /rest/certificates/client/rabbitmq/keypair/default

4.

Save the contents of the client certificate in the response body into a text file named
client.pem

.

You must copy and paste everything from -----BEGIN CERTIFICATE----- to -----END
CERTIFICATE-----

, including the dashes, but not including the quotes. You must replace

all instances of \n with CR/LF (carriage return / line feed).

5.

Save the contents of the private key in the response body into a text file named key.pem.

You must copy and paste everything from -----BEGIN RSA PRIVATE KEY----- to
-----END RSA PRIVATE KEY-----

, including the dashes, but not including the quotes.

You must replace all instances of \n with CR/LF (carriage return / line feed).

6.

Download the root CA certificate.

GET /rest/certificates/ca

7.

Save the contents in the response body into a text file named caroot.pem. You must copy
and paste everything from -----BEGIN CERTIFICATE----- to -----END
CERTIFICATE-----

, including the dashes, but not including the quotes. You must replace

all instances of \n with CR/LF (carriage return / line feed).

30.6.2 Pika

Example 6 Pika code example

When you invoke the script, you must pass –host:{hostname or IP}. See the following
examples:

--host:192.168.1.1

–host:my-appliance.example.com

IMPORTANT:

If the connection fails on the first attempt to invoke this script after an appliance

reboot, try invoking the script again.

import pika, ssl
from optparse import OptionParser
from pika.credentials import ExternalCredentials
import json
import logging

logging.basicConfig()

###############################################
# Callback function that handles messages
def callback(ch, method, properties, body):
msg = json.loads(body)
timestamp = msg['timestamp']
resourceUri = msg['resourceUri']
resource = msg['resource']
changeType = msg['changeType']

print

222 Using the State-Change Message Bus (SCMB)

Advertising