예제 #1
0
 def run(self):
     if (not hasattr(self.context, "LiveCd")):
         self.multiLog("No LiveCd Object in Context", log)
         raise dissomniag.taskManager.TaskFailed("No VM Object in Context")
     
     self.infoObj = dissomniag.model.LiveCdEnvironment()
     if not self.infoObj.prepared:
         self.multiLog("LiveCD Environment not prepared. No LiveCD creation possible!", log)
         raise dissomniag.taskManager.TaskFailed("LiveCD Environment not prepared. No LiveCD creation possible!")
     
     self.patternFolder = os.path.join(dissomniag.config.dissomniag.serverFolder,
                             dissomniag.config.dissomniag.liveCdPatternDirectory)
     
     with dissomniag.rootContext():
     
         try:
             
             if not dissomniag.chDir(self.patternFolder):
                 self.multiLog("Cannot chdir to %s" % self.patternFolder, log)
                 raise dissomniag.taskManager.TaskFailed()
             
             self.lockFile = os.path.join(self.patternFolder,
                                          dissomniag.config.dissomniag.patternLockFile)
             self.mylock = lockfile.FileLock(self.lockFile, threaded = True)
             
             with self.myLock:
                 
                 # 1. Copy infoXML
                 
                 self.versioningHash, self.liveInfoString = self.context.VM.getInfoXMLwithVersionongHash(self.job.getUser())
                 
                 with open("./config/includes.binary/liveInfo.xml") as f:
                     f.write(self.liveInfoString)
                     
                     
                 ###
                 #ToDo: At other thinks to binary include like Predefined Apps
                 ###
                 
                 #2. Make initial Build
                 # Try 10 times (Solves some repository connection timeout problems)
                 #cmd = "lb build"
                 #self.multiLog("Make initial build", log)
                 cmd = "lb binary"
                 self.multiLog("lb binary", log)
                 success = False
                 for i in range(1, 11):
                     if self.job._getStatePrivate() == dissomniag.taskManager.jobs.JobStates.CANCELLED:
                         self.multiLog("Job cancelled. Initial LivdCD build failed.")
                         raise dissomniag.taskManager.TaskFailed("Job cancelled. Initial LivdCD build failed.")
                     
                     ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                     if ret != 0:
                         self.multiLog("Initial LiveCD build failed. Retry %d" % i, log)
                         continue
                     else:
                         success = True
                         break
                 if not success:
                     self.multiLog("Initial LiveCD build failed finally.", log)
                     raise dissomniag.taskManager.TaskFailed("Initial LiveCD build failed finally.")
                 
                 #3. Copy iso to final Folder
                 # Check if folder for image exists
                 if not os.access(self.context.LiveCd.vm.getUtilityFolder(), os.F_OK):
                     os.makedirs(self.context.LiveCd.vm.getUtilityFolder())
                     
                 shutil.copy2("./binary.iso", self.context.LiveCd.vm.getLocalPathToCdImage(self.job.getUser()))
                 
                 with open(os.path.join(self.context.LiveCd.vm.getLocalUtilityFolder(), "configHash"), 'w') as f:
                     f.write(self.versioningHash)
                 
                 self.context.LiveCd.imageCreated = True
             
         finally:
                 if not dissomniag.resetDir():
                     self.multiLog("Cannot chdir to %s" % self.patternFolder, log)
                 
                 self.cleanUp()
     
     return dissomniag.taskManager.TaskReturns.SUCCESS
