- add the description and comment fields to the host table

- add the edit-host CLI command to allow editing of the arches, capacity, description, and comment fields of a host
 - add the --comment option to the enable-host and disable-host commands, to allow specifying a reason for changing the state of a host
 - display the description and comment on the hostinfo page
This commit is contained in:
Mike Bonnet 2010-03-10 16:40:28 -05:00
parent 98ae624480
commit e71519d5d1
6 changed files with 102 additions and 8 deletions

View file

@ -492,6 +492,48 @@ def handle_add_host(options, session, args):
if id:
print "%s added: id %d" % (host, id)
def handle_edit_host(options, session, args):
"[admin] Edit a host"
usage = _("usage: %prog edit-host hostname ... [options]")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--arches", help=_("Space-separated list of supported architectures"))
parser.add_option("--capacity", type="float", help=_("Capacity of this host"))
parser.add_option("--description", metavar="DESC", help=_("Description of this host"))
parser.add_option("--comment", help=_("A brief comment about this host"))
(subopts, args) = parser.parse_args(args)
if not args:
parser.error(_("Please specify a hostname"))
activate_session(session)
vals = {}
for key, val in subopts.__dict__.items():
if val is not None:
vals[key] = val
session.multicall = True
for host in args:
session.getHost(host)
error = False
for host, [info] in zip(args, session.multiCall(strict=True)):
if not info:
print _("Host %s does not exist") % host
error = True
if error:
print _("No changes made, please correct the command line")
return 1
session.multicall = True
for host in args:
session.editHost(host, **vals)
for host, [result] in zip(args, session.multiCall(strict=True)):
if result:
print _("Edited %s") % host
else:
print _("No changes made to %s") % host
def handle_add_host_to_channel(options, session, args):
"[admin] Add a host to a channel"
usage = _("usage: %prog add-host-to-channel [options] hostname channel")
@ -949,6 +991,7 @@ def handle_disable_host(options, session, args):
usage = _("usage: %prog disable-host [options] hostname ...")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--comment", help=_("Comment indicating why the host(s) are being disabled"))
(options, args) = parser.parse_args(args)
activate_session(session)
@ -966,6 +1009,8 @@ def handle_disable_host(options, session, args):
session.multicall = True
for host in args:
session.disableHost(host)
if options.comment:
session.editHost(host, comment=options.comment)
session.multiCall(strict=True)
def handle_enable_host(options, session, args):
@ -973,6 +1018,7 @@ def handle_enable_host(options, session, args):
usage = _("usage: %prog enable-host [options] hostname ...")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--comment", help=_("Comment indicating why the host(s) are being enabled"))
(options, args) = parser.parse_args(args)
activate_session(session)
@ -990,6 +1036,8 @@ def handle_enable_host(options, session, args):
session.multicall = True
for host in args:
session.enableHost(host)
if options.comment:
session.editHost(host, comment=options.comment)
session.multiCall(strict=True)
def handle_import(options, session, args):

View file

@ -0,0 +1,5 @@
-- upgrade script to migrate the Koji database schema
-- from version 1.3 to 1.4
ALTER TABLE host ADD COLUMN description TEXT;
ALTER TABLE host ADD COLUMN comment TEXT;

View file

@ -182,6 +182,8 @@ CREATE TABLE host (
arches TEXT,
task_load FLOAT CHECK (NOT task_load < 0) NOT NULL DEFAULT 0.0,
capacity FLOAT CHECK (capacity > 1) NOT NULL DEFAULT 2.0,
description TEXT,
comment TEXT,
ready BOOLEAN NOT NULL DEFAULT 'false',
enabled BOOLEAN NOT NULL DEFAULT 'true'
) WITHOUT OIDS;

View file

@ -3011,11 +3011,13 @@ def get_host(hostInfo, strict=False):
- arches
- task_load
- capacity
- description
- comment
- ready
- enabled
"""
fields = ('id', 'user_id', 'name', 'arches', 'task_load',
'capacity', 'ready', 'enabled')
'capacity', 'description', 'comment', 'ready', 'enabled')
query = """SELECT %s FROM host
WHERE """ % ', '.join(fields)
if isinstance(hostInfo, int) or isinstance(hostInfo, long):
@ -3027,6 +3029,42 @@ def get_host(hostInfo, strict=False):
return _singleRow(query, locals(), fields, strict)
def edit_host(hostInfo, **kw):
"""Edit information for an existing host.
hostInfo specifies the host to edit, either as an integer (id)
or a string (name).
fields to be changed are specified as keyword parameters:
- arches
- capacity
- description
- comment
Returns True if changes are made to the database, False otherwise.
"""
context.session.assertPerm('admin')
host = get_host(hostInfo, strict=True)
fields = ('arches', 'capacity', 'description', 'comment')
changes = []
for field in fields:
if field in kw and kw[field] != host[field]:
changed = True
if field == 'capacity':
# capacity is a float, so set the substitution format appropriately
changes.append('%s = %%(%s)f' % (field, field))
else:
changes.append('%s = %%(%s)s' % (field, field))
if not changes:
return False
update = 'UPDATE host set ' + ', '.join(changes) + ' where id = %(id)i'
data = kw.copy()
data['id'] = host['id']
_dml(update, data)
return True
def get_channel(channelInfo, strict=False):
"""Return information about a channel."""
fields = ('id', 'name')
@ -6560,6 +6598,7 @@ class RootExports(object):
set_host_enabled(hostname, False)
getHost = staticmethod(get_host)
editHost = staticmethod(edit_host)
addHostToChannel = staticmethod(add_host_to_channel)
removeHostFromChannel = staticmethod(remove_host_from_channel)

View file

@ -20,6 +20,12 @@
<tr>
<th>Task Load</th><td><a href="tasks?hostID=$host.id">#echo '%.2f' % $host.task_load#</a></td>
</tr>
<tr>
<th>Description</th><td class="usertext">$util.escapeHTML($host.description)</td>
</tr>
<tr>
<th>Comment</th><td class="usertext">$util.escapeHTML($host.comment)</td>
</tr>
<tr>
#set $enabled = $host.enabled and 'yes' or 'no'
<th>Enabled?</th>

View file

@ -418,7 +418,7 @@ abbr {
cursor: help;
}
.changelog {
.changelog, .rpmheader, .usertext {
font-family: monospace;
font-size: medium;
white-space: pre;
@ -443,12 +443,6 @@ span#loginInfo {
font-size: smaller;
}
.rpmheader {
font-family: monospace;
font-size: medium;
white-space: pre;
}
.error {
color: red;
}