[Cluster-devel] conga/luci/site/luci/Extensions LuciClusterAct ...
rmccabe at sourceware.org
rmccabe at sourceware.org
Mon May 14 18:00:17 UTC 2007
CVSROOT: /cvs/cluster
Module name: conga
Branch: EXPERIMENTAL
Changes by: rmccabe at sourceware.org 2007-05-14 18:00:14
Modified files:
luci/site/luci/Extensions: LuciClusterActions.py
LuciClusterInfo.py LuciDB.py
LuciSyslog.py LuciZope.py
PropsObject.py ResourceHandler.py
RicciQueries.py cluster_adapters.py
homebase_adapters.py
ricci_communicator.py
system_adapters.py
Log message:
Next pass of cleanup and refactor
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciClusterActions.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciClusterInfo.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciDB.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.4&r2=1.1.2.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciSyslog.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.11&r2=1.11.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciZope.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.2&r2=1.1.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/PropsObject.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.2.8.1&r2=1.2.8.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ResourceHandler.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/RicciQueries.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.255.2.3&r2=1.255.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.50.2.2&r2=1.50.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_communicator.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.25.2.2&r2=1.25.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/system_adapters.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.2.2.1&r2=1.2.2.2
--- conga/luci/site/luci/Extensions/Attic/LuciClusterActions.py 2007/05/08 22:19:35 1.1.2.1
+++ conga/luci/site/luci/Extensions/Attic/LuciClusterActions.py 2007/05/14 18:00:14 1.1.2.2
@@ -1,7 +1,11 @@
import RicciQueries as rq
-from conga_constants import CLUSTER_CONFIG
+from LuciDB import set_node_flag, getRicciAgent
+from LuciSyslog import get_logger
+from conga_constants import CLUSTER_CONFIG, LUCI_DEBUG_MODE
-def propagateClusterConfAsync(model, rc=None):
+luci_log = get_logger()
+
+def propagateClusterConfAsync(self, model, rc=None):
errors = list()
messages = list()
@@ -10,7 +14,8 @@
if not clustername:
raise Exception, 'cluster name from model.getClusterName() is blank'
except Exception, e:
- luci_log.debug_verbose('PCC0: getClusterName: %r' % e)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('PCC0: getClusterName: %r' % e)
errors.append('Unable to determine cluster name')
return (False, { 'errors': errors, 'messages': messages })
@@ -18,19 +23,36 @@
rc = getRicciAgent(self, clustername)
if not rc:
- luci_log.debug_verbose('PCC1: unable to find a ricci agent for the %s cluster' % clustername)
- errors.append('Unable to contact a ricci agent for cluster "%s"' % clustername)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('PCC1: no ricci agent for the %s cluster' \
+ % clustername)
+ errors.append('Unable to contact a ricci agent for cluster "%s"' \
+ % clustername)
+ return (False, { 'errors': errors, 'messages': messages })
+
+ try:
+ conf_str = str(model.exportModelAsString()).strip()
+ if not conf_str:
+ raise Exception, 'The new cluster configuration is blank'
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('PCC2: %r' % e)
+ errors.append(repr(e))
return (False, { 'errors': errors, 'messages': messages })
- batch_id, result = rq.setClusterConf(rc, str(conf_str))
+ batch_id, result = rq.setClusterConf(rc, conf_str)
if batch_id is None or result is None:
- luci_log.debug_verbose('PCC2: setCluserConf: batchid or result is None')
- errors.append('Unable to propagate the new cluster configuration for %s' % clustername)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('PCC3: batchid or result is None')
+ errors.append('Unable to propagate a new cluster configuration for %s' \
+ % clustername)
return (False, { 'errors': errors, 'messages': messages })
try:
set_node_flag(self, clustername, rc.hostname(), batch_id,
- CLUSTER_CONFIG, 'Adding new fence device "%s"' % retobj)
+ CLUSTER_CONFIG, 'Updating the cluster configuration for "%s"' %
+ clustername)
except Exception, e:
- luci_log.debug_verbose('PCC3: set_node_flag: %r' % e)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('PCC4: set_node_flag: %r' % e)
return (True, { 'errors': errors, 'messages': messages, 'batchid': batch_id })
--- conga/luci/site/luci/Extensions/Attic/LuciClusterInfo.py 2007/05/08 22:19:35 1.1.2.1
+++ conga/luci/site/luci/Extensions/Attic/LuciClusterInfo.py 2007/05/14 18:00:14 1.1.2.2
@@ -2,6 +2,7 @@
import RicciQueries as rq
from ricci_communicator import RicciCommunicator
from FenceHandler import FENCE_OPTS
+from LuciSyslog import get_logger
from conga_constants import CLUNAME, CLUSTER_CONFIG, CLUSTER_DELETE, \
CLUSTER_PROCESS, CLUSTER_RESTART, CLUSTER_START, CLUSTER_STOP, \
@@ -14,6 +15,15 @@
SERVICE, SERVICE_DELETE, SERVICE_MIGRATE, SERVICE_RESTART, \
SERVICE_START, SERVICE_STOP, VM_CONFIG
+luci_log = get_logger()
+
+def getnodes(self, model):
+ try:
+ return map(lambda x: str(x.getName()), model.getNodes())
+ except Exception, e:
+ luci_log.debug_verbose('getnodes0: %s' % str(e))
+ return []
+
def getResourceInfo(model, name, res=None):
if res is None:
try:
@@ -1469,3 +1479,14 @@
#CALL
return {}
+
+def getClusterName(self, model):
+ return model.getClusterName()
+
+def getClusterAlias(self, model):
+ if not model:
+ return ''
+ alias = model.getClusterAlias()
+ if not alias:
+ return model.getClusterName()
+ return alias
--- conga/luci/site/luci/Extensions/Attic/LuciDB.py 2007/05/14 16:02:11 1.1.2.4
+++ conga/luci/site/luci/Extensions/Attic/LuciDB.py 2007/05/14 18:00:14 1.1.2.5
@@ -2,13 +2,14 @@
import RicciQuery as rq
from ricci_communicator import RicciCommunicator
from LuciZope import isAdmin
+from LuciSyslog import get_logger
from conga_constants import CLUSTER_FOLDER_PATH, BATCH_ID, TASKTYPE, \
FLAG_DESC, CLUSTER_ADD, CLUSTER_NODE_ADDED, CLUSTER_NODE_NEED_AUTH, \
LAST_STATUS, PLONE_ROOT, STORAGE_FOLDER_PATH, CLUSTER_NODE_NOT_MEMBER, \
LUCI_DEBUG_MODE
-from homebase_adapters import luci_log
+luci_log = get_logger()
def getClusterNode(self, nodename, clustername):
try:
--- conga/luci/site/luci/Extensions/LuciSyslog.py 2006/11/29 18:15:20 1.11
+++ conga/luci/site/luci/Extensions/LuciSyslog.py 2007/05/14 18:00:14 1.11.4.1
@@ -18,14 +18,20 @@
except:
raise LuciSyslogError, 'unable to setup syslog functionality.'
+ def __del__(self):
+ self.close()
+
+ def initialized(self):
+ return self.__init > 0
+
def info(self, msg):
if not self.__init:
return
try:
syslog(LOG_INFO, msg)
except:
- pass
#raise LuciSyslogError, 'syslog info call failed'
+ pass
def warn(self, msg):
if not self.__init:
@@ -33,8 +39,8 @@
try:
syslog(LOG_WARNING, msg)
except:
- pass
#raise LuciSyslogError, 'syslog warn call failed'
+ pass
def private(self, msg):
if not self.__init:
@@ -42,8 +48,8 @@
try:
syslog(LOG_AUTH, msg)
except:
- pass
#raise LuciSyslogError, 'syslog private call failed'
+ pass
def debug_verbose(self, msg):
if not LUCI_DEBUG_MODE or LUCI_DEBUG_VERBOSITY < 2 or not self.__init:
@@ -73,8 +79,8 @@
try:
syslog(LOG_DEBUG, msg)
except:
- pass
#raise LuciSyslogError, 'syslog debug call failed'
+ pass
def close(self):
try:
@@ -82,3 +88,9 @@
closelog()
except:
pass
+
+luci_logc = None
+def get_logger():
+ if luci_logc is None or luci_logc.initialized() is False:
+ luci_logc = LuciSyslog()
+ return luci_logc
--- conga/luci/site/luci/Extensions/Attic/LuciZope.py 2007/05/08 22:19:35 1.1.2.2
+++ conga/luci/site/luci/Extensions/Attic/LuciZope.py 2007/05/14 18:00:14 1.1.2.3
@@ -87,3 +87,41 @@
if get_units_multiplier(units) > get_units_multiplier(p_units):
units = p_units
return (convert_bytes(bytes, units), units)
+
+def getTabs(self, req):
+ if not userAuthenticated(self):
+ return []
+
+ htab = {
+ 'Title': 'homebase',
+ 'Description': 'Home base for this luci server',
+ 'Taburl': '/luci/homebase',
+ 'isSelected': False
+ }
+ ctab = {
+ 'Title': 'cluster',
+ 'Description': 'Cluster configuration area',
+ 'Taburl': '/luci/cluster/index_html?pagetype=3',
+ 'isSelected': False
+ }
+ stab = {
+ 'Title': 'storage',
+ 'Description': 'Storage configuration page',
+ 'Taburl': '/luci/storage',
+ 'isSelected': False
+ }
+
+ try:
+ baseurl = req['URL']
+ if baseurl.find('cluster') > (-1):
+ ctab['isSelected'] = True
+ elif baseurl.find('storage') > (-1):
+ stab['isSelected'] = True
+ else:
+ htab['isSelected'] = True
+ except KeyError, e:
+ pass
+ except Exception, e:
+ htab['isSelected'] = True
+
+ return [ htab, ctab, stab ]
--- conga/luci/site/luci/Extensions/PropsObject.py 2007/05/04 19:10:24 1.2.8.1
+++ conga/luci/site/luci/Extensions/PropsObject.py 2007/05/14 18:00:14 1.2.8.2
@@ -1,7 +1,5 @@
-
-from ricci_defines import *
-
-from Variable import Variable, parse_variable
+from Variable import parse_variable
+from ricci_defines import PROPS_TAG
import xml
import xml.dom
--- conga/luci/site/luci/Extensions/Attic/ResourceHandler.py 2007/05/03 20:16:38 1.1.2.1
+++ conga/luci/site/luci/Extensions/Attic/ResourceHandler.py 2007/05/14 18:00:14 1.1.2.2
@@ -12,8 +12,10 @@
from ClusterModel.OpenLDAP import OpenLDAP
from ClusterModel.LVM import LVM
from ClusterModel.MySQL import MySQL
+from LuciSyslog import get_logger
+from conga_constants import LUCI_DEBUG_MODE
-from homebase_adapters import luci_log
+luci_log = get_logger()
def get_fsid_list(model):
obj_list = model.searchObjectTree('fs')
@@ -45,7 +47,8 @@
resPtr.removeChild(res)
return res
- luci_log.debug_verbose('GRFE0: unable to find resource "%s"' % name)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GRFE0: unable to find resource "%s"' % name)
raise KeyError, name
def addIp(res, rname, form, model):
@@ -57,9 +60,10 @@
raise KeyError, 'No IP address was given'
res.addAttribute('address', addr)
except KeyError, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addIp4: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addIp4: %s' % err)
if 'monitorLink' in form:
res.addAttribute('monitor_link', '1')
@@ -77,9 +81,10 @@
raise Exception, 'No mount point was given for "%s"' % rname
res.addAttribute('mountpoint', mountpoint)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addFs6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addFs6: %s' % err)
try:
device = form['device'].strip()
@@ -87,9 +92,10 @@
raise Exception, 'No device was given for "%s"' % rname
res.addAttribute('device', device)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addFs7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addFs7: %s' % err)
try:
options = form['options'].strip()
@@ -102,9 +108,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addFs8: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addFs8: %s' % err)
try:
fstype = form['fstype'].strip()
@@ -112,9 +119,10 @@
raise Exception, 'No filesystem type was given for "%s"' % rname
res.addAttribute('fstype', fstype)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addFs9: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addFs9: %s' % err)
try:
fsid = form['fsid'].strip()
@@ -153,9 +161,10 @@
raise Exception, 'No mount point was given for "%s"' % rname
res.addAttribute('mountpoint', mountpoint)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addGfs5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addGfs5: %s' % err)
try:
device = form['device'].strip()
@@ -163,9 +172,10 @@
raise Exception, 'No device was given for "%s"' % rname
res.addAttribute('device', device)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addGfs6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addGfs6: %s' % err)
try:
options = form['options'].strip()
@@ -178,9 +188,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addGfs7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addGfs7: %s' % err)
try:
fsid = form['fsid'].strip()
@@ -209,9 +220,10 @@
raise Exception, 'No mount point was given for "%s"' % rname
res.addAttribute('mountpoint', mountpoint)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsm5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsm5: %s' % err)
try:
host = form['host'].strip()
@@ -219,9 +231,10 @@
raise Exception, 'No host server was given for "%s"' % rname
res.addAttribute('host', host)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsm6 error: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsm6 error: %s' % err)
try:
options = form['options'].strip()
@@ -234,9 +247,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsm7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsm7: %s' % err)
try:
exportpath = form['exportpath'].strip()
@@ -244,9 +258,10 @@
raise Exception, 'No export path was given for "%s"' % rname
res.addAttribute('exportpath', exportpath)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsm8: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsm8: %s' % err)
try:
nfstype = form['nfstype'].strip().lower()
@@ -255,9 +270,10 @@
% (nfstype, rname)
res.addAttribute('nfstype', nfstype)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsm9: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsm9: %s' % err)
if form.has_key('forceunmount'):
res.addAttribute('force_unmount', '1')
@@ -275,9 +291,10 @@
raise Exception, 'No target was given for "%s"' % rname
res.addAttribute('target', target)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsc5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsc5: %s' % err)
try:
options = form['options'].strip()
@@ -290,9 +307,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addNfsc6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addNfsc6: %s' % err)
if form.has_key('allow_recover'):
res.addAttribute('allow_recover', '1')
@@ -314,9 +332,10 @@
raise Exception, 'No path to a script file was given for this "%s"' % rname
res.addAttribute('file', path)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addScr5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addScr5: %s' % err)
return errors
@@ -329,9 +348,10 @@
raise Exception, 'No workgroup was given for "%s"' % rname
res.addAttribute('workgroup', workgroup)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addSmb5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addSmb5: %s' % err)
return errors
@@ -344,9 +364,10 @@
raise KeyError, 'No server root was given for "%s"' % rname
res.addAttribute('server_root', server_root)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addApache5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addApache5: %s' % err)
try:
config_file = form['config_file'].strip()
@@ -354,9 +375,10 @@
raise KeyError, 'No path to the Apache configuration file was given for "%s"' % rname
res.addAttribute('config_file', config_file)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addApache6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addApache6: %s' % err)
try:
options = form['httpd_options'].strip()
@@ -369,9 +391,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addApache7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addApache7: %s' % err)
try:
shutdown_wait = int(form['shutdown_wait'].strip())
@@ -379,9 +402,10 @@
except KeyError, e:
res.addAttribute('shutdown_wait', '0')
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addApache7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addApache7: %s' % err)
return errors
@@ -394,9 +418,10 @@
raise KeyError, 'No path to the MySQL configuration file was given for "%s"' % rname
res.addAttribute('config_file', config_file)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addMySQL5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addMySQL5: %s' % err)
try:
listen_addr = form['listen_address'].strip()
@@ -404,9 +429,10 @@
raise KeyError, 'No address was given for "%s"' % rname
res.addAttribute('listen_address', listen_addr)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addMySQL6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addMySQL6: %s' % err)
try:
options = form['mysql_options'].strip()
@@ -419,9 +445,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addMySQL7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addMySQL7: %s' % err)
try:
shutdown_wait = int(form['shutdown_wait'].strip())
@@ -429,9 +456,10 @@
except KeyError, e:
res.addAttribute('shutdown_wait', '0')
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addMySQL7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addMySQL7: %s' % err)
return errors
@@ -444,9 +472,10 @@
raise KeyError, 'No URL list was given for "%s"' % rname
res.addAttribute('url_list', url_list)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addOpenLDAP5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addOpenLDAP5: %s' % err)
try:
config_file = form['config_file'].strip()
@@ -454,9 +483,10 @@
raise KeyError, 'No path to the OpenLDAP configuration file was given for "%s"' % rname
res.addAttribute('config_file', config_file)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addOpenLDAP6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addOpenLDAP6: %s' % err)
try:
options = form['slapd_options'].strip()
@@ -469,9 +499,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addOpenLDAP7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addOpenLDAP7: %s' % err)
try:
shutdown_wait = int(form['shutdown_wait'].strip())
@@ -479,9 +510,10 @@
except KeyError, e:
res.addAttribute('shutdown_wait', '0')
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addOpenLDAP7: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addOpenLDAP7: %s' % err)
return errors
@@ -493,9 +525,10 @@
raise KeyError, 'No postmaster user was given for "%s"' % rname
res.addAttribute('postmaster_user', user)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addPostgreSQL85: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addPostgreSQL85: %s' % err)
try:
config_file = form['config_file'].strip()
@@ -503,9 +536,10 @@
raise KeyError, 'No path to the PostgreSQL 8 configuration file was given for "%s"' % rname
res.addAttribute('config_file', config_file)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addPostgreSQL86: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addPostgreSQL86: %s' % err)
try:
options = form['postmaster_options'].strip()
@@ -518,9 +552,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addPostgreSQL87: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addPostgreSQL87: %s' % err)
try:
shutdown_wait = int(form['shutdown_wait'].strip())
@@ -528,9 +563,10 @@
except KeyError, e:
res.addAttribute('shutdown_wait', '0')
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addPostgreSQL87: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addPostgreSQL87: %s' % err)
return errors
@@ -543,9 +579,10 @@
raise KeyError, 'No Tomcat user was given for "%s"' % rname
res.addAttribute('tomcat_user', user)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addTomcat55: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addTomcat55: %s' % err)
try:
config_file = form['config_file'].strip()
@@ -553,9 +590,10 @@
raise KeyError, 'No path to the Tomcat 5 configuration file was given for "%s"' % rname
res.addAttribute('config_file', config_file)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addTomcat56: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addTomcat56: %s' % err)
try:
options = form['catalina_options'].strip()
@@ -568,9 +606,10 @@
except:
pass
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addTomcat57: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addTomcat57: %s' % err)
try:
catalina_base = form['catalina_base'].strip()
@@ -578,9 +617,10 @@
raise KeyError, 'No cataliny base directory was given for "%s"' % rname
res.addAttribute('catalina_base', catalina_base)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addTomcat58: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addTomcat58: %s' % err)
try:
shutdown_wait = int(form['shutdown_wait'].strip())
@@ -588,9 +628,10 @@
except KeyError, e:
res.addAttribute('shutdown_wait', '0')
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addTomcat59: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addTomcat59: %s' % err)
return errors
@@ -603,9 +644,10 @@
raise KeyError, 'No volume group name was given for "%s"' % rname
res.addAttribute('vg_name', vg_name)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addLVM5: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addLVM5: %s' % err)
try:
lv_name = form['lv_name'].strip()
@@ -613,9 +655,10 @@
raise KeyError, 'No logical volume name was given for "%s"' % rname
res.addAttribute('lv_name', lv_name)
except Exception, e:
- err = str(e)
+ err = repr(e)
errors.append(err)
- luci_log.debug_verbose('addLVM6: %s' % err)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('addLVM6: %s' % err)
return errors
--- conga/luci/site/luci/Extensions/Attic/RicciQueries.py 2007/05/03 20:16:38 1.1.2.1
+++ conga/luci/site/luci/Extensions/Attic/RicciQueries.py 2007/05/14 18:00:14 1.1.2.2
@@ -1,12 +1,10 @@
from xml.dom import minidom
from xml.dom.Node import ELEMENT_NODE
from ricci_communicator import RicciCommunicator, extract_module_status
-from LuciSyslog import LuciSyslog
+from LuciSyslog import get_logger
+from conga_constants import LUCI_DEBUG_MODE
-try:
- luci_log = LuciSyslog()
-except:
- pass
+luci_log = get_logger()
def checkBatch(rc, batch_id):
err_msg = 'An unknown Ricci error occurred on %s' % rc.hostname()
@@ -14,10 +12,14 @@
try:
batch = rc.batch_report(batch_id)
if batch is None:
- luci_log.debug_verbose('checkBatch0: batch id %s was not found' % batch_id)
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('checkBatch0: batch id %s not found' \
+ % batch_id)
return (True, 'batch id %s was not found' % batch_id)
except Exception, e:
- luci_log.debug_verbose('checkBatch0a: %s: %s' % (rc.hostname(), str(e)))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('checkBatch1: %s: %r' \
+ % (rc.hostname(), e))
return (-1, err_msg)
try:
@@ -26,7 +28,9 @@
err_msg = 'A Ricci error occurred on %s: %s' \
% (rc.hostname(), str(new_err_msg))
except Exception, e:
- luci_log.debug_verbose('checkBatch1: %s: %s' % (rc.hostname(), str(e)))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('checkBatch2: %s: %r' \
+ % (rc.hostname(), e))
return (-1, err_msg)
# In progress.
@@ -38,7 +42,8 @@
return (True, 'completed sucessfully')
# Error
- luci_log.debug_verbose('checkBatch2: %d: %s' % (code, rc.hostname()))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('checkBatch3: %d: %s' % (code, rc.hostname()))
return (-1, err_msg)
def addClusterNodeBatch(cluster_name,
@@ -290,7 +295,8 @@
if not batch or len(batch) < 1:
raise Exception, 'no batch tag was found'
except Exception, e:
- luci_log.debug_verbose('batchAttemptResult: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('BAR0: %r' % e)
return (None, None)
for i in batch:
@@ -299,13 +305,15 @@
result = i.getAttribute('status')
return (str(batch_number), str(result))
except Exception, e:
- luci_log.debug_verbose('batchAttemptResult: %s' % str(e))
-
- try:
- luci_log.debug_verbose('no batch with batchid and status found in \"%s\"' % doc.toxml())
- except:
- pass
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('BAR1: %s' % e)
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('BAR2: batchid, status not in \"%s\"' \
+ % doc.toxml())
+ except:
+ pass
return (None, None)
def getClusterStatusBatch(rc):
@@ -315,21 +323,25 @@
try:
cluster_tags = ricci_xml.getElementsByTagName('cluster')
except Exception, e:
- luci_log.debug_verbose('getClusterStatusBatch0: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCSB0: %r' % e)
return None
if len(cluster_tags) < 1:
- luci_log.debug_verbose('getClusterStatusBatch1: %d entries - expecting 1' \
- % len(cluster_tags))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCSB1: %d entries - expecting 1' \
+ % len(cluster_tags))
elif len(cluster_tags) > 1:
- luci_log.debug_verbose('getClusterStatusBatch2: %d entries - expecting 1, using the first' % len(cluster_tags))
-
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCSB2: %d entries, expecting 1 use first' \
+ % len(cluster_tags))
try:
cluster_node = cluster_tags[0]
if not cluster_node:
raise Exception, 'element 0 is None'
except Exception, e:
- luci_log.debug_verbose('getClusterStatusBatch3: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCSB3: %r' % e)
return None
try:
@@ -337,12 +349,13 @@
doc.appendChild(cluster_node)
return doc
except Exception, e:
- luci_log.debug_verbose('getClusterStatusBatch4: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCSB4: %r' % e)
return None
def setClusterConf(rc, clusterconf, propagate=True):
- if propagate == True:
+ if propagate is True:
propg = 'true'
else:
propg = 'false'
@@ -372,8 +385,9 @@
if not log_entries or len(log_entries) < 1:
raise Exception, 'no log data is available.'
except Exception, e:
- luci_log.debug_verbose('Error retrieving log data from %s: %s' \
- % (rc.hostname(), str(e)))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GNL0: retrieving log data from %s: %r' \
+ % (rc.hostname(), e))
return None
time_now = time()
@@ -524,7 +538,7 @@
else:
raise Exception, op
except Exception, e:
- elem.setAttribute('message', 'Unknown operation: %s' % str(e))
+ elem.setAttribute('message', 'Unknown operation: %r' % e)
doc.appendChild(elem)
return doc
@@ -564,13 +578,15 @@
batch_str = '<module name="service"><request API_version="1.0"><function_call name="list"><var mutable="false" name="description" type="boolean" value="true"/></function_call></request></module>'
ricci_xml = rc.batch_run(batch_str, async=False)
if not ricci_xml or not ricci_xml.firstChild:
- luci_log.debug_verbose('LS0: None returned')
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('LS0: None returned')
return None
try:
service_tags = ricci_xml.getElementsByTagName('service')
return service_tags
except Exception, e:
- luci_log.debug_verbose('LS1: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('LS1: %r' % e)
return None
def nodeIsVirtual(rc):
@@ -578,13 +594,15 @@
ricci_xml = rc.batch_run(batch_str, async=False)
if not ricci_xml or not ricci_xml.firstChild:
- luci_log.debug_verbose('nodeIsVirtual0: None returned')
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('nodeIsVirtual0: None returned')
return None
var_tags = ricci_xml.getElementsByTagName('var')
if not var_tags or len(var_tags) < 2:
- luci_log.debug_verbose('nodeIsVirtual1: unexpected response %s' \
- % ricci_xml.toxml())
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('nodeIsVirtual1: unexpected response %s' \
+ % ricci_xml.toxml())
return None
success = False
@@ -605,7 +623,8 @@
else:
raise Exception, 'unexpected attribute name: %s' % name
except Exception, e:
- luci_log.debug_verbose('nodeIsVirtual2: error: %s' % str(e))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('nodeIsVirtual2: error: %r' % e)
if not success:
return None
@@ -621,7 +640,8 @@
ricci_xml = rc.batch_run(''.join(batch_list), async=False)
if not ricci_xml or not ricci_xml.firstChild:
- luci_log.debug_verbose('no ricci_xml in getDaemonStates')
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GDS0: no ricci_xml')
return None
result = extractDaemonInfo(ricci_xml.firstChild)
return result
@@ -710,16 +730,18 @@
if rc is None:
raise Exception, 'unknown error'
except Exception, e:
- luci_log.debug_verbose('Ricci error while connecting to %s: %s' \
- % (system_info, str(e)))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCC0: connecting to %s: %r' \
+ % (system_info, e))
return None
# end workaround
try:
ret = rc.process_batch(batch)
except Exception, e:
- luci_log.debug_verbose('process_batch error for %s: %s' \
- % (system_info, str(e)))
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCC1: process_batch error for %s: %r' \
+ % (system_info, e))
return None
if not ret:
--- conga/luci/site/luci/Extensions/cluster_adapters.py 2007/05/08 22:19:35 1.255.2.3
+++ conga/luci/site/luci/Extensions/cluster_adapters.py 2007/05/14 18:00:14 1.255.2.4
@@ -1,8 +1,5 @@
from xml.dom import minidom
import AccessControl
-from conga_constants import *
-import RicciQueries as rq
-from ricci_communicator import RicciCommunicator, RicciError, batch_status, extract_module_status
from ClusterModel.ModelBuilder import ModelBuilder
from ClusterModel.FailoverDomain import FailoverDomain
@@ -19,22 +16,31 @@
from ClusterModel.Method import Method
from ClusterModel.GeneralError import GeneralError
+import RicciQueries as rq
from HelperFunctions import resolveOSType
-from LuciSyslog import LuciSyslog
+from LuciSyslog import get_logger
from ResourceHandler import create_resource
-from FenceHandler import validateNewFenceDevice, FENCE_OPTS, validateFenceDevice, validate_fenceinstance, FD_VAL_FAIL, FD_VAL_SUCCESS
-
from system_adapters import validate_svc_update
-
from homebase_adapters import parseHostForm
from LuciZope import userAuthenticated
+from LuciClusterInfo import getClusterInfo
+
+from conga_constants import *
-from LuciDB import manageCluster, createClusterSystems, havePermCreateCluster, setNodeFlag, delNodeFlag, getStorageNode, getClusterNode, delCluster, buildClusterCreateFlags, noNodeFlagsPresent, resolve_nodename, set_node_flag
+from FenceHandler import validateNewFenceDevice, FENCE_OPTS, \
+ validateFenceDevice, validate_fenceinstance, \
+ FD_VAL_FAIL, FD_VAL_SUCCESS
+
+from ricci_communicator import RicciCommunicator, RicciError, \
+ batch_status, extract_module_status
+
+from LuciDB import manageCluster, createClusterSystems, \
+ havePermCreateCluster, setNodeStatus, getStorageNode, \
+ getClusterNode, delCluster, buildClusterCreateFlags, \
+ noNodeStatussPresent, resolve_nodename, set_node_flag, \
+ getRicciAgent
-try:
- luci_log = LuciSyslog()
-except:
- pass
+luci_log = get_logger()
def parseClusterNodes(self, request, cluster_os):
check_certs = False
@@ -58,7 +64,7 @@
if clusterName is None:
luci_log.debug_verbose('PCN0: no cluster name was given')
- return (False, { 'errors': [ 'No cluster name was given.' ]})
+ return (False, { 'errors': [ 'No cluster name was given' ]})
shared_storage = False
try:
@@ -111,7 +117,7 @@
try:
if prev_auth:
- messages.append('Host %s is already authenticated.' \
+ messages.append('Host %s is already authenticated' \
% cur_host)
else:
rc.auth(cur_passwd)
@@ -190,7 +196,7 @@
clusterName = add_cluster['name']
if len(clusterName) > 15:
- errors.append('A cluster\'s name must be less than 16 characters long.')
+ errors.append('A cluster\'s name must be less than 16 characters long')
try:
cluster_os = add_cluster['cluster_os']
@@ -219,9 +225,9 @@
raise Exception, 'blank'
num_lockservers = len(lockservers)
if not num_lockservers in (1, 3, 5):
- errors.append('You must have exactly 1, 3, or 5 GULM lock servers. You submitted %d lock servers.' % num_lockservers)
+ errors.append('You must have exactly 1, 3, or 5 GULM lock servers. You submitted %d lock servers' % num_lockservers)
except:
- errors.append('No lock servers were given.')
+ errors.append('No lock servers were given')
if len(errors) > 0:
try:
@@ -326,7 +332,7 @@
if clusterName is None:
luci_log.debug_verbose('VACN0: no cluster name was given')
- return (False, { 'errors': [ 'No cluster name was given.' ]})
+ return (False, { 'errors': [ 'No cluster name was given' ]})
if cluster_os is None:
cluster_folder = None
@@ -336,7 +342,7 @@
raise Exception, 'cluster DB object is missing'
except Exception, e:
luci_log.debug_verbose('VACN1: %s: %s' % (clusterName, str(e)))
- return (False, { 'errors': [ 'The database object for %s is missing.' % clusterName ] })
+ return (False, { 'errors': [ 'The database object for %s is missing' % clusterName ] })
try:
cluster_os = cluster_folder.manage_getProperty('cluster_os')
@@ -356,7 +362,7 @@
if cluster_os is None:
luci_log.debug_verbose('Unable to determine cluster OS for %s' % clusterName)
- return (False, { 'errors': [ 'Unable to determine the version of the cluster suite this cluster is running.' ] })
+ return (False, { 'errors': [ 'Unable to determine the version of the cluster suite this cluster is running' ] })
shared_storage = False
try:
@@ -409,7 +415,7 @@
try:
if prev_auth:
- messages.append('Host %s is already authenticated.' \
+ messages.append('Host %s is already authenticated' \
% cur_host)
else:
rc.auth(cur_passwd)
@@ -473,7 +479,7 @@
raise Exception, 'Unable to find a ricci agent for %s' % clusterName
except Exception, e:
incomplete = True
- errors.append('Unable to contact a ricci agent for %s.' % clusterName)
+ errors.append('Unable to contact a ricci agent for %s' % clusterName)
luci_log.debug_verbose('VACN10: %s: %s' % (clusterName, str(e)))
if incomplete or len(errors) > 0:
@@ -554,14 +560,14 @@
model.setModified(True)
conf_str = str(model.exportModelAsString())
if not conf_str:
- raise Exception, 'Unable to save the new cluster model.'
+ raise Exception, 'Unable to save the new cluster model'
batch_number, result = rq.setClusterConf(cluster_ricci, conf_str)
if not batch_number or not result:
raise Exception, 'batch or result is None'
except Exception, e:
incomplete = True
- errors.append('Unable to save the new cluster model.')
+ errors.append('Unable to save the new cluster model')
luci_log.debug_verbose('VACN14: %s' % str(e))
# Propagate the new cluster.conf to the existing nodes
@@ -648,7 +654,7 @@
raise KeyError, 'form_xml must not be blank'
except Exception, e:
luci_log.debug_verbose('vSA0: no form_xml: %s' % str(e))
- return (False, {'errors': ['No resource data was supplied for this service.']})
+ return (False, {'errors': ['No resource data was supplied for this service']})
try:
model = request.SESSION.get('model')
@@ -656,7 +662,7 @@
raise Exception, 'model is None'
except Exception, e:
luci_log.debug_verbose('vSA0a: %s' % str(e))
- return (False, {'errors': [ 'The cluster model is missing from the session object.' ]})
+ return (False, {'errors': [ 'The cluster model is missing from the session object' ]})
try:
doc = minidom.parseString(form_xml)
@@ -665,7 +671,7 @@
raise
except Exception, e:
luci_log.debug_verbose('vSA1: error: %s' % str(e))
- return (False, {'errors': ['The resource data submitted for this service is not properly formed.']})
+ return (False, {'errors': ['The resource data submitted for this service is not properly formed']})
form_hash = {}
form_hash['toplevel'] = {'form': None, 'kids': [] }
@@ -711,11 +717,11 @@
dummy_form['resourceName'] = dummy_form['ip_address']
except Exception, e:
luci_log.debug_verbose('vSA3a: type is ip but no addr: %s' % str(e))
- return (False, {'errors': [ 'No IP address was given.' ]})
+ return (False, {'errors': [ 'No IP address was given' ]})
try:
if dummy_form.has_key('immutable'):
- newRes = getResource(model, dummy_form['resourceName'])
+ newRes = model.getResourceByName(dummy_form['resourceName'])
resObj = RefObject(newRes)
resObj.setRef(newRes.getName())
else:
@@ -754,7 +760,7 @@
service_name = request.form['svc_name'].strip()
except Exception, e:
luci_log.debug_verbose('vSA5: no service name: %s' % str(e))
- return (False, {'errors': [ 'No service name was given.' ]})
+ return (False, {'errors': [ 'No service name was given' ]})
autostart = "1"
try:
@@ -785,14 +791,14 @@
try:
if request.form['action'] == 'edit':
if cur_service is None:
- return (False, {'errors': [ 'The service %s could not be found for editing.' % service_name ]})
+ return (False, {'errors': [ 'The service %s could not be found for editing' % service_name ]})
model.deleteService(service_name)
elif request.form['action'] == 'add':
if cur_service is not None:
- return (False, {'errors': [ 'A service with the name %s already exists.' % service_name ]})
+ return (False, {'errors': [ 'A service with the name %s already exists' % service_name ]})
else:
luci_log.debug_verbose('vSA4a: unknown action %s' % request.form['action'])
- return (False, {'errors': [ 'An unknown action was specified.' ]})
+ return (False, {'errors': [ 'An unknown action was specified' ]})
except Exception, e:
luci_log.debug_verbose('vSA5: no action type: %s' % str(e))
@@ -835,7 +841,7 @@
except Exception, e:
luci_log.debug_verbose('vAS6a: exportModelAsString : %s' \
% str(e))
- return (False, {'errors': [ 'An error occurred while adding this service.' ]})
+ return (False, {'errors': [ 'An error occurred while adding this service' ]})
rc = getRicciAgent(self, clustername)
if not rc:
@@ -851,7 +857,7 @@
batch_number, result = rq.setClusterConf(rc, str(conf))
if batch_number is None or result is None:
luci_log.debug_verbose('vAS8: missing batch_number or result')
- raise Exception, 'unable to save the new cluster configuration.'
+ raise Exception, 'unable to save the new cluster configuration'
except Exception, e:
luci_log.debug_verbose('vAS9: %s' % str(e))
return 'An error occurred while propagating the new cluster.conf: %s' % str(e)
@@ -875,7 +881,7 @@
raise KeyError, 'type is blank'
except Exception, e:
luci_log.debug_verbose('VRA0: type is blank')
- return (False, {'errors': ['No resource type was given.']})
+ return (False, {'errors': ['No resource type was given']})
try:
model = request.SESSION.get('model')
@@ -912,7 +918,7 @@
try:
gulm_ptr = model.getGULMPtr()
if gulm_ptr:
- return (False, {'errors': ['Multicast cannot be used with GULM locking.']})
+ return (False, {'errors': ['Multicast cannot be used with GULM locking']})
except:
pass
@@ -946,7 +952,7 @@
addr_str = None
if (addr_str is None and mcast_manual != True) or (mcast_manual == True and addr_str == model.getMcastAddr()):
- errors.append('No multicast configuration changes were made.')
+ errors.append('No multicast configuration changes were made')
return (False, {'errors': errors})
try:
@@ -1044,7 +1050,7 @@
if num_heuristics < 1:
raise ValueError, form['num_heuristics']
except KeyError, e:
- errors.append('No number of heuristics was given.')
+ errors.append('No number of heuristics was given')
except ValueError, e:
errors.append('An invalid number of heuristics was given: %s' % str(e))
@@ -1135,20 +1141,20 @@
if not cluster_name:
raise KeyError('cluname')
except KeyError, e:
- errors.append('No cluster name was given.')
+ errors.append('No cluster name was given')
if len(cluster_name) > 15:
- errors.append('A cluster\'s name must be less than 16 characters long.')
+ errors.append('A cluster\'s name must be less than 16 characters long')
try:
version_num = int(form['cfgver'])
if version_num < old_ver:
- raise ValueError, 'configuration version number must be %d or greater.' % old_ver
+ raise ValueError, 'configuration version number must be %d or greater' % old_ver
if version_num != old_ver:
# we'll increment the cluster version before propagating it.
version_num -= 1
except KeyError, e:
- errors.append('No cluster configuration version was given.')
+ errors.append('No cluster configuration version was given')
except ValueError, e:
errors.append('An invalid configuration version was given: %s' % str(e))
@@ -1159,7 +1165,7 @@
cp.setConfigVersion(str(version_num))
except Exception, e:
luci_log.debug_verbose('unable to update general properties: %s' % str(e))
- errors.append('Unable to update the cluster configuration.')
+ errors.append('Unable to update the cluster configuration')
try:
cluster_version = form['cluster_version'].strip()
@@ -1246,23 +1252,23 @@
errors = list()
if model.getGULMPtr() is not None:
- return (False, {'errors': [ 'GULM clusters do not support fenced.' ]})
+ return (False, {'errors': [ 'GULM clusters do not support fenced' ]})
try:
post_fail_delay = int(form['post_fail_delay'])
if post_fail_delay < 0:
- raise ValueError('post fail delay values must be 0 or greater.')
+ raise ValueError('post fail delay values must be 0 or greater')
except KeyError, e:
- errors.append('No post fail delay was given.')
+ errors.append('No post fail delay was given')
except ValueError, e:
errors.append('Invalid post fail delay: %s' % str(e))
try:
post_join_delay = int(form['post_join_delay'])
if post_join_delay < 0:
- raise ValueError('post join delay values must be 0 or greater.')
+ raise ValueError('post join delay values must be 0 or greater')
except KeyError, e:
- errors.append('No post join delay was given.')
+ errors.append('No post join delay was given')
except ValueError, e:
errors.append('Invalid post join delay: %s' % str(e))
@@ -1284,13 +1290,13 @@
old_pf_delay = fd.getPostFailDelay()
if post_join_delay == old_pj_delay and post_fail_delay == old_pf_delay:
- errors.append('No fence daemon properties were changed.')
+ errors.append('No fence daemon properties were changed')
else:
fd.setPostJoinDelay(str(post_join_delay))
fd.setPostFailDelay(str(post_fail_delay))
except Exception, e:
luci_log.debug_verbose('Unable to update fence daemon properties: %s' % str(e))
- errors.append('An error occurred while attempting to update fence daemon properties.')
+ errors.append('An error occurred while attempting to update fence daemon properties')
if len(errors) > 0:
return (False, {'errors': errors })
@@ -1300,7 +1306,7 @@
def validateGULMConfig(model, form):
gulm_ptr = model.getGULMPtr()
if not gulm_ptr:
- return (False, {'errors': [ 'This cluster appears not to be using GULM locking.' ]})
+ return (False, {'errors': [ 'This cluster appears not to be using GULM locking' ]})
node_list = map(lambda x: x.getName(), gulm_ptr.getChildren())
for i in map(lambda x: x.getName(), model.getNodes()):
@@ -1327,7 +1333,7 @@
num_ls = len(gulm_lockservers)
if not num_ls in (1, 3, 5):
- return (False, {'errors': [ 'You must have exactly 1, 3, or 5 GULM lock servers. You submitted %d lock servers.' % num_ls ]})
+ return (False, {'errors': [ 'You must have exactly 1, 3, or 5 GULM lock servers. You submitted %d lock servers' % num_ls ]})
model.GULM_ptr.children = gulm_lockservers
return (True, {})
@@ -1341,123 +1347,110 @@
}
def validateConfigCluster(self, request):
- errors = list()
- messages = list()
- rc = None
+ errors = list()
+ messages = list()
+ rc = None
- try:
- model = request.SESSION.get('model')
- if not model:
- raise Exception, 'model is none'
- except Exception, e:
- model = None
- try:
- cluname = request.form['clustername']
- except:
- try:
- cluname = request['clustername']
- except:
- luci_log.debug_verbose('VCC0a: no model, no cluster name')
- return (False, {'errors': ['No cluster model was found.']})
+ try:
+ model = LuciExtractCluModel(self, request)
+ except Exception, e:
+ luci_log.debug_verbose('VCC0a: no model, no cluster name')
+ return (False, {'errors': ['No cluster model was found']})
- try:
- model = getModelForCluster(self, cluname)
- except:
- model = None
+ try:
+ if not request.form.has_key('configtype'):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('VCC2: no configtype')
+ raise Exception, 'no config type'
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('VCC2a: %r' % e)
+ return (False, {'errors': [ 'No configuration type was submitted' ]})
- if model is None:
- luci_log.debug_verbose('VCC0: unable to get model from session')
- return (False, {'errors': ['No cluster model was found.']})
- try:
- if not 'configtype' in request.form:
- luci_log.debug_verbose('VCC2: no configtype')
- raise Exception, 'no config type'
- except Exception, e:
- luci_log.debug_verbose('VCC2a: %s' % str(e))
- return (False, {'errors': ['No configuration type was submitted.']})
+ if not configFormValidators.has_key(request.form['configtype']):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('VCC3: invalid config type: %s' \
+ % request.form['configtype'])
+ return (False, { 'errors': [ 'An invalid configuration type was submitted' ]})
- if not request.form['configtype'] in configFormValidators:
- luci_log.debug_verbose('VCC3: invalid config type: %s' % request.form['configtype'])
- return (False, {'errors': ['An invalid configuration type was submitted.']})
+ try:
+ cp = model.getClusterPtr()
+ except:
+ luci_log.debug_verbose('VCC3a: getClusterPtr failed')
+ return (False, {'errors': ['No cluster model was found']})
- try:
- cp = model.getClusterPtr()
- except:
- luci_log.debug_verbose('VCC3a: getClusterPtr failed')
- return (False, {'errors': ['No cluster model was found.']})
+ config_validator = configFormValidators[request.form['configtype']]
+ ret = config_validator(model, request.form)
- config_validator = configFormValidators[request.form['configtype']]
- ret = config_validator(model, request.form)
+ retcode = ret[0]
+ if 'errors' in ret[1]:
+ errors.extend(ret[1]['errors'])
- retcode = ret[0]
- if 'errors' in ret[1]:
- errors.extend(ret[1]['errors'])
+ if 'messages' in ret[1]:
+ messages.extend(ret[1]['messages'])
- if 'messages' in ret[1]:
- messages.extend(ret[1]['messages'])
+ if retcode is True:
+ try:
+ config_ver = int(cp.getConfigVersion()) + 1
+ # always increment the configuration version
+ cp.setConfigVersion(str(config_ver))
+ model.setModified(True)
+ conf_str = model.exportModelAsString()
+ if not conf_str:
+ raise Exception, 'conf_str is none'
+ except Exception, e:
+ luci_log.debug_verbose('VCC4: export model as string failed: %s' \
+ % str(e))
+ errors.append('Unable to store the new cluster configuration')
- if retcode == True:
- try:
- config_ver = int(cp.getConfigVersion()) + 1
- # always increment the configuration version
- cp.setConfigVersion(str(config_ver))
- model.setModified(True)
- conf_str = model.exportModelAsString()
- if not conf_str:
- raise Exception, 'conf_str is none'
- except Exception, e:
- luci_log.debug_verbose('VCC4: export model as string failed: %s' \
- % str(e))
- errors.append('Unable to store the new cluster configuration')
+ try:
+ clustername = model.getClusterName()
+ if not clustername:
+ raise Exception, 'cluster name from model.getClusterName() is blank'
+ except Exception, e:
+ luci_log.debug_verbose('VCC5: error: getClusterName: %r' % e)
+ errors.append('Unable to determine cluster name from model')
- try:
- clustername = model.getClusterName()
- if not clustername:
- raise Exception, 'cluster name from model.getClusterName() is blank'
- except Exception, e:
- luci_log.debug_verbose('VCC5: error: getClusterName: %s' % str(e))
- errors.append('Unable to determine cluster name from model')
+ if len(errors) > 0:
+ return (retcode, {'errors': errors, 'messages': messages})
- if len(errors) > 0:
- return (retcode, {'errors': errors, 'messages': messages})
+ if not rc:
+ rc = getRicciAgent(self, clustername)
+ if not rc:
+ luci_log.debug_verbose('VCC6: unable to find a ricci agent for the %s cluster' % clustername)
+ errors.append('Unable to contact a ricci agent for cluster %s' \
+ % clustername)
- if not rc:
- rc = getRicciAgent(self, clustername)
- if not rc:
- luci_log.debug_verbose('VCC6: unable to find a ricci agent for the %s cluster' % clustername)
- errors.append('Unable to contact a ricci agent for cluster %s' \
- % clustername)
-
- if rc:
- batch_id, result = rq.setClusterConf(rc, str(conf_str))
- if batch_id is None or result is None:
- luci_log.debug_verbose('VCC7: setCluserConf: batchid or result is None')
- errors.append('Unable to propagate the new cluster configuration for %s' \
- % clustername)
- else:
- try:
- set_node_flag(self, clustername, rc.hostname(), batch_id, CLUSTER_CONFIG, 'Updating cluster configuration')
- except:
- pass
+ if rc:
+ batch_id, result = rq.setClusterConf(rc, str(conf_str))
+ if batch_id is None or result is None:
+ luci_log.debug_verbose('VCC7: setCluserConf: batchid or result is None')
+ errors.append('Unable to propagate the new cluster configuration for %s' % clustername)
+ else:
+ try:
+ set_node_flag(self, clustername, rc.hostname(), batch_id, CLUSTER_CONFIG, 'Updating cluster configuration')
+ except:
+ pass
- if len(errors) < 1:
- messages.append('The cluster properties have been updated.')
- else:
- return (retcode, {'errors': errors, 'messages': messages})
+ if len(errors) < 1:
+ messages.append('The cluster properties have been updated')
+ else:
+ return (retcode, {'errors': errors, 'messages': messages})
- response = request.RESPONSE
- response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
- % (request['URL'], CLUSTER_CONFIG, clustername))
+ response = request.RESPONSE
+ response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
+ % (request['URL'], CLUSTER_CONFIG, clustername))
def LuciExtractCluName(self, request):
cluname = None
+
try:
- cluname = request.form['clustername']
- except Exception, e:
- try:
- cluname = request['clustername']
- except Exception, e:
- cluname = None
+ if request.form.has_key('clustername'):
+ cluname = request.form['clustername'].strip()
+ if not cluname and request.has_key('clustername'):
+ cluname = request['clustername'].strip()
+ except Exception, e:
+ pass
if not cluname:
luci_log.debug_verbose('LECN0: no cluster name')
@@ -1482,49 +1475,38 @@
if not model:
luci_log.debug_verbose('LECM1: empty model')
model = None
- except Exception, e:
+ except Exception, e:
luci_log.debug_verbose('LECM2: no model: %s' % str(e))
model = None
return model
-def LuciFenceAddReq(self, request):
+def validateFenceAdd(self, request):
+ errors = list()
+
model = LuciExtractCluModel(self, request)
+
if not model:
luci_log.debug_verbose('VFE0: no model')
- return (False, [ 'No cluster model was found.' ])
-
- ret = validateFenceAdd(request, model)
- if ret[0] is not True:
- return (False, { 'errors': ret[1] })
-
-def validateFenceAdd(request, model):
- errors = list()
- messages = list()
+ return (False, [ 'No cluster model was found' ])
if not request.form:
luci_log.debug_verbose('VFE: no form was submitted')
- return (False, [ 'No form was submitted '])
+ return (False, [ 'No form was submitted' ])
- ret_code, ret_msgs = validateNewFenceDevice(form, model)
- if error_code != FD_VAL_SUCCESS:
- if ret_msgs:
- errors.extend(ret_msgs)
+ ret_code, ret_obj = validateNewFenceDevice(request.form, model)
+ if ret_code != FD_VAL_SUCCESS:
+ errors.extend(ret_obj)
return (False, errors)
- if ret_msgs:
- messages.extend(ret_msgs)
- return (True, ret_msgs)
-
- try:
- conf_str = model.exportModelAsString()
- if not conf_str:
- raise Exception, 'conf_str is none'
- except Exception, e:
- luci_log.debug_verbose('VFE: export model as string failed: %s' \
- % str(e))
- errors.append('Unable to store the new cluster configuration')
- response.redirect('%s?pagetype=%s&clustername=%s&fencename=%s&busyfirst=true' % (request['URL'], FENCEDEV, clustername, retobj))
+ try:
+ conf_str = str(model.exportModelAsString())
+ if not conf_str:
+ raise Exception, 'conf_str is none'
+ except Exception, e:
+ luci_log.debug_verbose('VFE: export model as string failed: %r' % e)
+ errors.append('Unable to store the new cluster configuration')
+ request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&fencename=%s&busyfirst=true' % (request['URL'], FENCEDEV, model.getClusterName(), ret_obj.getAttribute('name')))
def validateFenceEdit(self, request):
errors = list()
@@ -1544,7 +1526,7 @@
cluname = request['clustername']
except:
luci_log.debug_verbose('VFE: no model, no cluster name')
- return (False, {'errors': ['No cluster model was found.']})
+ return (False, {'errors': ['No cluster model was found']})
try:
model = getModelForCluster(self, cluname)
@@ -1553,7 +1535,7 @@
if model is None:
luci_log.debug_verbose('VFE: unable to get model from session')
- return (False, {'errors': ['No cluster model was found.']})
+ return (False, {'errors': ['No cluster model was found']})
form = None
try:
@@ -1626,13 +1608,13 @@
raise KeyError, 'form_xml must not be blank'
except Exception, e:
luci_log.debug_verbose('vNFC0: no form_xml: %s' % str(e))
- return (False, {'errors': ['No fence data was supplied.']})
+ return (False, {'errors': ['No fence data was supplied']})
try:
fence_level = int(request.form['fence_level'].strip())
except Exception, e:
luci_log.debug_verbose('vNFC1: no fence level: %s' % str(e))
- return (False, {'errors': ['No fence level was supplied.']})
+ return (False, {'errors': ['No fence level was supplied']})
try:
nodename = request['nodename']
@@ -1640,7 +1622,7 @@
raise Exception, 'nodename is blank'
except Exception, e:
luci_log.debug_verbose('vNFC2: no nodename: %s' % str(e))
- return (False, {'errors': ['No node name was given.']})
+ return (False, {'errors': ['No node name was given']})
try:
clustername = request['clustername']
@@ -1648,7 +1630,7 @@
raise Exception, 'clustername is blank'
except Exception, e:
luci_log.debug_verbose('vNFC3: no clustername: %s' % str(e))
- return (False, {'errors': ['No cluster name was given.']})
+ return (False, {'errors': ['No cluster name was given']})
try:
model = request.SESSION.get('model')
@@ -1663,19 +1645,19 @@
if model is None:
luci_log.debug_verbose('vNFC4: unable to get model for cluster %s' % clustername)
- return (False, {'errors': ['No cluster model was found.']})
+ return (False, {'errors': ['No cluster model was found']})
try:
doc = minidom.parseString(form_xml)
except Exception, e:
luci_log.debug_verbose('vNFC5: error: %s' % str(e))
- return (False, {'errors': ['The fence data submitted is not properly formed.']})
+ return (False, {'errors': ['The fence data submitted is not properly formed']})
try:
node = model.retrieveNodeByName(nodename)
except GeneralError, e:
luci_log.debug_verbose('vNFC6: unable to find node name %s in current node list' % (str(nodename), str(e)))
- return (False, {'errors': ['Unable to find the cluster node %s in the node list.' % str(nodename) ]})
+ return (False, {'errors': ['Unable to find the cluster node %s in the node list' % str(nodename) ]})
fence_level_num = int(fence_level)
levels = node.getFenceLevels()
@@ -1706,7 +1688,7 @@
luci_log.debug_verbose('vNFC6a: %s: %s' % (method_id, str(e)))
return (False, {'errors': ['An error occurred while deleting fence method %s' % method_id ]})
else:
- return (True, {'messages': ['No changes were made.'] })
+ return (True, {'messages': ['No changes were made'] })
form_hash = {}
for i in forms:
@@ -1742,14 +1724,14 @@
parent = dummy_form['parent_fencedev']
except:
luci_log.debug_verbose('vNFC9: no parent for instance')
- return (False, {'errors': [ 'Unable to determine what device the current instance uses.' ]})
+ return (False, {'errors': [ 'Unable to determine what device the current instance uses' ]})
try:
form_hash[parent][1].append(dummy_form)
del dummy_form['fence_instance']
except Exception, e:
luci_log.debug_verbose('vNFC10: no parent for instance')
- return (False, {'errors': [ 'Unable to determine what device the current instance uses.' ]})
+ return (False, {'errors': [ 'Unable to determine what device the current instance uses' ]})
else:
form_hash[form_id] = (dummy_form, list())
@@ -1779,7 +1761,7 @@
if not fencedev_name.strip():
raise Exception, 'no fence name'
except Exception, e:
- errors.append('You must provide a unique name for all fence devices.')
+ errors.append('You must provide a unique name for all fence devices')
continue
if fence_type is None:
@@ -1870,7 +1852,7 @@
except Exception, e:
luci_log.debug_verbose('vNFC17: exportModelAsString failed: %s' \
% str(e))
- return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
+ return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
rc = getRicciAgent(self, clustername)
if not rc:
@@ -1881,7 +1863,7 @@
batch_number, result = rq.setClusterConf(rc, conf)
if batch_number is None or result is None:
luci_log.debug_verbose('vNFC19: missing batch and/or result')
- return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
+ return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
try:
set_node_flag(self, clustername, ragent, str(batch_number), FENCEDEV_NODE_CONFIG, "Updating fence configuration for node \'%s\'" % nodename)
@@ -1909,7 +1891,7 @@
cluname = request['clustername']
except:
luci_log.debug_verbose('VFE: no model, no cluster name')
- return (False, {'errors': ['No cluster model was found.']})
+ return (False, {'errors': ['No cluster model was found']})
try:
model = getModelForCluster(self, cluname)
@@ -1918,11 +1900,11 @@
if model is None:
luci_log.debug_verbose('VFE: unable to get model from session')
- return (False, {'errors': ['No cluster model was found.']})
+ return (False, {'errors': ['No cluster model was found']})
form = None
try:
- response = request.response
+ response = request.RESPONSE
form = request.form
if not form:
form = None
@@ -2110,7 +2092,7 @@
raise Exception, 'no model'
except Exception, e:
luci_log.debug_verbose('validateFdom0: no model: %s' % str(e))
- return (False, {'errors': [ 'Unable to retrieve cluster information.' ]})
+ return (False, {'errors': [ 'Unable to retrieve cluster information' ]})
prioritized = False
try:
@@ -2138,14 +2120,14 @@
clustername = None
if not clustername:
- errors.append('Unable to determine this cluster\'s name.')
+ errors.append('Unable to determine this cluster\'s name')
try:
name = request.form['name'].strip()
if not name:
raise Exception, 'blank'
except Exception, e:
- errors.append('No name was given for this failover domain.')
+ errors.append('No name was given for this failover domain')
luci_log.debug_verbose('validateFdom0: %s' % str(e))
oldname = None
@@ -2158,14 +2140,14 @@
if oldname is None or oldname != name:
if model.getFailoverDomainByName(name) is not None:
- errors.append('A failover domain named "%s" already exists.' % name)
+ errors.append('A failover domain named "%s" already exists' % name)
fdom = None
if oldname is not None:
fdom = model.getFailoverDomainByName(oldname)
if fdom is None:
luci_log.debug_verbose('validateFdom1: No fdom named %s exists' % oldname)
- errors.append('No failover domain named "%s" exists.' % oldname)
+ errors.append('No failover domain named "%s" exists' % oldname)
else:
fdom.addAttribute('name', name)
fdom.children = list()
@@ -2211,7 +2193,7 @@
conf = str(model.exportModelAsString())
except Exception, e:
luci_log.debug_verbose('validateFdom2: %s' % str(e))
- errors.append('Unable to update the cluster configuration.')
+ errors.append('Unable to update the cluster configuration')
if len(errors) > 0:
return (False, {'errors': errors })
@@ -2225,7 +2207,7 @@
batch_number, result = rq.setClusterConf(rc, conf)
if batch_number is None or result is None:
luci_log.debug_verbose('validateFdom4: missing batch and/or result')
- return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
+ return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
try:
if oldname:
@@ -2250,7 +2232,7 @@
raise Exception, 'blank'
except Exception, e:
luci_log.debug_verbose('validateVM0: no vm name: %s' % str(e))
- errors.append('No virtual machine name was given.')
+ errors.append('No virtual machine name was given')
try:
vm_path = request.form['vmpath'].strip()
@@ -2258,7 +2240,7 @@
raise Exception, 'blank'
except Exception, e:
luci_log.debug_verbose('validateVM1: no vm path: %s' % str(e))
- errors.append('No path to the virtual machine configuration file was given.')
+ errors.append('No path to the virtual machine configuration file was given')
autostart = 1
try:
@@ -2318,7 +2300,7 @@
rmptr.removeChild(xvm)
delete_vm = True
except:
- return (False, {'errors': ['No virtual machine service named "%s" exists.' % old_name ]})
+ return (False, {'errors': ['No virtual machine service named "%s" exists' % old_name ]})
else:
if isNew is True:
xvm = Vm()
@@ -2332,7 +2314,7 @@
if not xvm:
raise Exception, 'not found'
except:
- return (False, {'errors': ['No virtual machine service named "%s" exists.' % old_name ]})
+ return (False, {'errors': ['No virtual machine service named "%s" exists' % old_name ]})
xvm.addAttribute('name', vm_name)
xvm.addAttribute('path', vm_path)
@@ -2369,7 +2351,7 @@
raise Exception, 'cluster name from model.getClusterName() is blank'
except Exception, e:
luci_log.debug_verbose('validateVM3: %s' % str(e))
- errors.append('Unable to determine the cluster name.')
+ errors.append('Unable to determine the cluster name')
if len(errors) > 0:
return (False, {'errors': errors })
@@ -2377,12 +2359,12 @@
rc = getRicciAgent(self, clustername)
if not rc:
luci_log.debug_verbose('validateVM4: no ricci for %s' % clustername)
- return (False, {'errors': ['Unable to contact a ricci agent for this cluster.']})
+ return (False, {'errors': ['Unable to contact a ricci agent for this cluster']})
batch_number, result = rq.setClusterConf(rc, stringbuf)
if batch_number is None or result is None:
luci_log.debug_verbose('validateVM5: missing batch and/or result')
- return (False, {'errors': [ 'Error creating virtual machine %s.' % vm_name ]})
+ return (False, {'errors': [ 'Error creating virtual machine %s' % vm_name ]})
try:
if delete_vm is True:
@@ -2542,13 +2524,6 @@
return dummynode
-def getnodes(self, model):
- try:
- return map(lambda x: str(x.getName()), model.getNodes())
- except Exception, e:
- luci_log.debug_verbose('getnodes0: %s' % str(e))
- return []
-
def createCluConfigTree(self, request, model):
dummynode = {}
@@ -2973,17 +2948,6 @@
return dummynode
-def getClusterName(self, model):
- return model.getClusterName()
-
-def getClusterAlias(self, model):
- if not model:
- return ''
- alias = model.getClusterAlias()
- if alias is None:
- return model.getClusterName()
- return alias
-
def getClusterURL(self, request, model):
try:
clustername = request.clustername
@@ -2996,59 +2960,10 @@
raise Exception, 'cluster name from model is blank'
except:
luci_log.debug_verbose('GCURL0: unable to get cluster name')
- return '.'
+ return ''
return '/luci/cluster/index_html?pagetype=7&clustername=%s' % clustername
-def getTabs(self, req):
- ###XXX Make this method return only tabs current user can use
- portaltabs = list()
- if not userAuthenticated(self):
- return portaltabs
-
- selectedtab = "homebase"
- try:
- baseurl = req['URL']
- if baseurl.find("cluster") > (-1):
- selectedtab = "cluster"
- elif baseurl.find("storage") > (-1):
- selectedtab = "storage"
- else:
- selectedtab = "homebase"
- except KeyError, e:
- selectedtab = None
-
- htab = { 'Title':"homebase",
- 'Description':"Home base for this luci server",
- 'Taburl':"/luci/homebase"}
- if selectedtab == "homebase":
- htab['isSelected'] = True
- else:
- htab['isSelected'] = False
-
-
- ctab = { 'Title':"cluster",
- 'Description':"Cluster configuration page",
- 'Taburl':"/luci/cluster/index_html?pagetype=3"}
- if selectedtab == "cluster":
- ctab['isSelected'] = True
- else:
- ctab['isSelected'] = False
-
- stab = { 'Title':"storage",
- 'Description':"Storage configuration page",
- 'Taburl':"/luci/storage"}
- if selectedtab == "storage":
- stab['isSelected'] = True
- else:
- stab['isSelected'] = False
-
- portaltabs.append(htab)
- portaltabs.append(ctab)
- portaltabs.append(stab)
-
- return portaltabs
-
def getRicciAgentForCluster(self, req):
clustername = None
try:
@@ -3380,7 +3295,7 @@
raise Exception, 'cluname is blank'
except:
luci_log.debug_verbose('CTP0: no model/no cluster name')
- return 'Unable to determine the cluster name.'
+ return 'Unable to determine the cluster name'
try:
model = getModelForCluster(self, cluname)
except Exception, e:
@@ -3402,7 +3317,7 @@
if ret is not None:
redirect_page = ret
else:
- return 'An unknown cluster task was requested.'
+ return 'An unknown cluster task was requested'
response = request.RESPONSE
response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
@@ -3420,7 +3335,7 @@
return None
objname = '%s____flag' % nodename_resolved
- fnpresent = noNodeFlagsPresent(self, nodefolder, objname, nodename_resolved)
+ fnpresent = noNodeStatussPresent(self, nodefolder, objname, nodename_resolved)
if fnpresent is None:
luci_log.debug('NL1: An error occurred while checking flags for %s' \
@@ -3609,12 +3524,12 @@
rc = None
try:
snode = getStorageNode(self, node[1].getId())
- setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(snode, CLUSTER_NODE_NEED_AUTH)
except:
pass
try:
- setNodeFlag(node[1], CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(node[1], CLUSTER_NODE_NEED_AUTH)
except:
pass
@@ -3682,13 +3597,13 @@
if not rc2.authed():
try:
- setNodeFlag(node[1], CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(node[1], CLUSTER_NODE_NEED_AUTH)
except:
pass
try:
snode = getStorageNode(self, node[0])
- setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(snode, CLUSTER_NODE_NEED_AUTH)
except:
pass
@@ -3784,7 +3699,7 @@
clustername = request.form['clustername']
except:
luci_log.debug('NTP0: missing cluster name')
- return (False, {'errors': [ 'No cluster name was given.' ]})
+ return (False, {'errors': [ 'No cluster name was given' ]})
try:
nodename = request['nodename']
@@ -3793,7 +3708,7 @@
nodename = request.form['nodename']
except:
luci_log.debug('NTP1: missing node name')
- return (False, {'errors': [ 'No node name was given.' ]})
+ return (False, {'errors': [ 'No node name was given' ]})
try:
task = request['task']
@@ -3802,7 +3717,7 @@
task = request.form['task']
except:
luci_log.debug('NTP2: missing task')
- return (False, {'errors': [ 'No node task was given.' ]})
+ return (False, {'errors': [ 'No node task was given' ]})
nodename_resolved = resolve_nodename(self, clustername, nodename)
@@ -3817,17 +3732,17 @@
except RicciError, e:
luci_log.debug('NTP3: ricci error from %s: %s' \
% (nodename_resolved, str(e)))
- return (False, {'errors': [ 'Unable to connect to the ricci agent on %s.' % nodename_resolved ]})
+ return (False, {'errors': [ 'Unable to connect to the ricci agent on %s' % nodename_resolved ]})
except:
luci_log.debug('NTP4: ricci error from %s: %s' \
% (nodename_resolved, str(e)))
- return (False, {'errors': [ 'Unable to connect to the ricci agent on %s.' % nodename_resolved ]})
+ return (False, {'errors': [ 'Unable to connect to the ricci agent on %s' % nodename_resolved ]})
cluinfo = rc.cluster_info()
if not cluinfo[0] and not cluinfo[1]:
luci_log.debug('NTP5: node %s not in a cluster (expected %s)' \
% (nodename_resolved, clustername))
- return (False, {'errors': [ 'Node "%s" reports it is not in a cluster.' % nodename_resolved ]})
+ return (False, {'errors': [ 'Node "%s" reports it is not in a cluster' % nodename_resolved ]})
cname = clustername.lower()
if cname != cluinfo[0].lower() and cname != cluinfo[1].lower():
@@ -3838,14 +3753,14 @@
rc = None
try:
snode = getStorageNode(self, nodename)
- setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(snode, CLUSTER_NODE_NEED_AUTH)
except:
# we'll hit it again, and try again then
pass
try:
cnode = getClusterNode(self, nodename, clustername)
- setNodeFlag(cnode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(cnode, CLUSTER_NODE_NEED_AUTH)
except:
# we'll hit it again, and try again then
pass
@@ -3853,7 +3768,7 @@
if rc is None:
luci_log.debug('NTP7: node %s is not authenticated' \
% nodename_resolved)
- return (False, {'errors': [ 'Node "%s" is not authenticated.' % nodename_resolved ]})
+ return (False, {'errors': [ 'Node "%s" is not authenticated' % nodename_resolved ]})
if task == NODE_LEAVE_CLUSTER:
if nodeLeave(self, rc, clustername, nodename_resolved) is None:
@@ -3874,7 +3789,7 @@
elif task == NODE_REBOOT:
if forceNodeReboot(self, rc, clustername, nodename_resolved) is None:
luci_log.debug_verbose('NTP10: nodeReboot failed')
- return (False, {'errors': [ 'Node "%s" failed to reboot.' \
+ return (False, {'errors': [ 'Node "%s" failed to reboot' \
% nodename_resolved ]})
response = request.RESPONSE
@@ -3883,7 +3798,7 @@
elif task == NODE_FENCE:
if forceNodeFence(self, clustername, nodename, nodename_resolved) is None:
luci_log.debug_verbose('NTP11: nodeFencefailed')
- return (False, {'errors': [ 'Fencing of node "%s" failed.' \
+ return (False, {'errors': [ 'Fencing of node "%s" failed' \
% nodename_resolved]})
response = request.RESPONSE
@@ -3892,7 +3807,7 @@
elif task == NODE_DELETE:
if nodeDelete(self, rc, model, clustername, nodename, nodename_resolved) is None:
luci_log.debug_verbose('NTP12: nodeDelete failed')
- return (False, {'errors': [ 'Deletion of node "%s" from cluster "%s" failed.' % (nodename_resolved, clustername) ]})
+ return (False, {'errors': [ 'Deletion of node "%s" from cluster "%s" failed' % (nodename_resolved, clustername) ]})
response = request.RESPONSE
response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
@@ -3941,18 +3856,18 @@
if not rc.authed():
try:
snode = getStorageNode(self, nodename)
- setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(snode, CLUSTER_NODE_NEED_AUTH)
except:
pass
if clustername:
try:
cnode = getClusterNode(self, nodename, clustername)
- setNodeFlag(cnode, CLUSTER_NODE_NEED_AUTH)
+ setNodeStatus(cnode, CLUSTER_NODE_NEED_AUTH)
except:
pass
- return 'Luci is not authenticated to node %s. Please reauthenticate first.' % nodename
+ return 'Luci is not authenticated to node %s. Please reauthenticate first' % nodename
return rq.getNodeLogs(rc)
@@ -4130,7 +4045,7 @@
node_report['statusmessage'] = '%s%s' % (RICCI_CONNECT_FAILURE_MSG, PRE_JOIN)
else:
node_report['statusindex'] = 0
- node_report['statusmessage'] = '%s Install is in an unknown state.' % RICCI_CONNECT_FAILURE_MSG
+ node_report['statusmessage'] = '%s Install is in an unknown state' % RICCI_CONNECT_FAILURE_MSG
nodereports.append(node_report)
continue
elif creation_status == -(INSTALL_TASK):
@@ -4307,7 +4222,7 @@
if name is None:
luci_log.debug_verbose('delService1: no service name')
- return (False, {'errors': [ '%s: no service name was provided.' % errstr ]})
+ return (False, {'errors': [ '%s: no service name was provided' % errstr ]})
clustername = None
try:
@@ -4320,12 +4235,12 @@
if clustername is None:
luci_log.debug_verbose('delService2: no cluster name for %s' % name)
- return (False, {'errors': [ '%s: no cluster name was provided.' % errstr ]})
+ return (False, {'errors': [ '%s: no cluster name was provided' % errstr ]})
rc = getRicciAgent(self, clustername)
if not rc:
luci_log.debug_verbose('delService3: unable to get ricci agent for cluster %s' % clustername)
- return (False, {'errors': [ '%s: unable to find a Ricci agent for this cluster.' % errstr ]})
+ return (False, {'errors': [ '%s: unable to find a Ricci agent for this cluster' % errstr ]})
try:
ragent = rc.hostname()
@@ -4333,7 +4248,7 @@
raise Exception, 'unable to determine the hostname of the ricci agent'
except Exception, e:
luci_log.debug_verbose('delService4: %s: %s' % (errstr, str(e)))
- return (False, {'errors': [ '%s: unable to find a Ricci agent for this cluster.' % errstr ]})
+ return (False, {'errors': [ '%s: unable to find a Ricci agent for this cluster' % errstr ]})
try:
model.deleteService(name)
@@ -4385,7 +4300,7 @@
if name is None:
luci_log.debug_verbose('delResource1: no resource name')
- return '%s: no resource name was provided.' % errstr
+ return '%s: no resource name was provided' % errstr
clustername = None
try:
@@ -4398,7 +4313,7 @@
if clustername is None:
luci_log.debug_verbose('delResource2: no cluster name for %s' % name)
- return '%s: could not determine the cluster name.' % errstr
+ return '%s: could not determine the cluster name' % errstr
try:
ragent = rc.hostname()
@@ -4406,7 +4321,7 @@
raise Exception, 'unable to determine the hostname of the ricci agent'
except Exception, e:
luci_log.debug_verbose('delResource3: %s: %s' % (errstr, str(e)))
- return '%s: could not determine the ricci agent hostname.' % errstr
+ return '%s: could not determine the ricci agent hostname' % errstr
resPtr = model.getResourcesPtr()
resources = resPtr.getChildren()
@@ -4420,7 +4335,7 @@
if not found:
luci_log.debug_verbose('delResource4: cant find res %s' % name)
- return '%s: the specified resource was not found.' % errstr
+ return '%s: the specified resource was not found' % errstr
try:
model.setModified(True)
@@ -4482,7 +4397,7 @@
batch_number, result = rq.setClusterConf(rc, str(conf))
if batch_number is None or result is None:
luci_log.debug_verbose('addResource5: missing batch_number or result')
- raise Exception, 'unable to save the new cluster configuration.'
+ raise Exception, 'unable to save the new cluster configuration'
except Exception, e:
luci_log.debug_verbose('addResource6: %s' % str(e))
return 'An error occurred while propagating the new cluster.conf: %s' % str(e)
@@ -4512,7 +4427,7 @@
request.SESSION.set('model', model)
except Exception, e:
luci_log.debug_verbose('Appending model to request failed: %r' % e)
- return 'An error occurred while storing the cluster model.'
+ return 'An error occurred while storing the cluster model'
def getModelBuilder(self, rc, isVirtualized):
try:
--- conga/luci/site/luci/Extensions/homebase_adapters.py 2007/05/04 19:10:24 1.50.2.2
+++ conga/luci/site/luci/Extensions/homebase_adapters.py 2007/05/14 18:00:14 1.50.2.3
@@ -2,10 +2,10 @@
STORAGE_FOLDER_PATH, CLUSTER_FOLDER_PATH
from RicciQueries import getClusterConf
-from LuciSyslog import LuciSyslog
+from LuciSyslog import get_logger
from HelperFunctions import resolveOSType
-from LuciDB import delCluster, delNodeFlag, delSystem, getClusterNode, \
+from LuciDB import delCluster, clearNodeStatus, delSystem, getClusterNode, \
getClusters, getStorage, getStorageNode, \
havePermAddCluster, havePermAddUser, havePermDelUser, \
havePermEditPerms, havePermRemCluster, havePermRemStorage, \
@@ -13,7 +13,6 @@
from ricci_communicator import RicciCommunicator
-
# Homebase area page types
HOMEBASE_ADD_USER = '1'
HOMEBASE_ADD_SYSTEM = '2'
@@ -24,50 +23,42 @@
HOMEBASE_ADD_CLUSTER_INITIAL = '7'
HOMEBASE_AUTH = '8'
-try:
- luci_log = LuciSyslog()
-except:
- pass
+luci_log = get_logger()
def validateDelSystem(self, request):
errors = list()
messages = list()
if '__SYSTEM' in request.form:
- sysNames = request.form['__SYSTEM']
- for i in sysNames:
- if i == '':
+ system_names = request.form['__SYSTEM']
+ for i in system_names:
+ if not i:
continue
- dsResult = delSystem(self, i)
- if dsResult:
- errors.append(dsResult)
+ err_msg = delSystem(self, i)
+ if err_msg:
+ errors.append(err_msg)
else:
messages.append('Removed storage system "%s" successfully' % i)
if '__CLUSTER' in request.form:
- cluNames = request.form['__CLUSTER']
- for i in cluNames:
- if i == '':
+ cluster_names = request.form['__CLUSTER']
+ for i in cluster_names:
+ if not i:
continue
- dcResult = delCluster(self, i)
- if dcResult:
- errors.append(dcResult)
+ err_msg = delCluster(self, i)
+ if err_msg:
+ errors.append(err_msg)
else:
messages.append('Removed cluster "%s" successfully' % i)
- if len(errors) > 0:
- retCode = False
- else:
- retCode = True
-
- return (retCode, {'messages': messages, 'errors': errors })
+ return (len(errors) < 1, { 'messages': messages, 'errors': errors })
def validateDelUser(self, request):
errors = list()
messages = list()
- if not 'deluserId' in request.form:
- return (False, {'errors': [ 'No User Id given' ] })
+ if not request.form.has_key('deluserId'):
+ return (False, { 'errors': [ 'No User ID given' ] })
userId = request.form['deluserId']
@@ -75,61 +66,66 @@
user = self.portal_membership.getMemberById(userId)
if not user:
raise Exception, 'user %s does not exist' % userId
- except:
+ except Exception, e:
+ luci_log.debug_verbose('VDU0: %s: %r' % (userId, e))
return (False, {'errors': [ 'No such user: "%s"' % userId ] })
for i in getClusters(self):
try:
- i[1].manage_delLocalRoles([userId])
- except:
+ i[1].manage_delLocalRoles([ userId ])
+ except Exception, e:
+ luci_log.debug_verbose('VDU1: %s %s: %r' % (userId, i[0], e))
errors.append('Error deleting roles from cluster "%s" for user "%s"' % (i[0], userId))
for i in getStorage(self):
try:
- i[1].manage_delLocalRoles([userId])
- except:
+ i[1].manage_delLocalRoles([ userId ])
+ except Exception, e:
+ luci_log.debug_verbose('VDU2: %s: %r' % (userId, i[0], e))
errors.append('Error deleting roles from storage system "%s" for user "%s"' % (i[0], userId))
try:
- self.acl_users.userFolderDelUsers([userId])
- except:
+ self.acl_users.userFolderDelUsers([ userId ])
+ except Exception, e:
+ luci_log.debug_verbose('VDU3: %s %r' % (userId, e))
errors.append('Unable to delete user "%s"' % userId)
return (False, {'errors': errors })
messages.append('User "%s" has been deleted' % userId)
- return (True, {'errors': errors, 'messages': messages })
+ return (True, { 'errors': errors, 'messages': messages })
def validateAddUser(self, request):
messages = list()
- if not 'newUserName' in request.form:
- return (False, { 'errors': ['No user name given'] })
- if not 'newPassword' in request.form:
- return (False, { 'errors': ['No password given'] })
- if not 'newPasswordConfirm' in request.form:
- return (False, {'errors': ['You didn\'t confirm the password'] })
+ if not request.form.has_key('newUserName'):
+ return (False, { 'errors': [ 'No user name given' ] })
+ if not request.form.has_key('newPassword'):
+ return (False, { 'errors': [ 'No password given' ] })
+ if not request.form.has_key('newPasswordConfirm'):
+ return (False, { 'errors': [ 'You didn\'t confirm the password' ] })
- user = request.form['newUserName']
+ user = request.form['newUserName'].strip()
if self.portal_membership.getMemberById(user):
- return (False, {'errors': ['The user "%s" already exists' % user ]})
+ return (False, { 'errors': [ 'The user "%s" already exists' % user ]})
passwd = request.form['newPassword']
pwconfirm = request.form['newPasswordConfirm']
if passwd != pwconfirm:
- return (False, {'errors': ['The passwords do not match']})
+ return (False, { 'errors': [ 'The passwords given do not match' ]})
try:
- self.portal_registration.addMember(user, passwd, properties = { 'username': user, 'password': passwd, 'confirm': passwd, 'roles': ['Member'], 'domains':[], 'email': '%s at example.com' % user })
- except:
- return (False, {'errors': [ 'Unable to add new user "%s"' % user ] })
+ self.portal_registration.addMember(user, passwd, properties = { 'username': user, 'password': passwd, 'confirm': passwd, 'roles': [ 'Member' ], 'domains': [], 'email': '%s at conga.example.com' % user })
+ except Exception, e:
+ luci_log.debug_verbose('VAU0: %s: %r' % (user, e))
+ return (False, { 'errors': [ 'Unable to add new user "%s"' % user ] })
if not self.portal_membership.getMemberById(user):
- return (False, {'errors': [ 'Unable to add new user "%s"' % user ] })
+ return (False, { 'errors': [ 'Unable to add new user "%s"' % user ] })
messages.append('Added new user "%s" successfully' % user)
- return (True, {'messages': messages, 'params': { 'user': user }})
+ return (True, { 'messages': messages, 'params': { 'user': user }})
def validateAddClusterInitial(self, request):
errors = list()
@@ -489,23 +485,14 @@
luci_log.debug_verbose('VAC1: no cluster os')
errors.append('Unable to determine the version of cluster %s.' % cluster_name)
- check_certs = False
- try:
- check_certs = 'check_certs' in request.form
- except:
- check_certs = False
+ check_certs = request.form.has_key('check_certs')
+ same_node_passwds = request.form.has_key('allSameCheckBox')
try:
pass_num = int(request.form['pass'].strip()) + 1
except:
pass_num = 1
- same_node_passwds = False
- try:
- same_node_passwds = 'allSameCheckBox' in request.form
- except:
- same_node_passwds = False
-
add_cluster = { 'name': cluster_name,
'pass': pass_num,
'cluster_os': cluster_os,
@@ -630,11 +617,7 @@
except:
pass
- check_certs = False
- try:
- check_certs = 'check_certs' in request.form
- except:
- check_certs = False
+ check_certs = request.form.has_key('check_certs')
add_systems, incomplete, errors, messages = parseHostForm(request, check_certs)
delete_keys = list()
@@ -691,22 +674,21 @@
errors = list()
username = None
- if not request.form.has_key('userList'):
- luci_log.debug_verbose('VP0: no user given')
- errors.append('No user name was given.')
- else:
+ if request.form.has_key('userList'):
username = request.form['userList'].strip()
+ if not username:
+ return (False, { 'errors': [ 'No user name was given' ]})
+
user_id = None
- if username is not None:
- try:
- user = self.portal_membership.getMemberById(username)
- if not user:
- raise Exception, 'no user'
- user_id = user.getUserId()
- except Exception, e:
- luci_log.debug_verbose('VP1: no user "%s": %s' % (username, str(e)))
- errors.append('An invalid user "%s" was given.' % username)
+ try:
+ user = self.portal_membership.getMemberById(username)
+ if not user:
+ raise Exception, 'no user'
+ user_id = user.getUserId()
+ except Exception, e:
+ luci_log.debug_verbose('VP1: no user "%s": %r' % (username, e))
+ errors.append('An invalid user "%s" was given' % username)
if len(errors) > 0:
return (False, { 'errors': errors })
@@ -724,7 +706,8 @@
else:
i[1].manage_delLocalRoles([ user_id ])
messages.append('Removed permission for user "%s" for cluster "%s"' % (user_id, i[0]))
- except:
+ except Exception, e:
+ luci_log.debug_verbose('VP2: %s %s: %r' % (user_id, i[0], e))
errors.append('Failed to remove permission for user "%s" for cluster "%s"' % (user_id, i[0]))
else:
for i in clusters:
@@ -735,7 +718,8 @@
roles.append('View')
i[1].manage_setLocalRoles(user_id, roles)
messages.append('Added permission for user "%s" for cluster "%s"' % (user_id, i[0]))
- except:
+ except Exception, e:
+ luci_log.debug_verbose('VP3: %s %s %r' % (user_id, i[0], e))
errors.append('Failed to add permission for user "%s" for cluster "%s"' % (user_id, i[0]))
else:
try:
@@ -749,9 +733,11 @@
i[1].manage_delLocalRoles([ user_id ])
messages.append('Removed permission for user "%s" for cluster "%s"' % (user_id, i[0]))
- except:
+ except Exception, e:
+ luci_log.debug_verbose('VP4: %s %s %r' % (user_id, i[0], e))
errors.append('Failed to remove permission for user "%s" for cluster "%s"' % (user_id, i[0]))
+
storage = self.restrictedTraverse('%s/systems/storage/objectItems' % PLONE_ROOT)('Folder')
if not request.form.has_key('__SYSTEM'):
for i in storage:
@@ -807,11 +793,7 @@
except:
pass
- check_certs = False
- try:
- check_certs = 'check_certs' in request.form
- except:
- check_certs = False
+ check_certs = request.form.has_key('check_certs')
system_list, incomplete, errors, messages = parseHostForm(request, check_certs)
delete_keys = list()
@@ -850,12 +832,12 @@
% cur_host)
delete_keys.append(i)
try:
- delNodeFlag(self, getStorageNode(self, cur_host), CLUSTER_NODE_NEED_AUTH)
+ clearNodeStatus(self, getStorageNode(self, cur_host), CLUSTER_NODE_NEED_AUTH)
except:
pass
try:
- delNodeFlag(self, getClusterNode(self, cur_host, rc.cluster_info()[0]), CLUSTER_NODE_NEED_AUTH)
+ clearNodeStatus(self, getClusterNode(self, cur_host, rc.cluster_info()[0]), CLUSTER_NODE_NEED_AUTH)
except:
pass
except Exception, e:
--- conga/luci/site/luci/Extensions/ricci_communicator.py 2007/05/04 19:10:24 1.25.2.2
+++ conga/luci/site/luci/Extensions/ricci_communicator.py 2007/05/14 18:00:14 1.25.2.3
@@ -1,482 +1,505 @@
import xml
import xml.dom
from xml.dom import minidom
-from LuciSyslog import LuciSyslog
+from LuciSyslog import get_logger
from conga_ssl import SSLSocket
+from conga_constants import LUCI_DEBUG_MODE
CERTS_DIR_PATH = '/var/lib/luci/var/certs/'
-
-try:
- luci_log = LuciSyslog()
-except:
- pass
+luci_log = get_logger()
class RicciError(Exception):
- pass
+ pass
class RicciCommunicator:
- def __init__(self, hostname, enforce_trust=True, port=11111):
- self.__hostname = hostname
- self.__port = port
-
- self.__timeout_init = 4
- self.__timeout_auth = 4
- self.__timeout_short = 6
- self.__timeout_long = 600
-
- self.__privkey_file = '%sprivkey.pem' % CERTS_DIR_PATH
- self.__cert_file = '%scacert.pem' % CERTS_DIR_PATH
-
- try:
- self.ss = SSLSocket(self.__hostname,
- self.__port,
- self.__timeout_init)
- if enforce_trust:
- if not self.ss.trusted():
- raise RicciError, 'ricci\'s certificate is not trusted'
- except Exception, e:
- raise RicciError, 'Error setting up SSL for connection to %s: %s' \
- % (self.__hostname, str(e))
- except:
- raise RicciError, 'Error setting up SSL for connection to %s' \
- % self.__hostname
-
- # receive ricci header
- hello = self.__receive(self.__timeout_init)
- try:
- luci_log.debug_verbose('RC:init0: Received header from %s: \"%s\"' \
- % (self.__hostname, hello.toxml()))
- except:
- pass
-
- self.__authed = hello.firstChild.getAttribute('authenticated') == 'true'
- self.__cluname = hello.firstChild.getAttribute('clustername')
- self.__clualias = hello.firstChild.getAttribute('clusteralias')
- self.__reported_hostname = hello.firstChild.getAttribute('hostname')
- self.__os = hello.firstChild.getAttribute('os')
- self.__dom0 = hello.firstChild.getAttribute('xen_host') == 'true'
-
- def hostname(self):
- luci_log.debug_verbose('RC:hostname: [auth %d] reported hostname = %s' \
- % (self.__authed, self.__hostname))
- return self.__hostname
- def authed(self):
- luci_log.debug_verbose('RC:authed: reported authed = %d for %s' \
- % (self.__authed, self.__hostname))
- return self.__authed
- def system_name(self):
- luci_log.debug_verbose('RC:system_name: [auth %d] reported system_name = %s for %s' \
- % (self.__authed, self.__reported_hostname, self.__hostname))
- return self.__reported_hostname
- def cluster_info(self):
- luci_log.debug_verbose('RC:cluster_info: [auth %d] reported cluster_info = (%s,%s) for %s' \
- % (self.__authed, self.__cluname, self.__clualias, self.__hostname))
- return (self.__cluname, self.__clualias)
- def os(self):
- luci_log.debug_verbose('RC:os: [auth %d] reported os = %s for %s' \
- % (self.__authed, self.__os, self.__hostname))
- return self.__os
- def dom0(self):
- luci_log.debug_verbose('RC:dom0: [auth %d] reported dom0 = %s for %s' \
- % (self.__authed, self.__dom0, self.__hostname))
- return self.__dom0
-
- def fingerprint(self):
- return self.ss.peer_fingerprint()
-
- def trust(self):
- return self.ss.trust()
-
- def untrust(self):
- return self.ss.untrust()
-
- def trusted(self):
- return self.ss.trusted()
-
- def auth(self, password):
- if self.authed():
- luci_log.debug_verbose('RC:auth0: already authenticated to %s' \
- % self.__hostname)
- return True
-
- # send request
- doc = minidom.Document()
- ricci = doc.createElement("ricci")
- ricci.setAttribute("version", "1.0")
- ricci.setAttribute("function", "authenticate")
- ricci.setAttribute("password", password)
- doc.appendChild(ricci)
- self.__send(doc, self.__timeout_auth)
-
- # receive response
- resp = self.__receive(self.__timeout_auth)
- self.__authed = resp.firstChild.getAttribute('authenticated') == 'true'
-
- if self.__authed:
- try:
- self.__cluname = resp.firstChild.getAttribute('clustername')
- self.__clualias = resp.firstChild.getAttribute('clusteralias')
- self.__reported_hostname = resp.firstChild.getAttribute('hostname')
- self.__os = resp.firstChild.getAttribute('os')
- self.__dom0 = resp.firstChild.getAttribute('xen_host') == 'true'
- except:
- pass
- luci_log.debug_verbose('RC:auth1: auth call returning %d' \
- % self.__authed)
- return self.__authed
-
- def unauth(self):
- doc = minidom.Document()
- ricci = doc.createElement('ricci')
- ricci.setAttribute('version', '1.0')
- ricci.setAttribute('function', 'unauthenticate')
- doc.appendChild(ricci)
- self.__send(doc, self.__timeout_auth)
- resp = self.__receive(self.__timeout_auth)
-
- luci_log.debug_verbose('RC:unauth0: trying to unauthenticate to %s' \
- % self.__hostname)
-
- try:
- ret = resp.firstChild.getAttribute('success')
- luci_log.debug_verbose('RC:unauth1: unauthenticate returned %s for %s' \
- % (ret, self.__hostname))
- if ret != '0':
- raise Exception, 'Invalid response'
- try:
- self.ss.untrust()
- except:
- pass
- except:
- errstr = 'Error authenticating to host %s: %s' \
- % (self.__hostname, str(ret))
- luci_log.debug_verbose('RC:unauth2: %s' % errstr)
- raise RicciError, errstr
- return True
-
-
- def process_batch(self, batch_xml, async=False):
- try:
- luci_log.debug_verbose('RC:PB0: [auth=%d] to %s for batch %s [async=%d]' \
- % (self.__authed, self.__hostname, batch_xml.toxml(), async))
- except:
- pass
-
- if not self.authed():
- raise RicciError, 'not authenticated to host %s' % self.__hostname
-
- # construct request
- doc = minidom.Document()
- ricci = doc.createElement("ricci")
- ricci.setAttribute("version", "1.0")
- ricci.setAttribute("function", "process_batch")
- async_str = None
- if async:
- async_str = 'true'
- else:
- async_str = 'false'
- ricci.setAttribute("async", async_str)
- doc.appendChild(ricci)
- ricci.appendChild(batch_xml.cloneNode(True))
-
- # send request
- try:
- self.__send(doc, self.__timeout_short)
- except Exception, e:
- luci_log.debug_verbose('RC:PB1: Error sending XML \"%s\" to host %s' \
- % (doc.toxml(), self.__hostname))
- raise RicciError, 'Error sending XML to host %s: %s' \
- % (self.__hostname, str(e))
- except:
- raise RicciError, 'Error sending XML to host %s' % self.__hostname
-
- # receive response
- doc = self.__receive(self.__timeout_long)
- try:
- luci_log.debug_verbose('RC:PB2: received from %s XML \"%s\"' \
- % (self.__hostname, doc.toxml()))
- except:
- pass
+ def __init__(self, hostname, enforce_trust=True, port=11111):
+ self.__hostname = hostname
+ self.__port = port
+
+ self.__timeout_init = 4
+ self.__timeout_auth = 4
+ self.__timeout_short = 6
+ self.__timeout_long = 600
+
+ self.__privkey_file = '%sprivkey.pem' % CERTS_DIR_PATH
+ self.__cert_file = '%scacert.pem' % CERTS_DIR_PATH
+
+ try:
+ self.ss = SSLSocket(self.__hostname,
+ self.__port,
+ self.__timeout_init)
+ if enforce_trust:
+ if not self.ss.trusted():
+ raise RicciError, 'ricci\'s certificate is not trusted'
+ except Exception, e:
+ raise RicciError, 'Error setting up SSL for connection to %s: %s' \
+ % (self.__hostname, str(e))
+ except:
+ raise RicciError, 'Error setting up SSL for connection to %s' \
+ % self.__hostname
+
+ # receive ricci header
+ hello = self.__receive(self.__timeout_init)
+ try:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:init0: recv header from %s: \"%s\"' \
+ % (self.__hostname, hello.toxml()))
+ except:
+ pass
+
+ self.__authed = hello.firstChild.getAttribute('authenticated') == 'true'
+ self.__cluname = hello.firstChild.getAttribute('clustername')
+ self.__clualias = hello.firstChild.getAttribute('clusteralias')
+ self.__reported_hostname = hello.firstChild.getAttribute('hostname')
+ self.__os = hello.firstChild.getAttribute('os')
+ self.__dom0 = hello.firstChild.getAttribute('xen_host') == 'true'
+
+ def hostname(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:hostname: [auth %d] hostname = %s' \
+ % (self.__authed, self.__hostname))
+ return self.__hostname
+
+ def authed(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:authed: reported authed = %d for %s' \
+ % (self.__authed, self.__hostname))
+ return self.__authed
+
+ def system_name(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:system_name: [auth %d] system_name = %s for %s' % (self.__authed, self.__reported_hostname, self.__hostname))
+ return self.__reported_hostname
+
+ def cluster_info(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:cluster_info: [auth %d] reported cluster_info = (%s,%s) for %s' % (self.__authed, self.__cluname, self.__clualias, self.__hostname))
+ return (self.__cluname, self.__clualias)
+
+ def os(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:os: [auth %d] reported os = %s for %s' \
+ % (self.__authed, self.__os, self.__hostname))
+ return self.__os
+
+ def dom0(self):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:dom0: [auth %d] dom0 = %s for %s' \
+ % (self.__authed, self.__dom0, self.__hostname))
+ return self.__dom0
+
+ def fingerprint(self):
+ fp = self.ss.peer_fingerprint()
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:fp: [auth %d] fp for %s = %s' \
+ % (self.__authed, self.__hostname, fp))
+ return fp
+
+ def trust(self):
+ return self.ss.trust()
+
+ def untrust(self):
+ return self.ss.untrust()
+
+ def trusted(self):
+ return self.ss.trusted()
+
+ def auth(self, password):
+ if self.authed():
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:auth0: already authenticated to %s' \
+ % self.__hostname)
+ return True
+
+ # send request
+ doc = minidom.Document()
+ ricci = doc.createElement("ricci")
+ ricci.setAttribute("version", "1.0")
+ ricci.setAttribute("function", "authenticate")
+ ricci.setAttribute("password", password)
+ doc.appendChild(ricci)
+ self.__send(doc, self.__timeout_auth)
+
+ # receive response
+ resp = self.__receive(self.__timeout_auth)
+ self.__authed = resp.firstChild.getAttribute('authenticated') == 'true'
+
+ if self.__authed:
+ try:
+ self.__cluname = resp.firstChild.getAttribute('clustername')
+ self.__clualias = resp.firstChild.getAttribute('clusteralias')
+ self.__reported_hostname = resp.firstChild.getAttribute('hostname')
+ self.__os = resp.firstChild.getAttribute('os')
+ self.__dom0 = resp.firstChild.getAttribute('xen_host') == 'true'
+ except:
+ pass
+
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:auth1: auth call returning %d' \
+ % self.__authed)
+ return self.__authed
+
+ def unauth(self):
+ doc = minidom.Document()
+ ricci = doc.createElement('ricci')
+ ricci.setAttribute('version', '1.0')
+ ricci.setAttribute('function', 'unauthenticate')
+ doc.appendChild(ricci)
+ self.__send(doc, self.__timeout_auth)
+ resp = self.__receive(self.__timeout_auth)
+
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:unauth0: unauthenticate %s' \
+ % self.__hostname)
+
+ try:
+ ret = resp.firstChild.getAttribute('success')
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:unauth1: unauthenticate %s for %s' \
+ % (ret, self.__hostname))
+ if ret != '0':
+ raise Exception, 'Invalid response'
+
+ try:
+ self.ss.untrust()
+ except:
+ pass
+ except:
+ errstr = 'Error authenticating to host %s: %s' \
+ % (self.__hostname, str(ret))
+
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:unauth2: %s' % errstr)
+ raise RicciError, errstr
+ return True
+
+
+ def process_batch(self, batch_xml, async=False):
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('RC:PB0: [auth=%d] to %s for batch %s [async=%d]' % (self.__authed, self.__hostname, batch_xml.toxml(), async))
+ except:
+ pass
+
+ if not self.authed():
+ raise RicciError, 'not authenticated to host %s' % self.__hostname
+
+ # construct request
+ doc = minidom.Document()
+ ricci = doc.createElement("ricci")
+ ricci.setAttribute("version", "1.0")
+ ricci.setAttribute("function", "process_batch")
+ async_str = None
+ if async:
+ async_str = 'true'
+ else:
+ async_str = 'false'
+ ricci.setAttribute("async", async_str)
+ doc.appendChild(ricci)
+ ricci.appendChild(batch_xml.cloneNode(True))
+
+ # send request
+ try:
+ self.__send(doc, self.__timeout_short)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:PB1: Error sending XML \"%s\" to host %s' % (doc.toxml(), self.__hostname))
+ raise RicciError, 'Error sending XML to host %s: %s' \
+ % (self.__hostname, str(e))
+ except:
+ raise RicciError, 'Error sending XML to host %s' % self.__hostname
+
+ # receive response
+ doc = self.__receive(self.__timeout_long)
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('RC:PB2: received from %s XML \"%s\"' \
+ % (self.__hostname, doc.toxml()))
+ except:
+ pass
- if doc.firstChild.getAttribute('success') != '0':
- luci_log.debug_verbose('RC:PB3: batch command failed')
- raise RicciError, 'The last ricci command to host %s failed' \
- % self.__hostname
-
- batch_node = None
- for node in doc.firstChild.childNodes:
- if node.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node.nodeName == 'batch':
- batch_node = node.cloneNode(True)
- if batch_node == None:
- luci_log.debug_verbose('RC:PB4: batch node missing <batch/>')
- raise RicciError, 'missing <batch/> in ricci\'s response from "%s"' \
- % self.__hostname
-
- return batch_node
-
- def batch_run(self, batch_str, async=True):
- try:
- batch_xml_str = '<?xml version="1.0" ?><batch>%s</batch>' % batch_str
- luci_log.debug_verbose('RC:BRun0: attempting batch "%s" for host "%s"' % (batch_xml_str, self.__hostname))
- batch_xml = minidom.parseString(batch_xml_str).firstChild
- except Exception, e:
- luci_log.debug_verbose('RC:BRun1: received invalid batch XML for %s: "%s": "%s"' % (self.__hostname, batch_xml_str, str(e)))
- raise RicciError, 'batch XML is malformed'
-
- try:
- ricci_xml = self.process_batch(batch_xml, async)
- try:
- luci_log.debug_verbose('RC:BRun2: received XML "%s" from host %s in response to batch command.' % (ricci_xml.toxml(), self.__hostname))
- except:
- pass
- except:
- luci_log.debug_verbose('RC:BRun3: An error occurred while trying to process the batch job: "%s"' % batch_xml_str)
- return None
-
- doc = minidom.Document()
- doc.appendChild(ricci_xml)
- return doc
-
- def batch_report(self, batch_id):
- luci_log.debug_verbose('RC:BRep0: [auth=%d] asking for batchid# %s for host %s' % (self.__authed, batch_id, self.__hostname))
-
- if not self.authed():
- raise RicciError, 'Not authenticated to host %s' % self.__hostname
-
- # construct request
- doc = minidom.Document()
- ricci = doc.createElement("ricci")
- ricci.setAttribute("version", "1.0")
- ricci.setAttribute("function", "batch_report")
- ricci.setAttribute("batch_id", str(batch_id))
- doc.appendChild(ricci)
-
- # send request
- self.__send(doc, self.__timeout_short)
+ if doc.firstChild.getAttribute('success') != '0':
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:PB3: batch command failed')
+ raise RicciError, 'The last ricci command to host %s failed' \
+ % self.__hostname
+
+ batch_node = None
+ for node in doc.firstChild.childNodes:
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node.nodeName == 'batch':
+ batch_node = node.cloneNode(True)
+ if batch_node == None:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:PB4: batch node missing <batch/>')
+ raise RicciError, 'missing <batch/> in ricci response from "%s"' \
+ % self.__hostname
+
+ return batch_node
+
+ def batch_run(self, batch_str, async=True):
+ try:
+ batch_xml_str = '<?xml version="1.0" ?><batch>%s</batch>' \
+ % batch_str
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BRun0: attempting batch "%s" for host "%s"' % (batch_xml_str, self.__hostname))
+ batch_xml = minidom.parseString(batch_xml_str).firstChild
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BRun1: received invalid batch XML for %s: "%s": "%s"' % (self.__hostname, batch_xml_str, str(e)))
+ raise RicciError, 'batch XML is malformed'
+
+ try:
+ ricci_xml = self.process_batch(batch_xml, async)
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('RC:BRun2: received XML "%s" from host %s in response to batch command.' % (ricci_xml.toxml(), self.__hostname))
+ except:
+ pass
+ except:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BRun3: An error occurred while trying to process the batch job: "%s"' % batch_xml_str)
+ return None
+
+ doc = minidom.Document()
+ doc.appendChild(ricci_xml)
+ return doc
+
+ def batch_report(self, batch_id):
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BRep0: [auth=%d] asking for batchid# %s for host %s' % (self.__authed, batch_id, self.__hostname))
+
+ if not self.authed():
+ raise RicciError, 'Not authenticated to host %s' % self.__hostname
+
+ # construct request
+ doc = minidom.Document()
+ ricci = doc.createElement("ricci")
+ ricci.setAttribute("version", "1.0")
+ ricci.setAttribute("function", "batch_report")
+ ricci.setAttribute("batch_id", str(batch_id))
+ doc.appendChild(ricci)
+
+ # send request
+ self.__send(doc, self.__timeout_short)
-
- # receive response
- doc = self.__receive(self.__timeout_short)
- if doc.firstChild.getAttribute('success') == '12':
- return None
- if doc.firstChild.getAttribute('success') != '0':
- raise RicciError, 'Error while retrieving batch report for batch #%d from host %s' % (batch_id, self.__hostname)
- batch_node = None
- for node in doc.firstChild.childNodes:
- if node.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node.nodeName == 'batch':
- batch_node = node.cloneNode(True)
- if batch_node == None:
- raise RicciError, 'Missing <batch/> in ricci\'s response from host %s' % self.__hostname
- return batch_node
-
-
-
-
-
- def __send(self, xml_doc, timeout):
- buff = '%s\n' % xml_doc.toxml()
- try:
- self.ss.send(buff, timeout)
- except Exception, e:
- luci_log.debug_verbose('RC:send0: Error sending XML "%s" to %s: %s' % (buff, self.__hostname, str(e)))
- raise RicciError, 'write error while sending XML to host %s' \
- % self.__hostname
- except:
- raise RicciError, 'write error while sending XML to host %s' \
- % self.__hostname
- try:
- luci_log.debug_verbose('RC:send1: Sent XML "%s" to host %s' \
- % (xml_doc.toxml(), self.__hostname))
- except:
- pass
- return
-
- def __receive(self, timeout):
- doc = None
- xml_in = ''
- try:
- xml_in = self.ss.recv(timeout)
- except Exception, e:
- luci_log.debug_verbose('RC:recv0: Error reading data from %s: %s' \
- % (self.__hostname, str(e)))
- raise RicciError, 'Error reading data from host %s' % self.__hostname
- except:
- raise RicciError, 'Error reading data from host %s' % self.__hostname
- luci_log.debug_verbose('RC:recv1: Received XML "%s" from host %s' \
- % (xml_in, self.__hostname))
-
- try:
- if doc == None:
- doc = minidom.parseString(xml_in)
- except Exception, e:
- luci_log.debug_verbose('RC:recv2: Error parsing XML "%s" from %s' \
- % (xml_in, str(e)))
- raise RicciError, 'Error parsing XML from host %s: %s' \
- % (self.__hostname, str(e))
-
- if not doc or not doc.firstChild:
- raise RicciError, \
- 'Error an empty response was received from host %s' \
- % self.__hostname
-
- try:
- if doc.firstChild.nodeName != 'ricci':
- luci_log.debug_verbose('RC:recv3: Expecting "ricci" got XML "%s" from %s' % (xml_in, self.__hostname))
- raise Exception, 'Expecting first XML child node to be "ricci"'
- except Exception, e:
- raise RicciError, 'Invalid XML ricci response from host %s' \
- % self.__hostname
-
- return doc
-
-
-
+
+ # receive response
+ doc = self.__receive(self.__timeout_short)
+ if doc.firstChild.getAttribute('success') == '12':
+ return None
+ if doc.firstChild.getAttribute('success') != '0':
+ raise RicciError, 'Error while retrieving batch report for batch #%d from host %s' % (batch_id, self.__hostname)
+ batch_node = None
+ for node in doc.firstChild.childNodes:
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node.nodeName == 'batch':
+ batch_node = node.cloneNode(True)
+ if batch_node == None:
+ raise RicciError, 'Missing <batch/> in ricci\'s response from host %s' % self.__hostname
+ return batch_node
+
+
+ def __send(self, xml_doc, timeout):
+ buff = '%s\n' % xml_doc.toxml()
+ try:
+ self.ss.send(buff, timeout)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:send0: Error sending XML "%s" to %s: %s' % (buff, self.__hostname, str(e)))
+ raise RicciError, 'write error while sending XML to host %s' \
+ % self.__hostname
+ except:
+ raise RicciError, 'write error while sending XML to host %s' \
+ % self.__hostname
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('RC:send1: Sent XML "%s" to host %s' \
+ % (xml_doc.toxml(), self.__hostname))
+ except:
+ pass
+ return
+
+ def __receive(self, timeout):
+ doc = None
+ xml_in = ''
+ try:
+ xml_in = self.ss.recv(timeout)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:recv0: Error reading from %s: %s' \
+ % (self.__hostname, str(e)))
+ raise RicciError, 'Error reading data from host %s' \
+ % self.__hostname
+ except:
+ raise RicciError, 'Error reading data from host %s' \
+ % self.__hostname
+
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:recv1: Received XML "%s" from host %s' \
+ % (xml_in, self.__hostname))
+
+ try:
+ if doc == None:
+ doc = minidom.parseString(xml_in)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:recv2: parsing XML "%s" from %s' \
+ % (xml_in, str(e)))
+ raise RicciError, 'Error parsing XML from host %s: %s' \
+ % (self.__hostname, str(e))
+
+ if not doc or not doc.firstChild:
+ raise RicciError, 'Error an empty response was received from host %s' % self.__hostname
+
+ try:
+ if doc.firstChild.nodeName != 'ricci':
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:recv3: Expecting "ricci" got XML "%s" from %s' % (xml_in, self.__hostname))
+ raise Exception, 'Expecting first XML child node to be "ricci"'
+ except Exception, e:
+ raise RicciError, 'Invalid XML ricci response from host %s' \
+ % self.__hostname
+ return doc
+
def get_ricci_communicator(self, hostname, allowed_systems):
- if not self.access_to_host_allowed(hostname, allowed_systems):
- return None
-
- try:
- return RicciCommunicator(hostname)
- except Exception, e:
- luci_log.debug_verbose('RC:GRC0: Error creating a ricci connection to %s: %s' % (hostname, str(e)))
- return None
+ if not self.access_to_host_allowed(hostname, allowed_systems):
+ return None
+
+ try:
+ return RicciCommunicator(hostname)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:GRC0: Error creating a ricci connection to %s: %s' % (hostname, str(e)))
+ return None
def ricci_get_called_hostname(self, ricci):
- return ricci.hostname()
+ return ricci.hostname()
def ricci_get_reported_hostname(self, ricci):
- return ricci.system_name()
+ return ricci.system_name()
def ricci_get_os(self, ricci):
- return ricci.os()
+ return ricci.os()
def ricci_get_dom0(self, ricci):
- return ricci.dom0()
+ return ricci.dom0()
def ricci_get_cluster_info(self, ricci):
- return ricci.cluster_info()
+ return ricci.cluster_info()
def ricci_get_authenticated(self, ricci):
- return ricci.authed()
+ return ricci.authed()
def ricci_authenticate(self, ricci, password):
- return ricci.auth(password)
+ return ricci.auth(password)
def ricci_unauthenticate(self, ricci):
- return ricci.unauth()
-
-
-
-
-
-
-
+ return ricci.unauth()
########## helpers to process batch as returned by ricci #############
-
-
-
-
# check the status of batch
# returns (int num, int total)
# * total:
-# total number of modules in batch
+# total number of modules in batch
# * num:
-# if num == total:
-# all modules in the batch completed successfuly
-# if num > 0:
-# last seq. number of module that successfuly finished
-# if num < 0:
-# module (-num) failed (next module won't be processed)
-def batch_status(batch_xml):
- if batch_xml.nodeName != 'batch':
- try:
- luci_log.debug_verbose('RC:BS0: Expecting an XML batch node. Got \"%s\"' \
- % batch_xml.toxml())
- except:
- pass
- raise RicciError, 'Not an XML batch node'
- total = 0
- last = 0
- for node in batch_xml.childNodes:
- if node.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node.nodeName == 'module':
- total = total + 1
- status = node.getAttribute('status')
- if status == '0':
- # success
- last = last + 1
- elif status == '3' or status == '4':
- # failure
- last = last + 1
- last = last - 2 * last
- try:
- luci_log.debug_verbose('RC:BS1: Returning (%d, %d) for batch_status("%s")' % (last, total, batch_xml.toxml()))
- except:
- luci_log.debug_verbose('RC:BS2: Returning last, total')
-
- return (last, total)
-
+# if num == total:
+# all modules in the batch completed successfuly
+# if num > 0:
+# last seq. number of module that successfuly finished
+# if num < 0:
+# module (-num) failed (next module won't be processed)
+def batch_status(batch_xml):
+ if batch_xml.nodeName != 'batch':
+ if LUCI_DEBUG_MODE is True:
+ try:
+ luci_log.debug_verbose('RC:BS0: Expecting an XML batch node. Got \"%s\"' % batch_xml.toxml())
+ except:
+ pass
+ raise RicciError, 'Not an XML batch node'
+
+ total = 0
+ last = 0
+ for node in batch_xml.childNodes:
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node.nodeName == 'module':
+ total = total + 1
+ status = node.getAttribute('status')
+ if status == '0':
+ # success
+ last = last + 1
+ elif status == '3' or status == '4':
+ # failure
+ last = last + 1
+ last = last - 2 * last
+ try:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BS1: Returning (%d, %d) for batch_status("%s")' % (last, total, batch_xml.toxml()))
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:BS2: error %r: (last, total)' % \
+ (e, last, total))
+ return (last, total)
# extract error_code from module's response
# * module_num:
-# 1-based seq. number of module to process
+# 1-based seq. number of module to process
#
# returns (int error_code, string error_msg)
# * error_code: each module defines own error codes, which are >0
-# -101 - in progress
-# -102 - scheduled
-# -103 - removed from schedule
-# -104 - failed to execute module
+# -101 - in progress
+# -102 - scheduled
+# -103 - removed from schedule
+# -104 - failed to execute module
#
-# >-3 - module executed. Following codes are defined:
-# -2 - API error
-# -1 - undefined error occured (msg not necesarily very informative)
-# 0 - no error (msg is empty string)
-# >0 - predefined error has occured
-# (check respective API, msg will be fully descriptive)
+# >-3 - module executed. Following codes are defined:
+# -2 - API error
+# -1 - undefined error occured (msg not necesarily very informative)
+# 0 - no error (msg is empty string)
+# >0 - predefined error has occured
+# (check respective API, msg will be fully descriptive)
# * error_msg: error message
-def extract_module_status(batch_xml, module_num=1):
- if batch_xml.nodeName != 'batch':
- luci_log.debug_verbose('RC:EMS0: Expecting "batch" got "%s"' % batch_xml.toxml())
- raise RicciError, 'Invalid XML node; expecting a batch node'
-
- c = 0
- for node in batch_xml.childNodes:
- if node.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node.nodeName == 'module':
- module_xml = node
- c = c + 1
- if c == module_num:
- status = module_xml.getAttribute('status')
- if status == '0' or status == '4':
- # module executed, dig deeper into request
- for node_i in module_xml.childNodes:
- if node_i.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node_i.nodeName == 'API_error':
- return -2, 'API error'
- elif node_i.nodeName == 'response':
- for node_j in node_i.childNodes:
- if node_j.nodeType == xml.dom.Node.ELEMENT_NODE:
- if node_j.nodeName == 'function_response':
- code = -11111111
- msg = 'BUG'
- for var in node_j.childNodes:
- if var.nodeType == xml.dom.Node.ELEMENT_NODE:
- if var.nodeName == 'var':
- if var.getAttribute('name') == 'success' and var.getAttribute('value') == 'true':
- return 0, ''
- elif var.getAttribute('name') == 'error_code':
- code = int(var.getAttribute('value'))
- elif var.getAttribute('name') == 'error_description':
- msg = var.getAttribute('value')
- return code, msg
-
- elif status == '1':
- return -102, 'module scheduled for execution'
- elif status == '2':
- return -101, 'module is being executed'
- elif status == '3':
- return -104, 'failed to locate/execute module'
- elif status == '5':
- return -103, 'module removed from schedule'
-
- raise RicciError, 'no %dth module in the batch, or malformed response' % module_num
+def extract_module_status(batch_xml, module_num=1):
+ if batch_xml.nodeName != 'batch':
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('RC:EMS0: Expecting "batch" got "%s"' \
+ % batch_xml.toxml())
+ raise RicciError, 'Invalid XML node; expecting a batch node'
+
+ c = 0
+ for node in batch_xml.childNodes:
+ if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node.nodeName == 'module':
+ module_xml = node
+ c = c + 1
+ if c == module_num:
+ status = module_xml.getAttribute('status')
+ if status == '0' or status == '4':
+ # module executed, dig deeper into request
+ for node_i in module_xml.childNodes:
+ if node_i.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node_i.nodeName == 'API_error':
+ return -2, 'API error'
+ elif node_i.nodeName == 'response':
+ for node_j in node_i.childNodes:
+ if node_j.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if node_j.nodeName == 'function_response':
+ code = -11111111
+ msg = 'BUG'
+ for var in node_j.childNodes:
+ if var.nodeType == xml.dom.Node.ELEMENT_NODE:
+ if var.nodeName == 'var':
+ if var.getAttribute('name') == 'success' and var.getAttribute('value') == 'true':
+ return 0, ''
+ elif var.getAttribute('name') == 'error_code':
+ code = int(var.getAttribute('value'))
+ elif var.getAttribute('name') == 'error_description':
+ msg = var.getAttribute('value')
+ return code, msg
+
+ elif status == '1':
+ return -102, 'module scheduled for execution'
+ elif status == '2':
+ return -101, 'module is being executed'
+ elif status == '3':
+ return -104, 'failed to locate/execute module'
+ elif status == '5':
+ return -103, 'module removed from schedule'
+
+ raise RicciError, 'no %dth module in the batch, or malformed response' % module_num
--- conga/luci/site/luci/Extensions/system_adapters.py 2007/05/03 20:16:38 1.2.2.1
+++ conga/luci/site/luci/Extensions/system_adapters.py 2007/05/14 18:00:14 1.2.2.2
@@ -1,12 +1,9 @@
from ricci_communicator import RicciCommunicator
from RicciQueries import list_services, updateServices, svc_manage
-from LuciSyslog import LuciSyslog
+from LuciSyslog import get_logger
from xml.dom import minidom
-try:
- luci_log = LuciSyslog()
-except:
- pass
+luci_log = get_logger()
def get_sys_svc_list(self, request, hostname):
try:
More information about the Cluster-devel
mailing list