Many methods are simple pure functions, and not depending on the object
state. We convert these to staticmethods.
---
lib/backend.py | 3 ++-
lib/cmdlib.py | 3 ++-
lib/http/__init__.py | 6 ++++--
lib/jqueue.py | 9 ++++++---
lib/rapi/connector.py | 6 ++++--
lib/rapi/rlib2.py | 15 ++++++++++-----
tools/burnin | 9 ++++++---
tools/cfgshell | 6 ++++--
8 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/lib/backend.py b/lib/backend.py
index 7de7abb..224df1e 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -2751,7 +2751,8 @@ class IAllocatorRunner(object):
the master side.
"""
- def Run(self, name, idata):
+ @staticmethod
+ def Run(name, idata):
"""Run an iallocator script.
@type name: str
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 978bacf..f5762ef 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -7607,7 +7607,8 @@ class LUSetInstanceParams(LogicalUnit):
nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes)
return env, nl, nl
- def _GetUpdatedParams(self, old_params, update_dict,
+ @staticmethod
+ def _GetUpdatedParams(old_params, update_dict,
default_values, parameter_types):
"""Return the new params dict for the given params.
diff --git a/lib/http/__init__.py b/lib/http/__init__.py
index c6e9ee0..d00aba4 100644
--- a/lib/http/__init__.py
+++ b/lib/http/__init__.py
@@ -302,10 +302,12 @@ class HttpVersionNotSupported(HttpException):
class HttpJsonConverter: # pylint: disable-msg=W0232
CONTENT_TYPE = "application/json"
- def Encode(self, data):
+ @staticmethod
+ def Encode(data):
return serializer.DumpJson(data)
- def Decode(self, data):
+ @staticmethod
+ def Decode(data):
return serializer.LoadJson(data)
diff --git a/lib/jqueue.py b/lib/jqueue.py
index 25f464e..ec2f52a 100644
--- a/lib/jqueue.py
+++ b/lib/jqueue.py
@@ -725,7 +725,8 @@ class JobQueue(object):
except KeyError:
pass
- def _CheckRpcResult(self, result, nodes, failmsg):
+ @staticmethod
+ def _CheckRpcResult(result, nodes, failmsg):
"""Verifies the status of an RPC call.
Since we aim to keep consistency should this node (the current
@@ -806,7 +807,8 @@ class JobQueue(object):
result = rpc.RpcRunner.call_jobqueue_rename(names, addrs, rename)
self._CheckRpcResult(result, self._nodes, "Renaming files (%r)" % rename)
- def _FormatJobID(self, job_id):
+ @staticmethod
+ def _FormatJobID(job_id):
"""Convert a job ID to string format.
Currently this just does C{str(job_id)} after performing some
@@ -1344,7 +1346,8 @@ class JobQueue(object):
return (archived_count, len(all_job_ids) - last_touched - 1)
- def _GetJobInfoUnlocked(self, job, fields):
+ @staticmethod
+ def _GetJobInfoUnlocked(job, fields):
"""Returns information about a job.
@type job: L{_QueuedJob}
diff --git a/lib/rapi/connector.py b/lib/rapi/connector.py
index aba95b7..bc9bb8c 100644
--- a/lib/rapi/connector.py
+++ b/lib/rapi/connector.py
@@ -99,7 +99,8 @@ class R_root(baserlib.R_Generic):
"""/ resource.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Show the list of mapped resources.
@return: a dictionary with 'name' and 'uri' keys for each of them.
@@ -142,7 +143,8 @@ class R_2(baserlib.R_Generic):
""" /2 resource, the root of the version 2 API.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Show the list of mapped resources.
@return: a dictionary with 'name' and 'uri' keys for each of them.
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index 934abe3..f475277 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -77,7 +77,8 @@ class R_version(baserlib.R_Generic):
to adapt clients accordingly.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Returns the remote API version.
"""
@@ -88,7 +89,8 @@ class R_2_info(baserlib.R_Generic):
"""Cluster info.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Returns cluster information.
"""
@@ -100,7 +102,8 @@ class R_2_os(baserlib.R_Generic):
"""/2/os resource.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Return a list of all OSes.
Can return error 500 in case of a problem.
@@ -131,7 +134,8 @@ class R_2_redist_config(baserlib.R_Generic):
"""/2/redistribute-config resource.
"""
- def PUT(self):
+ @staticmethod
+ def PUT():
"""Redistribute configuration to all nodes.
"""
@@ -142,7 +146,8 @@ class R_2_jobs(baserlib.R_Generic):
"""/2/jobs resource.
"""
- def GET(self):
+ @staticmethod
+ def GET():
"""Returns a dictionary of jobs.
@return: a dictionary with jobs id and uri.
diff --git a/tools/burnin b/tools/burnin
index b566df8..8adad91 100755
--- a/tools/burnin
+++ b/tools/burnin
@@ -675,15 +675,18 @@ class Burner(object):
Log("remove export", indent=2)
self.ExecOrQueue(instance, exp_op, rem_op, imp_op, erem_op)
- def StopInstanceOp(self, instance):
+ @staticmethod
+ def StopInstanceOp(instance):
"""Stop given instance."""
return opcodes.OpShutdownInstance(instance_name=instance)
- def StartInstanceOp(self, instance):
+ @staticmethod
+ def StartInstanceOp(instance):
"""Start given instance."""
return opcodes.OpStartupInstance(instance_name=instance, force=False)
- def RenameInstanceOp(self, instance, instance_new):
+ @staticmethod
+ def RenameInstanceOp(instance, instance_new):
"""Rename instance."""
return opcodes.OpRenameInstance(instance_name=instance,
new_name=instance_new)
diff --git a/tools/cfgshell b/tools/cfgshell
index b3d5968..62e501d 100755
--- a/tools/cfgshell
+++ b/tools/cfgshell
@@ -309,14 +309,16 @@ class ConfigShell(cmd.Cmd):
else:
print "Invalid node name"
- def do_EOF(self, line):
+ @staticmethod
+ def do_EOF(line):
"""Exit the application.
"""
print
return True
- def do_quit(self, line):
+ @staticmethod
+ def do_quit(line):
"""Exit the application.
"""
--
1.6.5.7