[Cluster-devel] conga/luci cluster/form-macros cluster/validat ...

rmccabe at sourceware.org rmccabe at sourceware.org
Thu Feb 8 03:43:00 UTC 2007


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-02-08 03:42:58

Modified files:
	luci/cluster   : form-macros validate_fdom.js 
	luci/site/luci/Extensions: cluster_adapters.py 

Log message:
	Support editing fdoms

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.181&r2=1.182
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/validate_fdom.js.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.233&r2=1.234

--- conga/luci/cluster/form-macros	2007/02/08 02:34:35	1.181
+++ conga/luci/cluster/form-macros	2007/02/08 03:42:58	1.182
@@ -4353,14 +4353,14 @@
 				<td>
 					<input type="checkbox" name="prioritized" id="prioritized"
 						onchange="fdom_set_prioritized(this.form, this.checked)"
-						tal:attributes="checked fdom/prioritied | nothing" />
+						tal:attributes="checked python: (fdom and 'prioritized' in fdom and fdom['prioritized'] == '1') and 'checked' or ''" />
 				</td>
 			</tr>
 			<tr class="systemsTable">
 				<td>Restrict failover to this domain's members</td>
 				<td>
 					<input type="checkbox" name="restricted"
-						tal:attributes="checked fdom/restricted | nothing" />
+						tal:attributes="checked python: (fdom and 'restricted' in fdom and fdom['restricted'] == '1') and 'checked' or ''" />
 				</td>
 			</tr>
 			<tr class="systemsTable">
@@ -4393,15 +4393,17 @@
 					<td class="systemsTable" width="10%">
 						<input type="checkbox"
 							onchange="fdom_set_member(this.form, this.name, this.checked)"
-							tal:attributes="name n" />
+							tal:attributes="
+								checked python: ('members' in fdom and n in fdom['members']) and 'checked' or '';
+								name n" />
 					</td>
 					<td class="systemsTable" width="75%">
 						<input type="text" class="fdom_priority"
 							tal:attributes="
 								id n;
 								name python: '__PRIORITY__' + n;
-								value from/members/n/priority | string:1;
-								disabled not:fdom/prioritied | nothing" />
+								value python: ('members' in fdom and n in fdom['members'] and 'priority' in fdom['members'][n]) and fdom['members'][n]['priority'] or '1';
+								disabled python: (not fdom or not 'prioritized' in fdom or fdom['prioritized'] != '1' or not 'members' in fdom or not n in fdom['members']) and 'disabled' or ''" />
 					</td>
 				</tr>
 			</tal:block>
@@ -4424,11 +4426,13 @@
 	<script type="text/javascript">
 		set_page_title('Luci — cluster — failover domains — Configure a failover domain');
 	</script>
-	<h2>Failover Domain Configuration Form</h2>
 </div>
 
 <div metal:define-macro="fdom-form">
 	<h2>Failover Domain Form</h2>
+	<tal:block tal:define="fdom python:here.getFdomInfo(modelb, request)">
+		<tal:block metal:use-macro="here/form-macros/macros/fdom-macro" />
+	</tal:block>
 </div>
 
 <div metal:define-macro="fdomprocess-form">
--- conga/luci/cluster/validate_fdom.js	2007/02/08 02:34:35	1.2
+++ conga/luci/cluster/validate_fdom.js	2007/02/08 03:42:58	1.3
@@ -31,6 +31,10 @@
 	if (error_dialog(errors))
 		return (-1);
 
-	if (confirm('Add this failover domain?'))
+	var confirm_msg = 'Add this failover domain?';
+	if (form.oldname)
+		confirm_msg = 'Update this failover domain?';
+
+	if (confirm(confirm_msg))
 		form.submit();
 }
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2007/02/08 02:34:36	1.233
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2007/02/08 03:42:58	1.234
@@ -2013,19 +2013,26 @@
 
 def validateFdom(self, request):
 	errors = list()
-	model = request.SESSION.get('model')
+
+	try:
+		model = request.SESSION.get('model')
+		if not model:
+			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.' ]})
 
 	prioritized = False
 	try:
 		prioritized = request.form.has_key('prioritized')
 	except:
-		pass
+		prioritized = False
 
 	restricted = False
 	try:
 		restricted = request.form.has_key('restricted')
 	except:
-		pass
+		restricted = False
 
 	clustername = None
 	try:
