Beispiel #1
0
	def copyFile(self, path, file, root):
		if file.getName() in [ 'TRANS.TBL' ]:
			return

		dir	 = os.path.join(root, path)
		fullname = os.path.join(dir, file.getName())
		if not os.path.isdir(dir):
			os.makedirs(dir)

		shutil.copy(file.getFullName(), fullname)
		os.utime(fullname, (file.getTimestamp(), file.getTimestamp()))
Beispiel #2
0
    def copyFile(self, path, file, root):
        if file.getName() in ['TRANS.TBL']:
            return

        dir = os.path.join(root, path)
        fullname = os.path.join(dir, file.getName())
        if not os.path.isdir(dir):
            os.makedirs(dir)

        shutil.copy(file.getFullName(), fullname)
        os.utime(fullname, (file.getTimestamp(), file.getTimestamp()))
Beispiel #3
0
    def builder(self, path, file, root):
        if not root:
            root = self.dist.getReleasePath()
        dir	 = os.path.join(root, path)
        fullname = os.path.join(dir, file.getName())

        if file.getFullName() == fullname:
            return

        if not os.path.isdir(dir):
            os.makedirs(dir)

        # Create the new distribution either with all symbolic links
        # into the mirror, contrib, and local rpms.  Or copy
        # everything.  The idea is local distributions should be all
        # symlinks, but a published base distribution (like the NPACI
        # Rocks master) should be copys.  This keeps the FTP chroot
        # environment happy, extends the lifetime of the release past
        # that of scattered RPMS.  It may also make sense to have your
        # master distribution for your cluster done by copy.
        
        if self.useLinks:
            file.symlink(fullname, self.dist.getRootPath())
        else:

            # For copied distributions, the timestamps of the new
            # files are forced to that of the source files.  This
            # keeps wget happy.

            if os.path.islink(file.getFullName()):
                os.symlink(os.readlink(file.getFullName()), fullname)
            else:
                shutil.copy(file.getFullName(), fullname)
                os.utime(fullname, (file.getTimestamp(), file.getTimestamp()))
Beispiel #4
0
	def run(self, params, args):

		if len(args) != 1:
			print 'running args=%s' % args
			self.abort('must supply one path')
		mirror_path = args[0]
		

		self.clean()
		
		self.mirror(mirror_path)

		list = []
		list.extend(self.getRPMS('RPMS'))

#                rockscmd='lsb_release -rs | cut -d . -f 1'
#for python 2.7
#		getrocksversion=subprocess.check_output(rockscmd)
		getrocksversion=subprocess.Popen([ 'lsb_release', '-rs' ],stdout=subprocess.PIPE).communicate()[0]
		for file in list:
			osgdir=getrocksversion[0:1]+'/x86_64'
			rpmfile=file.getName()
			if '-debuginfo-' in rpmfile:
				osgdir=getrocksversion[0:1]+'/debug'
			if 'noarch.rpm' in rpmfile:
				osgdir=getrocksversion[0:1]+'/noarch'
			if 'i386.rpm' in rpmfile:
				osgdir=getrocksversion[0:1]+'/i386'
			self.copyFile(osgdir,file)

		self.clean()
                print 'test rocks version=%s dir=%s' % (getrocksversion[0:1],osgdir)
Beispiel #5
0
    def buildKickstart(self):
	print 'Installing XML Kickstart profiles'

	build   = self.dist.getBuildPath()

	for rpm in self.dist.getRPMS():
		tok = rpm.getBaseName().split('-')
		if tok[0] != 'roll':
			continue
		try:
			k = tok.index('kickstart')
			rollname = '-'.join(tok[1:k])
		except ValueError:
			continue
			
		print '    installing "%s" profiles...' % rollname
		self.applyRPM(rpm.getBaseName(), build)

	# Copy local profiles into the distribution.
	if self.withSiteProfiles:
		print '    installing "site" profiles...'
		tree = self.dist.getSiteProfilesTree()
		for dir in tree.getDirs():
			for file in tree.getFiles(dir):
				path = os.path.join(build, dir)
				if not os.path.isdir(path):
					os.makedirs(path)
				shutil.copy(file.getFullName(),
					os.path.join(path, file.getName()))
				# make sure apache can read site XML
				file.chmod(0664)
