diff --git a/example/functions/python/openstack/send_zaqar_message.py b/example/functions/python/openstack/send_zaqar_message.py new file mode 100644 index 00000000..16e0b65a --- /dev/null +++ b/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 diff --git a/runtimes/python2/requirements.txt b/runtimes/python2/requirements.txt index 22918d98..d951f290 100644 --- a/runtimes/python2/requirements.txt +++ b/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 diff --git a/tools/clear_resources.sh b/tools/clear_resources.sh index 5a51d908..e096b382 100644 --- a/tools/clear_resources.sh +++ b/tools/clear_resources.sh @@ -34,4 +34,4 @@ function delete_resources(){ fi } -delete_resources +delete_resources $1