예제 #2
0
    def prepare(self, job):
        self.infoObj = dissomniag.model.LiveCdEnvironment()
        if not self.infoObj.prepared:
            self.multiLog(
                "LiveCD Environment not prepared. No LiveCD creation possible!",
                job, log)
            self.vm.changeState(dissomniag.model.NodeState.PREPARE_ERROR)
            raise dissomniag.taskManager.TaskFailed(
                "LiveCD Environment not prepared. No LiveCD creation possible!"
            )

        self.patternFolder = os.path.join(
            dissomniag.config.dissomniag.serverFolder,
            dissomniag.config.dissomniag.liveCdPatternDirectory)

        with dissomniag.rootContext():
            try:

                if not dissomniag.chDir(self.patternFolder):
                    self.multiLog("Cannot chdir to %s" % self.patternFolder,
                                  job, log)
                    self.vm.changeState(
                        dissomniag.model.NodeState.PREPARE_ERROR)
                    raise dissomniag.taskManager.TaskFailed(
                        "Could not change to pattern folder.")

                self.lockFile = os.path.join(
                    self.patternFolder,
                    dissomniag.config.dissomniag.patternLockFile)
                self.myLock = lockfile.FileLock(self.lockFile, threaded=True)

                with self.myLock:

                    cmd = "lb config"
                    self.multiLog("Run lb config", job, log)
                    ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                    if ret != 0:
                        self.multiLog("LB config error")
                        raise dissomniag.taskManager.TaskFailed()

                    # 1. Copy infoXML
                    self.liveInfoString, self.versioningHash = self.liveCd.getInfoXMLwithVersionongHash(
                        job.getUser())
                    lifeInfoFile = os.path.join(
                        self.patternFolder,
                        "config/includes.binary/liveInfo.xml")
                    self.multiLog(str(lifeInfoFile), job, log)
                    with open(lifeInfoFile, 'w') as f:
                        f.write(self.liveInfoString)

                    ###
                    #ToDo: At other thinks to binary include like Predefined Apps
                    ###

                    #2. Make initial Build
                    # Try 10 times (Solves some repository connection timeout problems)
                    #cmd = "lb build"
                    #self.multiLog("Make initial Build", job, log)

                    cmd = "lb binary"
                    self.multiLog("lb binary", job, log)
                    success = False
                    for i in range(1, 11):
                        if job._getStatePrivate(
                        ) == dissomniag.taskManager.jobs.JobStates.CANCELLED:
                            self.multiLog(
                                "Job cancelled. Initial LivdCD build failed.",
                                job, log)
                            self.vm.changeState(
                                dissomniag.model.NodeState.PREPARE_ERROR)
                            raise dissomniag.taskManager.TaskFailed(
                                "Job cancelled. Initial LivdCD build failed.")

                        ret, output = dissomniag.utils.StandardCmd(cmd,
                                                                   log).run()
                        if ret != 0:
                            self.multiLog(
                                "Initial LiveCD build failed. Retry %d" % i,
                                job, log)
                            continue
                        else:
                            success = True
                            break
                    if not success:
                        self.multiLog("Initial LiveCD build failed finally.",
                                      job, log)
                        self.vm.changeState(
                            dissomniag.model.NodeState.PREPARE_ERROR)
                        raise dissomniag.taskManager.TaskFailed(
                            "Initial LiveCD build failed finally.")

                    #3. Copy iso to final Folder
                    # Check if folder for image exists
                    if not os.access(
                            self.vm.getLocalUtilityFolder(job.getUser()),
                            os.F_OK):
                        os.makedirs(
                            self.vm.getLocalUtilityFolder(job.getUser()))
                    shutil.copy2("./binary.iso",
                                 self.vm.getLocalPathToCdImage(job.getUser()))

                    with open(
                            os.path.join(
                                self.vm.getLocalUtilityFolder(job.getUser()),
                                "configHash"), 'w') as f:
                        f.write(self.versioningHash)

                    self.liveCd.imageCreated = True

            finally:
                if not dissomniag.resetDir():
                    self.multiLog("Cannot chdir to %s" % self.patternFolder,
                                  job, log)

                self.cleanUpPrepare(job)

        self.multiLog("LiveCd Image created.", job, log)
        self.vm.changeState(dissomniag.model.NodeState.PREPARED)
        return True
