コード例 #1
0
    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, ''))
コード例 #2
0
ファイル: __init__.py プロジェクト: rocksclusters/core
	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, ''))
コード例 #3
0
ファイル: __init__.py プロジェクト: ppapadopoulos/base
    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, ""))