Commit 69b99987 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Code and docstring style fixes

Found using pylint and epydoc.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarGuido Trotter <>
parent 211b6132
......@@ -31,17 +31,18 @@ class AsyncNotifier(asyncore.file_dispatcher):
def __init__(self, watch_manager,
Constructor for AsyncNotifier, a special asyncore file_dispatcher that
actually wraps a pyinotify Notifier, making it asyncronous.
def __init__(self, watch_manager, default_proc_fun=None, map=None):
"""Initializes this class.
This is a a special asyncore file_dispatcher that actually wraps a
pyinotify Notifier, making it asyncronous.
if default_proc_fun is None:
default_proc_fun = pyinotify.ProcessEvent()
self.notifier = pyinotify.Notifier(watch_manager, default_proc_fun)
# here we need to steal the file descriptor from the notifier, so we can
# use it in the global asyncore select, and avoid calling the
# check_events() function of the notifier (which doesn't allow us to select
......@@ -52,4 +53,3 @@ class AsyncNotifier(asyncore.file_dispatcher):
def handle_read(self):
......@@ -1768,7 +1768,7 @@ def OSFromDisk(name, base_dir=None):
@raise RPCFail: if we don't find a valid OS
name_only = name.split('+',1)[0]
name_only = name.split("+", 1)[0]
status, payload = _TryOSFromDisk(name_only, base_dir)
if not status:
......@@ -25,7 +25,6 @@
import sys
import textwrap
import os.path
import copy
import time
import logging
from cStringIO import StringIO
......@@ -813,7 +812,7 @@ IGNORE_SECONDARIES_OPT = cli_option("--ignore-secondaries",
default=False, action="store_true",
help="Ignore errors from secondaries")
NOSHUTDOWN_OPT = cli_option("","--noshutdown", dest="shutdown",
NOSHUTDOWN_OPT = cli_option("--noshutdown", dest="shutdown",
action="store_false", default=True,
help="Don't shutdown the instance (unsafe)")
......@@ -29,7 +29,8 @@ This way the client library doesn't ever need to "wait" on a particular answer,
and can proceed even if some udp packets are lost. It's up to the user to
reschedule queries if they haven't received responses and they need them.
Example usage:
Example usage::
client = ConfdClient(...) # includes callback specification
req = confd_client.ConfdClientRequest(type=constants.CONFD_REQ_PING)
......@@ -43,6 +44,7 @@ You can use the provided ConfdFilterCallback to act as a filter, only passing
confirming what you already got.
import socket
import time
import random
......@@ -97,7 +99,7 @@ class ConfdClient:
@param callback: function to call when getting answers
@type port: integer
@keyword port: confd port (default: use GetDaemonPort)
@type logger: L{logging.Logger}
@type logger: logging.Logger
@keyword logger: optional logger for internal conditions
......@@ -318,7 +320,7 @@ class ConfdFilterCallback:
@type callback: f(L{ConfdUpcallPayload})
@param callback: function to call when getting answers
@type logger: L{logging.Logger}
@type logger: logging.Logger
@keyword logger: optional logger for internal conditions
......@@ -24,7 +24,6 @@
import asyncore
import os
import select
import signal
import errno
import logging
......@@ -158,25 +157,22 @@ class AsyncUDPSocket(asyncore.dispatcher):
class Mainloop(object):
"""Generic mainloop for daemons
@ivar scheduler: A sched.scheduler object, which can be used to register
timed events
def __init__(self):
"""Constructs a new Mainloop instance.
@ivar scheduler: A L{sched.scheduler} object, which can be used to register
timed events
self._signal_wait = []
self.scheduler = AsyncoreScheduler(time.time)
def Run(self, stop_on_empty=False, signal_handlers=None):
def Run(self, signal_handlers=None):
"""Runs the mainloop.
@type stop_on_empty: bool
@param stop_on_empty: Whether to stop mainloop once all I/O waiters
@type signal_handlers: dict
@param signal_handlers: signal->L{utils.SignalHandler} passed by decorator
......@@ -187,10 +183,6 @@ class Mainloop(object):
running = True
# Start actual main loop
while running:
# Stop if nothing is listening anymore
if stop_on_empty and not (self._io_wait):
if not self.scheduler.empty():
......@@ -234,11 +226,9 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
@type daemon_name: string
@param daemon_name: daemon name
@type optionparser: L{optparse.OptionParser}
@type optionparser: optparse.OptionParser
@param optionparser: initialized optionparser with daemon-specific options
(common -f -d options will be handled by this module)
@type options: object @param options: OptionParser result, should contain at
least the fork and the debug options
@type dirs: list of strings
@param dirs: list of directories that must exist for this daemon to work
@type check_fn: function which accepts (options, args)
......@@ -370,8 +370,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
monitor_dev = 'unix:%s,server,nowait' % \
monitor_dev = ("unix:%s,server,nowait" %
kvm_cmd.extend(['-monitor', monitor_dev])
if hvp[constants.HV_SERIAL_CONSOLE]:
serial_dev = ('unix:%s,server,nowait' %
......@@ -508,8 +508,9 @@ class XenPvmHypervisor(XenHypervisor):
class XenHvmHypervisor(XenHypervisor):
"""Xen HVM hypervisor interface"""
constants.HV_ACPI: hv_base.NO_CHECK,
......@@ -1027,7 +1027,7 @@ class JobQueue(object):
queue, in order for it to be picked up by the queue processors.
@type job_id: job ID
@param jod_id: the job ID for the new job
@param job_id: the job ID for the new job
@type ops: list
@param ops: The list of OpCodes that will become the new job.
@rtype: job ID
......@@ -18,6 +18,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# Disable "Invalid name ..." message
# pylint: disable-msg=C0103
"""Module implementing the Ganeti locking code."""
import os
......@@ -113,7 +116,7 @@ class _BaseCondition(object):
def __init__(self, lock):
"""Constructor for _BaseCondition.
@type lock: L{threading.Lock}
@type lock: threading.Lock
@param lock: condition base lock
......@@ -180,6 +183,9 @@ class SingleNotifyPipeCondition(_BaseCondition):
self._poller = None
def _check_unnotified(self):
"""Throws an exception if already notified.
if self._notified:
raise RuntimeError("cannot use already notified condition")
......@@ -38,7 +38,6 @@ from ganeti import errors
from ganeti import rpc
from ganeti import cmdlib
from ganeti import locking
from ganeti import utils
class _LockAcquireTimeout(Exception):
......@@ -114,7 +114,7 @@ class R_root(baserlib.R_Generic):
return baserlib.BuildUriList(rootlist, "/%s")
def _getResources(id):
def _getResources(id_):
"""Return a list of resources underneath given id.
This is to generalize querying of version resources lists.
......@@ -122,7 +122,7 @@ def _getResources(id):
@return: a list of resources names.
r_pattern = re.compile('^R_%s_([a-zA-Z0-9]+)$' % id)
r_pattern = re.compile('^R_%s_([a-zA-Z0-9]+)$' % id_)
rlist = []
for handler in CONNECTOR.values():
......@@ -439,7 +439,7 @@ class R_2_instances(baserlib.R_Generic):
for idx, d in enumerate(disk_data):
if not isinstance(d, int):
raise http.HttpBadRequest("Disk %d specification wrong: should"
" be an integer")
" be an integer" % idx)
disks.append({"size": d})
# nic processing (one nic only)
nics = [{"mac": fn("mac", constants.VALUE_AUTO)}]
......@@ -450,7 +450,7 @@ class R_2_instances(baserlib.R_Generic):
if fn("link", None) is not None:
nics[0]["link"] = fn("link")
if fn("bridge", None) is not None:
nics[0]["bridge"] = fn("bridge")
nics[0]["bridge"] = fn("bridge")
op = opcodes.OpCreateInstance(
......@@ -57,6 +57,14 @@ class SimpleConfigReader(object):
self._last_inode = None
self._last_mtime = None
self._last_size = None
self._config_data = None
self._instances_ips = None
self._inst_ips_by_link = None
self._ip_to_instance = None
self._mc_primary_ips = None
self._nodes_primary_ips = None
# we need a forced reload at class init time, to initialize _last_*
......@@ -79,16 +87,14 @@ class SimpleConfigReader(object):
mtime = cfg_stat.st_mtime
size = cfg_stat.st_size
reload = False
if force or inode != self._last_inode or \
mtime > self._last_mtime or \
size != self._last_size:
if (force or inode != self._last_inode or
mtime > self._last_mtime or
size != self._last_size):
self._last_inode = inode
self._last_mtime = mtime
self._last_size = size
reload = True
if not reload:
# Don't reload
return False
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