def __downloadNfsFile(self): """ Download config file for auto install via NFS. @rtype : nothing @returns: nothing """ try: nfsFile = self.__kickstartFile.split('/')[-1] nfsSections = self.__kickstartFile.split(':') if len(nfsSections) == 4: nfsDir = self.__kickstartFile.split(':')[3][:-len(nfsFile)] nfsOpts = self.__kickstartFile.split(':')[1] nfsServer = self.__kickstartFile.split(':')[2] else: nfsDir = self.__kickstartFile.split(':')[2][:-len(nfsFile)] nfsServer = self.__kickstartFile.split(':')[1] nfsOpts = "" if nfsOpts != "": nfsMount = "-o " + nfsOpts + " " + nfsServer + ":" + nfsDir else: nfsMount = nfsServer + ":" + nfsDir nfsMount = mount(nfsMount) nfsFile = os.path.join(nfsMount, nfsFile) shutil.copy(nfsFile, KICKSTART_FILE) umount(nfsMount) self.__kickstartFile = KICKSTART_FILE except Exception as e: self.__logger.critical("EXCEPTION:" + str(type(e))) self.__logger.critical(str(e)) self.__logger.critical("Stacktrace:" + str(traceback.format_exc())) raise PKVMError("PREINSTALL", "INSTALLAUTO", "DOWNLOAD_NFS")
def getPowerKVMBootPartitions(self, boot_parts=None): """Get a list of PowerKVM boot partitions that need to be erased. Each boot partition is searched for PowerKVM strings in grub.cfg. @rtype: List @return: A list of boot partitions to be erased""" if boot_parts == None: self.__logger.debug("getPowerKVMBootPartitions(): boot_parts == None") return None # mount each partition in boot_parts # search for <boot mnt>/grub2/grub.cfg # grep 'ibmpkvm_' in grub.cfg # add partition to list if above grep is true pkvm_boot_parts = [] for part in boot_parts: self.__logger.debug("getPowerKVMBootPartitions(): part = {0}".format(part)) mnt = mount(part) self.__logger.debug("getPowerKVMBootPartitions(): mnt = {0}".format(mnt)) if mnt == None: continue grubcfg = os.path.join(mnt, "grub2/grub.cfg") self.__logger.debug("getPowerKVMBootPartitions(): grubcfg = {0}".format(grubcfg)) if os.path.exists(grubcfg): self.__logger.debug("getPowerKVMBootPartitions(): file {0} exists".format(grubcfg)) with open(grubcfg, 'r') as g: lines = g.readlines() g.close() for line in lines: if VGROOT in line: self.__logger.debug("getPowerKVMBootPartitions(): {0} found in file {1}, line = {2}".format(VGROOT, grubcfg, line)) pkvm_boot_parts.append(part) # found one entry, don't need to continue # reading the lines break else: self.__logger.debug("getPowerKVMBootPartitions(): no such file {0}".format(grubcfg)) if umount(mnt) == False: self.__logger.debug("getPowerKVMBootPartitions(): cannot umount {0} - ignoring".format(mnt)) return list(set(pkvm_boot_parts))
def onPostInstall(self, data): """ Handles the post install event @type data: dict @param data: relevant arguments for that given event @rtype: None @returns: Nothing """ try: mountDir = data['model'].get('mountDir') logDir = mountDir + "/var/log" if data['model'].get('licenseAccepted'): subprocess.call('touch %s/.powerkvm_license_accepted' % mountDir, shell = True) self.__logger.info('License accepted') self.restoreCon(mountDir, data) # need to umount /var/log before / if not umount(logDir, False): self.__logger.critical("Failed to umount (%s)" % logDir) else: self.__logger.debug("%s umounted successfully" % logDir) # umount / if not umount(mountDir): self.__logger.critical("Failed to umount (%s)" % mountDir) else: self.__logger.debug("%s umounted successfully" % mountDir) except Exception as e: self.__logger.critical("Failed AutoUmounter module!") self.__logger.critical("EXCEPTION:" + str(type(e))) self.__logger.critical(str(e)) self.__logger.critical("Stacktrace:" + str(traceback.format_exc())) raise PKVMError("POSTINSTALL", "AUTOUMOUNTER", "POST_MODULES")