@@ -2069,12 +2076,14 @@
 		if fdom is None:
 			luci_log.debug_verbose('validateFdom1: No fdom named %s exists' % oldname)
 			errors.append('No failover domain named \"%s" exists.' % oldname)
-		fdom.children = list()
+		else:
+			fdom.addAttribute('name', name)
+			fdom.children = list()
 	else:
 		fdom = FailoverDomain()
 		fdom.addAttribute('name', name)
 
-	if fdom is None:
+	if fdom is None or len(errors) > 0:
 		return (False, {'errors': errors })
 
 	if prioritized:
@@ -2106,7 +2115,8 @@
 
 	try:
 		fdom_ptr = model.getFailoverDomainPtr()
-		fdom_ptr.addChild(fdom)
+		if not oldname:
+			fdom_ptr.addChild(fdom)
 		model.setModified(True)
 		conf = str(model.exportModelAsString())
 	except Exception, e:
@@ -2128,12 +2138,15 @@
 		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
 
 	try:
-		set_node_flag(self, clustername, ragent, str(batch_number), FDOM_ADD, 'Creating failover domain \"%s\"' % name)
+		if oldname:
+			set_node_flag(self, clustername, ragent, str(batch_number), FDOM, 'Updating failover domain \"%s\"' % oldname)
+		else:
+			set_node_flag(self, clustername, ragent, str(batch_number), FDOM_ADD, 'Creating failover domain \"%s\"' % name)
 	except Exception, e:
 		luci_log.debug_verbose('validateFdom5: failed to set flags: %s' % str(e))
 
 	response = request.RESPONSE
-	response.redirect(request['URL'] + "?pagetype=" + FDOM_CONFIG + "&clustername=" + clustername + '&fdomname=' + name + '&busyfirst=true')
+	response.redirect(request['URL'] + "?pagetype=" + FDOM + "&clustername=" + clustername + '&fdomname=' + name + '&busyfirst=true')
 
 def validateVM(self, request):
 	errors = list()
@@ -2249,6 +2262,7 @@
 	31: validateResourceAdd,
 	33: validateResourceAdd,
 	41: validateFdom,
+	44: validateFdom,
 	51: validateFenceAdd,
 	54: validateFenceEdit,
 	55: validateDaemonProperties,
@@ -3496,6 +3510,39 @@
 	response = req.RESPONSE
 	response.redirect(req['URL'] + "?pagetype=" + SERVICE_LIST + "&clustername=" + cluname + '&busyfirst=true')
 
+def getFdomInfo(self, model, request):
+	fhash = {}
+	fhash['members'] = {}
+
+	try:
+		fdom = model.getFailoverDomainByName(request['fdomname'])
+	except Exception, e:
+		luci_log.debug_verbose('getFdomInfo0: %s' % str(e))
+		return fhash
+
+	fhash['name'] = fdom.getName()
+
+	ordered_attr = fdom.getAttribute('ordered')
+	if ordered_attr is not None and (ordered_attr == "true" or ordered_attr == "1"):
+		fhash['prioritized'] = '1'
+	else:
+		fhash['prioritized'] = '0'
+
+	restricted_attr = fdom.getAttribute('restricted')
+	if restricted_attr is not None and (restricted_attr == "true" or restricted_attr == "1"):
+		fhash['restricted'] = '1'
+	else:
+		fhash['restricted'] = '0'
+
+	nodes = fdom.getChildren()
+	for node in nodes:
+		try:
+			priority = node.getAttribute('priority')
+		except:
+			priority = '1'
+		fhash['members'][node.getName()] = { 'priority': priority }
+	return fhash
+
 def getFdomsInfo(self, model, request, clustatus):
   slist = list()
   nlist = list()
@@ -3512,7 +3559,7 @@
   for fdom in fdoms:
     fdom_map = {}
     fdom_map['name'] = fdom.getName()
-    fdom_map['cfgurl'] = baseurl + "?pagetype=" + FDOM_LIST + "&clustername=" + clustername
+    fdom_map['cfgurl'] = baseurl + "?pagetype=" + FDOM + "&clustername=" + clustername + '&fdomname=' + fdom.getName()
     ordered_attr = fdom.getAttribute('ordered')
     restricted_attr = fdom.getAttribute('restricted')
     if ordered_attr is not None and (ordered_attr == "true" or ordered_attr == "1"):




More information about the Cluster-devel mailing list