Example #1
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')
        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, ''))
Example #2
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')
		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, ''))
Example #3
0
    def getPackage(self, name, list):
        matches = []
        for file in list:
            if file.getBaseName() == name:
                matches.append(file)

        if not matches:
            return None
        elif len(matches) == 1:
            return matches[0]
        else:
            raise DistRPMList(matches)
Example #4
0
	def getPackage(self, name, list):
		matches = []
		for file in list:
			if file.getBaseName() == name:
				matches.append(file)
		
		if not matches:
			return None
		elif len(matches) == 1:
			return matches[0]
		else:
			raise DistRPMList(matches)
Example #5
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))
Example #6
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))
Example #7
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, ""))
Example #8
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))
Example #9
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))