Beispiel #6
0
	def run(self, params, args):

		if len(args) != 1:
			self.abort('must supply one path')
		mirror_path = args[0]
		
		(version, arch) = self.fillParams(
			[('version', rocks.version),
			('arch',self.arch)])

		self.clean()
		
		self.mirror(mirror_path)

                list = []
		list.extend(self.getRPMS('RPMS'))

		for file in list:
			osgdir=version[0:1]+'/'+arch
			rpmfile=file.getName()
			if '-debuginfo-' in rpmfile:
				osgdir=version[0:1]+'/debug'
			if 'noarch.rpm' in rpmfile:
				osgdir=version[0:1]+'/noarch'
			if 'src.rpm' in rpmfile:
				osgdir=version[0:1]+'/src'
			self.copyFile(osgdir,file)

#debug#			print 'file base name %s ,full name=%s ' % (file.getBaseName(), file.getName())
		self.clean()
Beispiel #7
0
def getSiteProfiles():
    #
    # get all the files under site-profiles
    #
    print '<post>'
    cmd = '/opt/rocks/bin/rocks report distro'
    for line in os.popen(cmd).readlines():
        distrodir = line[:-1]
    tree = rocks.file.Tree('%s/site-profiles/' % (distrodir))

    for dir in tree.getDirs():
        for file in tree.getFiles(dir):
            #
            # don't get skeleton.xml
            #
            if file.getName() == 'skeleton.xml':
                continue
            #
            # get the permissions of the file
            #
            filename = file.getFullName()

            p = os.stat(filename)[stat.ST_MODE]
            perms = '%o' % (int(stat.S_IMODE(p)))
            userid = '%s' % (os.stat(filename)[stat.ST_UID])
            groupid = '%s' % (os.stat(filename)[stat.ST_GID])

            writeFile(filename, filename, perms, '%s.%s' % (userid, groupid))

    print '</post>'
    return
Beispiel #8
0
def getSiteProfiles():
    #
    # get all the files under site-profiles
    #
    print "<post>"
    cmd = "/opt/rocks/bin/rocks report distro"
    for line in os.popen(cmd).readlines():
        distrodir = line[:-1]
    tree = rocks.file.Tree("%s/site-profiles/" % (distrodir))

    for dir in tree.getDirs():
        for file in tree.getFiles(dir):
            #
            # don't get skeleton.xml
            #
            if file.getName() == "skeleton.xml":
                continue
                #
                # get the permissions of the file
                #
            filename = file.getFullName()

            p = os.stat(filename)[stat.ST_MODE]
            perms = "%o" % (int(stat.S_IMODE(p)))
            userid = "%s" % (os.stat(filename)[stat.ST_UID])
            groupid = "%s" % (os.stat(filename)[stat.ST_GID])

            writeFile(filename, filename, perms, "%s.%s" % (userid, groupid))

    print "</post>"
    return
Beispiel #9
0
    def buildKickstart(self):
	print 'Installing XML Kickstart profiles'

	build   = self.dist.getBuildPath()

	for rpm in self.dist.getRPMS():
		tok = rpm.getBaseName().split('-')
		if tok[0] != 'roll':
			continue
		try:
			k = tok.index('kickstart')
			rollname = '-'.join(tok[1:k])
		except ValueError:
			continue
			
		print '    installing "%s" profiles...' % rollname
		self.applyRPM(rpm.getBaseName(), build)

	# Copy local profiles into the distribution.
	if self.withSiteProfiles:
		print '    installing "site" profiles...'
		tree = self.dist.getSiteProfilesTree()
		for dir in tree.getDirs():
			for file in tree.getFiles(dir):
				path = os.path.join(build, dir)
				if not os.path.isdir(path):
					os.makedirs(path)
				shutil.copy(file.getFullName(),
					os.path.join(path, file.getName()))
				# make sure apache can read site XML
				file.chmod(0664)
Beispiel #10
0
    def builder(self, path, file, root):
        if not root:
            root = self.dist.getReleasePath()
        dir	 = os.path.join(root, path)
        fullname = os.path.join(dir, file.getName())

        if file.getFullName() == fullname:
            return

        if not os.path.isdir(dir):
            os.makedirs(dir)

        # Create the new distribution either with all symbolic links
        # into the mirror, contrib, and local rpms.  Or copy
        # everything.  The idea is local distributions should be all
        # symlinks, but a published base distribution (like the NPACI
        # Rocks master) should be copys.  This keeps the FTP chroot
        # environment happy, extends the lifetime of the release past
        # that of scattered RPMS.  It may also make sense to have your
        # master distribution for your cluster done by copy.
        
        if self.useLinks:
            file.symlink(fullname, self.dist.getRootPath())
        else:

            # For copied distributions, the timestamps of the new
            # files are forced to that of the source files.  This
            # keeps wget happy.

            if os.path.islink(file.getFullName()):
                os.symlink(os.readlink(file.getFullName()), fullname)
            else:
                shutil.copy(file.getFullName(), fullname)
                os.utime(fullname, (file.getTimestamp(), file.getTimestamp()))
