From c4fbefc8969d7b97baa1006f168c530641c6652e Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 20 Jan 2009 18:12:01 +0000 Subject: [PATCH] KVM: Remove sockets after shutdown Abstract the monitor and serial socket naming in two functions, and reuse them to cleanup the files after shutdown. Reviewed-by: iustinp --- lib/hypervisor/hv_kvm.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index b021c4613..05a6d09be 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -57,6 +57,18 @@ class KVMHypervisor(hv_base.BaseHypervisor): if not os.path.exists(mydir): os.mkdir(mydir) + def _InstanceMonitor(self, instance_name): + """Returns the instance monitor socket name + + """ + return '%s/%s.monitor' % (self._CTRL_DIR, instance_name) + + def _InstanceSerial(self, instance_name): + """Returns the instance serial socket name + + """ + return '%s/%s.serial' % (self._CTRL_DIR, instance_name) + def _WriteNetScript(self, instance, seq, nic): """Write a script to connect a net interface to the proper bridge. @@ -229,10 +241,10 @@ class KVMHypervisor(hv_base.BaseHypervisor): # How do we decide whether to have it or not?? :( #"vnc_bind_address", #"network_port" - base_control = '%s/%s' % (self._CTRL_DIR, instance.name) - monitor_dev = 'unix:%s.monitor,server,nowait' % base_control + monitor_dev = 'unix:%s,server,nowait' % \ + self._InstanceMonitor(instance.name) kvm_cmd.extend(['-monitor', monitor_dev]) - serial_dev = 'unix:%s.serial,server,nowait' % base_control + serial_dev = 'unix:%s,server,nowait' % self._InstanceSerial(instance.name) kvm_cmd.extend(['-serial', serial_dev]) result = utils.RunCmd(kvm_cmd) @@ -270,6 +282,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): if not utils.IsProcessAlive(pid): utils.RemoveFile(pid_file) + utils.RemoveFile(self._InstanceMonitor(instance.name)) + utils.RemoveFile(self._InstanceSerial(instance.name)) def RebootInstance(self, instance): """Reboot an instance. -- GitLab