Example #1
0
    def Exec(self, feedback_fn):
        """Run the allocator test.

    """
        if self.op.mode == constants.IALLOCATOR_MODE_ALLOC:
            req = iallocator.IAReqInstanceAlloc(
                name=self.op.name,
                memory=self.op.memory,
                disks=self.op.disks,
                disk_template=self.op.disk_template,
                group_name=self.op.group_name,
                os=self.op.os,
                tags=self.op.tags,
                nics=self.op.nics,
                vcpus=self.op.vcpus,
                spindle_use=self.op.spindle_use,
                hypervisor=self.op.hypervisor,
                node_whitelist=None)
        elif self.op.mode == constants.IALLOCATOR_MODE_RELOC:
            req = iallocator.IAReqRelocate(inst_uuid=self.inst_uuid,
                                           relocate_from_node_uuids=list(
                                               self.relocate_from_node_uuids))
        elif self.op.mode == constants.IALLOCATOR_MODE_CHG_GROUP:
            req = iallocator.IAReqGroupChange(
                instances=self.op.instances,
                target_groups=self.op.target_groups)
        elif self.op.mode == constants.IALLOCATOR_MODE_NODE_EVAC:
            req = iallocator.IAReqNodeEvac(instances=self.op.instances,
                                           evac_mode=self.op.evac_mode,
                                           ignore_soft_errors=False)
        elif self.op.mode == constants.IALLOCATOR_MODE_MULTI_ALLOC:
            disk_template = self.op.disk_template
            insts = [
                iallocator.IAReqInstanceAlloc(
                    name="%s%s" % (self.op.name, idx),
                    memory=self.op.memory,
                    disks=self.op.disks,
                    disk_template=disk_template,
                    group_name=self.op.group_name,
                    os=self.op.os,
                    tags=self.op.tags,
                    nics=self.op.nics,
                    vcpus=self.op.vcpus,
                    spindle_use=self.op.spindle_use,
                    hypervisor=self.op.hypervisor,
                    node_whitelist=None) for idx in range(self.op.count)
            ]
            req = iallocator.IAReqMultiInstanceAlloc(instances=insts)
        else:
            raise errors.ProgrammerError(
                "Uncatched mode %s in"
                " LUTestAllocator.Exec", self.op.mode)

        ial = iallocator.IAllocator(self.cfg, self.rpc, req)
        if self.op.direction == constants.IALLOCATOR_DIR_IN:
            result = ial.in_text
        else:
            ial.Run(self.op.iallocator, validate=False)
            result = ial.out_text
        return result
Example #2
0
    def _RunAllocator(self):
        """Run the allocator based on input opcode.

    """
        # FIXME: add a self.ignore_ipolicy option
        req = iallocator.IAReqRelocate(
            inst_uuid=self.instance_uuid,
            relocate_from_node_uuids=[self.instance.primary_node])
        ial = iallocator.IAllocator(self.cfg, self.rpc, req)

        ial.Run(self.lu.op.iallocator)

        if not ial.success:
            raise errors.OpPrereqError(
                "Can't compute nodes using"
                " iallocator '%s': %s" % (self.lu.op.iallocator, ial.info),
                errors.ECODE_NORES)
        self.target_node_uuid = self.cfg.GetNodeInfoByName(ial.result[0]).uuid
        self.lu.LogInfo("Selected nodes for instance %s via iallocator %s: %s",
                        self.instance_name, self.lu.op.iallocator,
                        utils.CommaJoin(ial.result))