Ejemplo n.º 1
0
def reset():
    #Some globals
    dict_config = dict()
    database_driver = ddriver.DbDriver()

    #First, we attempt to get all Gathering modules in our directory
    if (not os.path.exists(directory)):
        logger.subsection("could not find any modules in our gather directory")
        return False

    #Remove all .pyc and .pyo files
    commands.getoutput("rm " + directory + "*.pyc")
    files = os.listdir(directory)

    #Clear all previous entries in database
    database_driver.truncate_db(gather_table)

    #Now, get information for each module in the directory
    for file in files:
        module = __load_module(file)
        try:
            dict_config = module.open()
            dict_config["FULL_PATH"] = directory + file
            dict_config["STATE"] = "1"
            database_driver.insert_db(gather_table, dict_config)
            database_driver.insert_db(gather_active_table, dict_config)
            logger.subsection("loaded module: " + file)
        except:
            logger.subsection("module " + file + " could not be loaded")
    return True
Ejemplo n.º 2
0
    def clone(self):
        """retrieve all necessary data from db"""
        database = ddriver.DbDriver()
        primary_conf = database.select_db('Primary_Configuration')
        secondary_conf = database.select_db('Secondary_Configuration')
        general_conf = database.select_db('General_Configuration')
        """now set all variables necessary"""
        imager_config = []
        imager_config.append("GROUP_NAME:ha_group\n")
        imager_config.append("HA_ETH:" + primary_conf[0]["NIC_INFO"] + "\n")
        imager_config.append("IMAGE_DIR:/usr/share/haoscar/images\n")
        imager_config.append("IMAGE_NAME:ha_image\n")
        imager_config.append("MASK:" + general_conf[0]["MASK"] + "\n")
        imager_config.append("PRIMARY_HOSTNAME:" +
                             primary_conf[0]["HOSTNAME"] + "\n")
        imager_config.append("PRIMARY_IP:" + primary_conf[0]["IP_ADDR"] + "\n")
        imager_config.append("SECONDARY_HOSTNAME:"\
            +secondary_conf[0]["HOSTNAME"]+"\n")
        imager_config.append("SECONDARY_IP:" + secondary_conf[0]["IP_ADDR"] +
                             "\n")
        imager_config.append("SUBNET:" + general_conf[0]["SUBNET"] + "\n")

        #Now we do some writing
        FILE = open("/usr/share/haoscar/sysimager.conf", "w")
        for config in imager_config:
            FILE.writelines(config)
        FILE.close()
        logger.subsection("finished configuring sysimager.conf")

        logger.subsection("starting cloning process")
        #print commands.getoutput("echo \"I am in `pwd`\"")
        print commands.getoutput("haoscar-system-clone.sh")
Ejemplo n.º 3
0
 def setUp(self):
     self.db_path = "/tmp/db"
     self.schema_path = "/tmp/schema.sql"
     shutil.copy(
         "../share/schema.sql",
         self.schema_path)  #makes sure that the schema is up to date.
     self.db = ddriver.DbDriver(self.db_path, self.schema_path)
Ejemplo n.º 4
0
def getAllModules():
    #Globals:
    all_modules = []
    database_driver = ddriver.DbDriver()

    try:
        all_modules = database_driver.select_db("Gather_Modules")
    except:
        logger.subsection("failed to retrieve modules")
    return all_modules
Ejemplo n.º 5
0
    def test_removeActiveModules(self):
        database_driver = ddriver.DbDriver()
        active_modules = []

        x = gather.removeActiveModules(["Ganglia_Monitor_Test"])

        active_modules = database_driver.select_db("Active_Modules")

        for index in xrange(len(active_modules)):
            self.failIf(
                active_modules[index]["NAME"] is "Ganglia_Monitor_Test")
        self.assert_(x == True)
Ejemplo n.º 6
0
def removeActiveModules(module_names):
    #Globals:
    temp_module = dict()
    all_modules = []
    active_modules = []
    database_driver = ddriver.DbDriver()

    #Clear table first
    database_driver.truncate_db(gather_active_table)

    all_modules = getAllModules()

    #Regenerate active table
    for index in xrange(len(all_modules)):
        if (all_modules[index]["NAME"] not in module_names):
            database_driver.insert_db(gather_active_table, all_modules[index])
    return True
