Beispiel #1
0
	def getPackage(self, name, list):

		pkg = {}
		for file in list:
			if file.getBaseName() == name:
				arch = file.getPackageArch()
				if pkg.has_key(arch):
					# Already have a package for the arch, need to
					# decide which one to use.
					orig = pkg[arch]
					if file > orig:
						pkg[arch] = file
				else:
					pkg[arch] = file

		matches = []
		for key in pkg.keys():
			matches.append(pkg[key])

		
		if not matches:
			return None
		elif len(matches) == 1:
			return matches[0]
		else:
			raise DistRPMList(matches)
Beispiel #2
0
    def getPackage(self, name, list):

        pkg = {}
        for file in list:
            if file.getBaseName() == name:
                arch = file.getPackageArch()
                if pkg.has_key(arch):
                    # Already have a package for the arch, need to
                    # decide which one to use.
                    orig = pkg[arch]
                    if file > orig:
                        pkg[arch] = file
                else:
                    pkg[arch] = file

        matches = []
        for key in pkg.keys():
            matches.append(pkg[key])

        if not matches:
            return None
        elif len(matches) == 1:
            return matches[0]
        else:
            raise DistRPMList(matches)
	def run(self, args):

		(clean, prefix, treeinfo) = args

		name = None
		vers = None
		arch = None

		file = open(treeinfo, 'r')
		for line in file.readlines():
			a = line.split('=')

			if len(a) != 2:
				continue

			key = a[0].strip()
			value = a[1].strip()

			if key == 'family':
				if value == 'Red Hat Enterprise Linux':
					name = 'RHEL'
				elif value == 'CentOS':
					name = 'CentOS'
			elif key == 'version':
				vers = value
			elif key == 'arch':
				arch = value
		file.close()

		if not name:
			name = "BaseOS"
		if not vers:
			vers = stack.version
		if not arch:
			arch = 'x86_64'
			
		OS = 'redhat'
		roll_dir = os.path.join(prefix, name, vers, OS, arch)
		destdir = os.path.join(roll_dir, 'RPMS')

		if clean and os.path.exists(roll_dir):
			print 'Cleaning %s version %s ' % (name, vers),
			print 'for %s from pallets directory' % arch
			os.system('/bin/rm -rf %s' % roll_dir)
			os.makedirs(roll_dir)

		print 'Copying "%s" (%s,%s) pallet ...' % (name, vers, arch)
		if not os.path.exists(destdir):
			os.makedirs(destdir)

		cdtree = stack.file.Tree(self.owner.mountPoint)
		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 not (arch == 'i386' and \
					re.match('^kudzu.*', file.getBaseName())):
						os.system('cp -p %s %s' % (
							file.getFullName(), 
							destdir))
		#
		# lay down a minimal roll XML config file
		#
		f = open('%s' % os.path.join(roll_dir, 'roll-%s.xml' % name),
			'w')
		f.write('<roll name="%s" interface="6.0.2">\n' % name)
		f.write('<info version="%s" release="%s" arch="%s" os="%s"/>\n' % (vers, stack.release, arch, OS))
		f.write('<iso maxsize="0" bootable="0"/>\n')
		f.write('</roll>\n')
		f.close()

		return (name, vers, arch)