Beispiel #11
0
    def run(self, params, args):

        if len(args) != 1:
            print 'running args=%s' % args
            self.abort('must supply one path')
        mirror_path = args[0]

        self.clean()

        self.mirror(mirror_path)

        list = []
        list.extend(self.getRPMS('RPMS'))

        #                rockscmd='lsb_release -rs | cut -d . -f 1'
        #for python 2.7
        #		getrocksversion=subprocess.check_output(rockscmd)
        getrocksversion = subprocess.Popen(
            ['lsb_release', '-rs'], stdout=subprocess.PIPE).communicate()[0]
        for file in list:
            osgdir = getrocksversion[0:1] + '/x86_64'
            rpmfile = file.getName()
            if '-debuginfo-' in rpmfile:
                osgdir = getrocksversion[0:1] + '/debug'
            if 'noarch.rpm' in rpmfile:
                osgdir = getrocksversion[0:1] + '/noarch'
            if 'i386.rpm' in rpmfile:
                osgdir = getrocksversion[0:1] + '/i386'
            self.copyFile(osgdir, file)

        self.clean()
        print 'test rocks version=%s dir=%s' % (getrocksversion[0:1], osgdir)
Beispiel #12
0
    def run(self, params, args):

        if len(args) != 1:
            self.abort('must supply one path')
        mirror_path = args[0]

        (version, arch) = self.fillParams([('version', rocks.version),
                                           ('arch', self.arch)])

        self.clean()

        self.mirror(mirror_path)

        list = []
        list.extend(self.getRPMS('RPMS'))

        for file in list:
            osgdir = version[0:1] + '/' + arch
            rpmfile = file.getName()
            if '-debuginfo-' in rpmfile:
                osgdir = version[0:1] + '/debug'
            if 'noarch.rpm' in rpmfile:
                osgdir = version[0:1] + '/noarch'
            if 'src.rpm' in rpmfile:
                osgdir = version[0:1] + '/src'
            self.copyFile(osgdir, file)

#debug#			print 'file base name %s ,full name=%s ' % (file.getBaseName(), file.getName())
        self.clean()
Beispiel #13
0
    def copyFile(self, path, file):
        cwd = os.getcwd()
        dir = os.path.join(cwd, path)
        fullname = os.path.join(dir, file.getName())
        if not os.path.isdir(dir):
            os.makedirs(dir)

        shutil.copy2(file.getFullName(), fullname)
Beispiel #14
0
	def copyFile(self, path, file):
		cwd = os.getcwd()
		dir      = os.path.join(cwd,path)
		fullname = os.path.join(dir, file.getName())
		if not os.path.isdir(dir):
			os.makedirs(dir)

		shutil.copy2(file.getFullName(), fullname)
Beispiel #15
0
    def copyFile(self, path, file):
        cwd = os.getcwd()
        dir = os.path.join(cwd, path)
        fullname = os.path.join(dir, file.getName())
        if not os.path.isdir(dir):
            os.makedirs(dir)

#debug#		print ' copying ... %s to %s' % (file.getName(), dir)
        shutil.copy2(file.getFullName(), fullname)
Beispiel #16
0
	def copyFile(self, path, file):
		cwd = os.getcwd()
		dir      = os.path.join(cwd,path)
		fullname = os.path.join(dir, file.getName())
		if not os.path.isdir(dir):
			os.makedirs(dir)

#debug#		print ' copying ... %s to %s' % (file.getName(), dir)
		shutil.copy2(file.getFullName(), fullname)
Beispiel #17
0
    def normalizer(self, path, file, root):
        if not root:
            root = self.dist.getReleasePath()
        dir	 = os.path.join(root, path)
        fullname = os.path.join(dir, file.getName())

        # Reset the File to represent the one we just created in the new
        # distribution.
        
        if file.getFullName() != fullname:
            file.setFile(fullname)
Beispiel #18
0
    def normalizer(self, path, file, root):
        if not root:
            root = self.dist.getReleasePath()
        dir	 = os.path.join(root, path)
        fullname = os.path.join(dir, file.getName())

        # Reset the File to represent the one we just created in the new
        # distribution.
        
        if file.getFullName() != fullname:
            file.setFile(fullname)
