def dumpReport(report, logger): "Legacy" instance_name = get_instance() output_path = make_path(get_spkg_path(), instance_name, "output") if not os.path.isdir(output_path): os.makedirs(output_path) script_name = sys.argv[-1].split(".py")[0] output_file = "%s-output.yml" % script_name dump_string = yaml_dump(report) open(make_path(output_path, output_file), 'w').write(dump_string) for line in dump_string.split('\n'): logger.info("==REPORT==:%s" % line)
def _dump_report(self, report = None): ''' report -- a dictionary of the data that was generated For a command that was run on an spkg class, this provides data back to the CNM ''' if type(report) != type({}): report = self.report command = inspect.stack()[2][3] output_path = make_path(get_spkg_path(), self.instance_name, "output") if not os.path.isdir(output_path): os.makedirs(output_path) output_file = "%s-output.yml" % command dump_string = yaml_dump(report) open(make_path(output_path, output_file), 'w').write(dump_string) for line in dump_string.split('\n'): Logger.info("==REPORT==:%s" % line)
def create_manifest( self ): """Loop through subdirectories, collecting manifest data""" for inode in os.listdir( self.root_dir ): if inode in self.sub_dirs: temp_dictionary = {} full_path = make_path( self.root_dir, inode ) if os.path.isdir( full_path ): self.manifest_dictionary[inode] = \ self.create_path_dictionary( full_path, temp_dictionary )
def verify_manifest( self, mapping_dict ): """Loop through keys in manifest file, checking for files and md5sums as necessary. The mapping dictionary maps directories from the manifest file to directories in the file system.""" tuple_check_list = [] for subdir in self.manifest_dictionary.keys(): for inode in self.manifest_dictionary[subdir]: new_tuple = ( make_path( mapping_dict[subdir], inode ), self.manifest_dictionary[subdir][inode] ) tuple_check_list.append( new_tuple ) error_list = self.verify_file_md5_tuples( tuple_check_list ) return( error_list )
def __init__(self): spkg_path = get_spkg_path() self.python_logger = None self.formatter = None self.std_err_handler = None self.file_handler = None self.log_path = None if spkg_path: self.log_path = make_path(get_spkg_path(), LOG_FILE) if self.check_log_size() == FAIL: self.cycle_log() self.make_logger()
def create_path_dictionary( self, path, work_dict ): """Loop through the directories gathering data into the manifest""" for inode in os.listdir( path ): full_path = make_path( path, inode ) relative_path = self.get_relative_path(full_path) if os.path.isdir( full_path ): self.create_path_dictionary( full_path, work_dict ) elif os.path.isfile( full_path ): if inode.split('.')[-1].lower() in self.md5_extensions: handle = open( full_path, 'rb' ) data = handle.read() work_dict[relative_path] = md5_sum(data) handle.close() else: work_dict[relative_path] = '' return work_dict
def _read_local_config(self): """If there is a cleartext configuration file on the system, we will read that and ignore the configuration sent to us from the server.""" spkg_path = get_spkg_path() if not spkg_path: return FAIL config_path = make_path(get_spkg_path(), self.instance_name, CONFIG_FILE) if not os.path.isfile(config_path): return FAIL msg = "DETECTED A CLEARTEXT LOCAL CONFIGURATION FILE:" " IGNORING MANAGEMENT SERVER CONFIGURATION" Logger.warning(msg) file_handle = open(config_path, "r") try: config_data = file_handle.read() self.data = yaml_load(config_data) except: return FAIL return OK