Beispiel #4
0
	def run(self, params, args):

		(dryrun, ) = self.fillParams([ ('dryrun', 'true')])
		
                dryrun = self.str2bool(dryrun)
                
		script = []
		script.append('#!/bin/sh')

		rolls = []
		for roll in args:
			rolls.append(roll)
		if sys.stdin.isatty():
			xml = self.command('list.host.xml', [ 'localhost', 
				'pallet=%s' % string.join(rolls, ',') ])
		else:
			xml = sys.stdin.read()
		reader = Sax2.Reader()
		gen = getattr(stack.gen,'Generator_%s' % self.os)()
		gen.parse(xml)

		distPath = os.path.join(self.command('report.distribution')[:-1],
			'default')
                tree = stack.file.Tree(distPath)
		rpm_list = {}
		for file in tree.getFiles(os.path.join(self.arch, 
			'RedHat', 'RPMS')):
			if isinstance(file, stack.file.RPMFile):
				rpm_list[file.getBaseName()] = \
					file.getFullName()
				rpm_list["%s.%s" % (file.getBaseName(), \
					file.getPackageArch())] = \
						file.getFullName()
			
		rpms = []
		for line in gen.generate('packages'):
			if line.find('%package') == -1 and line.find('%end') == -1:
				rpms.append(line)
		for rpm in rpms:
			if rpm in rpm_list.keys():
				script.append('yum install -y %s' %
					rpm)
				script.append(rpm_force_template %
					rpm_list[rpm])


		cur_proc = False
		for line in gen.generate('post'):
			if not line.startswith('%post') and not line.startswith('%end'):
				script.append(line)
			else:
				if cur_proc == True:
					script.append('__POSTEOF__')
					script.append('%s %s' % (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__"' %
					t_name)
		
		script.append('\n# Boot scripts\n')
		for line in gen.generate('boot'):
			#
			# skip lines that start with '%post' or '%end'
			#
			if line[0:5] == '%post' or line[0:4] == '%end':
				continue

			script.append(line)

		if dryrun:
			self.addText(string.join(script, '\n'))
		else:
			os.system(string.join(script, '\n'))
Beispiel #5
0
    def run(self, params, args):

        (dryrun, ) = self.fillParams([('dryrun', 'true')])

        dryrun = self.str2bool(dryrun)

        script = []
        script.append('#!/bin/sh')

        rolls = []
        for roll in args:
            rolls.append(roll)
        if sys.stdin.isatty():
            xml = self.command(
                'list.host.xml',
                ['localhost',
                 'pallet=%s' % string.join(rolls, ',')])
        else:
            xml = sys.stdin.read()
        reader = Sax2.Reader()
        gen = getattr(stack.gen, 'Generator_%s' % self.os)()
        gen.parse(xml)

        distPath = os.path.join(
            self.command('report.distribution')[:-1], 'default')
        tree = stack.file.Tree(distPath)
        rpm_list = {}
        for file in tree.getFiles(os.path.join(self.arch, 'RedHat', 'RPMS')):
            if isinstance(file, stack.file.RPMFile):
                rpm_list[file.getBaseName()] = \
                 file.getFullName()
                rpm_list["%s.%s" % (file.getBaseName(), \
                 file.getPackageArch())] = \
                  file.getFullName()

        rpms = []
        for line in gen.generate('packages'):
            if line.find('%package') == -1 and line.find('%end') == -1:
                rpms.append(line)
        for rpm in rpms:
            if rpm in rpm_list.keys():
                script.append('yum install -y %s' % rpm)
                script.append(rpm_force_template % rpm_list[rpm])

        cur_proc = False
        for line in gen.generate('post'):
            if not line.startswith('%post') and not line.startswith('%end'):
                script.append(line)
            else:
                if cur_proc == True:
                    script.append('__POSTEOF__')
                    script.append('%s %s' % (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__"' % t_name)

        script.append('\n# Boot scripts\n')
        for line in gen.generate('boot'):
            #
            # skip lines that start with '%post' or '%end'
            #
            if line[0:5] == '%post' or line[0:4] == '%end':
                continue

            script.append(line)

        if dryrun:
            self.addText(string.join(script, '\n'))
        else:
            os.system(string.join(script, '\n'))
Beispiel #6
0
	def run(self, args):
		import stack

		(clean, prefix, treeinfo) = args

		name = None
		vers = None
		arch = None

		file = open(treeinfo, 'r')
		for line in file.readlines():
			a = line.split('=')

			if len(a) != 2:
				continue

			key = a[0].strip()
			value = a[1].strip()

			if key == 'family':
				if value == 'Red Hat Enterprise Linux':
					name = 'RHEL'
				elif value == 'CentOS':
					name = 'CentOS'
			elif key == 'version':
				vers = value
			elif key == 'arch':
				arch = value
		file.close()

		if not name:
			name = "BaseOS"
		if not vers:
			vers = stack.version
		if not arch:
			arch = 'x86_64'
			
		OS = 'redhat'
		roll_dir = os.path.join(prefix, name, vers, OS, arch)
		destdir = os.path.join(roll_dir, 'RPMS')

		print 'stack.release (%s)' % stack.release
		if stack.release == '7.x':
			liveosdir = os.path.join(roll_dir, 'LiveOS')

		if clean and os.path.exists(roll_dir):
			print 'Cleaning %s version %s ' % (name, vers),
			print 'for %s from pallets directory' % arch
			os.system('/bin/rm -rf %s' % roll_dir)
			os.makedirs(roll_dir)

		print 'Copying "%s" (%s,%s) pallet ...' % (name, vers, arch)
		if not os.path.exists(destdir):
			os.makedirs(destdir)

		if stack.release == '7.x' and not os.path.exists(liveosdir):
			os.makedirs(liveosdir)

		cdtree = stack.file.Tree(self.owner.mountPoint)
		for dir in cdtree.getDirs():
			for file in cdtree.getFiles(dir):
				if stack.release == '7.x' and dir == 'LiveOS' \
					and file.getName().endswith('.img'):

					os.system('cp -p %s %s' % (
						file.getFullName(), 
						liveosdir))
				else:
					if not file.getName().endswith('.rpm'):
						continue
					if file.getPackageArch() != 'src' and \
						file.getBaseName() != 'comps' and \
						file.getName() != 'comps.rpm' \
						and not (arch == 'i386' and \
						re.match('^kudzu.*', file.getBaseName())):
							os.system('cp -p %s %s' % (
								file.getFullName(), 
								destdir))
		#
		# lay down a minimal roll XML config file
		#
		f = open('%s' % os.path.join(roll_dir, 'roll-%s.xml' % name),
			'w')
		f.write('<roll name="%s" interface="6.0.2">\n' % name)
		f.write('<info version="%s" release="%s" arch="%s" os="%s"/>\n' % (vers, stack.release, arch, OS))
		f.write('<iso maxsize="0" bootable="0"/>\n')
		f.write('</roll>\n')
		f.close()

		return (name, vers, arch)