conga/luci/site/luci/Extensions cluster_adapte ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-10-13 22:56:28
Modified files:
luci/site/luci/Extensions: cluster_adapters.py
Log message:
detect changes in cluster membership and deal with them accordingly, part 1
luci/site/luci/Extensions/cluster_adapters.py +37 -8
@@ -2926,12 +2926,9 @@ def resolveClusterChanges(self, clusterName, modelb): try: - mb_nodes = dict.fromkeys(modelb.getNodes()) + mb_nodes = modelb.getNodes() if not mb_nodes or not len(mb_nodes): raise - mb_map = {} - for i in iter(mb_nodes): - mb_map[i] = i except: return 'Unable to find cluster nodes for ' + clusterName
@@ -2943,16 +2940,48 @@ return 'Unable to find an entry for ' + clusterName + ' in the Luci database.' try: - db_nodes = cluster_node.objectItems('Folder') + db_nodes = map(lambda x: x[0], cluster_node.objectItems('Folder')) if not db_nodes or not len(db_nodes): raise - db_map = {} - for i in iter(db_nodes): - db_map[i[0]] = i[0] except: # Should we just create them all? Can this even happen? return 'Unable to find database entries for any nodes in ' + clusterName + same_host = lambda x, y: x == y or x[:len(y) + 1] == y + '.' or y[:len(x) + 1] == x + '.' + + # this is a really great algorithm. + missing_list = list() + new_list = list() + for i in mb_nodes: + for j in db_nodes: + f = 0 + if same_host(i, j): + f = 1 + break + if not f: + new_list.append(i) + + for i in db_nodes: + for j in mb_nodes: + f = 0 + if same_host(i, j): + f = 1 + break + if not f: + missing_list.append(i) + + messages = list() + for i in missing_list: + cluster_node.delObjects([i]) + messages.append('Node \"' + i + '\" is no longer in a member of cluster \"' + clusterName + '.\". It has been deleted from the management interface for this cluster.') + + for i in new_list: + cluster_node.manage_addFolder(i, '__luci__:csystem:' + clusterName) + cluster_node.manage_addProperty('exceptions', 'auth', 'string') + messages.append('A new node, \"' + i + ',\" is now a member of cluster \"' + clusterName + '.\". It has added to the management interface for this cluster, but you must authenticate to it in order for it to be fully functional.') + + return messages + def addResource(self, request, ragent): if not request.form: return (False, {'errors': ['No form was submitted.']})