Revision 621b7678 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
4932 | 4932 |
return "originstname+%s" % instance.name |
4933 | 4933 |
|
4934 | 4934 |
|
4935 |
def _CreateDisks(lu, instance, to_skip=None): |
|
4935 |
def _CreateDisks(lu, instance, to_skip=None, target_node=None):
|
|
4936 | 4936 |
"""Create all disks for an instance. |
4937 | 4937 |
|
4938 | 4938 |
This abstracts away some work from AddInstance. |
... | ... | |
4943 | 4943 |
@param instance: the instance whose disks we should create |
4944 | 4944 |
@type to_skip: list |
4945 | 4945 |
@param to_skip: list of indices to skip |
4946 |
@type target_node: string |
|
4947 |
@param target_node: if passed, overrides the target node for creation |
|
4946 | 4948 |
@rtype: boolean |
4947 | 4949 |
@return: the success of the creation |
4948 | 4950 |
|
4949 | 4951 |
""" |
4950 | 4952 |
info = _GetInstanceInfoText(instance) |
4951 |
pnode = instance.primary_node |
|
4953 |
if target_node is None: |
|
4954 |
pnode = instance.primary_node |
|
4955 |
all_nodes = instance.all_nodes |
|
4956 |
else: |
|
4957 |
pnode = target_node |
|
4958 |
all_nodes = [pnode] |
|
4952 | 4959 |
|
4953 | 4960 |
if instance.disk_template == constants.DT_FILE: |
4954 | 4961 |
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
... | ... | |
4965 | 4972 |
logging.info("Creating volume %s for instance %s", |
4966 | 4973 |
device.iv_name, instance.name) |
4967 | 4974 |
#HARDCODE |
4968 |
for node in instance.all_nodes:
|
|
4975 |
for node in all_nodes: |
|
4969 | 4976 |
f_create = node == pnode |
4970 | 4977 |
_CreateBlockDev(lu, node, instance, device, f_create, info, f_create) |
4971 | 4978 |
|
4972 | 4979 |
|
4973 |
def _RemoveDisks(lu, instance): |
|
4980 |
def _RemoveDisks(lu, instance, target_node=None):
|
|
4974 | 4981 |
"""Remove all disks for an instance. |
4975 | 4982 |
|
4976 | 4983 |
This abstracts away some work from `AddInstance()` and |
... | ... | |
4982 | 4989 |
@param lu: the logical unit on whose behalf we execute |
4983 | 4990 |
@type instance: L{objects.Instance} |
4984 | 4991 |
@param instance: the instance whose disks we should remove |
4992 |
@type target_node: string |
|
4993 |
@param target_node: used to override the node on which to remove the disks |
|
4985 | 4994 |
@rtype: boolean |
4986 | 4995 |
@return: the success of the removal |
4987 | 4996 |
|
... | ... | |
4990 | 4999 |
|
4991 | 5000 |
all_result = True |
4992 | 5001 |
for device in instance.disks: |
4993 |
for node, disk in device.ComputeNodeTree(instance.primary_node): |
|
5002 |
if target_node: |
|
5003 |
edata = [(target_node, device)] |
|
5004 |
else: |
|
5005 |
edata = device.ComputeNodeTree(instance.primary_node) |
|
5006 |
for node, disk in edata: |
|
4994 | 5007 |
lu.cfg.SetDiskID(disk, node) |
4995 | 5008 |
msg = lu.rpc.call_blockdev_remove(node, disk).fail_msg |
4996 | 5009 |
if msg: |
... | ... | |
5000 | 5013 |
|
5001 | 5014 |
if instance.disk_template == constants.DT_FILE: |
5002 | 5015 |
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
5003 |
result = lu.rpc.call_file_storage_dir_remove(instance.primary_node, |
|
5004 |
file_storage_dir) |
|
5005 |
msg = result.fail_msg |
|
5006 |
if msg: |
|
5016 |
if target_node is node: |
|
5017 |
tgt = instance.primary_node |
|
5018 |
else: |
|
5019 |
tgt = instance.target_node |
|
5020 |
result = lu.rpc.call_file_storage_dir_remove(tgt, file_storage_dir) |
|
5021 |
if result.fail_msg: |
|
5007 | 5022 |
lu.LogWarning("Could not remove directory '%s' on node %s: %s", |
5008 |
file_storage_dir, instance.primary_node, msg) |
|
5023 |
file_storage_dir, instance.primary_node, result.fail_msg)
|
|
5009 | 5024 |
all_result = False |
5010 | 5025 |
|
5011 | 5026 |
return all_result |
Also available in: Unified diff