Esempio n. 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, ''))
Esempio n. 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, ''))
Esempio n. 3
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, ""))
Esempio n. 4
0
    def run(self, params, args):

        anacondaKickstart = '/root/anaconda-ks.cfg'
        postinstallXml = '/root/postinstall.xml'

        (args, file) = self.fillPositionalArgs(('file', ))

        if not file:
            self.abort('missing kcikstartfile')
        try:
            kickstartFile = open(file)
        except IOError:
            self.abort("Unable to open kickstart file %s." % file)

        for line in kickstartFile:
            if line.startswith("%packages"):
                break
        #now we start with the packages
        packages = []
        for line in kickstartFile:
            if len(line.strip()) == 0:
                pass
            elif line.startswith("%"):
                break
            else:
                packages.append(line.strip())

        #
        # get current installed rpms list
        #
        (installedRpms, ret) = getOutputAsList('rpm -qa', None)
        #plz no rocks-grub
        excludeRpm = ['rocks-boot-auto']
        installedRpms = installedRpms + excludeRpm
        print " - postinstall - Download RPMs..."
        cmd = ['yumdownloader', '--resolve', '--destdir', '/mnt/temp', \
                                      '--exclude=' + string.join(installedRpms, ',')] + packages
        cmd = string.join(cmd, " ")
        print " - execuing: ", cmd
        getOutputAsList(cmd, None)
        print " - postinstall - Installing downloaded RPMs..."
        getOutputAsList('rpm --force --nodeps -ih /mnt/temp/*.rpm', None)

        #
        # executing the postsection
        # first generate the xml kickstart with only the necessary postsections
        #
        # grub and grub-client  -> avoid messing ec2 grub menu
        # hpc-client            -> MaxStartups messes up the sshd.config
        # ntp-client, resolve, syslog,routes	-> private ip addresses
        excludedPackage = [
            './nodes/grub.xml', './nodes/grub-client.xml',
            './nodes/client-firewall.xml', './nodes/ntp-client.xml',
            './nodes/partitions-save.xml', './nodes/resolv.xml',
            './nodes/routes-client.xml', './nodes/syslog-client.xml',
            './nodes/hpc-client.xml'
        ]
        #get already run nodes
        cmd = "grep 'begin post section' " + anacondaKickstart + " | awk -F ':' '{print $1}' | sort -u "
        (nodesRunned, ret) = getOutputAsList(cmd, None)
        if ret != 0:
            self.abort("unable to get the list of executed nodes.")
        #get nodes to be executed
        cmd = """grep '<post' """ + postinstallXml + """ | awk -F 'file=' '{print $2}' |sort -u |awk -F '"' '{print $2}'"""
        (nodesNewKickstart, ret) = getOutputAsList(cmd, None)
        if ret != 0:
            self.abort("unable to get the list of nodes to be executed.")
        #make the diff
        nodesTobeRun = []
        for node in nodesNewKickstart:
            if node in excludedPackage:
                continue
            if node in nodesRunned:
                continue
            nodesTobeRun.append(node)
        print "List of nodes that will be executed: ", nodesTobeRun
        tree = xml.etree.ElementTree.parse(postinstallXml)
        root = tree.getroot()
        for node in root.findall("post"):
            if "file" in node.attrib and node.attrib["file"] in nodesTobeRun:
                #let's keep this node we need to execute it
                pass
            else:
                root.remove(node)
        #save this for debugging
        tree.write("/tmp/tempKickstart.xml")
        print "xml kickstart saved in /tmp/tempKickstart.xml"
        buffer = StringIO.StringIO()
        tree.write(buffer)
        buffer.seek(0)

        #
        # now that we have the xml kickstart let's generate the script
        #
        script = []
        script.append('#!/bin/sh\n')
        reader = Sax2.Reader()
        gen = getattr(rocks.gen, 'Generator_%s' % self.os)()
        gen.setOS(self.os)
        gen.parse(buffer.getvalue())
        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)

        #keep this for debuging
        fd = open("/tmp/kickstart.sh", 'w')
        fd.write(string.join(script, ''))
        fd.close()
        print "shell kickstart saved in /tmp/tempKickstart.xml, executing it..."
        os.system(string.join(script, ''))