def StopInstance(self, instance, force=False, retry=False, name=None,
                   timeout=None):
    assert(timeout is None or force is not None)

    if name is None:
      name = instance.name

    root_dir = self._InstanceDir(name)
    if not os.path.exists(root_dir) or not self._IsDirLive(root_dir):
      return

    timeout_cmd = []
    if timeout is not None:
      timeout_cmd.extend(["timeout", str(timeout)])

    # Run the chroot stop script only once
    if not retry and not force:
      result = utils.RunCmd(timeout_cmd.extend(["chroot", root_dir,
                                                "/ganeti-chroot", "stop"]))
      if result.failed:
        raise HypervisorError("Can't run the chroot stop script: %s" %
                              result.output)

    if not force:
      utils.RunCmd(["fuser", "-k", "-TERM", "-m", root_dir])
    else:
      utils.RunCmd(["fuser", "-k", "-KILL", "-m", root_dir])
      # 2 seconds at most should be enough for KILL to take action
      time.sleep(2)

    if self._IsDirLive(root_dir):
      if force:
        raise HypervisorError("Can't stop the processes using the chroot")
      return
Stop an instance.
dataset/ETHPy150Open ganeti/ganeti/lib/hypervisor/hv_chroot.py/ChrootManager.StopInstance