[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions FenceHandler.p ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	jparsons sourceware org	2006-12-18 04:44:52

Modified files:
	luci/site/luci/Extensions: FenceHandler.py cluster_adapters.py 
	                           conga_constants.py 

Log message:
	addresses 212021

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/FenceHandler.py.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.184&r2=1.185
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_constants.py.diff?cvsroot=cluster&r1=1.28&r2=1.29

--- conga/luci/site/luci/Extensions/FenceHandler.py	2006/11/09 16:45:02	1.5
+++ conga/luci/site/luci/Extensions/FenceHandler.py	2006/12/18 04:44:52	1.6
@@ -2,9 +2,12 @@
 from ValidationError import ValidationError
 import MessageLibrary
 import ModelBuilder
+from conga_constants import *
 
 INSTALLDIR="/usr/share/system-config-cluster"
 
+FD_NEW_SUCCESS = "New %s successfully added to cluster"
+FD_NEW_FAIL = "No agent type %s in shared device list"
 FD_PROVIDE_NAME = "A unique name must be provided for each Fence Device"
 
 FD_PROVIDE_PATH = "An xCAT path must be provided for each xCAT Fence Device"
@@ -52,6 +55,8 @@
               "fence_egenera":"Egenera SAN Controller",
               "fence_bullpap":"Bull PAP",
               "fence_drac":"DRAC",
+              "fence_xvm":"Virtual Machine Fencing",
+              "fence_scsi":"SCSI Reservation",
               "fence_ipmilan":"IPMI Lan",
               "fence_manual":"Manual Fencing" }
 
@@ -1025,4 +1030,262 @@
       gtkentry.set_text(name)
       # select text
       raise ValidationError('FATAL', ILLEGAL_CHARS_REPLACED)
- 
+
+  def validateNewFenceDevice(self, form, model): 
+    try:
+      agent_type = form['agent']
+    except KeyError, e:
+      return (FD_VAL_FAIL, "No agent type in form submission")
+
+    ##Now that we have an agent type, we should check the fencedev name
+    ##before wasting any time checking other fields.
+    try:
+      fencedev_name = form['name']
+      fencedev_name = fencedev_name.strip()
+    except KeyError, e:
+      return (FD_VAL_FAIL, "No device name in form submission")
+
+    if fencedev_name == "":
+      return (1, "A unique name is required for every fence device")
+
+    fencedevs = model.getFenceDevices()
+    for fd in fencedevs:
+      if fd.getName().strip() == fencedev_name
+        return (FD_VAL_FAIL, FD_PROVIDE_NAME)
+
+    if agent_type == "fence_apc":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_wti":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_brocade":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_vixel":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+
+    elif agent_type == "fence_mcdata":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+
+    elif agent_type == "fence_gnbd":
+      try:
+        server = form['server']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_SERVER)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("server",server)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_egenera":
+      try:
+        cserver = form['cserver']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_CSERVER)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("cserver",cserver)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+
+    elif agent_type == "fence_sanbox2":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_bladecenter":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_bullpap":
+      try:
+        ip = form['ipaddr']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_IP)
+      try:
+        log = form['login']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_LOGIN)
+      try:
+        pwd = form['passwd']
+      except KeyError, e:
+        return (FD_VAL_FAIL, FD_PROVIDE_PASSWD)
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedev.addAttribute("ipaddr",ip)
+      fencedev.addAttribute("login",log)
+      fencedev.addAttribute("passwd",pwd)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+
+    elif agent_type == "fence_xvm":
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    elif agent_type == "fence_scsi":
+
+      fencedev = FenceDevice()
+      fencedev.addAttribute("agent",agent_type)
+      fencedev.addAttribute("name",fencedev_name)
+      fencedevptr = model.getFenceDevicePtr()
+      fencedevptr.addChild(fencedev)
+      return (FD_VAL_SUCCESS, FD_NEW_SUCCESS % FENCE_OPTS[agent_type])
+
+    #Oh-oh...no agent match
+    else:
+      return (FD_VAL_FAIL, FD_NEW_FAIL % agent_type)
+      
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/12/14 23:14:54	1.184
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/12/18 04:44:52	1.185
@@ -1101,9 +1101,146 @@
 	response.redirect(request['URL'] + "?pagetype=" + CLUSTER_CONFIG + "&clustername=" + clustername + '&busyfirst=true')
 
 def validateFenceAdd(self, request):