Ejemplo n.º 7
0
def configure(secondary=False, configuration=None):
    #Does a file pre-exist?
    rsync_conf_path = "/etc/rsyncd.conf"
    if (path.isfile(rsync_conf_path)):
        logger.subsection("removing previous rsync configuration file to\
 rsyncd.bak")
        system("mv /etc/rsyncd.conf /etc/rsync.bak")
    logger.subsection("creating new rsync config file")

    rsync_conf.append(init_comment + "\n")
    ddriver = database.DbDriver()
    #Setup details for primary server
    if (secondary is False):
        #First we set some global rsync variables
        rsync_conf.append("motd file = /etc/rsyncd.motd\n")
        rsync_conf.append("log file = /var/log/rsyncd.log\n")
        rsync_conf.append("pid file = /var/run/haoscar_rsyncd.pid\n")
        rsync_conf.append("lock file = /var/run/rsync.lock\n")

        #Now we start setting up all paths specified in
        #First retrieve all paths and put in a list
        directory = ddriver.select_db('General_Configuration')
        ip = ddriver.select_db('Secondary_Configuration')

        sync_directory = directory[0]["DATA_DIR"]
        secondary_ip = ip[0]["IP_ADDR"]
        count = 0

        sync_directory = sync_directory.split(';')
        sync_directory.pop()  #Last item is void.

        for key in sync_directory:
            rsync_conf.append("[" + key + "]\n")
            rsync_conf.append("path = " + key + "\n")
            rsync_conf.append("read only = no\n")
            rsync_conf.append("list = no\n")
            rsync_conf.append("hosts allow = " + secondary_ip + "\n")
            rsync_conf.append("hosts deny = *\n")
            fp = open(rsync_conf_path, "w")
            fp.writelines(rsync_conf)
            fp.close()
    return 0
Ejemplo n.º 8
0
def getActiveModules():
    #Some globals
    all_modules = []
    active_modules = []
    temp_module = dict()
    database_driver = ddriver.DbDriver()

    #retreive all modules and check if state is 1 or 0
    try:
        all_modules = database_driver.select_db("Gather_Modules")
        try:
            for index in xrange(len(all_modules)):
                temp_module = all_modules[index]
                if (temp_module["STATE"] != "0"):
                    active_modules.append(temp_module)
        except:
            logger.subsection("an error occured when processing module state")
    except:
        exit.open("fatal error, failed to load gather modules!")

    return active_modules
Ejemplo n.º 9
0
def configure():
    #check if the auth already exists
    auth = "/etc/ha.d/authkeys"
    if (path.isfile(auth)):
        logger.subsection(
            "authentication configuration already exists, skipping")
    else:
        auth_value = []
        auth_value.append(init_comment)
        logger.subsection("creating authentication file")
        auth_passwd = getpass.getpass(
            "enter heartbeat authentication passwd: ")
        auth_value.append("\nauth 2\n2 sha1 ")
        auth_value.append(auth_passwd + "\n")
        FILE = open(auth, "w+")
        FILE.writelines(auth_value)
        system("chmod 600 /etc/ha.d/authkeys")

    hacf = "/etc/ha.d/ha.cf"
    if (path.isfile(hacf)):
        logger.subsection("ha.cf file already exists, re-writing")
    hacf_value = []
    hacf_value.append(init_comment)
    logger.subsection("auto generating heartbeat configuration file")
    hacf_value.append(hacf_config)

    #Edited by Chuka Okoye
    #*****ALL References to haoscar.conf need to be re-routed to
    #*****the HA-OSCAR database
    #We need to get the default interface from haoscar database
    #FILE =  open("/etc/haoscar/haoscar.conf", "r")
    #line = FILE.readline()
    #while("NIC_INFO=" not in line):
    #	line = FILE.readline()
    #temp = line.split("=")

    ddriver = database_driver.DbDriver()
    primary_conf = ddriver.select_db('Primary_Configuration')
    secondary_conf = ddriver.select_db('Secondary_Configuration')

    nic_info = ""
    nic_info = primary_conf[0]["NIC_INFO"]
    if (len(nic_info)):
        logger.subsection("using interface " + nic_info)
        hacf_value.append("\nbcast " + nic_info)
        hacf_value.append("\nauto_failback on\n")
        hacf_value.append("node " + commands.getoutput("uname -n") + "\n")

        if (secondary_conf[0]['HOSTNAME']):
            hacf_value.append("node " + secondary_conf[0]['HOSTNAME'] + "\n")
            FILE = open(hacf, "w")
            FILE.writelines(hacf_value)
            FILE.close()
    else:
        logger.subsection(
            "a fatal error has occured: could not retreive interface info")
        return 1

    haresources = "/etc/ha.d/haresources"
    if (path.isfile(haresources)):
        logger.subsection("haresource configuration exists, skipping")
    else:
        logger.subsection("writing haresource configuration")

        ip_addr = primary_conf[0]['IP_ADDR']
        if (len(ip_addr)):
            haresource = []
            haresource.append(commands.getoutput("uname -n") + " " + ip_addr)
            FILE = open("/etc/ha.d/haresources", "w")
            FILE.writelines(haresource)
        else:
            logger.subsection(
                "a fatal error has occured, could not retrieve ip information")
            return 1

    #If we have not yet died at this point we can assume the configuration was
    #a success
    return 0
Ejemplo n.º 10
0
def databaseSetup():
	logger.subsection("initializing database")
	#Create database
	database_init = ddriver.DbDriver()
        database_init.create_database()
	logger.subsection("database setup completed sucessfully")