from ..Playbooks.Playbook import PlaybookCredentialCollection, FileCleanupTask
from ...Logging.Logger import log, Severity
from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ..SetupStep import SetupStep

class ImportUcsLicense(SetupStep):
    def __init__(self, license_path: str):
        super().__init__()
        self.license_path = license_path

    def run(self, file_cleanup_stack : list[FileCleanupTask], credentials: PlaybookCredentialCollection) -> bool:
        log('Importing UCS license...', Severity.INFO)
        stdout, stderr, retval = MACHINE_COLLECTION.server.execute_shell_command('univention-license-import', self.license_path)
        if retval == 0:
            log('License imported.', Severity.DEBUG)
            return True
        else:
            log(f'Failed to import license: {stderr}', Severity.ERROR)
            return False
