Revision d4724b14 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
697 | 697 |
return cfg.GetNdParams(node)[constants.ND_OOB_PROGRAM] |
698 | 698 |
|
699 | 699 |
|
700 |
def _IsExclusiveStorageEnabledNode(cfg, node): |
|
701 |
"""Whether exclusive_storage is in effect for the given node. |
|
702 |
|
|
703 |
@type cfg: L{config.ConfigWriter} |
|
704 |
@param cfg: The cluster configuration |
|
705 |
@type node: L{objects.Node} |
|
706 |
@param node: The node |
|
707 |
@rtype: bool |
|
708 |
@return: The effective value of exclusive_storage |
|
709 |
|
|
710 |
""" |
|
711 |
return cfg.GetNdParams(node)[constants.ND_EXCLUSIVE_STORAGE] |
|
712 |
|
|
713 |
|
|
714 |
def _IsExclusiveStorageEnabledNodeName(cfg, nodename): |
|
715 |
"""Whether exclusive_storage is in effect for the given node. |
|
716 |
|
|
717 |
@type cfg: L{config.ConfigWriter} |
|
718 |
@param cfg: The cluster configuration |
|
719 |
@type nodename: string |
|
720 |
@param nodename: The node |
|
721 |
@rtype: bool |
|
722 |
@return: The effective value of exclusive_storage |
|
723 |
@raise errors.OpPrereqError: if no node exists with the given name |
|
724 |
|
|
725 |
""" |
|
726 |
ni = cfg.GetNodeInfo(nodename) |
|
727 |
if ni is None: |
|
728 |
raise errors.OpPrereqError("Invalid node name %s" % nodename, |
|
729 |
errors.ECODE_NOENT) |
|
730 |
return _IsExclusiveStorageEnabledNode(cfg, ni) |
|
731 |
|
|
732 |
|
|
700 | 733 |
def _CopyLockList(names): |
701 | 734 |
"""Makes a copy of a list of lock names. |
702 | 735 |
|
... | ... | |
8984 | 9017 |
|
8985 | 9018 |
""" |
8986 | 9019 |
(disk,) = _AnnotateDiskParams(instance, [device], lu.cfg) |
9020 |
excl_stor = _IsExclusiveStorageEnabledNodeName(lu.cfg, node) |
|
8987 | 9021 |
return _CreateBlockDevInner(lu, node, instance, disk, force_create, info, |
8988 |
force_open) |
|
9022 |
force_open, excl_stor)
|
|
8989 | 9023 |
|
8990 | 9024 |
|
8991 | 9025 |
def _CreateBlockDevInner(lu, node, instance, device, force_create, |
8992 |
info, force_open): |
|
9026 |
info, force_open, excl_stor):
|
|
8993 | 9027 |
"""Create a tree of block devices on a given node. |
8994 | 9028 |
|
8995 | 9029 |
If this device type has to be created on secondaries, create it and |
... | ... | |
9016 | 9050 |
L{backend.BlockdevCreate} function where it specifies |
9017 | 9051 |
whether we run on primary or not, and it affects both |
9018 | 9052 |
the child assembly and the device own Open() execution |
9053 |
@type excl_stor: boolean |
|
9054 |
@param excl_stor: Whether exclusive_storage is active for the node |
|
9019 | 9055 |
|
9020 | 9056 |
""" |
9021 | 9057 |
if device.CreateOnSecondary(): |
... | ... | |
9024 | 9060 |
if device.children: |
9025 | 9061 |
for child in device.children: |
9026 | 9062 |
_CreateBlockDevInner(lu, node, instance, child, force_create, |
9027 |
info, force_open) |
|
9063 |
info, force_open, excl_stor)
|
|
9028 | 9064 |
|
9029 | 9065 |
if not force_create: |
9030 | 9066 |
return |
9031 | 9067 |
|
9032 |
_CreateSingleBlockDev(lu, node, instance, device, info, force_open) |
|
9068 |
_CreateSingleBlockDev(lu, node, instance, device, info, force_open, |
|
9069 |
excl_stor) |
|
9033 | 9070 |
|
9034 | 9071 |
|
9035 |
def _CreateSingleBlockDev(lu, node, instance, device, info, force_open): |
|
9072 |
def _CreateSingleBlockDev(lu, node, instance, device, info, force_open, |
|
9073 |
excl_stor): |
|
9036 | 9074 |
"""Create a single block device on a given node. |
9037 | 9075 |
|
9038 | 9076 |
This will not recurse over children of the device, so they must be |
... | ... | |
9051 | 9089 |
L{backend.BlockdevCreate} function where it specifies |
9052 | 9090 |
whether we run on primary or not, and it affects both |
9053 | 9091 |
the child assembly and the device own Open() execution |
9092 |
@type excl_stor: boolean |
|
9093 |
@param excl_stor: Whether exclusive_storage is active for the node |
|
9054 | 9094 |
|
9055 | 9095 |
""" |
9056 | 9096 |
lu.cfg.SetDiskID(device, node) |
9057 | 9097 |
result = lu.rpc.call_blockdev_create(node, device, device.size, |
9058 | 9098 |
instance.name, force_open, info, |
9059 |
False)
|
|
9099 |
excl_stor)
|
|
9060 | 9100 |
result.Raise("Can't create block device %s on" |
9061 | 9101 |
" node %s for instance %s" % (device, node, instance.name)) |
9062 | 9102 |
if device.physical_id is None: |
... | ... | |
11597 | 11637 |
new_lvs = [lv_data, lv_meta] |
11598 | 11638 |
old_lvs = [child.Copy() for child in dev.children] |
11599 | 11639 |
iv_names[dev.iv_name] = (dev, old_lvs, new_lvs) |
11640 |
excl_stor = _IsExclusiveStorageEnabledNodeName(self.lu.cfg, node_name) |
|
11600 | 11641 |
|
11601 | 11642 |
# we pass force_create=True to force the LVM creation |
11602 | 11643 |
for new_lv in new_lvs: |
11603 | 11644 |
_CreateBlockDevInner(self.lu, node_name, self.instance, new_lv, True, |
11604 |
_GetInstanceInfoText(self.instance), False) |
|
11645 |
_GetInstanceInfoText(self.instance), False, |
|
11646 |
excl_stor) |
|
11605 | 11647 |
|
11606 | 11648 |
return iv_names |
11607 | 11649 |
|
... | ... | |
11810 | 11852 |
# Step: create new storage |
11811 | 11853 |
self.lu.LogStep(3, steps_total, "Allocate new storage") |
11812 | 11854 |
disks = _AnnotateDiskParams(self.instance, self.instance.disks, self.cfg) |
11855 |
excl_stor = _IsExclusiveStorageEnabledNodeName(self.lu.cfg, self.new_node) |
|
11813 | 11856 |
for idx, dev in enumerate(disks): |
11814 | 11857 |
self.lu.LogInfo("Adding new local storage on %s for disk/%d" % |
11815 | 11858 |
(self.new_node, idx)) |
11816 | 11859 |
# we pass force_create=True to force LVM creation |
11817 | 11860 |
for new_lv in dev.children: |
11818 | 11861 |
_CreateBlockDevInner(self.lu, self.new_node, self.instance, new_lv, |
11819 |
True, _GetInstanceInfoText(self.instance), False) |
|
11862 |
True, _GetInstanceInfoText(self.instance), False, |
|
11863 |
excl_stor) |
|
11820 | 11864 |
|
11821 | 11865 |
# Step 4: dbrd minors and drbd setups changes |
11822 | 11866 |
# after this, we must manually remove the drbd minors on both the |
... | ... | |
11860 | 11904 |
try: |
11861 | 11905 |
_CreateSingleBlockDev(self.lu, self.new_node, self.instance, |
11862 | 11906 |
anno_new_drbd, |
11863 |
_GetInstanceInfoText(self.instance), False) |
|
11907 |
_GetInstanceInfoText(self.instance), False, |
|
11908 |
excl_stor) |
|
11864 | 11909 |
except errors.GenericError: |
11865 | 11910 |
self.cfg.ReleaseDRBDMinors(self.instance.name) |
11866 | 11911 |
raise |
... | ... | |
13576 | 13621 |
self.diskparams) |
13577 | 13622 |
anno_disks = rpc.AnnotateDiskParams(constants.DT_DRBD8, new_disks, |
13578 | 13623 |
self.diskparams) |
13624 |
p_excl_stor = _IsExclusiveStorageEnabledNodeName(self.cfg, pnode) |
|
13625 |
s_excl_stor = _IsExclusiveStorageEnabledNodeName(self.cfg, snode) |
|
13579 | 13626 |
info = _GetInstanceInfoText(instance) |
13580 | 13627 |
feedback_fn("Creating additional volumes...") |
13581 | 13628 |
# first, create the missing data and meta devices |
13582 | 13629 |
for disk in anno_disks: |
13583 | 13630 |
# unfortunately this is... not too nice |
13584 | 13631 |
_CreateSingleBlockDev(self, pnode, instance, disk.children[1], |
13585 |
info, True) |
|
13632 |
info, True, p_excl_stor)
|
|
13586 | 13633 |
for child in disk.children: |
13587 |
_CreateSingleBlockDev(self, snode, instance, child, info, True) |
|
13634 |
_CreateSingleBlockDev(self, snode, instance, child, info, True, |
|
13635 |
s_excl_stor) |
|
13588 | 13636 |
# at this stage, all new LVs have been created, we can rename the |
13589 | 13637 |
# old ones |
13590 | 13638 |
feedback_fn("Renaming original volumes...") |
... | ... | |
13596 | 13644 |
feedback_fn("Initializing DRBD devices...") |
13597 | 13645 |
# all child devices are in place, we can now create the DRBD devices |
13598 | 13646 |
for disk in anno_disks: |
13599 |
for node in [pnode, snode]:
|
|
13647 |
for (node, excl_stor) in [(pnode, p_excl_stor), (snode, s_excl_stor)]:
|
|
13600 | 13648 |
f_create = node == pnode |
13601 |
_CreateSingleBlockDev(self, node, instance, disk, info, f_create) |
|
13649 |
_CreateSingleBlockDev(self, node, instance, disk, info, f_create, |
|
13650 |
excl_stor) |
|
13602 | 13651 |
|
13603 | 13652 |
# at this point, the instance has been modified |
13604 | 13653 |
instance.disk_template = constants.DT_DRBD8 |
Also available in: Unified diff