From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 15 Mar 2007 22:08:43 -0000 Subject: [Cluster-devel] conga/luci cluster/resource-form-macros cluste ... Message-ID: <20070315220843.2757.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 2007-03-15 22:08:43 Modified files: luci/cluster : resource-form-macros resource_form_handlers.js luci/site/luci/Extensions: ModelBuilder.py TagObject.py cluster_adapters.py Log message: Make the fsid field optional for fs and clusterfs resources. If the user provides nothing, an invalid id, or a duplicate, generate a unique fsid. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/resource-form-macros.diff?cvsroot=cluster&r1=1.36&r2=1.37 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/resource_form_handlers.js.diff?cvsroot=cluster&r1=1.33&r2=1.34 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ModelBuilder.py.diff?cvsroot=cluster&r1=1.25&r2=1.26 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/TagObject.py.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.249&r2=1.250 --- conga/luci/cluster/resource-form-macros 2007/03/07 18:04:05 1.36 +++ conga/luci/cluster/resource-form-macros 2007/03/15 22:08:42 1.37 @@ -463,7 +463,7 @@ - File system ID + File system ID (optional) - File system ID + File system ID (optional) 0: + for child in self.children: + if child == None: + continue + child.searchTree(objlist, tagtype) --- conga/luci/site/luci/Extensions/cluster_adapters.py 2007/03/12 05:46:59 1.249 +++ conga/luci/site/luci/Extensions/cluster_adapters.py 2007/03/15 22:08:42 1.250 @@ -56,6 +56,27 @@ except: pass +def get_fsid_list(model): + obj_list = model.searchObjectTree('fs') + obj_list.extend(model.searchObjectTree('clusterfs')) + return map(lambda x: x.getAttribute('fsid') and int(x.getAttribute('fsid')) or 0, obj_list) + +def fsid_is_unique(fsid): + fsid_list = get_fsid_list + return fsid not in fsid_list + +def generate_fsid(model, name): + import binascii + from random import random + fsid_list = get_fsid_list(model) + + fsid = binascii.crc32(name) & 0xffff + dupe = fsid in fsid_list + while dupe is True: + fsid = (fsid + random.randrange(1, 0xfffe)) & 0xffff + dupe = fsid in fsid_list + return fsid + def buildClusterCreateFlags(self, batch_map, clusterName): path = str(CLUSTER_FOLDER_PATH + clusterName) @@ -6130,11 +6151,12 @@ fsid = form['fsid'].strip() if not fsid: raise Exception, 'No filesystem ID was given for this filesystem resource.' - res.addAttribute('fsid', fsid) + fsid_int = int(fsid) + if not fsid_is_unique(fsid_int): + raise Exception, 'The filesystem ID provided is not unique.' except Exception, e: - err = str(e) - errors.append(err) - luci_log.debug_verbose('addFs10: %s' % err) + fsid = str(generate_fsid(model, name)) + res.addAttribute('fsid', fsid) if form.has_key('forceunmount'): res.addAttribute('force_unmount', '1') @@ -6246,11 +6268,12 @@ fsid = form['fsid'].strip() if not fsid: raise Exception, 'No filesystem ID was given for this cluster filesystem resource.' - res.addAttribute('fsid', fsid) + fsid_int = int(fsid) + if not fsid_is_unique(fsid_int): + raise Exception, 'The filesystem ID provided is not unique.' except Exception, e: - err = str(e) - errors.append(err) - luci_log.debug_verbose('addGfs8: %s' % err) + fsid = str(generate_fsid(model, name)) + res.addAttribute('fsid', fsid) if form.has_key('forceunmount'): res.addAttribute('force_unmount', '1')