from .SetInternalPasswords import SetInternalPasswords
from .SetupLmzRepo import SetupLmzRepo
from ..General.WriteMli import WriteMli
from ..OpsiServer.CopyVeyonKeys import CopyVeyonKeys
from ..OpsiServer.SetOpsiProductDefaultValues import SetOpsiProductDefaultValues
from ..Server.RegenerateVeyonKeys import RegenerateVeyonKeys
from ..General.SetSystemUuid import SetSystemUuid
from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ..General.CheckForSshSession import CheckForSSHSession
from ..General.TriggerUcsPasswordChange import TriggerUcsPasswordChange
from ...SetupSteps.Playbooks.Playbook import Playbook


class SetSystemIds(Playbook):
    def start(self):
        if not self.is_sub_playbook:
            self.run_steps(CheckForSSHSession())

        if self.credentials.mli is None or self.credentials.mli_password is None:
            self.credentials.mli = self.ui.get_input("Please enter your MLI:")
            self.credentials.mli_password = self.ui.get_password("Please enter your MLI password:")

        self.run_steps(
            WriteMli(MACHINE_COLLECTION.server),
            WriteMli(MACHINE_COLLECTION.backup),
            TriggerUcsPasswordChange(MACHINE_COLLECTION.server),
            TriggerUcsPasswordChange(MACHINE_COLLECTION.backup)
            )

        self.run_sub_playbook(SetupLmzRepo)
        self.run_sub_playbook(SetInternalPasswords)

        self.run_steps(
            SetSystemUuid(),
            RegenerateVeyonKeys(),
            CopyVeyonKeys(),
            SetOpsiProductDefaultValues()
        )