Esempio n. 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()))
Esempio n. 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()))
Esempio n. 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()))
Esempio n. 4
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()))
Esempio n. 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 '\tusing %s' % rpm.getBaseName()
		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)
Esempio n. 6
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('\tinstalling %s' % rpm.getBaseName())
		self.applyRPM(rpm.getBaseName(), build)

	# Copy local profiles into the distribution.
	if self.withSiteProfiles:
		print('\tinstalling 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(0o664)
                                
	# Copy cart profiles into the distribution.
        for cart in self.carts:
		print('\tinstalling %s cart' % cart)
                tree = stack.file.Tree(os.path.join('/export/stack/carts',
                                                            cart))
                for file in tree.getFiles('graph'):
                        shutil.copy(file.getFullName(),
                        	os.path.join(build, 'graphs', 'default', file.getName()))
                        
                for file in tree.getFiles('nodes'):
                        shutil.copy(file.getFullName(),
                        	os.path.join(build, 'nodes', file.getName()))
Esempio n. 7
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 '\tinstalling %s' % rpm.getBaseName()
            self.applyRPM(rpm.getBaseName(), build)

        # Copy local profiles into the distribution.
        if self.withSiteProfiles:
            print '\tinstalling 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)

        # Copy cart profiles into the distribution.
        for cart in self.carts:
            print '\tinstalling %s cart' % cart
            tree = stack.file.Tree(os.path.join('/export/stack/carts', cart))
            for file in tree.getFiles('graph'):
                shutil.copy(
                    file.getFullName(),
                    os.path.join(build, 'graphs', 'default', file.getName()))

            for file in tree.getFiles('nodes'):
                shutil.copy(file.getFullName(),
                            os.path.join(build, 'nodes', file.getName()))
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
	def findFile(self, name):
		trees = self.filetree.keys()

		#
		# look in the local tree first
		#
		if 'local' in trees:
			tree = self.filetree['local']
			for d in tree.getDirs():
				for file in tree.getFiles(d):
					try:
						if file.getPackageName() == name:
							return file
					except:
						pass

					try:
						if file.getName() == name:
							return file
					except:
						pass
		for key in trees:
			if key == 'local':
				continue

			tree = self.filetree[key]
			for d in tree.getDirs():
				for file in tree.getFiles(d):
					try:
						if file.getPackageName() == name:
							return file
					except:
						pass

					try:
						if file.getName() == name:
							return file
					except:
						pass

		return None
Esempio n. 11
0
	def findFile(self, name):
		trees = self.filetree.keys()

		#
		# look in the local tree first
		#
		if 'local' in trees:
			tree = self.filetree['local']
			for d in tree.getDirs():
				for file in tree.getFiles(d):
					try:
						if file.getPackageName() == name:
							return file
					except:
						pass

					try:
						if file.getName() == name:
							return file
					except:
						pass
		for key in trees:
			if key == 'local':
				continue

			tree = self.filetree[key]
			for d in tree.getDirs():
				for file in tree.getFiles(d):
					try:
						if file.getPackageName() == name:
							return file
					except:
						pass

					try:
						if file.getName() == name:
							return file
					except:
						pass

		return None
Esempio n. 12
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)
	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)
Esempio n. 14
0
	def run(self):

		# Make a list of all the files that we need to copy onto the
		# pallets 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'))
		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 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 
				
			if self.config.getRollInterface() == '4.0':
				# old style
				root = os.path.join(name,
						    self.config.getRollName(),
						    self.config.getRollVersion(),
						    self.config.getRollArch())
				rpmsdir = os.path.join('RedHat', 'RPMS')
			else:
				root = os.path.join(name,
						    self.config.getRollName(),
						    self.config.getRollVersion(),
						    'redhat',
						    self.config.getRollArch())
				rpmsdir = 'RPMS'

			os.makedirs(root)
			os.makedirs(os.path.join(root, rpmsdir))
			
			# Symlink in all the RPMS
			
			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, rpmsdir,
							     file.getName()))
				if file in required:
					del required[required.index(file)]
					
			if len(required) == 0:
				optional = 1
				
			# Copy the pallet 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)
				
			# write repo data 
			self.writerepo()
			
			# make the ISO.  This code will change and move into
			# the base class, and supported bootable pallets.  Get
			# this working here and then test on the bootable
			# kernel pallet.
			
			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)
