def __init__(self, swap_settings=None): """ Class constructor @param swap_settings: path to the main SWAP configuration file @param verbose: Print out SWAP frames or not @param monitor: Print out network events or not """ # Main configuration file self.swap_settings = swap_settings # Print SWAP activity self._print_swap = False try: self.main_settings = XmlSettings(self.swap_settings) # Set log file to trace lagarto exceptions LagartoException.error_file = XmlSettings.error_file # Superclass call SwapInterface.__init__(self, swap_settings) except: raise # Lagarto process constructor LagartoProcess.__init__(self, working_dir) if XmlSettings.debug == 2: self._print_swap = True self.lagarto_config = XmlLagarto( os.path.join(config_dir, "lagarto.xml"))
def __init__(self, working_dir): ''' Constructor @param working_dir: Working directory ''' cfg_path = os.path.join(working_dir, "config", "lagarto.xml") # Read configuration file self.config = XmlLagarto(cfg_path) ## Local IP address address = self._get_local_ip_address() # Save IP address in config file if self.config.address != address: self.config.address = address self.config.save() # HTTP server self.http_server = LagartoHttpServer(self, self.config, working_dir) self.http_server.start()
class LagartoProcess(object): """ Geenric Lagarto process class """ def get_status(self, endpoints): """ Return network status as a list of endpoints in JSON format Method to be overriden by subclass @param endpoints: list of endpoints being queried @return list of endpoints in JSON format """ print "get_status needs to be overriden" return None def set_status(self, endpoints): """ Set endpoint status Method to be overriden by subclass @param endpoints: list of endpoints in JSON format @return list of endpoints being controlled, with new values """ print "set_status needs to be overriden" return None def http_command_received(self, command, params): """ Process command sent from HTTP server. Method to be overrided by data server. Method to be overriden by subclass @param command: command string @param params: dictionary of parameters @return True if command successfukky processed by server. Return False otherwise """ print "http_command_received needs to be overriden" return False def _get_local_ip_address(self): """ Get local IP address @return local IP address """ ipaddr = socket.gethostbyname(socket.gethostname()) if ipaddr.startswith("127.0"): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("1.1.1.1", 8000)) ipaddr = s.getsockname()[0] s.close() except: pass return ipaddr def publish_status(self, status_data=None, endp=None): """ Publish network status (collection of endpoint data) @param status_data network status to be transmitted @param endp Endpoint data """ self.mqtt_client.publish_status(status_data, endp) def stop(self): """ Stop HTTP server """ self.http_server.stop() def __init__(self, working_dir): ''' Constructor @param working_dir: Working directory ''' cfg_path = os.path.join(working_dir, "config", "lagarto.xml") # Read configuration file self.config = XmlLagarto(cfg_path) ## Local IP address address = self._get_local_ip_address() # Save IP address in config file if self.config.address != address: self.config.address = address self.config.save() # MQTT Client self.mqtt_client = LagartoMqttClient(self, self.config) # HTTP server self.http_server = LagartoHttpServer(self, self.config, working_dir) self.http_server.start()
class LagartoProcess(object): """ Geenric Lagarto process class """ def get_status(self, endpoints): """ Return network status as a list of endpoints in JSON format Method to be overriden by subclass @param endpoints: list of endpoints being queried @return list of endpoints in JSON format """ print "get_status needs to be overriden" return None def set_status(self, endpoints): """ Set endpoint status Method to be overriden by subclass @param endpoints: list of endpoints in JSON format @return list of endpoints being controlled, with new values """ print "set_status needs to be overriden" return None def http_command_received(self, command, params): """ Process command sent from HTTP server. Method to be overrided by data server. Method to be overriden by subclass @param command: command string @param params: dictionary of parameters @return True if command successfukky processed by server. Return False otherwise """ print "http_command_received needs to be overriden" return False def _get_local_ip_address(self): """ Get local IP address @return local IP address """ ipaddr = socket.gethostbyname(socket.gethostname()) if ipaddr.startswith("127.0"): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("1.1.1.1", 8000)) ipaddr = s.getsockname()[0] s.close() except: pass return ipaddr def stop(self): """ Stop HTTP server """ self.http_server.stop() def __init__(self, working_dir): ''' Constructor @param working_dir: Working directory ''' cfg_path = os.path.join(working_dir, "config", "lagarto.xml") # Read configuration file self.config = XmlLagarto(cfg_path) ## Local IP address address = self._get_local_ip_address() # Save IP address in config file if self.config.address != address: self.config.address = address self.config.save() # HTTP server self.http_server = LagartoHttpServer(self, self.config, working_dir) self.http_server.start()