Commit a13e1743 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Centralize the creation of a WConfd context in Python code



This will allow easier modification of the structure of a client
identity later.

Also add a helper method for creating a WConfd context from a context.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent ece21e0b
......@@ -39,6 +39,7 @@ import os
import random
import logging
import time
import threading
import itertools
from ganeti import errors
......@@ -62,6 +63,25 @@ _config_lock = locking.SharedLock("ConfigWriter")
_UPGRADE_CONFIG_JID = "jid-cfg-upgrade"
def GetWConfdContext(ec_id, livelock):
"""Prepare a context for communication with WConfd.
WConfd needs to know the identity of each caller to properly manage locks and
detect job death. This helper function prepares the identity object given a
job ID (optional) and a livelock file.
@type ec_id: int, or None
@param ec_id: the job ID or None, if the caller isn't a job
@type livelock: L{ganeti.utils.livelock.LiveLock}
@param livelock: a livelock object holding the lockfile needed for WConfd
@return: the WConfd context
"""
return (ec_id,
threading.current_thread().ident,
livelock.lockfile.name)
def _ValidateConfig(data):
"""Verifies that a configuration objects looks valid.
......
......@@ -33,7 +33,6 @@ import logging
import random
import time
import itertools
import threading
import traceback
from ganeti import opcodes
......@@ -309,9 +308,8 @@ class Processor(object):
self.hmclass = hooksmaster.HooksMaster
self._enable_locks = enable_locks
self.wconfd = wconfd # Indirection to allow testing
self._wconfdcontext = (ec_id,
threading.current_thread().ident,
self.context.livelock.lockfile.name)
self._wconfdcontext = context.GetWConfdContext(ec_id)
def _CheckLocksEnabled(self):
"""Checks if locking is enabled.
......
......@@ -488,6 +488,9 @@ class GanetiContext(object):
assert self.__class__._instance is None, "Attempt to modify Ganeti Context"
object.__setattr__(self, name, value)
def GetWConfdContext(self, ec_id):
return config.GetWConfdContext(ec_id, self.livelock)
def AddNode(self, node, ec_id):
"""Adds a node to the configuration.
......
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