예제 #1
0
 def reg_msg_handler(self, msg_info, reply=None):
     try:
         logger.debug("Registration msg handler called.")
         if reply:
             for single_response in reply.payloads:
                 if single_response.return_value == 0:
                     logger.info("\t\tRegistration ACK received.")
                     # change status to YES in config file
                     config = ConfigObj(config_file_name)
                     config["Registered"] = "YES"
                     config["UTC Time"] = single_response.output
                     bashit("date -s@"+str(single_response.output))
                     config.write()
                     start_communication_with_nc_event.set()
                     logger.info("Start_communication_with_nc_event is set.")
                 else:
                     logger.critical("ERROR: Unknown ACK received: Discarding..")
             return   
         # handle failure
         logger.critical("Registration timeout.............")
         msg_info[2] = self.calculate_expiration_time(registration_type, None)
         self.add_to_sent_msgs_bfr(msg_info)
         self.send_msg_to_nc(msg_info[3])
         logger.critical("Registration msg resent.............")
     except Exception as inst:
         logger.critical("ERROR: Exception in reg_msg_handler: " + str(inst))
예제 #2
0
def write_to_config_file(sensor):
    config = ConfigObj(config_file_name)
    main_section_name = "Sensors Info"
    config[main_section_name][sensor.complete_sensor_name] = sensor.sensor_info_dict
    # code to validate the fields goes here
    config[main_section_name][sensor.complete_sensor_name]["Registered"] = 'YES'
    config.write()
예제 #3
0
 def save_session_id(self, tag_name, session_id):
     try:
         config = ConfigObj(self.log_file_name)
         config[tag_name] = session_id  
         config.write()
     except Exception as inst:
         logger.critical("ERROR: Exception in save_session_id: " + str(inst) )
예제 #4
0
def get_node_info(config_file_name):
        
    config_object = ConfigObj(config_file_name)
    config = config_object["Systems Info"]
    
    
    list_of_keywords = ["hostname", "noOfProcessors", "cpuModelName", "cpuVendorID", "extensions", "hardware", "interfaces",
                        "memTotal", "osName", "osVersion", "osID", "osPrettyName", "osVersionID", "osKernelRelease", "machineName", "kernelVersion", "diskStorage"]
    
    list_of_cmds = [
                    "hostname", 
                    "cat /proc/cpuinfo  | grep -i  processor | wc -l", 
                    "cat /proc/cpuinfo  | grep -i  model\ name | uniq | tr -s ' ' | cut -d ':' -f 2",
                    "cat /proc/cpuinfo | grep -i  vendor_id | uniq | cut -d ':' -f 2",
                    ["cat /proc/cpuinfo | grep -i  flags | tr ' ' '\n' | sort | uniq | grep -i  -v flag | tr '\n' ' '", "cat /proc/cpuinfo | grep -i  features | tr ' ' '\n' | sort | uniq | grep -i  -v features | tr '\n' ' '"],
                    "cat /proc/cpuinfo | grep -i hardware | cut -d ':' -f 2",
                    ["ls /sys/class/net/", "cat /sys/class/net/"],
                    'cat /proc/meminfo | tr -s " "  | grep -i  MemTotal | cut -d ":" -f 2',
                    'cat /etc/os-release | grep -i NAME | grep -vi "pretty_name" | cut -d "=" -f 2 ',
                    'cat /etc/os-release | grep -i VERSION | grep -vi "version_id" |cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i ID=ubuntu | cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i PRETTY_NAME | cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i VERSION_ID | cut -d "=" -f 2',
                    'uname -r',
                    'uname -m',
                    'cat /proc/version',
                    "df -h  | tr -s ' ' | cut -d ' ' -f 1,2,5,6 | tr '\n' ';' | sed 's/;/\ ;\ /g'"
                ]
                
    for key, cmd in zip(list_of_keywords, list_of_cmds):
        try:
            if not isinstance(cmd, list):
                config[key] = bashit(cmd)
            else:
                if key == "interfaces":
                    interfaces = bashit(cmd[0])
                    interfaces=interfaces.split('\n')
                    config[key] = interfaces
                    if interfaces:
                        interface_details = ''
                        for i in interfaces:
                            if i <> 'lo':
                                interface_details += str(i) + ',' + bashit(cmd[1]+str(i)+"/address") + '\n'
                        interface_details = interface_details.split('\n')
                        config[key] = interface_details
                elif key == 'extensions':
                    config[key] = bashit(cmd[0])
                    if not config[key]:
                        config[key] = bashit(cmd[1])
            if not config[key]:
                    del config[key]  
        except Exception as inst:
            logger.critical("Exception in get_system_info: " + str(inst) + "while executing command " + str(cmd) +"\n\n")
            return 1 
    config_object.write()        
    return 0
예제 #5
0
 def register_gn(self, gn_info):
     try:
         for single_gn_info in gn_info:
             config = ConfigObj(config_file_name)
             config["GN Info"][single_gn_info.instance_id] = single_gn_info.sys_info
             config["GN Info"][single_gn_info.instance_id]["Registered"] = 'NO'
             config.write()
             logger.info("GN registration info saved in config file.")
     except Exception as inst:
         logger.critical("Exception in register_gn:" + str(inst))
예제 #6
0
 def save_session_id(self, inst_id, tag_name, session_id):
     try:
         log = ConfigObj(self.log_file_name)
         if inst_id:
             # create an entry for the GN
             if inst_id not in log:
                 log[inst_id] = {}
             # ex: log[guest_node_id]["GN Session ID"]
             log[inst_id][tag_name] = session_id
         else:
             log[tag_name] = session_id
         log.write()
     except Exception as inst:
         logger.critical("Exception in save_session_id: " + str(inst))
예제 #7
0
 def process_reg_ack(self):
     try:
         with config_file_lock:
             logger.critical("Config file lock acquired.............\n\n")
             config = ConfigObj(config_file_name)
             if config["Registered"] == 'NO':
                 config["Registered"] = 'YES'
             for node in config["GN Info"]:
                 if config['GN Info'][node]["Registered"] == 'NO':
                     config['GN Info'][node]["Registered"] = 'YES'
             config.write()
             logger.critical("Config file lock released.............\n\n")
     except Exception as inst:
         logger.critical("Exception in process_reg_ack: " + str(inst))
예제 #8
0
 def update_last_sensors_registration_time(self):
     config = ConfigObj(config_file_name) 
     config["last_sensors_registration_time"] = time.time()
     config.write()