Пример #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
Пример #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)
Пример #3
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: [],
                })
Пример #4
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))
Пример #5
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)