cleaned up LibvirtNodeDriver.__init__ checking the uri string for +tcp before trying to do the SASL connection to the libvirtd service
Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f59c3922 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f59c3922 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f59c3922 Branch: refs/heads/trunk Commit: f59c3922ebd66e15f9b09ba5cfdfe5fcede6d1b6 Parents: bb202a2 Author: Rene Kjellerup <[email protected]> Authored: Fri Jul 8 11:49:33 2016 -0700 Committer: Tomaz Muraus <[email protected]> Committed: Wed Jul 13 11:31:20 2016 +0200 ---------------------------------------------------------------------- libcloud/compute/drivers/libvirt_driver.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/f59c3922/libcloud/compute/drivers/libvirt_driver.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py index 7a2e132..5586a6b 100644 --- a/libcloud/compute/drivers/libvirt_driver.py +++ b/libcloud/compute/drivers/libvirt_driver.py @@ -82,16 +82,18 @@ class LibvirtNodeDriver(NodeDriver): self._uri = uri self._key = key self._secret = secret - try: - self.connection = libvirt.open(uri) - except libvirt.libvirtError: - if key is None or secret is None: + if '+tcp' in self._uri: + if key is None and secret is None: raise RuntimeError('The remote Libvirt instance requires ' + 'authentication, please set \'key\' and ' + '\'secret\' parameters') auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], self._cred_callback, None] self.connection = libvirt.openAuth(uri, auth, 0) + else: + self.connection = libvirt.open(uri) + if self.connection is None: + raise RuntimeError('Unable to establish a connection to libvirtd') def _cred_callback(self, cred, user_data): """
