def getRPMS(self, path): """Return a list of all the RPMs in the given path, if multiple versions of a package are found only the most recent one will be included (just like rocks-dist)""" dict = {} tree = rocks.file.Tree(os.path.join(os.getcwd(), path)) for dir in tree.getDirs(): for file in tree.getFiles(dir): try: file.getPackageName() except AttributeError: continue # skip all non-rpm files # Skip RPMS for other architecures if file.getPackageArch() not in self.getCPUs(): continue # Resolve package versions name = file.getUniqueName() if not dict.has_key(name) or file >= dict[name]: dict[name] = file # convert the dictionary to a list and return all the RPMFiles list = [] for e in dict.keys(): list.append(dict[e]) return list
def run(self, params, args): (dryrun, host) = self.fillParams([('dryrun', None), ('host', None)]) if dryrun: dryrun = self.str2bool(dryrun) if not dryrun and host: self.abort("If you select a host you can't disable dryrun.") else: dryrun = True if not host: host = 'localhost' script = [] script.append('#!/bin/sh\n') script.append('yum clean all\n') rolls = [] for roll in args: rolls.append(roll) xml = self.command('list.host.xml', [host, 'roll=%s' % string.join(rolls, ',')]) reader = Sax2.Reader() gen = getattr(rocks.gen, 'Generator_%s' % self.os)() gen.setArch(self.arch) gen.setOS(self.os) gen.parse(xml) distPath = os.path.join( self.command('report.distro')[:-1], 'rocks-dist') tree = rocks.file.Tree(distPath) rpm_list = {} len_base_path = len('/export/rocks') base_url = "http://" + self.db.getHostAttr('localhost', 'Kickstart_PublicHostname') for file in tree.getFiles(os.path.join(self.arch, 'RedHat', 'RPMS')): if isinstance(file, rocks.file.RPMFile): rpm_url = base_url + file.getFullName()[len_base_path:] rpm_list[file.getBaseName()] = rpm_url rpm_list["%s.%s" % (file.getBaseName(), \ file.getPackageArch())] = rpm_url rpms = [] for line in gen.generate('packages'): if line.find('%package') == -1: rpms.append(line) for rpm in rpms: if rpm in rpm_list.keys(): script.append('yum install %s\n' % rpm) script.append(rpm_force_template % rpm_list[rpm]) script += gen.generate_config_script() if dryrun: self.addText(string.join(script, '')) else: os.system(string.join(script, ''))
def run(self, params, args): (dryrun, host ) = self.fillParams([('dryrun', None), ('host', None)]) if dryrun: dryrun = self.str2bool(dryrun) if not dryrun and host: self.abort("If you select a host you can't disable dryrun.") else: dryrun = True if not host: host = 'localhost' script = [] script.append('#!/bin/sh\n') script.append('yum clean all\n') rolls = [] for roll in args: rolls.append(roll) xml = self.command('list.host.xml', [ host, 'roll=%s' % string.join(rolls, ',') ]) reader = Sax2.Reader() gen = getattr(rocks.gen,'Generator_%s' % self.os)() gen.setArch(self.arch) gen.setOS(self.os) gen.parse(xml) distPath = os.path.join(self.command('report.distro')[:-1], 'rocks-dist') tree = rocks.file.Tree(distPath) rpm_list = {} len_base_path = len('/export/rocks') base_url = "http://" + self.db.getHostAttr('localhost', 'Kickstart_PublicHostname') for file in tree.getFiles(os.path.join(self.arch, 'RedHat', 'RPMS')): if isinstance(file, rocks.file.RPMFile): rpm_url = base_url + file.getFullName()[len_base_path:] rpm_list[file.getBaseName()] = rpm_url rpm_list["%s.%s" % (file.getBaseName(), \ file.getPackageArch())] = rpm_url rpms = [] for line in gen.generate('packages'): if line.find('%package') == -1: rpms.append(line) for rpm in rpms: if rpm in rpm_list.keys(): script.append('yum install %s\n' % rpm) script.append(rpm_force_template % rpm_list[rpm]) script += gen.generate_config_script() if dryrun: self.addText(string.join(script, '')) else: os.system(string.join(script, ''))
def copy_foreign_cd_linux(self, clean): """Copy a Linux OS CD. This is when the CD is a standard CentOS RHEL or Scientific Linux CD""" disc_info_file = os.path.join(self.cdrom_mount, '.discinfo') if not os.path.exists(disc_info_file): self.abort('Cannot read disk information') file = open(disc_info_file, 'r') t = file.readline() n = file.readline() a = file.readline() d = file.readline() file.close() timestamp = t[:-1] roll_name = n[:-1].replace(' ', '_') roll_arch = a[:-1] diskid = d[:-1] roll_vers = rocks.version roll_os = 'linux' dst = os.path.join( self.db.getHostAttr('', 'Kickstart_DistroDir'), self.db.getHostAttr('', 'Kickstart_PrivateKickstartBasedir'), 'rolls') roll_dir = os.path.join(dst, roll_name, roll_vers, roll_arch) destdir = os.path.join(roll_dir, 'RedHat', 'RPMS') if os.path.exists(roll_dir) and clean: str = 'Cleaning %s version %s ' % \ (roll_name, roll_vers) str += 'for %s from Rolls directory' % roll_arch print str self.clean_dir(roll_dir) os.makedirs(roll_dir) print 'Copying "%s" (%s,%s) roll...' % (roll_name, roll_vers, roll_arch) if not os.path.exists(destdir): os.makedirs(destdir) cdtree = rocks.file.Tree(self.cdrom_mount) for dir in cdtree.getDirs(): for file in cdtree.getFiles(dir): if not file.getName().endswith('.rpm'): continue if file.getPackageArch() != 'src' and \ file.getBaseName() != 'comps' and \ file.getName() != 'comps.rpm' and \ file.getBaseName() != 'anaconda' and \ file.getBaseName() != 'anaconda-runtime' \ and not (roll_arch == 'i386' and \ re.match('^kudzu.*', file.getBaseName())): subprocess.call('cp -p %s %s' % (file.getFullName(), destdir), shell=True) # Add roll information to the database rows = self.db.execute( "select * from rolls where" " name='%s' and Arch='%s' and OS='%s' and version='%s'" % (roll_name, roll_arch, roll_os, roll_vers)) if rows: pass else: self.db.execute("""insert into rolls (name, arch, os, version, enabled) values ('%s','%s','%s', '%s', 'no')""" % (roll_name, roll_arch, roll_os, roll_vers))
def copy_foreign_cd_linux(self, clean): """Copy a Linux OS CD. This is when the CD is a standard CentOS RHEL or Scientific Linux CD""" disc_info_file = os.path.join(self.cdrom_mount, '.discinfo') if not os.path.exists(disc_info_file): self.abort('Cannot read disk information') file = open(disc_info_file, 'r') t = file.readline() n = file.readline() a = file.readline() d = file.readline() file.close() timestamp = t[:-1] roll_name = n[:-1].replace(' ', '_') roll_arch = a[:-1] diskid = d[:-1] roll_vers = rocks.version roll_os = 'linux' dst = os.path.join(self.db.getHostAttr('', 'Kickstart_DistroDir'), self.db.getHostAttr('', 'Kickstart_PrivateKickstartBasedir'), 'rolls') roll_dir = os.path.join(dst, roll_name, roll_vers, roll_arch) destdir = os.path.join(roll_dir, 'RedHat', 'RPMS') if os.path.exists(roll_dir) and clean: str = 'Cleaning %s version %s ' % \ (roll_name, roll_vers) str += 'for %s from Rolls directory' % roll_arch print str self.clean_dir(roll_dir) os.makedirs(roll_dir) print 'Copying "%s" (%s,%s) roll...' % (roll_name, roll_vers, roll_arch) if not os.path.exists(destdir): os.makedirs(destdir) cdtree = rocks.file.Tree(self.cdrom_mount) for dir in cdtree.getDirs(): for file in cdtree.getFiles(dir): if not file.getName().endswith('.rpm'): continue if file.getPackageArch() != 'src' and \ file.getBaseName() != 'comps' and \ file.getName() != 'comps.rpm' and \ file.getBaseName() != 'anaconda' and \ file.getBaseName() != 'anaconda-runtime' \ and not (roll_arch == 'i386' and \ re.match('^kudzu.*', file.getBaseName())): subprocess.call('cp -p %s %s' % ( file.getFullName(), destdir), shell=True) # Add roll information to the database rows = self.db.execute( "select * from rolls where" " name='%s' and Arch='%s' and OS='%s' and version='%s'" % (roll_name, roll_arch, roll_os, roll_vers)) if rows: pass else: self.db.execute("""insert into rolls (name, arch, os, version, enabled) values ('%s','%s','%s', '%s', 'no')""" % (roll_name, roll_arch, roll_os, roll_vers))
def run(self, params, args): (dryrun, host) = self.fillParams([("dryrun", None), ("host", None)]) if dryrun: dryrun = self.str2bool(dryrun) if not dryrun and host: self.abort("If you select a host you can't disable dryrun.") else: dryrun = True if not host: host = "localhost" script = [] script.append("#!/bin/sh\n") rolls = [] for roll in args: rolls.append(roll) xml = self.command("list.host.xml", [host, "roll=%s" % string.join(rolls, ",")]) reader = Sax2.Reader() gen = getattr(rocks.gen, "Generator_%s" % self.os)() gen.setArch(self.arch) gen.setOS(self.os) gen.parse(xml) distPath = os.path.join(self.command("report.distro")[:-1], "rocks-dist") tree = rocks.file.Tree(distPath) rpm_list = {} len_base_path = len("/export/rocks") base_url = "http://" + self.db.getHostAttr("localhost", "Kickstart_PublicHostname") for file in tree.getFiles(os.path.join(self.arch, "RedHat", "RPMS")): if isinstance(file, rocks.file.RPMFile): rpm_url = base_url + file.getFullName()[len_base_path:] rpm_list[file.getBaseName()] = rpm_url rpm_list["%s.%s" % (file.getBaseName(), file.getPackageArch())] = rpm_url rpms = [] for line in gen.generate("packages"): if line.find("%package") == -1: rpms.append(line) for rpm in rpms: if rpm in rpm_list.keys(): script.append("yum install %s\n" % rpm) script.append(rpm_force_template % rpm_list[rpm]) cur_proc = False for line in gen.generate("post"): if not line.startswith("%post"): script.append(line) else: if cur_proc == True: script.append("__POSTEOF__\n") script.append("%s %s\n" % (interpreter, t_name)) cur_proc = False try: i = line.split().index("--interpreter") except ValueError: continue interpreter = line.split()[i + 1] t_name = tempfile.mktemp() cur_proc = True script.append('cat > %s << "__POSTEOF__"\n' % t_name) if dryrun: self.addText(string.join(script, "")) else: os.system(string.join(script, ""))
def run(self): # Make a list of all the files that we need to copy onto the # rolls cds. Don't worry about what the file types are right # now, we can figure that out later. list = [] if self.config.hasRPMS(): list.extend(self.getRPMS('RPMS')) if self.config.hasSRPMS(): list.extend(self.getRPMS('SRPMS')) for rpm in list: self.signRPM(rpm) # Make a list of both required and optional packages. The copy # code is here since python is by-reference for everything. # After we segregate the packages (old rocks-dist style) add # any local rpms to the required list. This makes sure we # pick up the roll-os-kickstart package. required = [] if self.config.hasRolls(): (required, optional) = self.getExternalRPMS() for file in list: required.append(file) print 'Required Packages', len(required) print 'Optional Packages', len(optional) for file in required: # make a copy of the list list.append(file) list.extend(optional) optional = 0 for (name, id, size, files) in self.spanDisks(list): print 'Creating %s (%.2fMB)...' % (name, size), if optional: print ' This disk is optional (extra rpms)' else: print root = os.path.join(name, self.config.getRollName(), self.config.getRollVersion(), self.config.getRollArch()) os.makedirs(root) os.makedirs(os.path.join(root, 'RedHat', 'RPMS')) os.makedirs(os.path.join(root, 'SRPMS')) # Symlink in all the RPMS and SRPMS for file in files: try: # # not RPM files will throw an exception # in getPackageArch() # arch = file.getPackageArch() except: continue if arch == 'src': file.symlink(os.path.join(root, 'SRPMS', file.getName())) else: file.symlink(os.path.join(root, 'RedHat', 'RPMS', file.getName())) if file in required: del required[required.index(file)] if len(required) == 0: optional = 1 # Copy the Roll XML file onto all the disks shutil.copy(self.config.getFullName(), root) # Create the .discinfo file self.stampDisk(name, self.config.getRollName(), self.config.getRollArch(), id) # make the ISO. This code will change and move into # the base class, and supported bootable rolls. Get # this working here and then test on the bootable # kernel roll. isoname = '%s-%s-%s.%s.%s.iso' % ( self.config.getRollName(), self.config.getRollVersion(), self.config.getRollRelease(), self.config.getRollArch(), name) if id == 1 and self.config.isBootable() == 1: self.makeBootable(name) self.mkisofs(isoname, self.config.getRollName(), name)
def run(self): # Make a list of all the files that we need to copy onto the # rolls cds. Don't worry about what the file types are right # now, we can figure that out later. list = [] if self.config.hasRPMS(): list.extend(self.getRPMS('RPMS')) if self.config.hasSRPMS(): list.extend(self.getRPMS('SRPMS')) for rpm in list: self.signRPM(rpm) # Make a list of both required and optional packages. The copy # code is here since python is by-reference for everything. # After we segregate the packages (old rocks-dist style) add # any local rpms to the required list. This makes sure we # pick up the roll-os-kickstart package. required = [] if self.config.hasRolls(): (required, optional) = self.getExternalRPMS() for file in list: required.append(file) print 'Required Packages', len(required) print 'Optional Packages', len(optional) for file in required: # make a copy of the list list.append(file) list.extend(optional) optional = 0 for (name, id, size, files) in self.spanDisks(list): print 'Creating %s (%.2fMB)...' % (name, size), if optional: print ' This disk is optional (extra rpms)' else: print root = os.path.join(name, self.config.getRollName(), self.config.getRollVersion(), self.config.getRollArch()) os.makedirs(root) os.makedirs(os.path.join(root, 'RedHat', 'RPMS')) os.makedirs(os.path.join(root, 'SRPMS')) # Symlink in all the RPMS and SRPMS for file in files: try: # # not RPM files will throw an exception # in getPackageArch() # arch = file.getPackageArch() except: continue if arch == 'src': file.symlink(os.path.join(root, 'SRPMS', file.getName())) else: file.symlink( os.path.join(root, 'RedHat', 'RPMS', file.getName())) if file in required: del required[required.index(file)] if len(required) == 0: optional = 1 # Copy the Roll XML file onto all the disks shutil.copy(self.config.getFullName(), root) # Create the .discinfo file self.stampDisk(name, self.config.getRollName(), self.config.getRollArch(), id) # make the ISO. This code will change and move into # the base class, and supported bootable rolls. Get # this working here and then test on the bootable # kernel roll. isoname = '%s-%s-%s.%s.%s.iso' % ( self.config.getRollName(), self.config.getRollVersion(), self.config.getRollRelease(), self.config.getRollArch(), name) if id == 1 and self.config.isBootable() == 1: self.makeBootable(name) self.mkisofs(isoname, self.config.getRollName(), name)