from ..General.DownloadCustomerFile import DownloadCustomerFile
from ..Server.ImportUcsLicense import ImportUcsLicense
from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ..General.CheckForSshSession import CheckForSSHSession
from ..Playbooks.Playbook import Playbook


class ApplyUcsLicense(Playbook):
    def start(self):
        LDIF_FILENAME = '/tmp/license.ldif'

        if not self.is_sub_playbook:
            self.run_steps(CheckForSSHSession())

        self.run_steps(DownloadCustomerFile('license.ldif', LDIF_FILENAME, MACHINE_COLLECTION.server),
                       ImportUcsLicense(LDIF_FILENAME)
                       )
