Revision 2bbf280e lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
59 | 59 |
from ganeti import ht |
60 | 60 |
from ganeti import rpc |
61 | 61 |
from ganeti import runtime |
62 |
from ganeti.masterd import iallocator |
|
62 | 63 |
|
63 | 64 |
import ganeti.masterd.instance # pylint: disable=W0611 |
64 | 65 |
|
... | ... | |
1618 | 1619 |
|
1619 | 1620 |
""" |
1620 | 1621 |
node = getattr(lu.op, node_slot, None) |
1621 |
iallocator = getattr(lu.op, iallocator_slot, None)
|
|
1622 |
ialloc = getattr(lu.op, iallocator_slot, None) |
|
1622 | 1623 |
|
1623 |
if node is not None and iallocator is not None:
|
|
1624 |
if node is not None and ialloc is not None: |
|
1624 | 1625 |
raise errors.OpPrereqError("Do not specify both, iallocator and node", |
1625 | 1626 |
errors.ECODE_INVAL) |
1626 |
elif node is None and iallocator is None:
|
|
1627 |
elif node is None and ialloc is None: |
|
1627 | 1628 |
default_iallocator = lu.cfg.GetDefaultIAllocator() |
1628 | 1629 |
if default_iallocator: |
1629 | 1630 |
setattr(lu.op, iallocator_slot, default_iallocator) |
... | ... | |
1635 | 1636 |
" iallocator", errors.ECODE_INVAL) |
1636 | 1637 |
|
1637 | 1638 |
|
1638 |
def _GetDefaultIAllocator(cfg, iallocator):
|
|
1639 |
def _GetDefaultIAllocator(cfg, ialloc): |
|
1639 | 1640 |
"""Decides on which iallocator to use. |
1640 | 1641 |
|
1641 | 1642 |
@type cfg: L{config.ConfigWriter} |
1642 | 1643 |
@param cfg: Cluster configuration object |
1643 |
@type iallocator: string or None
|
|
1644 |
@param iallocator: Iallocator specified in opcode
|
|
1644 |
@type ialloc: string or None |
|
1645 |
@param ialloc: Iallocator specified in opcode |
|
1645 | 1646 |
@rtype: string |
1646 | 1647 |
@return: Iallocator name |
1647 | 1648 |
|
1648 | 1649 |
""" |
1649 |
if not iallocator:
|
|
1650 |
if not ialloc: |
|
1650 | 1651 |
# Use default iallocator |
1651 |
iallocator = cfg.GetDefaultIAllocator()
|
|
1652 |
ialloc = cfg.GetDefaultIAllocator() |
|
1652 | 1653 |
|
1653 |
if not iallocator:
|
|
1654 |
if not ialloc: |
|
1654 | 1655 |
raise errors.OpPrereqError("No iallocator was specified, neither in the" |
1655 | 1656 |
" opcode nor as a cluster-wide default", |
1656 | 1657 |
errors.ECODE_INVAL) |
1657 | 1658 |
|
1658 |
return iallocator
|
|
1659 |
return ialloc |
|
1659 | 1660 |
|
1660 | 1661 |
|
1661 | 1662 |
class LUClusterPostInit(LogicalUnit): |
... | ... | |
7094 | 7095 |
# they should be already be marked as drained or offline, and hence |
7095 | 7096 |
# skipped by the allocator. If instance disks have been lost for other |
7096 | 7097 |
# reasons, then recreating the disks on the same nodes should be fine. |
7097 |
ial = IAllocator(self.cfg, self.rpc, |
|
7098 |
mode=constants.IALLOCATOR_MODE_ALLOC, |
|
7099 |
name=self.op.instance_name, |
|
7100 |
disk_template=self.instance.disk_template, |
|
7101 |
tags=list(self.instance.GetTags()), |
|
7102 |
os=self.instance.os, |
|
7103 |
nics=[{}], |
|
7104 |
vcpus=be_full[constants.BE_VCPUS], |
|
7105 |
memory=be_full[constants.BE_MAXMEM], |
|
7106 |
spindle_use=be_full[constants.BE_SPINDLE_USE], |
|
7107 |
disks=[{constants.IDISK_SIZE: d.size, |
|
7108 |
constants.IDISK_MODE: d.mode} |
|
7109 |
for d in self.instance.disks], |
|
7110 |
hypervisor=self.instance.hypervisor) |
|
7111 |
|
|
7112 |
assert ial.required_nodes == len(self.instance.all_nodes) |
|
7098 |
disk_template = self.instance.disk_template |
|
7099 |
spindle_use = be_full[constants.BE_SPINDLE_USE] |
|
7100 |
req = iallocator.IAReqInstanceAlloc(name=self.op.instance_name, |
|
7101 |
disk_template=disk_template, |
|
7102 |
tags=list(self.instance.GetTags()), |
|
7103 |
os=self.instance.os, |
|
7104 |
nics=[{}], |
|
7105 |
vcpus=be_full[constants.BE_VCPUS], |
|
7106 |
memory=be_full[constants.BE_MAXMEM], |
|
7107 |
spindle_use=spindle_use, |
|
7108 |
disks=[{constants.IDISK_SIZE: d.size, |
|
7109 |
constants.IDISK_MODE: d.mode} |
|
7110 |
for d in self.instance.disks], |
|
7111 |
hypervisor=self.instance.hypervisor) |
|
7112 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
7113 | 7113 |
|
7114 | 7114 |
ial.Run(self.op.iallocator) |
7115 | 7115 |
|
7116 |
assert ial.required_nodes == len(self.instance.all_nodes) |
|
7117 |
|
|
7116 | 7118 |
if not ial.success: |
7117 | 7119 |
raise errors.OpPrereqError("Can't compute nodes using iallocator '%s':" |
7118 | 7120 |
" %s" % (self.op.iallocator, ial.info), |
... | ... | |
8247 | 8249 |
|
8248 | 8250 |
""" |
8249 | 8251 |
# FIXME: add a self.ignore_ipolicy option |
8250 |
ial = IAllocator(self.cfg, self.rpc, |
|
8251 |
mode=constants.IALLOCATOR_MODE_RELOC, |
|
8252 |
name=self.instance_name, |
|
8253 |
relocate_from=[self.instance.primary_node], |
|
8254 |
) |
|
8252 |
req = iallocator.IAReqRelocate(name=self.instance_name, |
|
8253 |
relocate_from=[self.instance.primary_node]) |
|
8254 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
8255 | 8255 |
|
8256 | 8256 |
ial.Run(self.lu.op.iallocator) |
8257 | 8257 |
|
... | ... | |
9505 | 9505 |
|
9506 | 9506 |
""" |
9507 | 9507 |
nics = [n.ToDict() for n in self.nics] |
9508 |
ial = IAllocator(self.cfg, self.rpc,
|
|
9509 |
mode=constants.IALLOCATOR_MODE_ALLOC,
|
|
9510 |
name=self.op.instance_name,
|
|
9511 |
disk_template=self.op.disk_template, |
|
9512 |
tags=self.op.tags, |
|
9513 |
os=self.op.os_type, |
|
9514 |
vcpus=self.be_full[constants.BE_VCPUS], |
|
9515 |
memory=self.be_full[constants.BE_MAXMEM],
|
|
9516 |
spindle_use=self.be_full[constants.BE_SPINDLE_USE],
|
|
9517 |
disks=self.disks, |
|
9518 |
nics=nics, |
|
9519 |
hypervisor=self.op.hypervisor,
|
|
9520 |
)
|
|
9508 |
memory = self.be_full[constants.BE_MAXMEM]
|
|
9509 |
spindle_use = self.be_full[constants.BE_SPINDLE_USE]
|
|
9510 |
req = iallocator.IAReqInstanceAlloc(name=self.op.instance_name,
|
|
9511 |
disk_template=self.op.disk_template,
|
|
9512 |
tags=self.op.tags,
|
|
9513 |
os=self.op.os_type,
|
|
9514 |
vcpus=self.be_full[constants.BE_VCPUS],
|
|
9515 |
memory=memory,
|
|
9516 |
spindle_use=spindle_use,
|
|
9517 |
disks=self.disks,
|
|
9518 |
nics=nics,
|
|
9519 |
hypervisor=self.op.hypervisor)
|
|
9520 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req)
|
|
9521 | 9521 |
|
9522 | 9522 |
ial.Run(self.op.iallocator) |
9523 | 9523 |
|
... | ... | |
10605 | 10605 |
self.node_secondary_ip = None |
10606 | 10606 |
|
10607 | 10607 |
@staticmethod |
10608 |
def CheckArguments(mode, remote_node, iallocator):
|
|
10608 |
def CheckArguments(mode, remote_node, ialloc): |
|
10609 | 10609 |
"""Helper function for users of this class. |
10610 | 10610 |
|
10611 | 10611 |
""" |
10612 | 10612 |
# check for valid parameter combination |
10613 | 10613 |
if mode == constants.REPLACE_DISK_CHG: |
10614 |
if remote_node is None and iallocator is None:
|
|
10614 |
if remote_node is None and ialloc is None: |
|
10615 | 10615 |
raise errors.OpPrereqError("When changing the secondary either an" |
10616 | 10616 |
" iallocator script must be used or the" |
10617 | 10617 |
" new node given", errors.ECODE_INVAL) |
10618 | 10618 |
|
10619 |
if remote_node is not None and iallocator is not None:
|
|
10619 |
if remote_node is not None and ialloc is not None: |
|
10620 | 10620 |
raise errors.OpPrereqError("Give either the iallocator or the new" |
10621 | 10621 |
" secondary, not both", errors.ECODE_INVAL) |
10622 | 10622 |
|
10623 |
elif remote_node is not None or iallocator is not None:
|
|
10623 |
elif remote_node is not None or ialloc is not None: |
|
10624 | 10624 |
# Not replacing the secondary |
10625 | 10625 |
raise errors.OpPrereqError("The iallocator and new node options can" |
10626 | 10626 |
" only be used when changing the" |
... | ... | |
10631 | 10631 |
"""Compute a new secondary node using an IAllocator. |
10632 | 10632 |
|
10633 | 10633 |
""" |
10634 |
ial = IAllocator(lu.cfg, lu.rpc, |
|
10635 |
mode=constants.IALLOCATOR_MODE_RELOC, |
|
10636 |
name=instance_name, |
|
10637 |
relocate_from=list(relocate_from)) |
|
10634 |
req = iallocator.IAReqRelocate(name=instance_name, |
|
10635 |
relocate_from=list(relocate_from)) |
|
10636 |
ial = iallocator.IAllocator(lu.cfg, lu.rpc, req) |
|
10638 | 10637 |
|
10639 | 10638 |
ial.Run(iallocator_name) |
10640 | 10639 |
|
... | ... | |
11582 | 11581 |
|
11583 | 11582 |
elif self.op.iallocator is not None: |
11584 | 11583 |
# TODO: Implement relocation to other group |
11585 |
ial = IAllocator(self.cfg, self.rpc, constants.IALLOCATOR_MODE_NODE_EVAC, |
|
11586 |
evac_mode=self._MODE2IALLOCATOR[self.op.mode], |
|
11587 |
instances=list(self.instance_names)) |
|
11584 |
evac_mode = self._MODE2IALLOCATOR[self.op.mode] |
|
11585 |
req = iallocator.IAReqNodeEvac(evac_mode=evac_mode, |
|
11586 |
instances=list(self.instance_names)) |
|
11587 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
11588 | 11588 |
|
11589 | 11589 |
ial.Run(self.op.iallocator) |
11590 | 11590 |
|
... | ... | |
13181 | 13181 |
|
13182 | 13182 |
assert instances == [self.op.instance_name], "Instance not locked" |
13183 | 13183 |
|
13184 |
ial = IAllocator(self.cfg, self.rpc, constants.IALLOCATOR_MODE_CHG_GROUP, |
|
13185 |
instances=instances, target_groups=list(self.target_uuids)) |
|
13184 |
req = iallocator.IAReqGroupChange(instances=instances, |
|
13185 |
target_groups=list(self.target_uuids)) |
|
13186 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
13186 | 13187 |
|
13187 | 13188 |
ial.Run(self.op.iallocator) |
13188 | 13189 |
|
... | ... | |
14436 | 14437 |
|
14437 | 14438 |
assert self.group_uuid not in self.target_uuids |
14438 | 14439 |
|
14439 |
ial = IAllocator(self.cfg, self.rpc, constants.IALLOCATOR_MODE_CHG_GROUP, |
|
14440 |
instances=instances, target_groups=self.target_uuids) |
|
14440 |
req = iallocator.IAReqGroupChange(instances=instances, |
|
14441 |
target_groups=self.target_uuids) |
|
14442 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
14441 | 14443 |
|
14442 | 14444 |
ial.Run(self.op.iallocator) |
14443 | 14445 |
|
... | ... | |
14875 | 14877 |
|
14876 | 14878 |
""" |
14877 | 14879 |
if self.op.mode == constants.IALLOCATOR_MODE_ALLOC: |
14878 |
ial = IAllocator(self.cfg, self.rpc, |
|
14879 |
mode=self.op.mode, |
|
14880 |
name=self.op.name, |
|
14881 |
memory=self.op.memory, |
|
14882 |
disks=self.op.disks, |
|
14883 |
disk_template=self.op.disk_template, |
|
14884 |
os=self.op.os, |
|
14885 |
tags=self.op.tags, |
|
14886 |
nics=self.op.nics, |
|
14887 |
vcpus=self.op.vcpus, |
|
14888 |
hypervisor=self.op.hypervisor, |
|
14889 |
spindle_use=self.op.spindle_use, |
|
14890 |
) |
|
14880 |
req = iallocator.IAReqInstanceAlloc(name=self.op.name, |
|
14881 |
memory=self.op.memory, |
|
14882 |
disks=self.op.disks, |
|
14883 |
disk_template=self.op.disk_template, |
|
14884 |
os=self.op.os, |
|
14885 |
tags=self.op.tags, |
|
14886 |
nics=self.op.nics, |
|
14887 |
vcpus=self.op.vcpus, |
|
14888 |
spindle_use=self.op.spindle_use, |
|
14889 |
hypervisor=self.op.hypervisor) |
|
14891 | 14890 |
elif self.op.mode == constants.IALLOCATOR_MODE_RELOC: |
14892 |
ial = IAllocator(self.cfg, self.rpc, |
|
14893 |
mode=self.op.mode, |
|
14894 |
name=self.op.name, |
|
14895 |
relocate_from=list(self.relocate_from), |
|
14896 |
) |
|
14891 |
req = iallocator.IAReqRelocate(name=self.op.name, |
|
14892 |
relocate_from=list(self.relocate_from)) |
|
14897 | 14893 |
elif self.op.mode == constants.IALLOCATOR_MODE_CHG_GROUP: |
14898 |
ial = IAllocator(self.cfg, self.rpc, |
|
14899 |
mode=self.op.mode, |
|
14900 |
instances=self.op.instances, |
|
14901 |
target_groups=self.op.target_groups) |
|
14894 |
req = iallocator.IAReqGroupChange(instances=self.op.instances, |
|
14895 |
target_groups=self.op.target_groups) |
|
14902 | 14896 |
elif self.op.mode == constants.IALLOCATOR_MODE_NODE_EVAC: |
14903 |
ial = IAllocator(self.cfg, self.rpc, |
|
14904 |
mode=self.op.mode, |
|
14905 |
instances=self.op.instances, |
|
14906 |
evac_mode=self.op.evac_mode) |
|
14897 |
req = iallocator.IAReqNodeEvac(instances=self.op.instances, |
|
14898 |
evac_mode=self.op.evac_mode) |
|
14907 | 14899 |
else: |
14908 | 14900 |
raise errors.ProgrammerError("Uncatched mode %s in" |
14909 | 14901 |
" LUTestAllocator.Exec", self.op.mode) |
14910 | 14902 |
|
14903 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
|
14911 | 14904 |
if self.op.direction == constants.IALLOCATOR_DIR_IN: |
14912 | 14905 |
result = ial.in_text |
14913 | 14906 |
else: |
Also available in: Unified diff