Skip to content

Commit

Permalink
Merge pull request #150 from rsnyman/fix-logging
Browse files Browse the repository at this point in the history
Fix the error logging for once and for all
  • Loading branch information
psav authored Jul 7, 2017
2 parents 58b0ca1 + d098b7c commit 0764428
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions wrapanapi/virtualcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
]


def get_task_error_message(task):
"""Depending on the error type, a different attribute may contain the error message. This
function will figure out the error message.
"""
if hasattr(task.info.error, 'message'):
message = str(task.info.error.message)
elif hasattr(task.info.error, 'localizedMessage'):
message = str(task.info.error.localizedMessage)
elif hasattr(task.info.error, 'msg'):
message = str(task.info.error.msg)
else:
message = 'Unknown error type: {}'.format(task.info.error)
return message


class VMWareSystem(WrapanapiAPIBase):
"""Client to Vsphere API
Expand Down Expand Up @@ -678,13 +693,7 @@ def _check(store=[task]):
wait_for(_check, num_sec=provision_timeout, delay=4)

if task.info.state != 'success':
if hasattr(task.info.error, 'localizedMessage'):
message = str(task.info.error.localizedMessage)
elif hasattr(task.info.error, 'faultMessage'):
message = str(task.info.error.faultMessage.message)
else:
message = 'Unknown error type: {}'.format(task.info.error)
self.logger.error('Clone VM failed: %s', message)
self.logger.error('Clone VM failed: %s', get_task_error_message(task))
raise VMInstanceNotCloned(source)
else:
return destination
Expand All @@ -711,7 +720,7 @@ def remove_host_from_cluster(self, host_name):

if status != 'success':
raise HostNotRemoved("Host {} not removed: {}".format(
host_name, task.info.error.localizedMessage))
host_name, get_task_error_message(task)))

task = host.Destroy_Task()
status, t = wait_for(self._task_wait, [task], fail_condition=None)
Expand Down

0 comments on commit 0764428

Please sign in to comment.