Commit 7e950d31 authored by Iustin Pop's avatar Iustin Pop
Browse files

Convert to static methods (where appropriate)



Many methods are simple pure functions, and not depending on the object
state. We convert these to staticmethods.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent f4ad2ef0
......@@ -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
......
......@@ -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.
......
......@@ -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)
......
......@@ -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}
......
......@@ -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.
......
......@@ -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.
......
......@@ -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)
......
......@@ -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.
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment