_LS_ACQUIRE_ALL,
_LS_ACQUIRE_OPPORTUNISTIC) = range(1, 4)
-_LS_ACQUIRE_MODES = frozenset([
+_LS_ACQUIRE_MODES = compat.UniqueFrozenset([
_LS_ACQUIRE_EXACT,
_LS_ACQUIRE_ALL,
_LS_ACQUIRE_OPPORTUNISTIC,
]
# Lock levels which are modifiable
-LEVELS_MOD = frozenset([
+LEVELS_MOD = compat.UniqueFrozenset([
LEVEL_NODE_RES,
LEVEL_NODE,
LEVEL_NODEGROUP,
"""
_instance = None
- def __init__(self, nodes, nodegroups, instances, networks):
+ def __init__(self, node_uuids, nodegroups, instance_names, networks):
"""Constructs a new GanetiLockManager object.
There should be only a GanetiLockManager object at any time, so this
function raises an error if this is not the case.
- @param nodes: list of node names
+ @param node_uuids: list of node UUIDs
@param nodegroups: list of nodegroup uuids
- @param instances: list of instance names
+ @param instance_names: list of instance names
"""
assert self.__class__._instance is None, \
# locking order.
self.__keyring = {
LEVEL_CLUSTER: LockSet([BGL], "cluster", monitor=self._monitor),
- LEVEL_NODE: LockSet(nodes, "node", monitor=self._monitor),
- LEVEL_NODE_RES: LockSet(nodes, "node-res", monitor=self._monitor),
+ LEVEL_NODE: LockSet(node_uuids, "node", monitor=self._monitor),
+ LEVEL_NODE_RES: LockSet(node_uuids, "node-res", monitor=self._monitor),
LEVEL_NODEGROUP: LockSet(nodegroups, "nodegroup", monitor=self._monitor),
- LEVEL_INSTANCE: LockSet(instances, "instance", monitor=self._monitor),
+ LEVEL_INSTANCE: LockSet(instance_names, "instance",
+ monitor=self._monitor),
LEVEL_NETWORK: LockSet(networks, "network", monitor=self._monitor),
LEVEL_NODE_ALLOC: LockSet([NAL], "node-alloc", monitor=self._monitor),
}
"""
return level == LEVEL_CLUSTER and (names is None or BGL in names)
- def acquire(self, level, names, timeout=None, shared=0, priority=None):
+ def acquire(self, level, names, timeout=None, shared=0, priority=None,
+ opportunistic=False):
"""Acquire a set of resource locks, at the same level.
@type level: member of locking.LEVELS
@param timeout: Maximum time to acquire all locks
@type priority: integer
@param priority: Priority for acquiring lock
+ @type opportunistic: boolean
+ @param opportunistic: Acquire locks opportunistically; use the return value
+ to determine which locks were actually acquired
"""
assert level in LEVELS, "Invalid locking level %s" % level
# Acquire the locks in the set.
return self.__keyring[level].acquire(names, shared=shared, timeout=timeout,
- priority=priority)
+ priority=priority,
+ opportunistic=opportunistic)
def downgrade(self, level, names=None):
"""Downgrade a set of resource locks from exclusive to shared mode.