remove_channel command

This commit is contained in:
Mike McLean 2010-07-15 12:49:47 -04:00
parent 4f77e08b3f
commit 054e5cb5fb
2 changed files with 42 additions and 0 deletions

View file

@ -617,6 +617,23 @@ def handle_remove_host_from_channel(options, session, args):
session.removeHostFromChannel(host, channel)
def handle_remove_channel(options, session, args):
"[admin] Remove a channel entirely"
usage = _("usage: %prog remove-channel [options] channel")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--force", action="store_true", help=_("force removal, if possible"))
(options, args) = parser.parse_args(args)
if len(args) != 1:
parser.error(_("Incorrect number of arguments"))
assert False
activate_session(session)
cinfo = session.getChannel(args[0])
if not cinfo:
print "No such channel: %s" % args[0]
return 1
session.removeChannel(args[0], force=options.force)
def handle_rename_channel(options, session, args):
"[admin] Rename a channel"
usage = _("usage: %prog rename-channel [options] old-name new-name")

View file

@ -1884,6 +1884,30 @@ def rename_channel(old, new):
update.set(name=new)
update.execute()
def remove_channel(channel_name, force=False):
"""Remove a channel
Channel must have no hosts, unless force is set to True
If a channel has associated tasks, it cannot be removed
"""
context.session.assertPerm('admin')
channel_id = get_channel_id(channel_name, strict=True)
# check for task references
query = QueryProcessor(tables=['task'], clauses=['channel_id=%(channel_id)i'],
values=locals(), columns=['id'], opts={'limit':1})
#XXX slow query
if query.execute():
raise koji.GenericError, 'channel %s has task references' % channel_name
query = QueryProcessor(tables=['host_channels'], clauses=['channel_id=%(channel_id)i'],
values=locals(), columns=['host_id'], opts={'limit':1})
if query.execute():
if not force:
raise koji.GenericError, 'channel %s has host references' % channel_name
delete = """DELETE FROM host_channels WHERE channel_id=%(channel_id)i"""
_dml(delete, locals())
delete = """DELETE FROM channels WHERE id=%(channel_id)i"""
_dml(delete, locals())
def get_ready_hosts():
"""Return information about hosts that are ready to build.
@ -7734,6 +7758,7 @@ class RootExports(object):
addHostToChannel = staticmethod(add_host_to_channel)
removeHostFromChannel = staticmethod(remove_host_from_channel)
renameChannel = staticmethod(rename_channel)
removeChannel = staticmethod(remove_channel)
def listHosts(self, arches=None, channelID=None, ready=None, enabled=None, userID=None, queryOpts=None):
"""Get a list of hosts. "arches" is a list of string architecture