[Cluster-devel] conga/luci cluster/form-macros cluster/validat ...
rmccabe at sourceware.org
rmccabe at sourceware.org
Thu Feb 8 02:34:38 UTC 2007
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-02-08 02:34:36
Modified files:
luci/cluster : form-macros validate_fdom.js
luci/site/luci/Extensions: FailoverDomain.py ModelBuilder.py
cluster_adapters.py
Log message:
Support for adding failover domains
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.180&r2=1.181
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/validate_fdom.js.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/FailoverDomain.py.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ModelBuilder.py.diff?cvsroot=cluster&r1=1.21&r2=1.22
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.232&r2=1.233
--- conga/luci/cluster/form-macros 2007/02/07 22:06:40 1.180
+++ conga/luci/cluster/form-macros 2007/02/08 02:34:35 1.181
@@ -4324,6 +4324,9 @@
<tal:block metal:define-macro="fdom-macro">
<script type="text/javascript"
+ src="/luci/homebase/homebase_common.js">
+</script>
+<script type="text/javascript"
src="/luci/cluster/validate_fdom.js">
</script>
@@ -4348,8 +4351,8 @@
<tr class="systemsTable">
<td>Prioritized</td>
<td>
- <input type="checkbox" name="prioritized"
- onchange="fdom_set_prioritized(this.form, !this.checked)"
+ <input type="checkbox" name="prioritized" id="prioritized"
+ onchange="fdom_set_prioritized(this.form, this.checked)"
tal:attributes="checked fdom/prioritied | nothing" />
</td>
</tr>
@@ -4371,7 +4374,8 @@
<tfoot class="systemsTable">
<tr class="systemsTable"><td>
<div class="hbSubmit">
- <input type="button" name="submit" value="Submit" />
+ <input type="button" name="add" value="Submit"
+ onclick="validate_add_fdom(this.form)" />
</div>
</td></tr>
</tfoot>
@@ -4387,12 +4391,15 @@
<td class="systemsTable" width="33%">
<tal:block tal:replace="n" />
<td class="systemsTable" width="10%">
- <input type="checkbox" name="n" />
+ <input type="checkbox"
+ onchange="fdom_set_member(this.form, this.name, this.checked)"
+ tal:attributes="name n" />
</td>
<td class="systemsTable" width="75%">
<input type="text" class="fdom_priority"
tal:attributes="
- name python: '__PRIORITY__:' + n;
+ id n;
+ name python: '__PRIORITY__' + n;
value from/members/n/priority | string:1;
disabled not:fdom/prioritied | nothing" />
</td>
--- conga/luci/cluster/validate_fdom.js 2007/02/07 22:06:40 1.1
+++ conga/luci/cluster/validate_fdom.js 2007/02/08 02:34:35 1.2
@@ -4,14 +4,25 @@
return (-1);
for (var i = 0 ; i < prilist.length ; i++) {
if (prilist[i].type == 'text' && prilist[i].className == 'fdom_priority')
- prilist[i].disabled = state;
+ prilist[i].disabled = !state || !form[prilist[i].id][0].checked;
}
}
+function fdom_set_member(form, name, state) {
+ var prioritized = document.getElementById('prioritized');
+ if (!prioritized)
+ return (-1);
+ prioritized = prioritized.checked;
+ var member_pri_elem = document.getElementById(name);
+ if (!member_pri_elem)
+ return (-1);
+ member_pri_elem.disabled = !prioritized || !state;
+}
+
function validate_add_fdom(form) {
var errors = new Array();
- if (!form.name || str_is_blank(fdom.name.value)) {
+ if (!form.name || str_is_blank(form.name.value)) {
set_form_err(form.name);
errors.append('No name was given for this failover domain.');
} else
--- conga/luci/site/luci/Extensions/FailoverDomain.py 2006/05/30 20:17:21 1.1
+++ conga/luci/site/luci/Extensions/FailoverDomain.py 2007/02/08 02:34:36 1.2
@@ -22,7 +22,7 @@
def getProperties(self):
stringbuf = ""
restricted_status = ""
- ordereded_status = ""
+ ordered_status = ""
string_restricted = ""
string_ordered = ""
string_num_kin = ""
--- conga/luci/site/luci/Extensions/ModelBuilder.py 2007/02/07 16:55:15 1.21
+++ conga/luci/site/luci/Extensions/ModelBuilder.py 2007/02/08 02:34:36 1.22
@@ -627,10 +627,17 @@
return list()
else:
return self.failoverdomains_ptr.getChildren()
-
+
def getFailoverDomainPtr(self):
return self.failoverdomains_ptr
+ def getFailoverDomainByName(self, fdom_name):
+ fdoms = self.getFailoverDomains()
+ for i in fdoms:
+ if i.getName() == fdom_name:
+ return i
+ return None
+
def getFailoverDomainsForNode(self, nodename):
matches = list()
faildoms = self.getFailoverDomains()
--- conga/luci/site/luci/Extensions/cluster_adapters.py 2007/02/07 22:06:40 1.232
+++ conga/luci/site/luci/Extensions/cluster_adapters.py 2007/02/08 02:34:36 1.233
@@ -11,6 +11,8 @@
from Ip import Ip
from Clusterfs import Clusterfs
from Fs import Fs
+from FailoverDomain import FailoverDomain
+from FailoverDomainNode import FailoverDomainNode
from RefObject import RefObject
from ClusterNode import ClusterNode
from NFSClient import NFSClient
@@ -2009,6 +2011,130 @@
response.redirect(request['URL'] + "?pagetype=" + NODE + "&clustername=" + clustername + '&nodename=' + nodename + '&busyfirst=true')
+def validateFdom(self, request):
+ errors = list()
+ model = request.SESSION.get('model')
+
+ prioritized = False
+ try:
+ prioritized = request.form.has_key('prioritized')
+ except:
+ pass
+
+ restricted = False
+ try:
+ restricted = request.form.has_key('restricted')
+ except:
+ pass
+
+ clustername = None
+ try:
+ clustername = request.form['clustername'].strip()
+ if not clustername:
+ raise Exception, 'blank'
+ except:
+ try:
+ clustername = model.getClusterName()
+ if not clustername:
+ raise Exception, 'blank'
+ except:
+ clustername = None
+
+ if not clustername:
+ 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.')
+ luci_log.debug_verbose('validateFdom0: %s' % str(e))
+
+ oldname = None
+ try:
+ oldname = request.form['oldname'].strip()
+ if not oldname:
+ raise Exception, 'blank'
+ except:
+ pass
+
+ if oldname is None or oldname != name:
+ if model.getFailoverDomainByName(name) is not None:
+ 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)
+ fdom.children = list()
+ else:
+ fdom = FailoverDomain()
+ fdom.addAttribute('name', name)
+
+ if fdom is None:
+ return (False, {'errors': errors })
+
+ if prioritized:
+ fdom.addAttribute('ordered', '1')
+ else:
+ fdom.addAttribute('ordered', '0')
+
+ if restricted:
+ fdom.addAttribute('restricted', '1')
+ else:
+ fdom.addAttribute('restricted', '0')
+
+ cluster_nodes = map(lambda x: str(x.getName()), model.getNodes())
+
+ for i in cluster_nodes:
+ if request.form.has_key(i):
+ fdn = FailoverDomainNode()
+ fdn.addAttribute('name', i)
+ if prioritized:
+ priority = 1
+ try:
+ priority = int(request.form['__PRIORITY__' + i].strip())
+ if priority < 1:
+ priority = 1
+ except Exception, e:
+ priority = 1
+ fdn.addAttribute('priority', str(priority))
+ fdom.addChild(fdn)
+
+ try:
+ fdom_ptr = model.getFailoverDomainPtr()
+ fdom_ptr.addChild(fdom)
+ model.setModified(True)
+ conf = str(model.exportModelAsString())
+ except Exception, e:
+ luci_log.debug_verbose('validateFdom2: %s' % str(e))
+ errors.append('Unable to update the cluster configuration.')
+
+ if len(errors) > 0:
+ return (False, {'errors': errors })
+
+ rc = getRicciAgent(self, clustername)
+ if not rc:
+ luci_log.debug_verbose('validateFdom3: unable to find a ricci agent for cluster %s' % clustername)
+ return (False, {'errors': ['Unable to find a ricci agent for the %s cluster' % clustername ]})
+ ragent = rc.hostname()
+
+ batch_number, result = 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.' ]})
+
+ try:
+ 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')
+
def validateVM(self, request):
errors = list()
@@ -2122,6 +2248,7 @@
24: validateServiceAdd,
31: validateResourceAdd,
33: validateResourceAdd,
+ 41: validateFdom,
51: validateFenceAdd,
54: validateFenceEdit,
55: validateDaemonProperties,
More information about the Cluster-devel
mailing list