Fix rabbitmq modules for python3 import

Also get rid of unnecessary capture of exception into a variable for
python-2.4 compat.
This commit is contained in:
Toshio Kuratomi 2017-08-07 18:52:33 -07:00
parent 441376c754
commit 8894c57753
3 changed files with 18 additions and 16 deletions

View file

@ -103,15 +103,15 @@ EXAMPLES = '''
'''
import json
import urllib
try:
import requests
HAS_REQUESTS = True
except ImportError as e:
except ImportError:
HAS_REQUESTS = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main():
@ -143,15 +143,15 @@ def main():
if module.params['routing_key'] == "":
props = "~"
else:
props = urllib.quote(module.params['routing_key'],'')
props = urllib_parse.quote(module.params['routing_key'],'')
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib.quote(module.params['name'],''),
urllib_parse.quote(module.params['vhost'],''),
urllib_parse.quote(module.params['name'],''),
dest_type,
urllib.quote(module.params['destination'],''),
urllib_parse.quote(module.params['destination'],''),
props
)
@ -190,10 +190,10 @@ def main():
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib.quote(module.params['name'],''),
urllib_parse.quote(module.params['vhost'],''),
urllib_parse.quote(module.params['name'],''),
dest_type,
urllib.quote(module.params['destination'],'')
urllib_parse.quote(module.params['destination'],'')
)
r = requests.post(

View file

@ -105,14 +105,15 @@ EXAMPLES = '''
'''
import json
try:
import requests
HAS_REQUESTS = True
except ImportError as e:
except ImportError:
HAS_REQUESTS = False
import urllib
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main():
@ -137,8 +138,8 @@ def main():
url = "http://%s:%s/api/exchanges/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib.quote(module.params['name'],'')
urllib_parse.quote(module.params['vhost'],''),
urllib_parse.quote(module.params['name'],'')
)
if not HAS_REQUESTS:

View file

@ -120,14 +120,15 @@ EXAMPLES = '''
'''
import json
try:
import requests
HAS_REQUESTS = True
except ImportError as e:
except ImportError:
HAS_REQUESTS = False
import urllib
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main():
@ -155,7 +156,7 @@ def main():
url = "http://%s:%s/api/queues/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib_parse.quote(module.params['vhost'],''),
module.params['name']
)