VMware: Misc fixes in HTTPAPI connection plugin (#65764)
* Error handling * Support session URL Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
24b1409667
commit
8d542edeae
1 changed files with 21 additions and 9 deletions
|
@ -10,6 +10,7 @@ import sys
|
||||||
|
|
||||||
from ansible.module_utils.connection import Connection
|
from ansible.module_utils.connection import Connection
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
# VMware ReST APIs
|
# VMware ReST APIs
|
||||||
#
|
#
|
||||||
|
@ -307,6 +308,11 @@ INVENTORY = dict(
|
||||||
url='/tagging/tag',
|
url='/tagging/tag',
|
||||||
filters=[],
|
filters=[],
|
||||||
),
|
),
|
||||||
|
session=dict(
|
||||||
|
api='cis',
|
||||||
|
url='/session',
|
||||||
|
filters=[],
|
||||||
|
),
|
||||||
vm=dict(
|
vm=dict(
|
||||||
api='vcenter',
|
api='vcenter',
|
||||||
url='/vm',
|
url='/vm',
|
||||||
|
@ -363,6 +369,13 @@ class VmwareRestModule(AnsibleModule):
|
||||||
# Initialize AnsibleModule superclass before params
|
# Initialize AnsibleModule superclass before params
|
||||||
super(VmwareRestModule, self).__init__(*args, **kwargs)
|
super(VmwareRestModule, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Turn on debug if not specified, but ANSIBLE_DEBUG is set
|
||||||
|
self.module_debug = {}
|
||||||
|
if self._debug:
|
||||||
|
self.warn('Enable debug output because ANSIBLE_DEBUG was set.')
|
||||||
|
self.params['log_level'] = 'debug'
|
||||||
|
self.log_level = self.params['log_level']
|
||||||
|
|
||||||
# Params
|
# Params
|
||||||
#
|
#
|
||||||
# REQUIRED: Their absence will chuck a rod
|
# REQUIRED: Their absence will chuck a rod
|
||||||
|
@ -373,7 +386,10 @@ class VmwareRestModule(AnsibleModule):
|
||||||
self.state = self.params.get('state')
|
self.state = self.params.get('state')
|
||||||
|
|
||||||
# Initialize connection via httpapi connector. See "REST API Calls"
|
# Initialize connection via httpapi connector. See "REST API Calls"
|
||||||
self._connection = Connection(self._socket_path)
|
try:
|
||||||
|
self._connection = Connection(self._socket_path)
|
||||||
|
except Exception as e:
|
||||||
|
self.fail(msg=to_native(e))
|
||||||
|
|
||||||
# Register default status handlers. See "Dynamic Status Handlers"
|
# Register default status handlers. See "Dynamic Status Handlers"
|
||||||
self._status_handlers = {
|
self._status_handlers = {
|
||||||
|
@ -385,13 +401,6 @@ class VmwareRestModule(AnsibleModule):
|
||||||
if self.use_object_handler:
|
if self.use_object_handler:
|
||||||
self._status_handlers['default'] = self.handle_default_object
|
self._status_handlers['default'] = self.handle_default_object
|
||||||
|
|
||||||
# Turn on debug if not specified, but ANSIBLE_DEBUG is set
|
|
||||||
self.module_debug = {}
|
|
||||||
if self._debug:
|
|
||||||
self.warn('Enable debug output because ANSIBLE_DEBUG was set.')
|
|
||||||
self.params['log_level'] = 'debug'
|
|
||||||
self.log_level = self.params['log_level']
|
|
||||||
|
|
||||||
# Debugging
|
# Debugging
|
||||||
#
|
#
|
||||||
# Tools to handle debugging output from the APIs.
|
# Tools to handle debugging output from the APIs.
|
||||||
|
@ -523,7 +532,10 @@ class VmwareRestModule(AnsibleModule):
|
||||||
method='POST',
|
method='POST',
|
||||||
)
|
)
|
||||||
self.key = key
|
self.key = key
|
||||||
self.response['status'], self.response['data'] = self._connection.send_request(url, data, method='POST')
|
try:
|
||||||
|
self.response['status'], self.response['data'] = self._connection.send_request(url, data, method='POST')
|
||||||
|
except Exception as e:
|
||||||
|
self.fail(msg=to_native(e))
|
||||||
self._use_handler()
|
self._use_handler()
|
||||||
|
|
||||||
def put(self, url='/rest', data=None, key='result'):
|
def put(self, url='/rest', data=None, key='result'):
|
||||||
|
|
Loading…
Add table
Reference in a new issue