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 CheckPrereq(self):
        """Check prerequisite.

    """
        if self.op.iallocator:
            cluster = self.cfg.GetClusterInfo()
            default_vg = self.cfg.GetVGName()
            ec_id = self.proc.GetECId()

            if self.op.opportunistic_locking:
                # Only consider nodes for which a lock is held
                node_whitelist = self.cfg.GetNodeNames(
                    set(self.owned_locks(locking.LEVEL_NODE))
                    & set(self.owned_locks(locking.LEVEL_NODE_RES)))
            else:
                node_whitelist = None

            insts = [
                CreateInstanceAllocRequest(
                    op, ComputeDisks(op.disks, op.disk_template, default_vg),
                    ComputeNics(op, cluster, None, self.cfg, ec_id),
                    ComputeFullBeParams(op, cluster), node_whitelist)
                for op in self.op.instances
            ]

            req = iallocator.IAReqMultiInstanceAlloc(instances=insts)
            ial = iallocator.IAllocator(self.cfg, self.rpc, req)

            ial.Run(self.op.iallocator)

            if not ial.success:
                raise errors.OpPrereqError(
                    "Can't compute nodes using"
                    " iallocator '%s': %s" % (self.op.iallocator, ial.info),
                    errors.ECODE_NORES)

            self.ia_result = ial.result

        if self.op.dry_run:
            self.dry_run_result = objects.FillDict(
                self._ConstructPartialResult(), {
                    constants.JOB_IDS_KEY: [],
                })