From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 5 Dec 2006 23:32:36 -0000 Subject: [Cluster-devel] conga/luci cluster/form-macros cluster/resourc ... Message-ID: <20061205233236.13429.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2006-12-05 23:32:35 Modified files: luci/cluster : form-macros resource_form_handlers.js luci/site/luci/Extensions: cluster_adapters.py Log message: service add and edit fixes Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.120&r2=1.121 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/resource_form_handlers.js.diff?cvsroot=cluster&r1=1.23&r2=1.24 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.171&r2=1.172 --- conga/luci/cluster/form-macros 2006/12/05 06:44:09 1.120 +++ conga/luci/cluster/form-macros 2006/12/05 23:32:34 1.121 @@ -2857,6 +2857,14 @@ + + + Automatically start this service + + + + + @@ -2880,6 +2888,7 @@ + @@ -3022,7 +3031,8 @@ tal:content="sinfo/name | nothing" tal:attributes="class python: running and 'running' or 'stopped'" /> - +
@@ -3090,9 +3100,16 @@
+ + + +
+ Automatically start this service +
+ tal:attributes="value sinfo/name | string:1" /> +
@@ -3109,6 +3126,7 @@ + --- conga/luci/cluster/resource_form_handlers.js 2006/12/05 06:44:09 1.23 +++ conga/luci/cluster/resource_form_handlers.js 2006/12/05 23:32:34 1.24 @@ -381,6 +381,7 @@ var errors = new Array(); var form_xml = ''; var svc_name = null; + var autostart = 1; var form = document.getElementsByTagName('form'); for (var i = 0 ; i < form.length ; i++) { @@ -393,17 +394,40 @@ clr_form_err(form[i].service_name); svc_name = form[i].service_name.value; } + if (!form[i].autostart.checked) + autostart = 0; continue; } if (form[i].name == 'master' || !form[i].uuid || !form[i].uuid.value) continue; + var err = check_form(form[i]); if (err) errors = errors.concat(err); - var temp = form[i].innerHTML.match(/]+>/ig).toString().replace(/>(,|$)/g, '/>'); - if (!temp) - continue; + var temp = ''; + + var input_elem = form[i].getElementsByTagName('input'); + for (var j = 0 ; j < input_elem.length ; j++) { + var res_type = input_elem[j].type; + if (res_type == 'hidden' || res_type == 'text' || + res_type == 'password') + { + temp += ''; + } else if (res_type == 'checkbox' || res_type == 'radio') { + if (input_elem[j].checked) + temp += ''; + } + form_xml += '
' + temp + '
'; } @@ -420,6 +444,7 @@ /* sort this out in the backend */ master_form.form_xml.value = '' + form_xml + ''; master_form.svc_name.value = svc_name; + master_form.autostart = autostart; var confirm_msg = null; if (master_form.action.value == 'add') --- conga/luci/site/luci/Extensions/cluster_adapters.py 2006/12/05 06:44:10 1.171 +++ conga/luci/site/luci/Extensions/cluster_adapters.py 2006/12/05 23:32:35 1.172 @@ -12,8 +12,10 @@ from Ip import Ip from Clusterfs import Clusterfs from Fs import Fs +from RefObject import RefObject from NFSClient import NFSClient from NFSExport import NFSExport +from Service import Service from Netfs import Netfs from Vm import Vm from Script import Script @@ -396,15 +398,26 @@ response.redirect(request['URL'] + "?pagetype=" + CLUSTER_CONFIG + "&clustername=" + clusterName + '&busyfirst=true') def validateServiceAdd(self, request): + errors = list() + try: form_xml = request['form_xml'] if not form_xml: raise KeyError, 'form_xml must not be blank' + luci_log.debug_verbose('VSAXML DUMP: %s' % form_xml) 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.']}) try: + model = request.SESSION.get('model') + if not model: + 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.' ]}) + + try: doc = minidom.parseString(form_xml) forms = doc.getElementsByTagName('form') if len(forms) < 1: @@ -447,20 +460,21 @@ try: res_type = dummy_form['type'].strip() - if not res_type or not res_type in resourceAddHandler: + if not res_type: + raise Exception, 'no resource type was given' + if not res_type in resourceAddHandler: raise Exception, 'invalid resource type: %s' % res_type except Exception, e: luci_log.debug_verbose('vSA3: %s' % str(e)) - return (False, {'errors': ['An invalid resource type was specified: ' + res_type]}) + return (False, {'errors': [ 'An invalid resource type was specified' ]}) try: if dummy_form.has_key('immutable'): - model = request.SESSION.get('model') - if not model: - raise Exception, 'model is None' - resObj = getResource(model, dummy_form['resourceName']) + newRes = getResource(model, dummy_form['resourceName']) + resObj = RefObject(newRes) + resObj.setRef(newRes.getName()) else: - resObj = resourceAddHandler[res_type](request, dummy_form) + resObj = resourceAddHandler[res_type](request, dummy_form)[0] except Exception, e: resObj = None luci_log.debug_verbose('vSA4: type %s: %s' % (res_type, str(e))) @@ -468,8 +482,109 @@ if resObj is None: return (False, {'errors': [ 'An error occurred while adding %s' % res_type ]}) form_hash[form_id]['obj'] = resObj - - return (True, {'messages': ['This service has been updated.']}) + + if len(errors) > 0: + return (False, {'errors': errors}) + + try: + 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.' ]}) + + autostart = "1" + try: + if not request.form.has_key('autostart'): + autostart = "0" + except: + pass + + try: + cur_service = model.retrieveServiceByName(service_name) + except GeneralError, e: + luci_log.debug_verbose('vSA5a: no service named %s found' % service_name) + cur_service = None + except Exception, e: + luci_log.debug_verbose('vSA5a: no service named %s found: %s' % (service_name, str(e))) + cur_service = None + + 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 ]}) + 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 ]}) + else: + luci_log.debug_verbose('vSA4a: unknown action %s' % request.form['action']) + return (False, {'errors': [ 'An unknown action was specified.' ]}) + except Exception, e: + luci_log.debug_verbose('vSA5: no action type: %s' % str(e)) + + def buildSvcTree(parent, child_id_list): + for i in child_id_list: + try: + child = form_hash[i]['obj'] + if not child: + raise Exception, 'No object for %s' % i + except Exception, e: + luci_log.debug_verbose('bST0: %s' % str(e)) + continue + parent.addChild(child) + if 'kids' in form_hash[i]: + buildSvcTree(child, form_hash[i]['kids']) + + new_service = Service() + new_service.addAttribute('name', service_name) + new_service.attr_hash['autostart'] = autostart + + buildSvcTree(new_service, form_hash['toplevel']['kids']) + model.resourcemanager_ptr.addChild(new_service) + + clustername = model.getClusterName() + if not clustername: + luci_log.debug_verbose('vAS6: no cluname from mb') + return (False, {'errors': [ 'Unable to determine cluster name' ]}) + + try: + conf = model.exportModelAsString() + if not conf: + raise Exception, 'model string for %s is blank' % clustername + except Exception, e: + luci_log.debug_verbose('vAS6a: exportModelAsString : %s' \ + % str(e)) + return (False, {'errors': [ 'An error occurred while adding this service.' ]}) + + rc = getRicciAgent(self, clustername) + if not rc: + luci_log.debug_verbose('vAS6b: unable to find a ricci agent for cluster %s' % clustername) + return 'Unable to find a ricci agent for the %s cluster' % clustername + + try: + ragent = rc.hostname() + if not ragent: + luci_log.debug_verbose('vAS7: missing ricci hostname') + raise Exception, 'unknown ricci agent hostname' + + batch_number, result = 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.' + except Exception, e: + luci_log.debug_verbose('vAS9: %s' % str(e)) + return 'An error occurred while propagating the new cluster.conf: %s' % str(e) + + try: + if request.form['action'] == 'edit': + set_node_flag(self, clustername, ragent, str(batch_number), SERVICE_CONFIG, "Configuring service \'%s\'" % service_name) + else: + set_node_flag(self, clustername, ragent, str(batch_number), SERVICE_ADD, "Adding new service \'%s\'" % service_name) + except Exception, e: + luci_log.debug_verbose('vAS10: failed to set flags: %s' % str(e)) + + response = request.RESPONSE + response.redirect(request['URL'] + "?pagetype=" + SERVICES + "&clustername=" + clustername + '&busyfirst=true') def validateResourceAdd(self, request): try: @@ -1856,6 +1971,7 @@ if item['name'] == servicename: hmap['name'] = servicename starturls = list() + hmap['autostart'] = item['autostart'] if item['running'] == "true": hmap['running'] = "true" #In this case, determine where it can run... @@ -3952,6 +4068,9 @@ if form is None: form = request.form + if form is not None: + luci_log.debug_verbose('addIp DUMP: %s' % str(form.items())) + if not form: luci_log.debug_verbose('addIp error: form is missing') return None @@ -4526,7 +4645,7 @@ 'gfs': addGfs, 'nfsm': addNfsm, 'nfsx': addNfsx, - 'nfsc': addNfsx, + 'nfsc': addNfsc, 'scr': addScr, 'smb': addSmb }