Get hipchat, sns, and typetalk notification modules compiling on py3 (#2782)

This commit is contained in:
Toshio Kuratomi 2016-08-24 08:40:31 -07:00 committed by GitHub
parent b8db87d206
commit 65eba72ee6
4 changed files with 42 additions and 27 deletions

View file

@ -102,13 +102,10 @@ env:
network/nmcli.py
network/openvswitch_bridge.py
network/openvswitch_port.py
notification/hipchat.py
notification/irc.py
notification/jabber.py
notification/mail.py
notification/mqtt.py
notification/sns.py
notification/typetalk.py"
notification/mqtt.py"
before_install:
- git config user.name "ansible"
- git config user.email "ansible@ansible.com"

View file

@ -97,6 +97,15 @@ EXAMPLES = '''
#
import urllib
try:
import json
except ImportError:
import simplejson as json
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.urls import fetch_url
DEFAULT_URI = "https://api.hipchat.com/v1"
@ -104,10 +113,10 @@ MSG_URI_V1 = "/rooms/message"
NOTIFY_URI_V2 = "/room/{id_or_name}/notification"
def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
color='yellow', notify=False, api=MSG_URI_V1):
color='yellow', notify=False, api=MSG_URI_V1):
'''sending message to hipchat v1 server'''
print "Sending message to v1 server"
params = {}
params['room_id'] = room
@ -133,11 +142,10 @@ def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
def send_msg_v2(module, token, room, msg_from, msg, msg_format='text',
color='yellow', notify=False, api=NOTIFY_URI_V2):
color='yellow', notify=False, api=NOTIFY_URI_V2):
'''sending message to hipchat v2 server'''
print "Sending message to v2 server"
headers = {'Authorization':'Bearer %s' % token, 'Content-Type':'application/json'}
headers = {'Authorization': 'Bearer %s' % token, 'Content-Type': 'application/json'}
body = dict()
body['message'] = msg
@ -200,14 +208,12 @@ def main():
send_msg_v2(module, token, room, msg_from, msg, msg_format, color, notify, api)
else:
send_msg_v1(module, token, room, msg_from, msg, msg_format, color, notify, api)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg="unable to send msg: %s" % e)
changed = True
module.exit_json(changed=changed, room=room, msg_from=msg_from, msg=msg)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
if __name__ == '__main__':
main()

View file

@ -61,7 +61,7 @@ options:
required: false
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key']
@ -77,7 +77,8 @@ options:
required: false
aliases: ['aws_region', 'ec2_region']
requirements: [ "boto" ]
requirements:
- "boto"
"""
EXAMPLES = """
@ -97,10 +98,14 @@ EXAMPLES = """
topic: "deploy"
"""
import sys
try:
import json
except ImportError:
import simplejson as json
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import ec2_argument_spec, connect_to_aws, get_aws_connection_info
from ansible.module_utils.pycompat24 import get_exception
try:
import boto
@ -156,7 +161,8 @@ def main():
module.fail_json(msg="region must be specified")
try:
connection = connect_to_aws(boto.sns, region, **aws_connect_params)
except boto.exception.NoAuthHandlerFound, e:
except boto.exception.NoAuthHandlerFound:
e = get_exception()
module.fail_json(msg=str(e))
# .publish() takes full ARN topic id, but I'm lazy and type shortnames
@ -185,9 +191,11 @@ def main():
try:
connection.publish(topic=arn_topic, subject=subject,
message_structure='json', message=json_msg)
except boto.exception.BotoServerError, e:
except boto.exception.BotoServerError:
e = get_exception()
module.fail_json(msg=str(e))
module.exit_json(msg="OK")
main()
if __name__ == '__main__':
main()

View file

@ -57,6 +57,11 @@ except ImportError:
except ImportError:
json = None
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.urls import fetch_url, ConnectionError
def do_request(module, url, params, headers=None):
data = urllib.urlencode(params)
@ -72,6 +77,7 @@ def do_request(module, url, params, headers=None):
raise exc
return r
def get_access_token(module, client_id, client_secret):
params = {
'client_id': client_id,
@ -95,7 +101,8 @@ def send_message(module, client_id, client_secret, topic, msg):
}
do_request(module, url, {'message': msg}, headers)
return True, {'access_token': access_token}
except ConnectionError, e:
except ConnectionError:
e = get_exception()
return False, e
@ -126,8 +133,5 @@ def main():
module.exit_json(changed=True, topic=topic, msg=msg)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()