[Cluster-devel] conga/luci cluster/form-macros site/luci/Exten ...
rmccabe at sourceware.org
rmccabe at sourceware.org
Wed Jan 31 23:36:27 UTC 2007
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-01-31 23:36:26
Modified files:
luci/cluster : form-macros
luci/site/luci/Extensions: cluster_adapters.py
Log message:
fix vm service code
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.168&r2=1.169
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.221&r2=1.222
--- conga/luci/cluster/form-macros 2007/01/31 05:26:44 1.168
+++ conga/luci/cluster/form-macros 2007/01/31 23:36:26 1.169
@@ -3735,31 +3735,93 @@
</div>
<div metal:define-macro="xenvmadd-form">
- <span tal:define="global vmforminfo python: here.getXenVMInfo(modelb, request)"/>
- <form method="get" tal:attributes="action vmforminfo/formurl">
- <h4>Name for this VM: </h4><input type="text" name="xenvmname" value=""/>
- <h4>Path to configuration file: </h4><input type="text" name="xenvmpath" value=""/>
- <input type="submit" value="Create Xen VM"/>
- </form>
+<form method="post" action="">
+ <input type="hidden" name="clustername"
+ tal:attributes="value request/clustername | nothing" />
+
+ <input type="hidden" name="pagetype"
+ tal:attributes="value request/pagetype | nothing" />
+
+ <div class="service_comp_list">
+ <table class="systemsTable">
+ <thead class="systemsTable">
+ <tr class="systemsTable"><td class="systemsTable">
+ <p class="reshdr">Create a Virtual Machine Service</p>
+ </td></tr>
+ <tfoot class="systemsTable">
+ <tr class="systemsTable"><td colspan="2">
+ <div class="hbSubmit">
+ <input type="submit" value="Create Virtual Machine" />
+ </div>
+ </td></tr>
+ </tfoot>
+ <tbody class="systemsTable">
+ <tr class="systemsTable">
+ <td>Virtual machine name</td>
+ <td><input type="text" name="vmname" value="" /></td>
+ </tr>
+ <tr class="systemsTable">
+ <td>Path to VM configuration file</td>
+ <td><input type="text" name="vmpath" value="" /></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+</form>
</div>
<div metal:define-macro="xenvmconfig-form">
- <h4>Properties for Xen VM <font color="green"><span tal:content="request/servicename"/></font></h4>
- <span tal:define="global xeninfo python:here.getXenVMInfo(modelb, request)">
- <form method="get" tal:attributes="action xeninfo/formurl">
- <h4>Name of VM: </h4><input type="text" name="xenvmname" value="" tal:attributes="value xeninfo/name"/>
- <h4>Path to configuration file: </h4><input type="text" name="xenvmpath" value="" tal:attributes="value xeninfo/path"/>
- <input type="button" value="Delete"/>
- <input type="submit" value="Update"/>
- </form>
- </span>
+<form method="post" action=""
+ tal:define="vminfo python:here.getXenVMInfo(modelb, request)">
+
+ <input type="hidden" name="clustername"
+ tal:attributes="value request/clustername | nothing" />
+
+ <input type="hidden" name="pagetype"
+ tal:attributes="value request/pagetype | nothing" />
+
+ <input type="hidden" name="oldname"
+ tal:attributes="value vminfo/name | nothing" />
+
+ <div class="service_comp_list">
+ <table class="systemsTable">
+ <thead class="systemsTable">
+ <tr class="systemsTable"><td class="systemsTable">
+ <p class="reshdr">Properties for <tal:block tal:replace="vminfo/name | string:virtual machine"/></p>
+ </td></tr>
+ <tfoot class="systemsTable">
+ <tr class="systemsTable"><td colspan="2">
+ <div class="hbSubmit">
+ <input name="submit" type="submit" value="Update Virtual Machine" />
+ <input name="delete" type="submit" value="Delete Virtual Machine" />
+ </div>
+ </td></tr>
+ </tfoot>
+ <tbody class="systemsTable">
+ <tr class="systemsTable">
+ <td>Virtual machine name</td>
+ <td>
+ <input type="text" name="vmname"
+ tal:attributes="value vminfo/name | nothing" />
+ </td>
+ </tr>
+ <tr class="systemsTable">
+ <td>Path to VM configuration file</td>
+ <td>
+ <input type="text" name="vmpath"
+ tal:attributes="value vminfo/path | nothing" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+</form>
</div>
<div metal:define-macro="xenvmprocess">
<span tal:define="retrn python:here.processXenVM(request)"/>
</div>
-
<div metal:define-macro="serviceadd-form">
<script type="text/javascript">
set_page_title('Luci â cluster â services â Add a new service');
--- conga/luci/site/luci/Extensions/cluster_adapters.py 2007/01/31 19:28:08 1.221
+++ conga/luci/site/luci/Extensions/cluster_adapters.py 2007/01/31 23:36:26 1.222
@@ -1980,10 +1980,101 @@
response.redirect(request['URL'] + "?pagetype=" + NODE + "&clustername=" + clustername + '&nodename=' + nodename + '&busyfirst=true')
+def validateVM(self, request):
+ errors = list()
+
+ model = request.SESSION.get('model')
+
+ try:
+ vm_name = request.form['vmname'].strip()
+ if not vm_name:
+ 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.')
+
+ try:
+ vm_path = request.form['vmpath'].strip()
+ if not vm_path:
+ raise '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.')
+
+ if len(errors) > 0:
+ return (False, {'errors': errors })
+
+ isNew = False
+ try:
+ old_name = request.form['oldname'].strip()
+ if not old_name:
+ raise KeyError, 'oldname'
+ except KeyError, e:
+ isNew = True
+
+ if isNew is True:
+ xvm = Vm()
+ xvm.addAttribute('name', vm_name)
+ xvm.addAttribute('path', vm_path)
+ rmptr = model.getResourceManagerPtr()
+ rmptr.addChild(xvm)
+ else:
+ try:
+ xvm = model.retrieveXenVMsByName(old_name)
+ if not xvm:
+ raise Exception, 'not found'
+ except:
+ return (False, {'errors': ['No virtual machine named \"%s\" exists.' % old_name ]})
+ xvm.addAttribute('name', vm_name)
+ xvm.addAttribute('path', vm_path)
+
+ try:
+ model.setModified(True)
+ stringbuf = str(model.exportModelAsString())
+ if not stringbuf:
+ raise Exception, 'model is blank'
+ except Exception, e:
+ luci_log.debug_verbose('validateVM2: %s' % str(e))
+ errors.append('Unable to update the cluster model')
+
+ try:
+ clustername = model.getClusterName()
+ if not clustername:
+ 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.')
+
+ if len(errors) > 0:
+ return (False, {'errors': errors })
+
+ 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.']})
+
+ batch_number, result = 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 ]})
+
+ try:
+ if isNew is True:
+ set_node_flag(self, clustername, rc.hostname(), str(batch_number), XENVM_ADD, "Creating virtual machine \'%s\'" % vm_name)
+ else:
+ set_node_flag(self, clustername, rc.hostname(), str(batch_number), XENVM_CONFIG, "Configuring virtual machine \'%s\'" % vm_name)
+ except Exception, e:
+ luci_log.debug_verbose('validateVM6: failed to set flags: %s' % str(e))
+
+ response = request.RESPONSE
+ response.redirect(request['URL'] + "?pagetype=" + SERVICES + "&clustername=" + clustername + '&busyfirst=true')
+
formValidators = {
6: validateCreateCluster,
7: validateConfigCluster,
15: validateAddClusterNode,
+ 18: validateVM,
+ 19: validateVM,
21: validateServiceAdd,
24: validateServiceAdd,
31: validateResourceAdd,
@@ -2959,7 +3050,10 @@
itemmap['cfgurl'] = baseurl + "?" + "clustername=" + cluname + "&servicename=" + item['name'] + "&pagetype=" + SERVICE
itemmap['delurl'] = baseurl + "?" + "clustername=" + cluname + "&servicename=" + item['name'] + "&pagetype=" + SERVICE_DELETE
- svc = model.retrieveServiceByName(item['name'])
+ try:
+ svc = model.retrieveServiceByName(item['name'])
+ except:
+ continue
dom = svc.getAttribute("domain")
if dom is not None:
itemmap['faildom'] = dom
@@ -4727,49 +4821,7 @@
return getNodeLogs(rc)
def processXenVM(self, req):
- model = req.SESSION.get('model')
- isNew = False
- try:
- xenvmname = req['servicename']
- except KeyError, e:
- isNew = True
-
- if isNew == True:
- xvm = Vm()
- xvm.addAttribute("name", req.form['xenvmname'])
- xvm.addAttribute("path", req.form['xenvmpath'])
- rmptr = model.getResourceManagerPtr()
- rmptr.addChild(xvm)
- else:
- xvm = model.retrieveXenVMsByName(self, xenvmname)
- xvm.addAttribute("name", req.form['xenvmname'])
- xvm.addAttribute("path", req.form['xenvmpath'])
-
- try:
- cp = model.getClusterPtr()
- cp.incrementConfigVersion()
- model.setModified(True)
- stringbuf = model.exportModelAsString()
- if not stringbuf:
- raise Exception, 'model is blank'
- except Exception, e:
- luci_log.debug_verbose('exportModelAsString error: %s' % str(e))
- return None
-
- try:
- clustername = model.getClusterName()
- if not clustername:
- raise Exception, 'cluster name from model.getClusterName() is blank'
- except Exception, e:
- luci_log.debug_verbose('error: getClusterName: %s' % str(e))
- return None
-
- rc = getRicciAgent(self, clustername)
- if not rc:
- luci_log.debug_verbose('Unable to find a ricci agent for the %s cluster' % clustername)
- return None
-
- setClusterConf(rc, stringbuf)
+ pass
def getXenVMInfo(self, model, request):
map = {}
More information about the Cluster-devel
mailing list