Commit 7548396c authored by Guido Trotter's avatar Guido Trotter
Browse files

KVM: add an instance uid file concept

If this file exists, for an instance, we release the uid contained
inside back to the uid pool, at instance shutdown.
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarIustin Pop <>
parent ff20190d
......@@ -45,9 +45,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
_ROOT_DIR = constants.RUN_GANETI_DIR + "/kvm-hypervisor"
_PIDS_DIR = _ROOT_DIR + "/pid" # contains live instances pids
_UIDS_DIR = _ROOT_DIR + "/uid" # contains instances reserved uids
_CTRL_DIR = _ROOT_DIR + "/ctrl" # contains instances control sockets
_CONF_DIR = _ROOT_DIR + "/conf" # contains instances startup data
constants.HV_KERNEL_PATH: hv_base.OPT_FILE_CHECK,
......@@ -109,6 +110,13 @@ class KVMHypervisor(hv_base.BaseHypervisor):
return utils.PathJoin(cls._PIDS_DIR, instance_name)
def _InstanceUidFile(cls, instance_name):
"""Returns the instance uidfile.
return utils.PathJoin(cls._UIDS_DIR, instance_name)
def _InstancePidInfo(cls, pid):
"""Check pid file for instance information.
......@@ -217,6 +225,22 @@ class KVMHypervisor(hv_base.BaseHypervisor):
return utils.PathJoin(cls._CONF_DIR, "%s.runtime" % instance_name)
def _TryReadUidFile(cls, uid_file):
"""Try to read a uid file
if os.path.exists(uid_file):
uid = int(utils.ReadFile(uid_file))
except EnvironmentError:
logging.warning("Can't read uid file", exc_info=True)
return None
except (TypeError, ValueError):
logging.warning("Can't parse uid file contents", exc_info=True)
return None
return uid
def _RemoveInstanceRuntimeFiles(cls, pidfile, instance_name):
"""Removes an instance's rutime sockets/files.
......@@ -226,6 +250,11 @@ class KVMHypervisor(hv_base.BaseHypervisor):
uid_file = cls._InstanceUidFile(instance_name)
uid = cls._TryReadUidFile(uid_file)
if uid is not None:
def _WriteNetScript(self, instance, seq, nic):
"""Write a script to connect a net interface to the proper bridge.
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