Revision 218f4c3d lib/config.py
b/lib/config.py | ||
---|---|---|
38 | 38 |
import random |
39 | 39 |
import logging |
40 | 40 |
import time |
41 |
import itertools |
|
41 | 42 |
|
42 | 43 |
from ganeti import errors |
43 | 44 |
from ganeti import locking |
... | ... | |
1517 | 1518 |
else: |
1518 | 1519 |
nodegroup_obj.members.remove(node.name) |
1519 | 1520 |
|
1521 |
@locking.ssynchronized(_config_lock) |
|
1522 |
def AssignGroupNodes(self, mods): |
|
1523 |
"""Changes the group of a number of nodes. |
|
1524 |
|
|
1525 |
@type mods: list of tuples; (node name, new group UUID) |
|
1526 |
@param modes: Node membership modifications |
|
1527 |
|
|
1528 |
""" |
|
1529 |
groups = self._config_data.nodegroups |
|
1530 |
nodes = self._config_data.nodes |
|
1531 |
|
|
1532 |
resmod = [] |
|
1533 |
|
|
1534 |
# Try to resolve names/UUIDs first |
|
1535 |
for (node_name, new_group_uuid) in mods: |
|
1536 |
try: |
|
1537 |
node = nodes[node_name] |
|
1538 |
except KeyError: |
|
1539 |
raise errors.ConfigurationError("Unable to find node '%s'" % node_name) |
|
1540 |
|
|
1541 |
if node.group == new_group_uuid: |
|
1542 |
# Node is being assigned to its current group |
|
1543 |
logging.debug("Node '%s' was assigned to its current group (%s)", |
|
1544 |
node_name, node.group) |
|
1545 |
continue |
|
1546 |
|
|
1547 |
# Try to find current group of node |
|
1548 |
try: |
|
1549 |
old_group = groups[node.group] |
|
1550 |
except KeyError: |
|
1551 |
raise errors.ConfigurationError("Unable to find old group '%s'" % |
|
1552 |
node.group) |
|
1553 |
|
|
1554 |
# Try to find new group for node |
|
1555 |
try: |
|
1556 |
new_group = groups[new_group_uuid] |
|
1557 |
except KeyError: |
|
1558 |
raise errors.ConfigurationError("Unable to find new group '%s'" % |
|
1559 |
new_group_uuid) |
|
1560 |
|
|
1561 |
assert node.name in old_group.members, \ |
|
1562 |
("Inconsistent configuration: node '%s' not listed in members for its" |
|
1563 |
" old group '%s'" % (node.name, old_group.uuid)) |
|
1564 |
assert node.name not in new_group.members, \ |
|
1565 |
("Inconsistent configuration: node '%s' already listed in members for" |
|
1566 |
" its new group '%s'" % (node.name, new_group.uuid)) |
|
1567 |
|
|
1568 |
resmod.append((node, old_group, new_group)) |
|
1569 |
|
|
1570 |
# Apply changes |
|
1571 |
for (node, old_group, new_group) in resmod: |
|
1572 |
assert node.uuid != new_group.uuid and old_group.uuid != new_group.uuid, \ |
|
1573 |
"Assigning to current group is not possible" |
|
1574 |
|
|
1575 |
node.group = new_group.uuid |
|
1576 |
|
|
1577 |
# Update members of involved groups |
|
1578 |
if node.name in old_group.members: |
|
1579 |
old_group.members.remove(node.name) |
|
1580 |
if node.name not in new_group.members: |
|
1581 |
new_group.members.append(node.name) |
|
1582 |
|
|
1583 |
# Update timestamps and serials (only once per node/group object) |
|
1584 |
now = time.time() |
|
1585 |
for obj in frozenset(itertools.chain(*resmod)): # pylint: disable-msg=W0142 |
|
1586 |
obj.serial_no += 1 |
|
1587 |
obj.mtime = now |
|
1588 |
|
|
1589 |
# Force ssconf update |
|
1590 |
self._config_data.cluster.serial_no += 1 |
|
1591 |
|
|
1592 |
self._WriteConfig() |
|
1593 |
|
|
1520 | 1594 |
def _BumpSerialNo(self): |
1521 | 1595 |
"""Bump up the serial number of the config. |
1522 | 1596 |
|
Also available in: Unified diff