Commit d73ef63f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

A few style fixes


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarLuca Bigliardi <shammash@google.com>
parent 508e9b20
......@@ -22,4 +22,3 @@
"""Ganeti confd library
"""
#!/usr/bin/python
#
#
# Copyright (C) 2009, Google Inc.
......@@ -27,12 +27,14 @@ import logging
from ganeti import constants
# constants for some common errors to return from a query
QUERY_UNKNOWN_ENTRY_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
constants.CONFD_ERROR_UNKNOWN_ENTRY)
QUERY_INTERNAL_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
constants.CONFD_ERROR_INTERNAL)
class ConfdQuery(object):
"""Confd Query base class.
......@@ -82,6 +84,7 @@ class PingQuery(ConfdQuery):
return status, answer
class ClusterMasterQuery(ConfdQuery):
"""Cluster master query.
......@@ -163,4 +166,3 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
return QUERY_INTERNAL_ERROR
return constants.CONFD_REPL_STATUS_OK, pnode_primary_ip
#!/usr/bin/python
#
#
# Copyright (C) 2009, Google Inc.
......@@ -47,12 +47,12 @@ class ConfdProcessor(object):
"""
DISPATCH_TABLE = {
constants.CONFD_REQ_PING: querylib.PingQuery,
constants.CONFD_REQ_NODE_ROLE_BYNAME: querylib.NodeRoleQuery,
constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP:
querylib.InstanceIpToNodePrimaryIpQuery,
constants.CONFD_REQ_CLUSTER_MASTER: querylib.ClusterMasterQuery,
}
constants.CONFD_REQ_PING: querylib.PingQuery,
constants.CONFD_REQ_NODE_ROLE_BYNAME: querylib.NodeRoleQuery,
constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP:
querylib.InstanceIpToNodePrimaryIpQuery,
constants.CONFD_REQ_CLUSTER_MASTER: querylib.ClusterMasterQuery,
}
def __init__(self):
"""Constructor for ConfdProcessor
......@@ -174,4 +174,3 @@ class ConfdProcessor(object):
"""
return serializer.DumpSigned(reply.ToDict(), self.hmac_key, rsalt)
......@@ -143,12 +143,12 @@ MASTER_SCRIPT = "ganeti-master"
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
DAEMONS_LOGFILES = {
# "daemon-name": "logfile"
NODED: LOG_DIR + "node-daemon.log",
CONFD: LOG_DIR + "conf-daemon.log",
RAPI: LOG_DIR + "rapi-daemon.log",
MASTERD: LOG_DIR + "master-daemon.log",
}
# "daemon-name": "logfile"
NODED: LOG_DIR + "node-daemon.log",
CONFD: LOG_DIR + "conf-daemon.log",
RAPI: LOG_DIR + "rapi-daemon.log",
MASTERD: LOG_DIR + "master-daemon.log",
}
LOG_OS_DIR = LOG_DIR + "os"
LOG_WATCHER = LOG_DIR + "watcher.log"
LOG_COMMANDS = LOG_DIR + "commands.log"
......
......@@ -69,6 +69,7 @@ NO_CHECK = (False, None, None, None, None)
# required, but no other checks
REQUIRED_CHECK = (True, None, None, None, None)
def ParamInSet(required, my_set):
"""Builds parameter checker for set membership.
......
......@@ -63,7 +63,7 @@ class ChrootManager(hv_base.BaseHypervisor):
PARAMETERS = {
constants.HV_INIT_SCRIPT: (True, utils.IsNormAbsPath,
"must be an absolute normalized path",
None, None)
None, None),
}
def __init__(self):
......@@ -116,11 +116,11 @@ class ChrootManager(hv_base.BaseHypervisor):
def GetInstanceInfo(self, instance_name):
"""Get instance properties.
Args:
instance_name: the instance name
@type instance_name: string
@param instance_name: the instance name
@return: (name, id, memory, vcpus, stat, times)
Returns:
(name, id, memory, vcpus, stat, times)
"""
dir_name = "%s/%s" % (self._ROOT_DIR, instance_name)
if not self._IsDirLive(dir_name):
......@@ -130,8 +130,8 @@ class ChrootManager(hv_base.BaseHypervisor):
def GetAllInstancesInfo(self):
"""Get properties of all instances.
Returns:
[(name, id, memory, vcpus, stat, times),...]
@return: [(name, id, memory, vcpus, stat, times),...]
"""
data = []
for file_name in os.listdir(self._ROOT_DIR):
......@@ -252,8 +252,7 @@ class ChrootManager(hv_base.BaseHypervisor):
def Verify(self):
"""Verify the hypervisor.
For the chroot manager, it just checks the existence of the base
dir.
For the chroot manager, it just checks the existence of the base dir.
"""
if not os.path.exists(self._ROOT_DIR):
......
......@@ -87,7 +87,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
data = []
for file_name in os.listdir(self._ROOT_DIR):
try:
fh = open(self._ROOT_DIR+"/"+file_name, "r")
fh = open(self._ROOT_DIR + "/" + file_name, "r")
inst_id = "-1"
memory = 0
vcpus = 1
......
......@@ -55,22 +55,22 @@ class KVMHypervisor(hv_base.BaseHypervisor):
constants.HV_KERNEL_ARGS: hv_base.NO_CHECK,
constants.HV_ACPI: hv_base.NO_CHECK,
constants.HV_SERIAL_CONSOLE: hv_base.NO_CHECK,
constants.HV_VNC_BIND_ADDRESS: \
(False, lambda x: (utils.IsValidIP(x) or utils.IsNormAbsPath(x)),
"the VNC bind address must be either a valid IP address or an absolute"
" pathname", None, None),
constants.HV_VNC_BIND_ADDRESS:
(False, lambda x: (utils.IsValidIP(x) or utils.IsNormAbsPath(x)),
"the VNC bind address must be either a valid IP address or an absolute"
" pathname", None, None),
constants.HV_VNC_TLS: hv_base.NO_CHECK,
constants.HV_VNC_X509: hv_base.OPT_DIR_CHECK,
constants.HV_VNC_X509_VERIFY: hv_base.NO_CHECK,
constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_BOOT_ORDER: \
hv_base.ParamInSet(True, constants.HT_KVM_VALID_BO_TYPES),
constants.HV_NIC_TYPE: \
hv_base.ParamInSet(True, constants.HT_KVM_VALID_NIC_TYPES),
constants.HV_DISK_TYPE: \
hv_base.ParamInSet(True, constants.HT_KVM_VALID_DISK_TYPES),
constants.HV_USB_MOUSE: \
hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
constants.HV_BOOT_ORDER:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_BO_TYPES),
constants.HV_NIC_TYPE:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_NIC_TYPES),
constants.HV_DISK_TYPE:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_DISK_TYPES),
constants.HV_USB_MOUSE:
hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
}
_MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)',
......@@ -177,8 +177,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
# mounted noexec sometimes, so we'll have to find another place.
(tmpfd, tmpfile_name) = tempfile.mkstemp()
tmpfile = os.fdopen(tmpfd, 'w')
tmpfile.write(script.getvalue())
tmpfile.close()
try:
tmpfile.write(script.getvalue())
finally:
tmpfile.close()
os.chmod(tmpfile_name, 0755)
return tmpfile_name
......
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