Improve logging
parent
bd5d15fbe7
commit
927e24e13e
|
@ -349,23 +349,23 @@ class OpengnsysGitInstaller:
|
||||||
client_initrd_path = os.path.join(tftp_dir, ogclient, INITRD)
|
client_initrd_path = os.path.join(tftp_dir, ogclient, INITRD)
|
||||||
client_initrd_path_new = client_initrd_path + ".new"
|
client_initrd_path_new = client_initrd_path + ".new"
|
||||||
|
|
||||||
self.__logger.info("initrd path is %s", client_initrd_path)
|
self.__logger.debug("initrd path for ogclient %s is %s", ogclient, client_initrd_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
temp_dir = tempfile.TemporaryDirectory()
|
temp_dir = tempfile.TemporaryDirectory()
|
||||||
#temp_dir_path = temp_dir.name()
|
temp_dir_path = temp_dir.name
|
||||||
|
|
||||||
temp_dir_path = "/tmp/extracted"
|
#temp_dir_path = "/tmp/extracted"
|
||||||
if os.path.exists(temp_dir_path):
|
if os.path.exists(temp_dir_path):
|
||||||
shutil.rmtree(temp_dir_path)
|
shutil.rmtree(temp_dir_path)
|
||||||
|
|
||||||
|
|
||||||
pathlib.Path(temp_dir_path).mkdir(parents=True, exist_ok = True)
|
pathlib.Path(temp_dir_path).mkdir(parents=True, exist_ok = True)
|
||||||
|
|
||||||
self.__logger.info("Uncompressing initrd %s into %s", client_initrd_path, temp_dir_path)
|
self.__logger.debug("Uncompressing initrd %s into %s", client_initrd_path, temp_dir_path)
|
||||||
os.chdir(temp_dir_path)
|
os.chdir(temp_dir_path)
|
||||||
libarchive.extract_file(client_initrd_path, flags = EXTRACT_UNLINK | EXTRACT_OWNER | EXTRACT_PERM | EXTRACT_FFLAGS | EXTRACT_TIME)
|
libarchive.extract_file(client_initrd_path, flags = EXTRACT_UNLINK | EXTRACT_OWNER | EXTRACT_PERM | EXTRACT_FFLAGS | EXTRACT_TIME)
|
||||||
ssh_key_dir = os.path.join(temp_dir_path, "scripts", "ssl")
|
ssh_key_dir = os.path.join(temp_dir_path, "scripts", "ssl")
|
||||||
|
@ -374,11 +374,13 @@ class OpengnsysGitInstaller:
|
||||||
authorized_keys_path = os.path.join(ssh_key_dir, "authorized_keys")
|
authorized_keys_path = os.path.join(ssh_key_dir, "authorized_keys")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create a SSH key on the oglive, if needed
|
||||||
pathlib.Path(ssh_key_dir).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(ssh_key_dir).mkdir(parents=True, exist_ok=True)
|
||||||
if os.path.exists(client_key_path):
|
if os.path.exists(client_key_path):
|
||||||
self.__logger.debug("Creating SSH key not necessary, it already is in the initrd")
|
self.__logger.info("Creating SSH key not necessary, it already is in the initrd")
|
||||||
else:
|
else:
|
||||||
self.__logger.debug("Writing new SSH key into %s", client_key_path)
|
self.__logger.info("Writing new SSH key into %s", client_key_path)
|
||||||
subprocess.run(["/usr/bin/ssh-keygen", "-t", "ed25519", "-N", "", "-f", client_key_path], check=True)
|
subprocess.run(["/usr/bin/ssh-keygen", "-t", "ed25519", "-N", "", "-f", client_key_path], check=True)
|
||||||
|
|
||||||
public_keys = ""
|
public_keys = ""
|
||||||
|
@ -772,10 +774,31 @@ class OpengnsysGitInstaller:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)20s - [%(levelname)5s] - %(message)s')
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
opengnsys_log_dir = "/opt/opengnsys/log"
|
||||||
|
|
||||||
|
logger = logging.getLogger(__package__)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
logger.info("Inicio del programa")
|
|
||||||
|
streamLog = logging.StreamHandler()
|
||||||
|
streamLog.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
if not os.path.exists(opengnsys_log_dir):
|
||||||
|
os.mkdir(opengnsys_log_dir)
|
||||||
|
|
||||||
|
logFilePath = f"{opengnsys_log_dir}/git_installer.log"
|
||||||
|
fileLog = logging.FileHandler(logFilePath)
|
||||||
|
fileLog.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)24s - [%(levelname)5s] - %(message)s')
|
||||||
|
|
||||||
|
streamLog.setFormatter(formatter)
|
||||||
|
fileLog.setFormatter(formatter)
|
||||||
|
|
||||||
|
logger.addHandler(streamLog)
|
||||||
|
logger.addHandler(fileLog)
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="OpenGnsys Installer",
|
prog="OpenGnsys Installer",
|
||||||
|
@ -791,10 +814,19 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('--extract-ssh-key', action='store_true', help="Extract SSH key from oglive")
|
parser.add_argument('--extract-ssh-key', action='store_true', help="Extract SSH key from oglive")
|
||||||
parser.add_argument('--set-ssh-key', action='store_true', help="Configure SSH key in oglive")
|
parser.add_argument('--set-ssh-key', action='store_true', help="Configure SSH key in oglive")
|
||||||
parser.add_argument('--oglive', type=int, metavar='NUM', help = "Do SSH key manipulation on this oglive")
|
parser.add_argument('--oglive', type=int, metavar='NUM', help = "Do SSH key manipulation on this oglive")
|
||||||
|
parser.add_argument('--quiet', action='store_true', help="Quiet console output")
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true", help = "Verbose console output")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.quiet:
|
||||||
|
streamLog.setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
if args.verbose:
|
||||||
|
streamLog.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
installer = OpengnsysGitInstaller()
|
installer = OpengnsysGitInstaller()
|
||||||
installer.set_testmode(args.testmode)
|
installer.set_testmode(args.testmode)
|
||||||
installer.set_ignoresshkey(args.ignoresshkey)
|
installer.set_ignoresshkey(args.ignoresshkey)
|
||||||
|
@ -811,7 +843,7 @@ if __name__ == '__main__':
|
||||||
installer.set_ssh_user_group("oggit2", "oggit2")
|
installer.set_ssh_user_group("oggit2", "oggit2")
|
||||||
elif args.extract_ssh_key:
|
elif args.extract_ssh_key:
|
||||||
key = installer._extract_ssh_key()
|
key = installer._extract_ssh_key()
|
||||||
print(f"Key: {key}")
|
print(f"{key}")
|
||||||
|
|
||||||
elif args.set_ssh_key:
|
elif args.set_ssh_key:
|
||||||
installer.set_ssh_key()
|
installer.set_ssh_key()
|
||||||
|
|
Loading…
Reference in New Issue