Browse Source

Add python-zaqarclient to python runtime

Add an example using zaqar.

Change-Id: I130a87d2b1315dca8b8712db5baea31c8eebbd9e
changes/33/516833/2
Lingxian Kong 4 years ago
parent
commit
1ea8b39051
  1. 45
      example/functions/python/openstack/send_zaqar_message.py
  2. 3
      runtimes/python2/requirements.txt
  3. 2
      tools/clear_resources.sh

45
example/functions/python/openstack/send_zaqar_message.py

@ -0,0 +1,45 @@
import os
import requests
from zaqarclient.queues import client
def _send_message(z_client, queue_name, status, message=''):
queue_name = queue_name or 'test_queue'
queue = z_client.queue(queue_name)
queue.post({"body": {'status': status, 'message': message}})
print 'message posted.'
def check_and_trigger(context, **kwargs):
file_name = 'count.txt'
r = requests.get('http://httpbin.org/status/500')
if r.status_code != requests.codes.ok:
if not os.path.isfile(file_name):
count = 1
with open(file_name, 'w') as f:
f.write(str(count))
else:
with open(file_name, 'r+') as f:
count = int(f.readline())
count += 1
if count >= 3:
z_client = client.Client(
session=context['os_session'],
version=2,
)
_send_message(z_client, kwargs.get('queue'), r.status_code,
'Service Not Available!')
count = 0
f.seek(0)
f.write(str(count))
f.truncate()
print('new count: %s' % count)
else:
try:
os.remove(file_name)
except OSError:
pass

3
runtimes/python2/requirements.txt

@ -3,4 +3,7 @@ python-openstackclient>=3.3.0,!=3.10.0 # Apache-2.0
python-neutronclient>=6.3.0 # Apache-2.0
python-swiftclient>=3.2.0 # Apache-2.0
python-ceilometerclient>=2.5.0 # Apache-2.0
python-zaqarclient>=1.0.0 # Apache-2.0
python-octaviaclient>=1.0.0 # Apache-2.0
python-mistralclient>=3.1.0 # Apache-2.0
keystoneauth1>=2.21.0 # Apache-2.0

2
tools/clear_resources.sh

@ -34,4 +34,4 @@ function delete_resources(){
fi
}
delete_resources
delete_resources $1

Loading…
Cancel
Save