return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name)
-class InstReason(object):
- """Class representing the reason for a change of state of a VM.
-
- It is used to allow an easy serialization of the reason, so that it can be
- written on a file.
-
- """
- def __init__(self, source, text):
- """Initialize the class with all the required values.
-
- @type text: string
- @param text: The textual description of the reason for changing state
- @type source: string
- @param source: The source of the state change (RAPI, CLI, ...)
-
- """
- self.source = source
- self.text = text
-
- def GetJson(self):
- """Get the JSON representation of the InstReason.
-
- @rtype: string
- @return : The JSON representation of the object
-
- """
- return serializer.DumpJson(dict(source=self.source, text=self.text))
-
- def Store(self, instance_name):
- """Serialize on a file the reason for the last state change of an instance.
-
- The exact location of the file depends on the name of the instance and on
- the configuration of the Ganeti cluster defined at deploy time.
-
- @type instance_name: string
- @param instance_name: The name of the instance
- @rtype: None
-
- """
- filename = GetInstReasonFilename(instance_name)
- utils.WriteFile(filename, data=self.GetJson())
-
-
def _Fail(msg, *args, **kwargs):
"""Log an error and the raise an RPCFail exception.
_RemoveBlockDevLinks(iname, instance.disks)
-def InstanceReboot(instance, reboot_type, shutdown_timeout, reason):
+def InstanceReboot(instance, reboot_type, shutdown_timeout):
"""Reboot an instance.
@type instance: L{objects.Instance}
if reboot_type == constants.INSTANCE_REBOOT_SOFT:
try:
hyper.RebootInstance(instance)
- reason.Store(instance.name)
except errors.HypervisorError, err:
_Fail("Failed to soft reboot instance %s: %s", instance.name, err)
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
InstanceShutdown(instance, shutdown_timeout)
result = StartInstance(instance, False)
- reason.Store(instance.name)
return result
except errors.HypervisorError, err:
_Fail("Failed to hard reboot instance %s: %s", instance.name, err)
" only (determined by the exit code)"))
REASON_OPT = cli_option("--reason", default=None,
- help="The reason for executing a VM-state-changing"
- " operation")
+ help="The reason for executing the command")
def _PriorityOptionCb(option, _, value, parser):
return opcodes.OpInstanceReboot(instance_name=name,
reboot_type=opts.reboot_type,
ignore_secondaries=opts.ignore_secondaries,
- shutdown_timeout=opts.shutdown_timeout,
- reason=(constants.INSTANCE_REASON_SOURCE_CLI,
- opts.reason))
+ shutdown_timeout=opts.shutdown_timeout)
def _ShutdownInstance(name, opts):
[m_force_multi, REBOOT_TYPE_OPT, IGNORE_SECONDARIES_OPT, m_node_opt,
m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, SUBMIT_OPT,
m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt,
- m_inst_tags_opt, SHUTDOWN_TIMEOUT_OPT, DRY_RUN_OPT, PRIORITY_OPT,
- REASON_OPT],
+ m_inst_tags_opt, SHUTDOWN_TIMEOUT_OPT, DRY_RUN_OPT, PRIORITY_OPT],
"<instance>", "Reboots an instance"),
"activate-disks": (
ActivateDisks, ARGS_ONE_INSTANCE,
instance = self.instance
ignore_secondaries = self.op.ignore_secondaries
reboot_type = self.op.reboot_type
- reason = self.op.reason
remote_info = self.rpc.call_instance_info(instance.primary_node,
instance.name,
self.cfg.SetDiskID(disk, node_current)
result = self.rpc.call_instance_reboot(node_current, instance,
reboot_type,
- self.op.shutdown_timeout,
- reason)
+ self.op.shutdown_timeout)
result.Raise("Could not reboot instance")
else:
if instance_running:
# The version identifier for builtin data collectors
BUILTIN_DATA_COLLECTOR_VERSION = "B"
-# The source reasons for the change of state of an instance
-INSTANCE_REASON_SOURCE_CLI = "cli"
-INSTANCE_REASON_SOURCE_RAPI = "rapi"
-INSTANCE_REASON_SOURCE_UNKNOWN = "unknown"
-
-INSTANCE_REASON_SOURCES = compat.UniqueFrozenset([
- INSTANCE_REASON_SOURCE_CLI,
- INSTANCE_REASON_SOURCE_RAPI,
- INSTANCE_REASON_SOURCE_UNKNOWN,
- ])
-
-# The default reasons for the change of state of an instance
-INSTANCE_REASON_REBOOT = "reboot"
-
# Do not re-export imported modules
del re, _vcsversion, _autoconf, socket, pathutils, compat
("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
"Destination group names or UUIDs (defaults to \"all but current group\")")
-# The reason for a state change of an instance
-_PReason = \
- ("reason", (constants.INSTANCE_REASON_SOURCE_UNKNOWN, None),
- ht.TAnd(ht.TIsLength(2),
- ht.TItems([
- ht.TElemOf(constants.INSTANCE_REASON_SOURCES),
- ht.TMaybeString,
- ])),
- "The reason why the state of the instance is changing")
-
#: OP_ID conversion regular expression
_OPID_RE = re.compile("([a-z])([A-Z])")
"Whether to start the instance even if secondary disks are failing"),
("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
"How to reboot instance"),
- _PReason,
]
OP_RESULT = ht.TNone
(GANETI_RAPI_VERSION, instance)), query, None)
def RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None,
- dry_run=False, reason_text=None):
+ dry_run=False):
"""Reboots an instance.
@type instance: str
while re-assembling disks (in hard-reboot mode only)
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @type reason_text: string
- @param reason_text: the reason for the reboot
@rtype: string
@return: job id
_AppendIf(query, reboot_type, ("type", reboot_type))
_AppendIf(query, ignore_secondaries is not None,
("ignore_secondaries", ignore_secondaries))
- _AppendIf(query, reason_text, ("reason_text", reason_text))
return self._SendRequest(HTTP_POST,
("/%s/instances/%s/reboot" %
self.queryargs.get("type", [constants.INSTANCE_REBOOT_HARD])[0],
"ignore_secondaries": bool(self._checkIntVariable("ignore_secondaries")),
"dry_run": self.dryRun(),
- "reason":
- (constants.INSTANCE_REASON_SOURCE_RAPI,
- self._checkStringVariable("reason_text",
- default=constants.INSTANCE_REASON_REBOOT)),
})
("inst", ED_INST_DICT, "Instance object"),
("reboot_type", None, None),
("shutdown_timeout", None, None),
- ("reason_text", None, "Reason for the reboot"),
], None, None, "Returns the list of running instances on the given nodes"),
("instance_shutdown", SINGLE, None, constants.RPC_TMO_NORMAL, [
("instance", ED_INST_DICT, "Instance object"),
instance = objects.Instance.FromDict(params[0])
reboot_type = params[1]
shutdown_timeout = params[2]
- (reason_source, reason_text) = params[3]
- reason_text = _DefaultAlternative(reason_text,
- constants.INSTANCE_REASON_REBOOT)
- reason = backend.InstReason(reason_source, reason_text)
- return backend.InstanceReboot(instance, reboot_type, shutdown_timeout,
- reason)
+ return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
@staticmethod
def perspective_instance_balloon_memory(params):
, pShutdownTimeout
, pIgnoreSecondaries
, pRebootType
- , pReason
])
, ("OpInstanceMove",
[ pInstanceName
, pOpPriority
, pDependencies
, pComment
- , pReason
, pEnabledDiskTemplates
, dOldQuery
, dOldQueryNoLocking
pComment :: Field
pComment = optionalNullSerField $ stringField "comment"
--- | The description of the state change reason.
-pReason :: Field
-pReason = simpleField "reason" [t| (InstReasonSrc, NonEmptyString) |]
-
-- * Entire opcode parameter list
-- | Old-style query opcode, with locking.
, opStatusToRaw
, opStatusFromRaw
, ELogType(..)
- , InstReasonSrc(..)
) where
import Control.Monad (liftM)
, ("ELogJqueueTest", 'C.elogJqueueTest)
])
$(THH.makeJSONInstance ''ELogType)
-
--- | Type for the source of the state change of instances.
-$(THH.declareSADT "InstReasonSrc"
- [ ("IRSCli", 'C.instanceReasonSourceCli)
- , ("IRSRapi", 'C.instanceReasonSourceRapi)
- ])
-$(THH.makeJSONInstance ''InstReasonSrc)
-
-
$(genArbitrary ''DiskAccess)
-$(genArbitrary ''InstReasonSrc)
-
instance Arbitrary OpCodes.DiskIndex where
arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex
arbitrary <*> arbitrary
"OP_INSTANCE_REBOOT" ->
OpCodes.OpInstanceReboot <$> genFQDN <*> arbitrary <*>
- arbitrary <*> arbitrary <*> ((,) <$> arbitrary <*> genStringNE)
+ arbitrary <*> arbitrary
"OP_INSTANCE_MOVE" ->
OpCodes.OpInstanceMove <$> genFQDN <*> arbitrary <*> arbitrary <*>
genNodeNameNE <*> arbitrary
octets <- vectorOf 3 $ choose (0::Int, 255)
mkNonEmpty . intercalate ":" $ map (printf "%02x") octets
--- | Generate a non empty string
-genStringNE :: Gen NonEmptyString
-genStringNE = genName >>= mkNonEmpty
-
-- | Arbitrary instance for MetaOpCode, defined here due to TH ordering.
$(genArbitrary ''OpCodes.MetaOpCode)
self._Test("inst1.example.com", idx)
-class TestInstReason(unittest.TestCase):
- def testGetJson(self):
- reason_text = "OS Update"
- reason_source = constants.INSTANCE_REASON_SOURCE_CLI
- origDict = dict(text=reason_text, source=reason_source)
-
- reason = backend.InstReason(reason_source, reason_text)
- json = reason.GetJson()
- resultDict = serializer.LoadJson(json)
-
- self.assertEqual(origDict, resultDict)
-
-
if __name__ == "__main__":
testutils.GanetiTestProgram()
def testRebootInstance(self):
self.rapi.AddResponse("6146")
job_id = self.client.RebootInstance("i-bar", reboot_type="hard",
- ignore_secondaries=True, dry_run=True,
- reason_text="Updates")
+ ignore_secondaries=True, dry_run=True)
self.assertEqual(6146, job_id)
self.assertHandler(rlib2.R_2_instances_name_reboot)
self.assertItems(["i-bar"])
self.assertDryRun()
self.assertQuery("type", ["hard"])
self.assertQuery("ignore_secondaries", ["1"])
- self.assertQuery("reason_text", ["Updates"])
def testRebootInstanceDefaultReason(self):
self.rapi.AddResponse("6146")
self.assertDryRun()
self.assertQuery("type", ["hard"])
self.assertQuery("ignore_secondaries", ["1"])
- self.assertQuery("reason_text", None)
def testShutdownInstance(self):
self.rapi.AddResponse("1487")
handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], {
"dry-run": ["1"],
"ignore_secondaries": ["1"],
- "reason_text": ["System update"],
}, {}, clfactory)
job_id = handler.POST()
self.assertEqual(op.reboot_type, constants.INSTANCE_REBOOT_HARD)
self.assertTrue(op.ignore_secondaries)
self.assertTrue(op.dry_run)
- self.assertEqual(op.reason,
- (constants.INSTANCE_REASON_SOURCE_RAPI, "System update"))
self.assertRaises(IndexError, cl.GetNextSubmittedJob)