Skip to content

Commit

Permalink
Better connection failure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Novacek committed Aug 16, 2016
1 parent ee482b7 commit ff2419f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions virtwho/virt/esx/esx.py
Expand Up @@ -320,7 +320,6 @@ def login(self):
try:
self.client = suds.client.Client(wsdl, location="%s/sdk" % self.url, **kwargs)
except requests.RequestException as e:
self.logger.exception("Unable to connect to ESX")
raise virt.VirtError(str(e))

self.client.set_options(timeout=self.MAX_WAIT_TIME)
Expand All @@ -333,7 +332,6 @@ def login(self):
try:
self.sc = self.client.service.RetrieveServiceContent(_this=self.moRef)
except requests.RequestException as e:
self.logger.exception("Unable to connect to ESX")
raise virt.VirtError(str(e))

# Login to server using given credentials
Expand All @@ -342,6 +340,8 @@ def login(self):
logging.getLogger('suds.client').setLevel(logging.CRITICAL)
self.client.service.Login(_this=self.sc.sessionManager, userName=self.username, password=self.password)
logging.getLogger('suds.client').setLevel(logging.ERROR)
except requests.RequestException as e:
raise virt.VirtError(str(e))
except suds.WebFault as e:
self.logger.exception("Unable to login to ESX")
raise virt.VirtError(str(e))
Expand Down Expand Up @@ -375,7 +375,10 @@ def createFilter(self):
"config.network.dnsConfig.domainName"])
]

return self.client.service.CreateFilter(_this=self.sc.propertyCollector, spec=pfs, partialUpdates=0)
try:
return self.client.service.CreateFilter(_this=self.sc.propertyCollector, spec=pfs, partialUpdates=0)
except requests.RequestException as e:
raise virt.VirtError(str(e))

def applyUpdates(self, updateSet):
for filterSet in updateSet.filterSet:
Expand Down
3 changes: 3 additions & 0 deletions virtwho/virt/xen/xen.py
Expand Up @@ -6,6 +6,7 @@
from XenAPI import NewMaster, Failure
from collections import defaultdict
import logging
import requests

from virtwho import virt
from virtwho.util import RequestsXmlrpcTransport
Expand Down Expand Up @@ -56,6 +57,8 @@ def login(self, url=None):
url = '%s://%s' % (self.url.partition(":")[0], url)
self.logger.debug("Switching to new master: %s", url)
return self.login(url)
except requests.ConnectionError as e:
raise virt.VirtError(str(e))
except Exception as e:
self.logger.exception("Unable to login to XENserver %s" % self.url)
raise virt.VirtError(str(e))
Expand Down

0 comments on commit ff2419f

Please sign in to comment.