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, ''))
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, ''))
def run(self, params, args): (clear, showattr) = \ self.fillParams([ ('clear', 'n'), ('showattr', 'n') ]) hostname = self.newdb.getCategoryAttr('global', 'global', 'Kickstart_PrivateHostname_old') if not hostname or not self.isValidHostname(hostname): # Kickstart_PrivateHostname did not get changed # so we can use the original value hostname = self.newdb.getCategoryAttr('global', 'global', 'Kickstart_PrivateHostname') if not hostname: self.abort("unable to get the value of Kickstart_PrivateHostname") if not self.isValidHostname(hostname): self.abort("The value of your Kickstart_PrivateHostname is invalid (%s)" % hostname) # # show which attr will be modified # if self.str2bool(showattr) : current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) self.addText("User modified attributes\n") self.beginOutput() for name in attrs: self.addOutput("", (name, current_attr[name + "_old"], attrs[name])) if additional_attr : self.addOutput("", (" ", " ", " ")) self.addOutput("", ("Additional attributes", " ", " ")) for name in additional_attr: self.addOutput("", (name, current_attr[name], additional_attr[name])) self.endOutput(header=['host', 'attr', 'old value ->', 'new value']) return # # clear attributes historical values # if self.str2bool(clear) : current_attr = self.db.getHostAttrs(hostname, 1) for name in current_attr: if name.endswith("_old"): # we need to delete this one if current_attr[name][1] == 'H': command = 'remove.host.attr' elif current_attr[name][1] == 'G': command = 'remove.attr' elif current_attr[name][1] == 'A': command = 'remove.appliance.attr' elif current_attr[name][1] == 'O': command = 'remove.os.attr' self.command(command, [name]) return # # really run the script # # first fix the missing attribute current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) for name in additional_attr: if name == 'dhcp_nextserver': # this is an appliance attribute it needs special care s = self.newdb.getSession() apps = s.query(sqlalchemy.distinct(Catindex.name))\ .join(Catindex.attributes)\ .join(Attribute.category)\ .filter(Attribute.attr == "dhcp_nextserver", \ Category.name == 'appliance')\ .all() for app_name in apps: self.command('set.appliance.attr', [app_name[0], name, additional_attr[name]]) else: self.command('set.attr', [name, additional_attr[name]]) # apparently session and connection view two different state of the database # hence to see the changes above a commit on the sessions will not be enough # (i tried commit, flush, and close_all) the connection will see the old # values in the DB # # So only closing the connection will fix this self.newdb.close() self.newdb.connect() rolls = [] for roll in args: rolls.append(roll) xml = self.command('list.host.xml', [ hostname, 'roll=%s' % string.join(rolls, ',') ]) if self.os != 'linux': self.abort('it runs only on linux!!') gen = rocks.gen.Generator_linux() # set reconfigure stage gen.set_phases(["reconfigure"]) gen.parse(xml) script = [] script.append('#!/bin/sh\n') script += gen.generate_config_script() self.addText(string.join(script, ''))
def run(self, params, args): (clear, showattr) = \ self.fillParams([ ('clear', 'n'), ('showattr', 'n') ]) hostname = self.newdb.getCategoryAttr('global', 'global', 'Kickstart_PrivateHostname_old') if not hostname or not self.isValidHostname(hostname): # Kickstart_PrivateHostname did not get changed # so we can use the original value hostname = self.newdb.getCategoryAttr('global', 'global', 'Kickstart_PrivateHostname') if not hostname: self.abort( "unable to get the value of Kickstart_PrivateHostname") if not self.isValidHostname(hostname): self.abort( "The value of your Kickstart_PrivateHostname is invalid (%s)" % hostname) # # show which attr will be modified # if self.str2bool(showattr): current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) self.addText("User modified attributes\n") self.beginOutput() for name in attrs: self.addOutput( "", (name, current_attr[name + "_old"], attrs[name])) if additional_attr: self.addOutput("", (" ", " ", " ")) self.addOutput("", ("Additional attributes", " ", " ")) for name in additional_attr: self.addOutput( "", (name, current_attr[name], additional_attr[name])) self.endOutput( header=['host', 'attr', 'old value ->', 'new value']) return # # clear attributes historical values # if self.str2bool(clear): current_attr = self.db.getHostAttrs(hostname, 1) for name in current_attr: if name.endswith("_old"): # we need to delete this one if current_attr[name][1] == 'H': command = 'remove.host.attr' elif current_attr[name][1] == 'G': command = 'remove.attr' elif current_attr[name][1] == 'A': command = 'remove.appliance.attr' elif current_attr[name][1] == 'O': command = 'remove.os.attr' self.command(command, [name]) return # # really run the script # # first fix the missing attribute current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) for name in additional_attr: if name == 'dhcp_nextserver': # this is an appliance attribute it needs special care s = self.newdb.getSession() apps = s.query(sqlalchemy.distinct(Catindex.name))\ .join(Catindex.attributes)\ .join(Attribute.category)\ .filter(Attribute.attr == "dhcp_nextserver", \ Category.name == 'appliance')\ .all() for app_name in apps: self.command('set.appliance.attr', [app_name[0], name, additional_attr[name]]) else: self.command('set.attr', [name, additional_attr[name]]) # apparently session and connection view two different state of the database # hence to see the changes above a commit on the sessions will not be enough # (i tried commit, flush, and close_all) the connection will see the old # values in the DB # # So only closing the connection will fix this self.newdb.close() self.newdb.connect() rolls = [] for roll in args: rolls.append(roll) xml = self.command( 'list.host.xml', [hostname, 'roll=%s' % string.join(rolls, ',')]) if self.os != 'linux': self.abort('it runs only on linux!!') gen = rocks.gen.Generator_linux() # set reconfigure stage gen.set_phases(["reconfigure"]) gen.parse(xml) script = [] script.append('#!/bin/sh\n') script += gen.generate_config_script() self.addText(string.join(script, ''))
def run(self, params, args): (clear, showattr) = self.fillParams([("clear", "n"), ("showattr", "n")]) hostname = "localhost" # # show which attr will be modified # if self.str2bool(showattr): current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) self.addText("User modified attributes\n") self.beginOutput() for name in attrs: self.addOutput("", (name, current_attr[name + "_old"], attrs[name])) if additional_attr: self.addOutput("", (" ", " ", " ")) self.addOutput("", ("Additional attributes", " ", " ")) for name in additional_attr: self.addOutput("", (name, current_attr[name], additional_attr[name])) self.endOutput(header=["host", "attr", "old value ->", "new value"]) return # # clear attributes historical values # if self.str2bool(clear): current_attr = self.db.getHostAttrs(hostname, 1) for name in current_attr: if name.endswith("_old"): # we need to delete this one if current_attr[name][1] == "H": command = "remove.host.attr" elif current_attr[name][1] == "G": command = "remove.attr" elif current_attr[name][1] == "A": command = "remove.appliance.attr" elif current_attr[name][1] == "O": command = "remove.os.attr" self.command(command, [name]) return # # really run the script # # first fix the missing attribute current_attr = self.db.getHostAttrs(hostname) attrs = self.get_modified_attr(hostname, current_attr) additional_attr = get_additional_attr(attrs, current_attr) for name in additional_attr: if name == "dhcp_nextserver": # this is an appliance attribute it needs special care rows = self.db.execute( '''select name from appliance_attributes, appliances where Appliance = id and Attr = "dhcp_nextserver"''' ) for (app_name,) in self.db.fetchall(): self.command("set.appliance.attr", [app_name, name, additional_attr[name]]) else: self.command("set.attr", [name, additional_attr[name]]) rolls = [] for roll in args: rolls.append(roll) xml = self.command("list.host.xml", [hostname, "roll=%s" % string.join(rolls, ",")]) if self.os != "linux": self.abort("it runs only on linux!!") gen = rocks.gen.Generator_linux() # set reconfigure stage gen.set_phases(["reconfigure"]) gen.parse(xml) script = [] script.append("#!/bin/sh\n") script += gen.generate_config_script() self.addText(string.join(script, ""))