On Mon, Apr 19, 2010 at 04:54:42PM +0100, Guido Trotter wrote:
> If this file exists, for an instance, we release the uid contained
> inside back to the uid pool, at instance shutdown.
> 
> Signed-off-by: Guido Trotter <[email protected]>
> ---
>  lib/hypervisor/hv_kvm.py |   20 +++++++++++++++++++-
>  1 files changed, 19 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
> index cc81521..b73e6c7 100644
> --- a/lib/hypervisor/hv_kvm.py
> +++ b/lib/hypervisor/hv_kvm.py
> @@ -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
> -  _DIRS = [_ROOT_DIR, _PIDS_DIR, _CTRL_DIR, _CONF_DIR]
> +  _DIRS = [_ROOT_DIR, _PIDS_DIR, _UIDS_DIR, _CTRL_DIR, _CONF_DIR]
>  
>    PARAMETERS = {
>      constants.HV_KERNEL_PATH: hv_base.OPT_FILE_CHECK,
> @@ -110,6 +111,13 @@ class KVMHypervisor(hv_base.BaseHypervisor):
>      return utils.PathJoin(cls._PIDS_DIR, instance_name)
>  
>    @classmethod
> +  def _InstanceUidFile(cls, instance_name):
> +    """Returns the instance uidfile.
> +
> +    """
> +    return utils.PathJoin(cls._UIDS_DIR, instance_name)
> +
> +  @classmethod
>    def _InstancePidInfo(cls, pid):
>      """Check pid file for instance information.
>  
> @@ -226,6 +234,16 @@ class KVMHypervisor(hv_base.BaseHypervisor):
>      utils.RemoveFile(cls._InstanceMonitor(instance_name))
>      utils.RemoveFile(cls._InstanceSerial(instance_name))
>      utils.RemoveFile(cls._InstanceKVMRuntime(instance_name))
> +    uid_file = cls._InstanceUidFile(instance_name)
> +    if os.path.exists(uid_file):
> +      try:
> +        uid = int(utils.ReadFile(uid_file))
> +        uidpool.ReleaseUid(uid)
> +      except EnvironmentError:
> +        logging.warning("Can't read uid file", exc_info=True)
> +      except (TypeError, ValueError):
> +        logging.warning("Can't parse uid file contents", exc_info=True)

Please move the read of the uid file into its own function (TryReadUid
or such).

> +    utils.RemoveFile(uid_file)

LGTM otherwise.

iustin


-- 
Subscription settings: 
http://groups.google.com/group/ganeti-devel/subscribe?hl=en

Reply via email to