Commit f11d9396 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Hrvoje Ribicic

kvm: Minor refactor of MonitorSocket

Create socket upon connect(), keep the status of connection
(self._connected = False) in close(), make existing connect()
method protected and let connect() act as a reconnect method.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent d65da96a
...@@ -140,10 +140,6 @@ class MonitorSocket(object): ...@@ -140,10 +140,6 @@ class MonitorSocket(object):
""" """
self.monitor_filename = monitor_filename self.monitor_filename = monitor_filename
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# We want to fail if the server doesn't send a complete message
# in a reasonable amount of time
self.sock.settimeout(self._SOCKET_TIMEOUT)
self._connected = False self._connected = False
def _check_socket(self): def _check_socket(self):
...@@ -168,6 +164,13 @@ class MonitorSocket(object): ...@@ -168,6 +164,13 @@ class MonitorSocket(object):
" invoke connect() on it") " invoke connect() on it")
def connect(self): def connect(self):
"""Connect to the monitor socket if not already connected.
"""
if not self._connected:
self._connect()
def _connect(self):
"""Connects to the monitor. """Connects to the monitor.
Connects to the UNIX socket Connects to the UNIX socket
...@@ -182,6 +185,10 @@ class MonitorSocket(object): ...@@ -182,6 +185,10 @@ class MonitorSocket(object):
# Check file existance/stuff # Check file existance/stuff
try: try:
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# We want to fail if the server doesn't send a complete message
# in a reasonable amount of time
self.sock.settimeout(self._SOCKET_TIMEOUT)
self.sock.connect(self.monitor_filename) self.sock.connect(self.monitor_filename)
except EnvironmentError: except EnvironmentError:
raise errors.HypervisorError("Can't connect to qmp socket") raise errors.HypervisorError("Can't connect to qmp socket")
...@@ -194,6 +201,7 @@ class MonitorSocket(object): ...@@ -194,6 +201,7 @@ class MonitorSocket(object):
""" """
self.sock.close() self.sock.close()
self._connected = False
def GetFd(self, fds, kvm_devid): def GetFd(self, fds, kvm_devid):
"""Pass file descriptor to kvm process via monitor socket using SCM_RIGHTS """Pass file descriptor to kvm process via monitor socket using SCM_RIGHTS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment