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 get_instance(): "provides the name of the machine this is running on" path = get_slash_cwd() spkg_path = get_spkg_path() sub_dir = path.split(spkg_path)[1] instance_name = sub_dir.split(os.path.sep)[1] return instance_name
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
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)