Esempio n. 15
0
    def run(self, hosts):

        pathSource = os.path.join(os.sep, 'export', 'stack', 'salt')
        self.pathCompiled = os.path.join(pathSource, 'compiled')
        attrs = {}
        for host in hosts['hosts']:
            attrs[host] = {}
            host_path = os.path.join(self.pathCompiled, host)
            if os.path.exists(host_path):
                shutil.rmtree(host_path)

        for row in self.owner.call('list.host.attr', hosts['hosts']):
            attrs[row['host']][row['attr']] = row['value']

        for host in hosts['hosts']:
            host_attrs = attrs[host]
            paths = [os.path.join(pathSource, 'default')]
            if 'environment' in host_attrs:
                paths.append(
                    os.path.join(pathSource, host_attrs['environment']))
            for path in paths:
                tree = stack.file.Tree(path)
                for dir in tree.getDirs():
                    for file in tree.getFiles(dir):
                        if not os.path.splitext(file.getName())[1] == '.xml':
                            continue
                        parser = make_parser()
                        handler = FileHandler(host_attrs)
                        parser.setContentHandler(handler)
                        parser.feed(handler.getXMLHeader())
                        parser.feed('<salt>')
                        fin = open(file.getFullName(), 'r')

                        # Parse as XML-ish to pickup the
                        # entities that correspond to host
                        # attributes.  But we assume the <file
                        # ...> and </file> tags start at col 0
                        # on a line by themselves.  Anything
                        # between the file tags is first
                        # sanitized for '<' and '&'
                        # (non-entity refs only).  This keep
                        # the file in XML-ish mode, and
                        # prevents the need for using CDATA.
                        # Node.xml files do not behave this
                        # we, so while a node.xml <file>
                        # section can move into this framework
                        # the reverse is not true (yet).

                        for line in fin.readlines():

                            if line.find('<file') == 0 or \
                             line.find('</file>') == 0:
                                s = line
                            else:
                                s = ''
                                for i in range(0, len(line)):
                                    if line[i] == '<':
                                        s += '&lt;'
                                    elif line[i] == '&':
                                        if not re.match(
                                                '&[A-Za-z_.][A-Za-z0-9_.]*;',
                                                line[i:]):
                                            s += '&amp;'
                                        else:
                                            s += line[i]
                                    else:
                                        s += line[i]
                            try:
                                parser.feed(s)
                            except:
                                print('Parsing Error file %s line %s' %
                                      (file.getFullName(), line))
                        parser.feed('</salt>')
                        fin.close()

                        for parsed in handler.getFiles():
                            if stack.cond.EvalCondExpr(parsed.get('cond'),
                                                       host_attrs):
                                self.writeSalt(host, parsed)
Esempio n. 16
0
	def getBaseFile(self, name):
		for file in self.getFiles('release',
					  os.path.join('RedHat', 'base')):
			if file.getName() == name:
				return file
		return None
Esempio n. 17
0
 def getBaseFile(self, name):
     for file in self.getFiles('release', os.path.join('RedHat', 'base')):
         if file.getName() == name:
             return file
     return None
Esempio n. 18
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()))
Esempio n. 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()))
Esempio n. 20
0
    def run(self):

        # Make a list of all the files that we need to copy onto the
        # pallets 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'))

        # 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 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), end=' ')
            if optional:
                print(' This disk is optional (extra rpms)')
            else:
                print()

            root = os.path.join(name, self.config.getRollName(),
                                self.config.getRollVersion(),
                                self.config.getRollRelease(),
                                self.config.getRollOS(),
                                self.config.getRollArch())

            rpmsdir = 'RPMS'

            os.makedirs(root)
            if self.config.getRollOS() in ['redhat', 'sles']:
                os.makedirs(os.path.join(root, rpmsdir))

            # Symlink in all the RPMS

            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, rpmsdir, file.getName()))
                if file in required:
                    del required[required.index(file)]

            if len(required) == 0:
                optional = 1

            # Copy the pallet 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)

            # write repodata
            if self.config.getRollOS() in ['redhat', 'sles']:
                self.writerepo(self.config.getRollName(),
                               self.config.getRollVersion(),
                               self.config.getRollRelease(),
                               self.config.getRollOS(),
                               self.config.getRollArch())

            # copy the graph and node XMLs files into the pallet
            self.copyXMLs(self.config.getRollOS(), self.config.getRollName(),
                          self.config.getRollVersion(),
                          self.config.getRollRelease(),
                          self.config.getRollArch())

            # make the ISO.	 This code will change and move into
            # the base class, and supported bootable pallets.  Get
            # this working here and then test on the bootable
            # kernel pallet.

            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:
                try:
                    self.makeBootable(self.config.getRollName(),
                                      self.config.getRollVersion(),
                                      self.config.getRollRelease(),
                                      self.config.getRollArch())
                except ValueError as msg:
                    print('ERROR -', msg)
                    print('Pallet is not bootable')
                    self.config.setBootable(False)

            self.mkisofs(isoname, self.config.getRollName(), name)