Beispiel #19
0
 def cleaner(self, path, file, root):
     if not root:
         root = self.dist.getReleasePath()
     dir = os.path.join(root, path)
     if dir not in [ self.dist.getForceRPMSPath() ]:
         os.unlink(os.path.join(dir, file.getName()))
Beispiel #20
0
 def getBaseFile(self, name):
     for file in self.getFiles("release", os.path.join("RedHat", "base")):
         if file.getName() == name:
             return file
     return None
Beispiel #21
0
    def run(self, params, args):
        if len(args):
            self.abort('command does not take arguments')

        ver = self.db.getHostAttr('localhost', 'rocks_version')
        url = self.db.getHostAttr('localhost', 'updates_url')
        path = self.db.getHostAttr('localhost', 'updates_path')

        if not ver:
            self.abort('unknown rocks version')

        if not url:
            url = 'http://www.rocksclusters.org/'
            url += 'ftp-site/pub/rocks/rocks-%s/%s/updates/' % \
             (ver, self.os)

        if not path:
            path = '/export/rocks/updates'

        try:
            host = url.split('//', 1)[1].split('/')[0]
        except:
            self.abort('invalid url')

        if not os.path.exists(path):
            os.system('mkdir -p %s' % path)

        if not self.httpExists(url):
            print "No updates are available at the moment..."
            return
        os.chdir(path)
        self.command('create.mirror', [url, 'rollname=rocks-updates'])
        os.system('createrepo %s' % host)

        # Always re-write the rocks-updates.repo yum file

        repo = '/etc/yum.repos.d/rocks-updates.repo'
        file = open(repo, 'w')
        file.write('[Rocks-%s-Updates]\n' % ver)
        file.write('name=Rocks %s Updates\n' % ver)
        file.write('baseurl=file://%s/%s\n' % (path, host))
        file.close()

        # Add the updates roll and enable it, but do not rebuild the
        # distribution.  The user should do this when they are ready.
        # We also nuke the .iso since it is not really safe to use
        # outside of this command.

        self.command('add.roll', [
            'rocks-updates-%s-0.%s.disk1.iso' % (ver, self.arch), 'clean=yes'
        ])
        os.unlink('rocks-updates-%s-0.%s.disk1.iso' % (ver, self.arch))
        os.unlink('roll-rocks-updates.xml')
        self.command(
            'enable.roll',
            ['rocks-updates',
             'arch=%s' % self.arch,
             'version=%s' % ver])

        # Update the packages on the frontend, but only from this new
        # YUM repository.

        os.system('yum --disablerepo="*" '
                  '--enablerepo=Rocks-%s-Updates update' % ver)

        # Determine what Rolls are on the disk and remove the XML
        # and update scripts from Rolls that we do not have enabled

        self.db.execute("""select name from rolls where
			enabled='yes' and version='%s'""" % ver)
        rolls = []
        for roll, in self.db.fetchall():
            rolls.append(roll)

        # Go into the rocks-updates Roll and remove the
        # kickstart profile rpms that are for rolls we are not
        # using (not enabled).

        tree = rocks.file.Tree(
            os.path.join('..', 'install', 'rolls', 'rocks-updates', ver,
                         self.arch, 'RedHat', 'RPMS'))
        for file in tree.getFiles():
            name, ext = os.path.splitext(file.getName())
            try:
                file.getPackageName()
            except AttributeError:
                continue
            tokens = file.getBaseName().split('-')
            if len(tokens) != 3:
                continue
            if tokens[0] == 'roll' and tokens[2] == 'kickstart':
                if tokens[2] in rolls:
                    continue
                print '+ roll not enabled, removed %s' \
                 % file.getName()
                os.unlink(file.getFullName())

        # Scan the updates for any .sh files and run these to update
        # the Frontend after the RPMs are installed.
        # Skip update scripts for Rolls that are not enabled.

        dir = url.split('//', 1)[1]
        for file in os.listdir(dir):
            if os.path.splitext(file)[1] != '.sh':
                continue
            tokens = file.split('-', 1)
            if tokens[0] == 'update':
                if not tokens[1] in rolls:
                    print '+ roll not enabled, ignored %s' \
                          % file
                    continue
            os.system('sh -x %s' % os.path.join(dir, file))
Beispiel #22
0
    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)
Beispiel #23
0
	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))
Beispiel #24
0
    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))
