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

pull/18777/head
Toshio Kuratomi 8 years ago committed by Matt Clay
parent 4999bb28cd
commit 7a8b080506

@ -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"

@ -98,10 +98,26 @@ EXAMPLES = '''
MSG_URI = "https://api.hipchat.com/v1/rooms/message"
import urllib
try:
import json
except ImportError:
import simplejson as json
def send_msg(module, token, room, msg_from, msg, msg_format='text',
color='yellow', notify=False, api=MSG_URI):
'''sending message to hipchat'''
# 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"
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):
'''sending message to hipchat v1 server'''
params = {}
params['room_id'] = room
@ -127,11 +143,10 @@ def send_msg(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
@ -190,15 +205,16 @@ def main():
api = module.params["api"]
try:
send_msg(module, token, room, msg_from, msg, msg_format, color, notify, api)
except Exception, e:
if api.find('/v2') != -1:
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 = 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()

@ -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()

@ -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()

Loading…
Cancel
Save