Revision 87e25be1 lib/cmdlib/instance_utils.py
b/lib/cmdlib/instance_utils.py | ||
---|---|---|
448 | 448 |
|
449 | 449 |
""" |
450 | 450 |
return "originstname+%s" % instance.name |
451 |
|
|
452 |
|
|
453 |
def _CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name): |
|
454 |
"""Checks if a node has enough free memory. |
|
455 |
|
|
456 |
This function checks if a given node has the needed amount of free |
|
457 |
memory. In case the node has less memory or we cannot get the |
|
458 |
information from the node, this function raises an OpPrereqError |
|
459 |
exception. |
|
460 |
|
|
461 |
@type lu: C{LogicalUnit} |
|
462 |
@param lu: a logical unit from which we get configuration data |
|
463 |
@type node: C{str} |
|
464 |
@param node: the node to check |
|
465 |
@type reason: C{str} |
|
466 |
@param reason: string to use in the error message |
|
467 |
@type requested: C{int} |
|
468 |
@param requested: the amount of memory in MiB to check for |
|
469 |
@type hypervisor_name: C{str} |
|
470 |
@param hypervisor_name: the hypervisor to ask for memory stats |
|
471 |
@rtype: integer |
|
472 |
@return: node current free memory |
|
473 |
@raise errors.OpPrereqError: if the node doesn't have enough memory, or |
|
474 |
we cannot check the node |
|
475 |
|
|
476 |
""" |
|
477 |
nodeinfo = lu.rpc.call_node_info([node], None, [hypervisor_name], False) |
|
478 |
nodeinfo[node].Raise("Can't get data from node %s" % node, |
|
479 |
prereq=True, ecode=errors.ECODE_ENVIRON) |
|
480 |
(_, _, (hv_info, )) = nodeinfo[node].payload |
|
481 |
|
|
482 |
free_mem = hv_info.get("memory_free", None) |
|
483 |
if not isinstance(free_mem, int): |
|
484 |
raise errors.OpPrereqError("Can't compute free memory on node %s, result" |
|
485 |
" was '%s'" % (node, free_mem), |
|
486 |
errors.ECODE_ENVIRON) |
|
487 |
if requested > free_mem: |
|
488 |
raise errors.OpPrereqError("Not enough memory on node %s for %s:" |
|
489 |
" needed %s MiB, available %s MiB" % |
|
490 |
(node, reason, requested, free_mem), |
|
491 |
errors.ECODE_NORES) |
|
492 |
return free_mem |
|
493 |
|
|
494 |
|
|
495 |
def _CheckInstanceBridgesExist(lu, instance, node=None): |
|
496 |
"""Check that the brigdes needed by an instance exist. |
|
497 |
|
|
498 |
""" |
|
499 |
if node is None: |
|
500 |
node = instance.primary_node |
|
501 |
_CheckNicsBridgesExist(lu, instance.nics, node) |
|
502 |
|
|
503 |
|
|
504 |
def _CheckNicsBridgesExist(lu, target_nics, target_node): |
|
505 |
"""Check that the brigdes needed by a list of nics exist. |
|
506 |
|
|
507 |
""" |
|
508 |
cluster = lu.cfg.GetClusterInfo() |
|
509 |
paramslist = [cluster.SimpleFillNIC(nic.nicparams) for nic in target_nics] |
|
510 |
brlist = [params[constants.NIC_LINK] for params in paramslist |
|
511 |
if params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED] |
|
512 |
if brlist: |
|
513 |
result = lu.rpc.call_bridges_exist(target_node, brlist) |
|
514 |
result.Raise("Error checking bridges on destination node '%s'" % |
|
515 |
target_node, prereq=True, ecode=errors.ECODE_ENVIRON) |
Also available in: Unified diff