#!/usr/bin/env python # Copyright (C) 2007 Platform Computing Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # # # import os import os.path import re import shutil from kusu.addhost import * from kusu.util.verify import verifyIP import kusu.core.db class AddHostPlugin(AddHostPluginBase): def enabled(self): return True def removed(self, nodename, info): os.system("rm -rf /var/lib/ganglia/rrds/*/%s*" % (nodename)) def finished(self, nodelist, prePopulateMode): # stop receiving any data first. os.system("service gmetad stop") os.system("service gmond stop") iplist = [] rrdsdir = '/var/lib/ganglia/rrds/Cluster/' # clean nodes naming with IP addresses. try: self.dbconn.execute('SELECT nics.ip FROM nics') iplist = [row[0] for row in self.dbconn.fetchall()] # list IP dirs and remove them dirlist = [ x for x in os.listdir(rrdsdir) if verifyIP(x)[0] and x in iplist ] for ipdir in dirlist: ippath = os.path.join(rrdsdir, ipdir) if os.path.isdir(ippath): shutil.rmtree(ippath) except: pass # start ganglia daemons. os.system("service gmetad start") os.system("service gmond start")