On Fri, Jan 3, 2014 at 9:42 AM, Jose A. Lopes <[email protected]> wrote: > * modify the KVM hypervisor to look for the shutdown files created by > the KVM daemon, which determine whether an instance was shutdown by > the user > * modify the KVM hypervisor to spawn the KVM daemon if it is not > running > > Signed-off-by: Jose A. Lopes <[email protected]> > --- > lib/hypervisor/hv_kvm.py | 43 +++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 41 insertions(+), 2 deletions(-) > > diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py > index dc6eaeb..e45c499 100644 > --- a/lib/hypervisor/hv_kvm.py > +++ b/lib/hypervisor/hv_kvm.py > @@ -886,6 +886,13 @@ class KVMHypervisor(hv_base.BaseHypervisor): > """ > return utils.PathJoin(cls._CTRL_DIR, "%s.qmp" % instance_name) > > + @classmethod > + def _InstanceShutdownMonitor(cls, instance_name): > + """Returns the instance QMP output filename > + > + """ > + return utils.PathJoin(cls._CTRL_DIR, "%s.shutdown" % instance_name) > + > @staticmethod > def _SocatUnixConsoleParams(): > """Returns the correct parameters for socat > @@ -1146,10 +1153,18 @@ class KVMHypervisor(hv_base.BaseHypervisor): > """ > result = [] > for name in os.listdir(self._PIDS_DIR): > - if self._InstancePidAlive(name)[2]: > + if self._InstancePidAlive(name)[2] or self._IsUserShutdown(name): > result.append(name) > return result > > + @classmethod > + def _IsUserShutdown(cls, instance_name): > + return os.path.exists(cls._InstanceShutdownMonitor(instance_name)) > + > + @classmethod > + def _ClearUserShutdown(cls, instance_name): > + utils.RemoveFile(cls._InstanceShutdownMonitor(instance_name)) > + > def GetInstanceInfo(self, instance_name, hvparams=None): > """Get instance properties. > > @@ -1163,7 +1178,10 @@ class KVMHypervisor(hv_base.BaseHypervisor): > """ > _, pid, alive = self._InstancePidAlive(instance_name) > if not alive: > - return None > + if self._IsUserShutdown(instance_name): > + return (instance_name, -1, 0, 0, hv_base.HvInstanceState.SHUTDOWN, 0) > + else: > + return None > > _, memory, vcpus = self._InstancePidInfo(pid) > istat = hv_base.HvInstanceState.RUNNING > @@ -1745,6 +1763,9 @@ class KVMHypervisor(hv_base.BaseHypervisor): > name = instance.name > self._CheckDown(name) > > + self._ClearUserShutdown(instance.name) > + self._StartKvmd(instance.hvparams) > + > temp_files = [] > > kvm_cmd, kvm_nics, up_hvp, kvm_disks = kvm_runtime > @@ -1947,6 +1968,21 @@ class KVMHypervisor(hv_base.BaseHypervisor): > # explicitly requested resume the vm status. > self._CallMonitorCommand(instance.name, self._CONT_CMD) > > + @staticmethod > + def _StartKvmd(hvparams): > + """Ensure that the Kvm daemon is running. > + > + """ > + if hvparams is None \ > + or not hvparams[constants.HV_KVM_USER_SHUTDOWN] \ > + or utils.IsDaemonAlive(constants.KVMD): > + return > + > + result = utils.RunCmd(constants.KVMD) > + > + if result.failed: > + raise errors.HypervisorError("Failed to start KVM daemon") > + > def StartInstance(self, instance, block_devices, startup_paused): > """Start an instance. > > @@ -2229,6 +2265,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): > utils.KillProcess(pid) > else: > cls._CallMonitorCommand(name, "system_powerdown") > + cls._ClearUserShutdown(instance.name) > > def StopInstance(self, instance, force=False, retry=False, name=None): > """Stop an instance. > @@ -2244,6 +2281,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): > if pid > 0 and alive: > raise errors.HypervisorError("Cannot cleanup a live instance") > self._RemoveInstanceRuntimeFiles(pidfile, instance_name) > + self._ClearUserShutdown(instance_name) > > def RebootInstance(self, instance): > """Reboot an instance. > @@ -2382,6 +2420,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): > self._RemoveInstanceRuntimeFiles(pidfile, instance.name) > elif live: > self._CallMonitorCommand(instance.name, self._CONT_CMD) > + self._ClearUserShutdown(instance.name) > > def GetMigrationStatus(self, instance): > """Get the migration status > -- > 1.8.5.1 >
LGTM, thanks. Michele -- Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
