예제 #1
0
파일: build.py 프로젝트: Sudoka/base
    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()))
예제 #2
0
파일: build.py 프로젝트: hocks/core
    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()))
예제 #3
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
예제 #4
0
파일: build.py 프로젝트: Sudoka/base
    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)
예제 #5
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
예제 #6
0
파일: build.py 프로젝트: hocks/core
    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)
예제 #7
0
파일: __init__.py 프로젝트: jeramirez/base
	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, ''))
예제 #8
0
파일: __init__.py 프로젝트: jeramirez/base
    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, ''))
예제 #9
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)
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
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()))
예제 #14
0
파일: build.py 프로젝트: hocks/core
    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)
예제 #15
0
파일: build.py 프로젝트: Sudoka/base
    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)
예제 #16
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()))
예제 #17
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))
예제 #18
0
파일: __init__.py 프로젝트: jeramirez/base
	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))
예제 #19
0
파일: __init__.py 프로젝트: jeramirez/base
    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))
예제 #20
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))
예제 #21
0
    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, ""))