Change in vdsm[master]: libvirtconnection: refactor: open a new connection in specia...
danken at redhat.com
danken at redhat.com
Wed Jun 4 11:43:10 UTC 2014
Dan Kenigsberg has uploaded a new change for review.
Change subject: libvirtconnection: refactor: open a new connection in special function
......................................................................
libvirtconnection: refactor: open a new connection in special function
This patch splits opening of a new connection to qemu:///system into a
new function, distinct of further decorations. get() is a cumbersome
function that could use some trimming.
Change-Id: I33f83d20d1906dcba7b3652abaeddcba14bec6c4
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M lib/vdsm/libvirtconnection.py
1 file changed, 19 insertions(+), 15 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/28348/1
diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py
index 31b6a3a..b1332db 100644
--- a/lib/vdsm/libvirtconnection.py
+++ b/lib/vdsm/libvirtconnection.py
@@ -77,6 +77,24 @@
__connectionLock = threading.Lock()
+def _open_qemu_connection():
+ def req(credentials, user_data):
+ passwd = file(constants.P_VDSM_LIBVIRT_PASSWD).readline().rstrip("\n")
+ for cred in credentials:
+ if cred[0] == libvirt.VIR_CRED_AUTHNAME:
+ cred[4] = constants.SASL_USERNAME
+ elif cred[0] == libvirt.VIR_CRED_PASSPHRASE:
+ cred[4] = passwd
+ return 0
+
+ auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
+ req, None]
+
+ libvirtOpen = functools.partial(
+ libvirt.openAuth, 'qemu:///system', auth, 0)
+ return utils.retry(libvirtOpen, timeout=10, sleep=0.2)
+
+
def get(target=None, killOnFailure=True):
"""Return current connection to libvirt or open a new one.
Use target to get/create the connection object linked to that object.
@@ -126,25 +144,11 @@
raise
return wrapper
- def req(credentials, user_data):
- passwd = file(constants.P_VDSM_LIBVIRT_PASSWD).readline().rstrip("\n")
- for cred in credentials:
- if cred[0] == libvirt.VIR_CRED_AUTHNAME:
- cred[4] = constants.SASL_USERNAME
- elif cred[0] == libvirt.VIR_CRED_PASSPHRASE:
- cred[4] = passwd
- return 0
-
- auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
- req, None]
-
with __connectionLock:
conn = __connections.get(id(target))
if not conn:
- libvirtOpenAuth = functools.partial(libvirt.openAuth,
- 'qemu:///system', auth, 0)
log.debug('trying to connect libvirt')
- conn = utils.retry(libvirtOpenAuth, timeout=10, sleep=0.2)
+ conn = _open_qemu_connection()
__connections[id(target)] = conn
setattr(conn, 'pingLibvirt', getattr(conn, 'getLibVersion'))
--
To view, visit http://gerrit.ovirt.org/28348
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I33f83d20d1906dcba7b3652abaeddcba14bec6c4
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>
More information about the vdsm-patches
mailing list