示例#1
0
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster and is not running.

    """
        instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert instance is not None, \
          "Cannot retrieve locked instance %s" % self.op.instance_name
        CheckNodeOnline(self, instance.primary_node, "Instance primary node"
                        " offline, cannot reinstall")

        if not instance.disks:
            raise errors.OpPrereqError(
                "Instance '%s' has no disks" % self.op.instance_name,
                errors.ECODE_INVAL)
        CheckInstanceState(self,
                           instance,
                           INSTANCE_DOWN,
                           msg="cannot reinstall")

        # Handle OS parameters
        self._MergeValidateOsParams(instance)

        self.instance = instance
示例#2
0
文件: instance.py 项目: dimara/ganeti
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster and is not running.

    """
        (self.op.instance_uuid, self.op.instance_name) = \
          ExpandInstanceUuidAndName(self.cfg, self.op.instance_uuid,
                                    self.op.instance_name)
        instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert instance is not None

        # It should actually not happen that an instance is running with a disabled
        # disk template, but in case it does, the renaming of file-based instances
        # will fail horribly. Thus, we test it before.
        for disk in self.cfg.GetInstanceDisks(instance.uuid):
            if (disk.dev_type in constants.DTS_FILEBASED
                    and self.op.new_name != instance.name):
                # TODO: when disks are separate objects, this should check for disk
                # types, not disk templates.
                CheckDiskTemplateEnabled(self.cfg.GetClusterInfo(),
                                         disk.dev_type)

        CheckNodeOnline(self, instance.primary_node)
        CheckInstanceState(self,
                           instance,
                           INSTANCE_NOT_RUNNING,
                           msg="cannot rename")
        self.instance = instance

        self._PerformChecksAndResolveNewName()

        if self.op.new_name != instance.name:
            CheckInstanceExistence(self, self.op.new_name)
示例#3
0
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster.

    """
        self.instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert self.instance is not None, \
          "Cannot retrieve locked instance %s" % self.op.instance_name
        CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
        CheckNodeOnline(self, self.instance.primary_node)

        # check bridges existence
        CheckInstanceBridgesExist(self, self.instance)
示例#4
0
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster.

    """
        self.instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert self.instance is not None, \
          "Cannot retrieve locked instance %s" % self.op.instance_name

        if not self.op.force:
            CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
        else:
            self.LogWarning("Ignoring offline instance check")

        self.primary_offline = \
          self.cfg.GetNodeInfo(self.instance.primary_node).offline

        if self.primary_offline and self.op.ignore_offline_nodes:
            self.LogWarning("Ignoring offline primary node")
        else:
            CheckNodeOnline(self, self.instance.primary_node)
示例#5
0
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster.

    """
        self.instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert self.instance is not None, \
          "Cannot retrieve locked instance %s" % self.op.instance_name

        if self.op.force:
            self.LogWarning("Ignoring offline instance check")
        else:
            CheckInstanceState(self, self.instance, INSTANCE_ONLINE)

        self.primary_offline = \
          self.cfg.GetNodeInfo(self.instance.primary_node).offline

        if self.primary_offline and self.op.ignore_offline_nodes:
            self.LogWarning("Ignoring offline primary node")
        else:
            CheckNodeOnline(self, self.instance.primary_node)

        if self.op.admin_state_source == constants.USER_SOURCE:
            cluster = self.cfg.GetClusterInfo()

            result = self.rpc.call_instance_info(
                self.instance.primary_node, self.instance.name,
                self.instance.hypervisor,
                cluster.hvparams[self.instance.hypervisor])
            result.Raise("Error checking instance '%s'" % self.instance.name,
                         prereq=True)

            if not _IsInstanceUserDown(cluster, self.instance, result.payload):
                raise errors.OpPrereqError(
                    "Instance '%s' was not shutdown by the user" %
                    self.instance.name)
示例#6
0
    def CheckPrereq(self):
        """Check prerequisites.

    This checks that the instance is in the cluster.

    """
        self.instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
        assert self.instance is not None, \
          "Cannot retrieve locked instance %s" % self.op.instance_name

        cluster = self.cfg.GetClusterInfo()
        # extra hvparams
        if self.op.hvparams:
            # check hypervisor parameter syntax (locally)
            utils.ForceDictType(self.op.hvparams,
                                constants.HVS_PARAMETER_TYPES)
            filled_hvp = cluster.FillHV(self.instance)
            filled_hvp.update(self.op.hvparams)
            hv_type = hypervisor.GetHypervisorClass(self.instance.hypervisor)
            hv_type.CheckParameterSyntax(filled_hvp)
            CheckHVParams(self, self.cfg.GetInstanceNodes(self.instance.uuid),
                          self.instance.hypervisor, filled_hvp)

        CheckInstanceState(self, self.instance, INSTANCE_ONLINE)

        self.primary_offline = \
          self.cfg.GetNodeInfo(self.instance.primary_node).offline

        if self.primary_offline and self.op.ignore_offline_nodes:
            self.LogWarning("Ignoring offline primary node")

            if self.op.hvparams or self.op.beparams:
                self.LogWarning("Overridden parameters are ignored")
        else:
            CheckNodeOnline(self, self.instance.primary_node)

            bep = self.cfg.GetClusterInfo().FillBE(self.instance)
            bep.update(self.op.beparams)

            # check bridges existence
            CheckInstanceBridgesExist(self, self.instance)

            remote_info = self.rpc.call_instance_info(
                self.instance.primary_node, self.instance.name,
                self.instance.hypervisor,
                cluster.hvparams[self.instance.hypervisor])
            remote_info.Raise("Error checking node %s" %
                              self.cfg.GetNodeName(self.instance.primary_node),
                              prereq=True,
                              ecode=errors.ECODE_ENVIRON)

            self.requires_cleanup = False

            if remote_info.payload:
                if _IsInstanceUserDown(self.cfg.GetClusterInfo(),
                                       self.instance, remote_info.payload):
                    self.requires_cleanup = True
            else:  # not running already
                CheckNodeFreeMemory(
                    self, self.instance.primary_node,
                    "starting instance %s" % self.instance.name,
                    bep[constants.BE_MINMEM], self.instance.hypervisor,
                    self.cfg.GetClusterInfo().hvparams[
                        self.instance.hypervisor])