Beispiel #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
Beispiel #2
0
    def Exec(self, feedback_fn):
        instances = list(self.owned_locks(locking.LEVEL_INSTANCE))

        assert instances == [self.op.instance_name], "Instance not locked"

        req = iallocator.IAReqGroupChange(instances=instances,
                                          target_groups=list(
                                              self.target_uuids))
        ial = iallocator.IAllocator(self.cfg, self.rpc, req)

        ial.Run(self.op.iallocator)

        if not ial.success:
            raise errors.OpPrereqError(
                "Can't compute solution for changing group of"
                " instance '%s' using iallocator '%s': %s" %
                (self.op.instance_name, self.op.iallocator, ial.info),
                errors.ECODE_NORES)

        jobs = LoadNodeEvacResult(self, ial.result, self.op.early_release,
                                  False)

        self.LogInfo(
            "Iallocator returned %s job(s) for changing group of"
            " instance '%s'", len(jobs), self.op.instance_name)

        return ResultWithJobs(jobs)
Beispiel #3
0
    def Exec(self, feedback_fn):
        inst_names = list(self.owned_locks(locking.LEVEL_INSTANCE))

        assert self.group_uuid not in self.target_uuids

        req = iallocator.IAReqGroupChange(instances=inst_names,
                                          target_groups=self.target_uuids)
        ial = iallocator.IAllocator(self.cfg, self.rpc, req)

        ial.Run(self.op.iallocator)

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

        jobs = LoadNodeEvacResult(self, ial.result, self.op.early_release,
                                  False)

        self.LogInfo(
            "Iallocator returned %s job(s) for evacuating node group %s",
            len(jobs), self.op.group_name)

        if self.op.force_failover:
            self.LogInfo("Will insist on failovers")
            jobs = [[self._MigrateToFailover(op) for op in job]
                    for job in jobs]

        if self.op.sequential:
            self.LogInfo("Jobs will be submitted to run sequentially")
            for job in jobs[1:]:
                for op in job:
                    op.depends = [(-1, ["error", "success"])]

        return ResultWithJobs(jobs)