-	return (True, {})
+  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('VFE: no model, no cluster name')
+        return (False, {'errors': ['No cluster model was found.']})
+                                                                                
+    try:
+      model = getModelForCluster(self, cluname)
+    except:
+      model = None
+                                                                                
+    if model is None:
+      luci_log.debug_verbose('VFE: unable to get model from session')
+      return (False, {'errors': ['No cluster model was found.']})
+
+	form = None
+	try:
+		response = request.response
+		form = request.form
+		if not form:
+			form = None
+			raise Exception, 'no form was submitted'
+	except:
+		pass
+
+	if form is None:
+		luci_log.debug_verbose('VFE: no form was submitted')
+		return (False, {'errors': ['No form was submitted']})
+
+  fencehandler = FenceHandler()
+  error_code,error_string = fencehandler.validateNewFenceDevice(form, model)
+  if error_code == FD_VAL_SUCCESS:
+    message.append(error_string)
+		try:
+      cp = model.getClusterPtr()
+			cp.incrementConfigVersion()
+			model.setModified(True)
+			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')
+
+	  try:
+		  clustername = model.getClusterName()
+		  if not clustername:
+			  raise Exception, 'cluster name from modelb.getClusterName() is blank'
+	  except Exception, e:
+		  luci_log.debug_verbose('VFA: error: getClusterName: %s' % str(e))
+		  errors.append('Unable to determine cluster name from model') 
+
+	  if not rc:
+		  rc = getRicciAgent(self, clustername)
+		  if not rc:
+			  luci_log.debug_verbose('VFA: 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 = setClusterConf(rc, str(conf_str))
+		  if batch_id is None or result is None:
+			  luci_log.debug_verbose('VFA: 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
+
+		return (TRUE, {'errors': errors, 'messages': messages})
+  else:
+    errors.append(error_string)
+		return (FALSE, {'errors': errors, 'messages': messages})
+
 
 def validateFenceEdit(self, request):
+  errors = list()
+  messages = list()
+                                                                                
+  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('VFE: no model, no cluster name')
+        return (False, {'errors': ['No cluster model was found.']})
+                                                                                
+    try:
+      model = getModelForCluster(self, cluname)
+    except:
+      model = None
+                                                                                
+    if model is None:
+      luci_log.debug_verbose('VFE: unable to get model from session')
+      return (False, {'errors': ['No cluster model was found.']})
+
+	form = None
+	try:
+		response = request.response
+		form = request.form
+		if not form:
+			form = None
+			raise Exception, 'no form was submitted'
+	except:
+		pass
+
+	if form is None:
+		luci_log.debug_verbose('VFE: no form was submitted')
+		return (False, {'errors': ['No form was submitted']})
+
+  #This is a fence edit situation, so the model should already have an
+  #entry for this fence device.
+  #
+  #pass form and model to validation method, then save changes if it passes.
+
+  ##########End of orig method
 	return (True, {})
 
 def validateDaemonProperties(self, request):
@@ -1213,7 +1350,7 @@
 		luci_log.debug_verbose('VP1: no handler for page type %d' % pagetype)
 		return None
 	else:
-		return formValidators[pagetype](self, request)
+		return formValidators[pagetype](self, model, request)
 
 
 def createCluChooser(self, request, systems):
--- conga/luci/site/luci/Extensions/conga_constants.py	2006/12/06 18:38:55	1.28
+++ conga/luci/site/luci/Extensions/conga_constants.py	2006/12/18 04:44:52	1.29
@@ -92,6 +92,9 @@
 NODE_INACTIVE_STR="Not a Cluster Member"
 NODE_UNKNOWN_STR="Unknown State"
 
+FD_VAL_FAIL=1
+FD_VAL_SUCCESS=0
+
 #cluster/node create batch task index
 INSTALL_TASK = 1
 DISABLE_SVC_TASK = 2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]