conga/luci/site/luci/Extensions cluster_adapte ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-07-19 20:19:53
Modified files:
luci/site/luci/Extensions: cluster_adapters.py
homebase_adapters.py
Log message:
cluster create, and cluster remove (stop managing) bits
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&r1=1.13&r2=1.14
luci/site/luci/Extensions/cluster_adapters.py +101 -1
@@ -14,12 +14,111 @@ #then only display chooser if the current user has #permissions on at least one. If the user is admin, show ALL clusters - +from homebase_adapters import nodeAuth, nodeUnauth CLUSTER_FOLDER_PATH = '/luci/systems/cluster/' +def validatePost(request): + if int(request.form['pagetype']) != 6: + return + + errors = list() + nodeList = list() + nodeHash = {} + rnodeHash = {} + oldNodeHash = {} + oldRnodeHash = {} + requestResults = {} + + sessionData = request.SESSION.get('checkRet') + if sessionData and 'requestResults' in sessionData: + requestResults = sessionData['requestResults'] + if 'nodeHash' in requestResults: + oldNodeHash = requestResults['nodeHash'] + if 'rnodeHash' in requestResults: + oldRnodeHash = requestResults['rnodeHash'] + + if not 'clusterName' in request.form or not request.form['clusterName']: + return (False, {'errors': [ 'No cluster name was specified.' ] }) + clusterName = request.form['clusterName'] + + try: + numStorage = int(request.form['numStorage']) + except: + return (False, { 'errors': ['Unknown number of systems entered'], 'requestResults': requestResults }) + + if numStorage < 2: + return (False, { 'errors': ['A cluster must contain@least two nodes'], 'requestResults': requestResults }) + + i = 0 + while i < numStorage: + try: + sysData = request.form['__SYSTEM' + str(i)] + if not sysData or sysData[0] == '': + raise + + if len(sysData) < 2 or sysData[1] == '': + errors.append('No password was specified for host \"' + sysData[0] + '\"') + raise + except: + i += 1 + continue + + if len(sysData) > 1: + node = nodeAuth(None, sysData[0], sysData[1]) + + if oldRnodeHash and node['ricci_host'] in oldRnodeHash: + oldNode = oldRnodeHash[node['ricci_host']] + elif oldNodeHash and node['host'] in nodeHash: + oldNode = oldNodeHash[node['host']] + else: + oldNode = None + + if 'errors' in node: + errors.append(node['errors']) + node['errors'] = True + + if node['host'] in nodeHash or node['ricci_host'] in rnodeHash: + node['errors'] = True + errors.append('You added the node \"' + node['host'] + '\" more than once') + else: + if oldNode and 'prev_auth' in oldNode: + node['prev_auth'] = oldNode['prev_auth'] + + nodeHash[node['host']] = node + rnodeHash[node['ricci_host']] = node + nodeList.append(node) + i += 1 + + if len(nodeList) < 2: + errors.append('A cluster must contain@least two nodes') + + sfn = lambda x, y: \ + x['cur_auth'] - y['cur_auth'] or (('errors' in y) - ('errors' in x)) + nodeList.sort(sfn) + + dfn = lambda x: not 'cur_auth' in x or x['cur_auth'] != True + cluster_properties = { + 'clusterName': clusterName, + 'nodeList': nodeList, + 'nodeHash': nodeHash, + 'rnodeHash': rnodeHash, + 'isComplete': len(errors) < 1 and len(filter(dfn, nodeList)) == 0 + } + return (len(errors) < 1, {'errors': errors, 'requestResults': cluster_properties }) + def createCluChooser(self, request, systems): dummynode = {} + + if request.REQUEST_METHOD == 'POST': + ret = validatePost(request) + try: + request.SESSION.set('checkRet', ret[1]) + except: + request.SESSION.set('checkRet', {}) + else: + try: request.SESSION.set('checkRet', {}) + except: pass #First, see if a cluster is chosen, then #check that the current user can access that system
@@ -39,6 +138,7 @@ except KeyError, e: pagetype = "0" + cldata = {} cldata['Title'] = "Cluster List" cldata['cfg_type'] = "clusters"
luci/site/luci/Extensions/homebase_adapters.py +60 -46
177 lines not on this page · raw message