예제 #3
0
 def run(self):
     self.infoObj = dissomniag.model.LiveCdEnvironment()
     if self.infoObj.prepared:
         return self.returnSuccess()
     
     #If the Environment is not prepared, create it.
     
     #1. Check if Pattern folder exists. 
     #    True: Delete, and recreate it
     #    False: just create it
     self.patternFolder = os.path.join(dissomniag.config.dissomniag.serverFolder,
                             dissomniag.config.dissomniag.liveCdPatternDirectory)
     
     with dissomniag.rootContext():
     
         self.checkIfPatternFolderExists()
         
         try:
             #3. Change current working Directory
             if not dissomniag.chDir(self.patternFolder):
                 self.multiLog("Cannot chdir to %s" % self.patternFolder, log)
                 raise dissomniag.taskManager.TaskFailed()
             
             self.deleteOldDebianLiveFolders(self.patternFolder)
             
             #2. Create File Lock for Pattern environment
             self.lockFile = os.path.join(self.patternFolder,
                                          dissomniag.config.dissomniag.patternLockFile)
             self.mylock = lockfile.FileLock(self.lockFile, threaded = True)
             
             with self.mylock:
                 
                 #3a. Make auto Directory and link config files
                 self.autoFolder = os.path.join(self.patternFolder, "auto/")
                 try:
                     os.makedirs(self.autoFolder)
                 except OSError:
                     self.multiLog("Cannot create AutoFolder")
                     raise dissomniag.taskManager.TaskFailed()
                 
                 staticAutoFolder = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "auto")
                 infiles = os.listdir(staticAutoFolder)
                 for myfile in infiles:
                     try:
                         #print os.path.join(staticAutoFolder, myfile)
                         #print os.path.join(self.autoFolder, myfile)
                         os.symlink(os.path.join(staticAutoFolder, myfile), os.path.join(self.autoFolder, myfile))
                     except OSError:
                         self.multiLog("Cannot Symlink %s" % myfile , log)
                         if myfile == "config":
                             raise dissomniag.taskManager.TaskFailed()
                         
                 #3b. Create initial stucture
                 cmd = "lb config"
                 self.multiLog("running %s" % cmd)
                 ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 if ret != 0:
                     self.multiLog("LB Config error")
                     raise dissomniag.taskManager.TaskFailed()
                 
                 #3c. Copy dissomniag packagelist
                 packageListFile = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "packagesLists/dissomniag.list")
                 chrootLocalPackagesListFolder = os.path.join(self.patternFolder, "config/package-lists")
                 try:
                     os.symlink(os.path.abspath(packageListFile), os.path.join(chrootLocalPackagesListFolder, "dissomniag.list"))
                 except OSError:
                     self.multiLog("Cannot Symlink dissomniag.list")
                     raise dissomniag.taskManager.TaskFailed()
                 
                 #3d. Copy all chroot_local files
                 chrootLocalFilesDir = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "chroot_local-includes")
                 listings = os.listdir(chrootLocalFilesDir)
                 for infile in listings:
                     try:
                         shutil.copytree(os.path.join(chrootLocalFilesDir, infile), os.path.join(self.patternFolder, "config/includes.chroot/" + infile), symlinks = True)
                     except OSError:
                         src = os.path.join(chrootLocalFilesDir, infile)
                         dst = os.path.join(self.patternFolder, "config/includes.chroot/" + infile)
                         self.multiLog("Cannot copy an includes.chroot, src= %s , dst= %s" % (src,dst), log)
                 
                 #3e. Copy all chroot_local hooks
                 hooksFilesDir = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "hooks")
                 listings = os.listdir(hooksFilesDir)
                 for infile in listings:
                     try:
                         shutil.copy2(os.path.join(hooksFilesDir, infile), os.path.join(self.patternFolder, "config/hooks/"))
                     except OSError:
                         self.multiLog("Cannot copy an chroot_local-hook")
                         
                 tasksFilesDir = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "task-lists/")
                 listings = os.listdir(tasksFilesDir)
                 for infile in listings:
                     try:
                         shutil.copy2(os.path.join(tasksFilesDir, infile), os.path.join(self.patternFolder, "config/task-lists/"))
                     except OSError:
                         self.multiLog("Cannot copy an chroot_local-hook")
                 
                 #4. Install Live Daemon
                 
                 self.installLiveDaemon(self.patternFolder)
                 
                 #5. Copy needed files. (like OMNeT binaries)
                 
                 self.installOmnet(self.patternFolder)
                 
                 #5b Copy syslinux Debian package
                 packagesChrootStaticDir = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "packages.chroot")
                 listings = os.listdir(packagesChrootStaticDir)
                 for infile in listings:
                     try:
                         shutil.copy2(os.path.join(packagesChrootStaticDir, infile), os.path.join(self.patternFolder, "config/packages.chroot/"))
                     except OSError:
                         self.multiLog("Cannot copy packages.chroot")
                         
                 #6c Copy isolinux cfg
                 isolinuxCfgDir = os.path.join(dissomniag.config.dissomniag.staticLiveFolder, "includes.binary/isolinux")
                 try:
                     os.makedirs(os.path.join(self.patternFolder, "config/includes.binary/isolinux/"))
                 except OSError:
                     self.multiLog("Cannot create config/includes.binary/isolinux/")
                 listings = os.listdir(isolinuxCfgDir)
                 for infile in listings:
                     try:
                         shutil.copy2(os.path.join(isolinuxCfgDir, infile), os.path.join(self.patternFolder, "config/includes.binary/isolinux/"))
                     except OSError:
                         self.multiLog("Cannot copy includes.binary")
                   
                 #6. Init debian live environment
                 cmd = "lb config"
                 self.multiLog("running %s" % cmd)
                 ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 if ret != 0:
                     self.multiLog("LB Config error")
                     raise dissomniag.taskManager.TaskFailed() 
                 
                 #7. Make bootstrap
                 # Try 10 times (Solves some repository connection timeout problems)
                 cmd = "lb bootstrap"
                 self.multiLog("Run lb bootstrap", log)
                 ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 if ret != 0:
                     self.multiLog("LB bootstrap error")
                     raise dissomniag.taskManager.TaskFailed() 
                 
                 #8. Make chrooot
                 # Try 10 times (Solves some repository connection timeout problems)
                 cmd = "lb chroot"
                 self.multiLog("Run lb chroot", log)
                 ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 if ret != 0:
                     self.multiLog("LB chroot error")
                     raise dissomniag.taskManager.TaskFailed()
                 
                 #9. Make binary
                 # Try 10 times (Solves some repository connection timeout problems)
                 cmd = "lb binary"
                 self.multiLog("Run lb binary", log)
                 ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 if ret != 0:
                     self.multiLog("LB binary error")
                     raise dissomniag.taskManager.TaskFailed()   
                 
                 #8. 
                 #cmd = "lb build"
                 #self.multiLog("Run lb build", log)
                 #ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 #success = False
                 #for i in range(1, 11):
                 #    if self.job._getStatePrivate() == dissomniag.taskManager.jobs.JobStates.CANCELLED:
                 #        self.multiLog("Job cancelled. Initial LivdCD build failed. (lb build")
                 #        raise dissomniag.taskManager.TaskFailed("Job cancelled. Initial LivdCD build failed.")
                 #    
                 #    ret, output = dissomniag.utils.StandardCmd(cmd, log).run()
                 #    if ret != 0:
                 #        self.multiLog("Initial LiveCD build failed. Retry %d" % i, log)
                 #        continue
                 #    else:
                 #        success = True
                 #        break
                 #if not success:
                 #   self.multiLog("Initial LiveCD build failed finally.", log)
                 #    raise dissomniag.taskManager.TaskFailed("Initial LiveCD build failed finally.")
                 
                 #8.
 
                 #7. Mark environment as Prepared
                 preparedFile = os.path.join(self.patternFolder, "CHECKED")
                 myFile = open(preparedFile, 'w')
                 myFile.write("CHECKED")
                 myFile.close()
                 self.infoObj.usable = True
                 self.infoObj.prepared = True
                 self.returnSuccess()
         finally:
                 if not dissomniag.resetDir():
                     self.multiLog("Cannot chdir to %s" % self.patternFolder, log)
                 
                 self.cleanUp()