diff --git a/lib/backend.py b/lib/backend.py index 3668d4f64578d727ce9e715b5335d14ba31d3007..2c5471b861b4ba37afd975a6141d61f1417bd199 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -122,49 +122,6 @@ def GetInstReasonFilename(instance_name): 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. @@ -1451,7 +1408,7 @@ def InstanceShutdown(instance, timeout): _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} @@ -1481,14 +1438,12 @@ def InstanceReboot(instance, reboot_type, shutdown_timeout, reason): 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) diff --git a/lib/cli.py b/lib/cli.py index 491c0092c58ea36b5df157ba73261237608ed604..7ff6e6456d6b46a0f8941c7cb8179d38db78747c 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1406,8 +1406,7 @@ FAILURE_ONLY_OPT = cli_option("--failure-only", default=False, " 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): diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py index aba7e66b027cdcb524b65e38261fde15b7f4f2f4..07db3a62cc0ac728f5dd137f03de2ab53974be7a 100644 --- a/lib/client/gnt_instance.py +++ b/lib/client/gnt_instance.py @@ -630,9 +630,7 @@ def _RebootInstance(name, opts): 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): @@ -1559,8 +1557,7 @@ commands = { [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, diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 99077d5e3f9dc2602593be2fef326daef8868438..2c6d216a37eed83df42e81cb05d9055ba8f34c3f 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -7440,7 +7440,6 @@ class LUInstanceReboot(LogicalUnit): 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, @@ -7456,8 +7455,7 @@ class LUInstanceReboot(LogicalUnit): 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: diff --git a/lib/constants.py b/lib/constants.py index 6d781a58eb8a51a10a63130d9764a651800c8d5f..50b11ba7a069310ff228f402134c242961ede78c 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -2435,19 +2435,5 @@ AUTO_REPAIR_ALL_RESULTS = frozenset([ # 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 diff --git a/lib/opcodes.py b/lib/opcodes.py index 7a48115e2b324b1e4cd04be0e129fb26f9579076..8bf6c778e5d3bc6d671ff742a445bab855178157 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -184,16 +184,6 @@ _PTargetGroups = \ ("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])") @@ -1465,7 +1455,6 @@ class OpInstanceReboot(OpCode): "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 diff --git a/lib/rapi/client.py b/lib/rapi/client.py index b7600785c37d90aea440c3209b2ede947682cf8a..5fc576f8869dda39e7f1058c93698d084990a58c 100644 --- a/lib/rapi/client.py +++ b/lib/rapi/client.py @@ -1001,7 +1001,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904 (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 @@ -1013,8 +1013,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904 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 @@ -1024,7 +1022,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904 _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" % diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index cc8a796b8db123d47e067ca8df0512b24bd7fef5..d35e3aacb439b1441ac38651c6030c6b64290f82 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -1040,10 +1040,6 @@ class R_2_instances_name_reboot(baserlib.OpcodeResource): 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)), }) diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index a9ed9dad13c36791d0552610101066c897dad1b3..f5f1c34b23f50452bca6f6a31934f778ca55ceb1 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -230,7 +230,6 @@ _INSTANCE_CALLS = [ ("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"), diff --git a/lib/server/noded.py b/lib/server/noded.py index 96ad1acc70e0a924c4c92c65d7b15d44a9d83f67..1351b9c90c54793d6056a6124b71125465166da0 100644 --- a/lib/server/noded.py +++ b/lib/server/noded.py @@ -650,12 +650,7 @@ class NodeRequestHandler(http.server.HttpServerHandler): 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): diff --git a/src/Ganeti/OpCodes.hs b/src/Ganeti/OpCodes.hs index cf34b22222c67d79693ab1b6499abeb0303bb016..6f284454427ed65be2eb7509fb43b0eec2b4627b 100644 --- a/src/Ganeti/OpCodes.hs +++ b/src/Ganeti/OpCodes.hs @@ -345,7 +345,6 @@ $(genOpCode "OpCode" , pShutdownTimeout , pIgnoreSecondaries , pRebootType - , pReason ]) , ("OpInstanceMove", [ pInstanceName diff --git a/src/Ganeti/OpParams.hs b/src/Ganeti/OpParams.hs index 7001f83bf0a2ccf724b735a3f1c30d14b60d02a4..51d47b2520ffb03142997859977d7be643a01be2 100644 --- a/src/Ganeti/OpParams.hs +++ b/src/Ganeti/OpParams.hs @@ -236,7 +236,6 @@ module Ganeti.OpParams , pOpPriority , pDependencies , pComment - , pReason , pEnabledDiskTemplates , dOldQuery , dOldQueryNoLocking @@ -1445,10 +1444,6 @@ pDependencies = 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. diff --git a/src/Ganeti/Types.hs b/src/Ganeti/Types.hs index ae402952c842d77a57eca43a2a4a338ed83a03dc..6bd3ade4c965f967de1e173e2c25eccd5c002db1 100644 --- a/src/Ganeti/Types.hs +++ b/src/Ganeti/Types.hs @@ -92,7 +92,6 @@ module Ganeti.Types , opStatusToRaw , opStatusFromRaw , ELogType(..) - , InstReasonSrc(..) ) where import Control.Monad (liftM) @@ -486,12 +485,3 @@ $(THH.declareSADT "ELogType" , ("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) - - diff --git a/test/hs/Test/Ganeti/OpCodes.hs b/test/hs/Test/Ganeti/OpCodes.hs index a37517b93a7b3da8e2fccd899b388ed53a0bfcb1..1183741426576ec5dcd6d6f67199271f17d2ea72 100644 --- a/test/hs/Test/Ganeti/OpCodes.hs +++ b/test/hs/Test/Ganeti/OpCodes.hs @@ -69,8 +69,6 @@ $(genArbitrary ''OpCodes.ReplaceDisksMode) $(genArbitrary ''DiskAccess) -$(genArbitrary ''InstReasonSrc) - instance Arbitrary OpCodes.DiskIndex where arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex @@ -241,7 +239,7 @@ instance Arbitrary OpCodes.OpCode where 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 @@ -398,10 +396,6 @@ genMacPrefix = do 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) diff --git a/test/py/ganeti.backend_unittest.py b/test/py/ganeti.backend_unittest.py index 86f88bc409bc8246755104c7f8c7dfaff567380f..4ad743af7ab3aae4a35771cfafd940a262e72261 100755 --- a/test/py/ganeti.backend_unittest.py +++ b/test/py/ganeti.backend_unittest.py @@ -538,18 +538,5 @@ class TestGetBlockDevSymlinkPath(unittest.TestCase): 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() diff --git a/test/py/ganeti.rapi.client_unittest.py b/test/py/ganeti.rapi.client_unittest.py index e78a1d9b6ae104d97f2af5ca0de3f06dca04dc28..ab518e5fe15605ba86fa611cac1d3282f6da0deb 100755 --- a/test/py/ganeti.rapi.client_unittest.py +++ b/test/py/ganeti.rapi.client_unittest.py @@ -594,15 +594,13 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): 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") @@ -614,7 +612,6 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): self.assertDryRun() self.assertQuery("type", ["hard"]) self.assertQuery("ignore_secondaries", ["1"]) - self.assertQuery("reason_text", None) def testShutdownInstance(self): self.rapi.AddResponse("1487") diff --git a/test/py/ganeti.rapi.rlib2_unittest.py b/test/py/ganeti.rapi.rlib2_unittest.py index 374f1feb727339abc1a0fc7f0460a262da447657..d4d36027c4b8771e2a381e8bec06a3d7320e84c6 100755 --- a/test/py/ganeti.rapi.rlib2_unittest.py +++ b/test/py/ganeti.rapi.rlib2_unittest.py @@ -370,7 +370,6 @@ class TestInstanceReboot(unittest.TestCase): handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], { "dry-run": ["1"], "ignore_secondaries": ["1"], - "reason_text": ["System update"], }, {}, clfactory) job_id = handler.POST() @@ -384,8 +383,6 @@ class TestInstanceReboot(unittest.TestCase): 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)