Revision 4fe5cf90 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
10533 | 10533 |
self.remove_locks[locking.LEVEL_NODEGROUP] = self.group_uuid |
10534 | 10534 |
|
10535 | 10535 |
|
10536 |
class LURenameGroup(LogicalUnit): |
|
10537 |
HPATH = "group-rename" |
|
10538 |
HTYPE = constants.HTYPE_GROUP |
|
10539 |
|
|
10540 |
_OP_PARAMS = [ |
|
10541 |
("old_name", ht.NoDefault, ht.TNonEmptyString), |
|
10542 |
("new_name", ht.NoDefault, ht.TNonEmptyString), |
|
10543 |
] |
|
10544 |
|
|
10545 |
REQ_BGL = False |
|
10546 |
|
|
10547 |
def ExpandNames(self): |
|
10548 |
# This raises errors.OpPrereqError on its own: |
|
10549 |
self.group_uuid = self.cfg.LookupNodeGroup(self.op.old_name) |
|
10550 |
|
|
10551 |
self.needed_locks = { |
|
10552 |
locking.LEVEL_NODEGROUP: [self.group_uuid], |
|
10553 |
} |
|
10554 |
|
|
10555 |
def CheckPrereq(self): |
|
10556 |
"""Check prerequisites. |
|
10557 |
|
|
10558 |
This checks that the given old_name exists as a node group, and that |
|
10559 |
new_name doesn't. |
|
10560 |
|
|
10561 |
""" |
|
10562 |
try: |
|
10563 |
new_name_uuid = self.cfg.LookupNodeGroup(self.op.new_name) |
|
10564 |
except errors.OpPrereqError: |
|
10565 |
pass |
|
10566 |
else: |
|
10567 |
raise errors.OpPrereqError("Desired new name '%s' clashes with existing" |
|
10568 |
" node group (UUID: %s)" % |
|
10569 |
(self.op.new_name, new_name_uuid), |
|
10570 |
errors.ECODE_EXISTS) |
|
10571 |
|
|
10572 |
def BuildHooksEnv(self): |
|
10573 |
"""Build hooks env. |
|
10574 |
|
|
10575 |
""" |
|
10576 |
env = { |
|
10577 |
"OLD_NAME": self.op.old_name, |
|
10578 |
"NEW_NAME": self.op.new_name, |
|
10579 |
} |
|
10580 |
|
|
10581 |
mn = self.cfg.GetMasterNode() |
|
10582 |
all_nodes = self.cfg.GetAllNodesInfo() |
|
10583 |
run_nodes = [mn] |
|
10584 |
all_nodes.pop(mn, None) |
|
10585 |
|
|
10586 |
for node in all_nodes.values(): |
|
10587 |
if node.group == self.group_uuid: |
|
10588 |
run_nodes.append(node.name) |
|
10589 |
|
|
10590 |
return env, run_nodes, run_nodes |
|
10591 |
|
|
10592 |
def Exec(self, feedback_fn): |
|
10593 |
"""Rename the node group. |
|
10594 |
|
|
10595 |
""" |
|
10596 |
group = self.cfg.GetNodeGroup(self.group_uuid) |
|
10597 |
|
|
10598 |
if group is None: |
|
10599 |
raise errors.OpExecError("Could not retrieve group '%s' (UUID: %s)" % |
|
10600 |
(self.op.old_name, self.group_uuid)) |
|
10601 |
|
|
10602 |
group.name = self.op.new_name |
|
10603 |
self.cfg.Update(group, feedback_fn) |
|
10604 |
|
|
10605 |
return self.op.new_name |
|
10606 |
|
|
10607 |
|
|
10536 | 10608 |
class TagsLU(NoHooksLU): # pylint: disable-msg=W0223 |
10537 | 10609 |
"""Generic tags LU. |
10538 | 10610 |
|
Also available in: Unified diff