def __init__(self, options, positionals): """ Initialize our master with the config of controllers """ print "* Starting up LOPHI Master Process" self.COMMANDS = { G.CTRL_CMD_START: self.command_start, G.CTRL_CMD_LIST: self.command_list, G.CTRL_CMD_PAUSE: self.command_abstract, G.CTRL_CMD_UNPAUSE: self.command_abstract, G.CTRL_CMD_SPLASH: self.command_splash, G.CTRL_CMD_UPDATE_HW: self.command_update_hw, G.CTRL_CMD_STOP: self.command_abstract, G.CTRL_CMD_DIE: self.command_abstract, G.CTRL_CMD_ATTACH: self.command_abstract, G.CTRL_CMD_EXECUTE: self.command_abstract } self.MSG_TYPES = set([G.CTRL_TYPE, G.REG_TYPE]) # response header self.RESP_HEADER = "[LOPHI Master] " logger.debug("Importing config files...") # Save our config file self.master_config_file = options.config_file # Save our config file self.analysis_directory = options.analysis_directory # Read our config into an internal structure self.config_list = Configs.import_from_config(self.master_config_file, "controller") # Read our analysis scripts into an internal structure self.update_analysis() # Connect to our database self.DB_analysis = DB.DatastoreAnalysis(options.services_host) # Set our RabbitMQ host self.amqp_host = options.services_host
def __init__(self, options, positionals): """ Initialize our master with the config of controllers """ print "* Starting up LOPHI Master Process" self.COMMANDS = {G.CTRL_CMD_START: self.command_start, G.CTRL_CMD_LIST: self.command_list, G.CTRL_CMD_PAUSE: self.command_abstract, G.CTRL_CMD_UNPAUSE: self.command_abstract, G.CTRL_CMD_SPLASH: self.command_splash, G.CTRL_CMD_UPDATE_HW: self.command_update_hw, G.CTRL_CMD_STOP: self.command_abstract, G.CTRL_CMD_DIE: self.command_abstract, G.CTRL_CMD_ATTACH: self.command_abstract, G.CTRL_CMD_EXECUTE: self.command_abstract} self.MSG_TYPES = set([G.CTRL_TYPE, G.REG_TYPE]) # response header self.RESP_HEADER = "[LOPHI Master] " logger.debug("Importing config files...") # Save our config file self.master_config_file = options.config_file # Save our config file self.analysis_directory = options.analysis_directory # Read our config into an internal structure self.config_list = Configs.import_from_config(self.master_config_file, "controller") # Read our analysis scripts into an internal structure self.update_analysis() # Connect to our database self.DB_analysis = DB.DatastoreAnalysis(options.services_host) # Set our RabbitMQ host self.amqp_host = options.services_host
def __init__(self, options, positionals): """ Initialize our controller. This includes initializing all of the configurations and opening all of the appropriate logfiles. """ # Set our port to bind to self._sock = None self.PORT_NUM = options.port # AMQP Host (Only used to hand off to analysis self.services_host = options.services_host # What config file are we loading? sensor_config_file = options.sensor_config_file # What config file are we loading? machine_config_file = options.machine_config_file # Disk images config file images_config_file = options.images_config_file # Import our available sensors logger.debug("Importing sensor config file (%s)" % sensor_config_file) self.sensor_list = Configs.import_from_config(sensor_config_file, "sensor") # Import our available machines logger.debug("Importing machine config file (%s)" % machine_config_file) self.machine_list = Configs.import_from_config(machine_config_file, "machine") # Import our image mappings logger.debug("Importing images config file (%s)" % images_config_file) self.images_map = Configs.import_from_config(images_config_file, "images") # Provision the number of requested VMs print "* Initializing %d virtual machines..." % options.vm_count for x in range(0, options.vm_count): tmp_name = "lophi-%d" % x self.machine_list[tmp_name] = VirtualMachine(tmp_name, force_new=True) # Build our dictionary of queues # This queues are handed to analysis for scheduling self.MACHINE_QUEUES = {} self.ANALYSIS_SCHEDULER = {} print "* Assigning sensors to machines, and configure machines" for m in self.machine_list: # Setup their image maps self.machine_list[m].add_image_map( \ self.images_map[self.machine_list[m].type]) # Add sensors and PXE server to physical machines if self.machine_list[m].type == G.MACHINE_TYPES.PHYSICAL: # Add sensors self.machine_list[m].add_sensors(self.sensor_list) # Add pxe_server from lophinet.pxeserver import PXEServer pxe_server = PXEServer(options.pxe_server) self.machine_list[m].add_pxe_server(pxe_server) manager = multiprocessing.Manager() for m in self.machine_list: # Get our indices t = self.machine_list[m].type # New queue? if t not in self.MACHINE_QUEUES: machine_queue = manager.Queue() self.MACHINE_QUEUES[t] = machine_queue self.ANALYSIS_SCHEDULER[t] = LophiScheduler( self.machine_list, machine_queue) self.ANALYSIS_SCHEDULER[t].start() # Add to queue self.MACHINE_QUEUES[t].put(m) # Ensure that we can share this list with our analysis threads # self.machine_list = multiprocessing.Manager().dict(self.machine_list) # Setup our FTP info self.ftp_ip_physical = self.ftp_ip_virtual = None try: self.ftp_ip_physical = NET.get_ip_address(options.ftp_physical) except: logger.error("Could not find ip for physical FTP interface. (%s)" % options.ftp_physical) try: self.ftp_ip_virtual = NET.get_ip_address(options.ftp_virtual) except: logger.error("Could not find ip for virtual FTP interface. (%s)" % options.ftp_virtual) # Server stuff self.RUNNING = True # Init our multiprocess multiprocessing.Process.__init__(self) """
def __init__(self, options, positionals): """ Initialize our controller. This includes initializing all of the configurations and opening all of the appropriate logfiles. """ # Set our port to bind to self._sock = None self.PORT_NUM = options.port # AMQP Host (Only used to hand off to analysis self.services_host = options.services_host # What config file are we loading? sensor_config_file = options.sensor_config_file # What config file are we loading? machine_config_file = options.machine_config_file # Disk images config file images_config_file = options.images_config_file # Import our available sensors logger.debug("Importing sensor config file (%s)"%sensor_config_file) self.sensor_list = Configs.import_from_config(sensor_config_file, "sensor") # Import our available machines logger.debug("Importing machine config file (%s)"%machine_config_file) self.machine_list = Configs.import_from_config(machine_config_file, "machine") # Import our image mappings logger.debug("Importing images config file (%s)"%images_config_file) self.images_map = Configs.import_from_config(images_config_file, "images") # Provision the number of requested VMs print "* Initializing %d virtual machines..."%options.vm_count for x in range(0,options.vm_count): tmp_name = "lophi-%d"%x self.machine_list[tmp_name] = VirtualMachine(tmp_name,force_new=True) # Build our dictionary of queues # This queues are handed to analysis for scheduling self.MACHINE_QUEUES = {} self.ANALYSIS_SCHEDULER = {} print "* Assigning sensors to machines, and configure machines" for m in self.machine_list: # Setup their image maps self.machine_list[m].add_image_map( \ self.images_map[self.machine_list[m].type]) # Add sensors and PXE server to physical machines if self.machine_list[m].type == G.MACHINE_TYPES.PHYSICAL: # Add sensors self.machine_list[m].add_sensors(self.sensor_list) # Add pxe_server from lophinet.pxeserver import PXEServer pxe_server = PXEServer(options.pxe_server) self.machine_list[m].add_pxe_server(pxe_server) manager = multiprocessing.Manager() for m in self.machine_list: # Get our indices t = self.machine_list[m].type # New queue? if t not in self.MACHINE_QUEUES: machine_queue = manager.Queue() self.MACHINE_QUEUES[t] = machine_queue self.ANALYSIS_SCHEDULER[t] = LophiScheduler(self.machine_list, machine_queue) self.ANALYSIS_SCHEDULER[t].start() # Add to queue self.MACHINE_QUEUES[t].put(m) # Ensure that we can share this list with our analysis threads # self.machine_list = multiprocessing.Manager().dict(self.machine_list) # Setup our FTP info self.ftp_ip_physical = self.ftp_ip_virtual = None try: self.ftp_ip_physical = NET.get_ip_address(options.ftp_physical) except: logger.error("Could not find ip for physical FTP interface. (%s)"% options.ftp_physical) try: self.ftp_ip_virtual = NET.get_ip_address(options.ftp_virtual) except: logger.error("Could not find ip for virtual FTP interface. (%s)"% options.ftp_virtual) # Server stuff self.RUNNING = True # Init our multiprocess multiprocessing.Process.__init__(self) """