Beispiel #25
0
	def getBaseFile(self, name):
		for file in self.getFiles('release',
					  os.path.join('RedHat', 'base')):
			if file.getName() == name:
				return file
		return None
Beispiel #26
0
	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)
Beispiel #27
0
 def getBaseFile(self, name):
     for file in self.getFiles('release', os.path.join('RedHat', 'base')):
         if file.getName() == name:
             return file
     return None
Beispiel #28
0
	def run(self, params, args):
		if len(args):
			self.abort('command does not take arguments')

		ver	= self.db.getHostAttr('localhost', 'rocks_version')
		url	= self.db.getHostAttr('localhost', 'updates_url')
		path	= self.db.getHostAttr('localhost', 'updates_path')
		
		if not ver:
			self.abort('unknown rocks version')

		if not url:
			url  = 'http://www.rocksclusters.org/'
			url += 'ftp-site/pub/rocks/rocks-%s/%s/updates/' % \
				(ver, self.os)

		if not path:
			path = '/export/rocks/updates'

		try:
			host = url.split('//', 1)[1].split('/')[0]
		except:
			self.abort('invalid url')

		if not os.path.exists(path):
			os.system('mkdir -p %s' % path)
		
		if not self.httpExists(url) : 
			print "No updates are available at the moment..."
			return
		os.chdir(path)
		self.command('create.mirror', [ url, 'rollname=rocks-updates' ])
		os.system('createrepo %s' % host)

		# Always re-write the rocks-updates.repo yum file

		repo = '/etc/yum.repos.d/rocks-updates.repo'
		file = open(repo, 'w')
		file.write('[Rocks-%s-Updates]\n' % ver)
		file.write('name=Rocks %s Updates\n' % ver)
		file.write('baseurl=file://%s/%s\n' % (path, host))
		file.close()

		# Add the updates roll and enable it, but do not rebuild the
		# distribution.  The user should do this when they are ready.
		# We also nuke the .iso since it is not really safe to use
		# outside of this command.

		self.command('add.roll', [
			'rocks-updates-%s-0.%s.disk1.iso' % (ver, self.arch),
			'clean=yes'
			])
		os.unlink('rocks-updates-%s-0.%s.disk1.iso' % (ver, self.arch))
		os.unlink('roll-rocks-updates.xml')
		self.command('enable.roll', [
			'rocks-updates',
			'arch=%s' % self.arch,
			'version=%s' % ver
			])

		# Update the packages on the frontend, but only from this new
		# YUM repository.

		os.system('yum --disablerepo="*" '
			'--enablerepo=Rocks-%s-Updates update' % ver)

		# Determine what Rolls are on the disk and remove the XML
		# and update scripts from Rolls that we do not have enabled

		self.db.execute("""select name from rolls where
			enabled='yes' and version='%s'""" % ver)
		rolls = []
		for roll, in self.db.fetchall():
			rolls.append(roll)
	
		# Go into the rocks-updates Roll and remove the
		# kickstart profile rpms that are for rolls we are not
		# using (not enabled).

		tree = rocks.file.Tree(os.path.join('..', 'install', 'rolls',
			'rocks-updates', ver, self.arch,
			'RedHat', 'RPMS'))
		for file in tree.getFiles():
			name, ext  = os.path.splitext(file.getName())
                        try:
	                        file.getPackageName()
                        except AttributeError:
				continue
			tokens = file.getBaseName().split('-')
			if len(tokens) != 3:
				continue
			if tokens[0] == 'roll' and tokens[2] == 'kickstart':
				if tokens[2] in rolls:
					continue
				print '+ roll not enabled, removed %s' \
					% file.getName()
				os.unlink(file.getFullName())


		# Scan the updates for any .sh files and run these to update
		# the Frontend after the RPMs are installed.
		# Skip update scripts for Rolls that are not enabled.

		dir = url.split('//', 1)[1]
		for file in os.listdir(dir):
			if os.path.splitext(file)[1] != '.sh':
				continue
			tokens = file.split('-', 1)
			if tokens[0] == 'update':
				if not tokens[1] in rolls:
					print '+ roll not enabled, ignored %s' \
					      % file
					continue
			os.system('sh -x %s' % os.path.join(dir, file))
Beispiel #29
0
 def cleaner(self, path, file, root):
     if not root:
         root = self.dist.getReleasePath()
     dir = os.path.join(root, path)
     if dir not in [ self.dist.getForceRPMSPath() ]:
         os.unlink(os.path.join(dir, file.getName()))