additional sanity checking for the add-host-to-channel, remove-host-from-channel, and add-target cli commands (patch by Cristian Balint)

This commit is contained in:
Mike Bonnet 2007-06-19 19:19:20 -04:00
parent 1f39c90f5a
commit 2a982af119

View file

@ -463,17 +463,28 @@ def handle_add_host_to_channel(options, session, args):
usage = _("usage: %prog add-host-to-channel [options] hostname channel")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--list", action="store_true", help=_("List possible channels"))
(options, args) = parser.parse_args(args)
if len(args) != 2:
if not options.list and len(args) != 2:
parser.error(_("Please specify a hostname and a channel"))
assert False
host = args[0]
activate_session(session)
id = session.getHost(host)
if not id:
print "%s is not a host" % host
channels = dict([(p['name'], p['id']) for p in session.getAllChannels()])
if options.list:
for p in channels.keys():
print p
return
channel = args[1]
channel_id = channels.get(channel, None)
if not channel_id:
print "No such channel: %s" % channel
return 1
session.addHostToChannel(host, args[1])
host = args[0]
hostinfo = session.getHost(host)
if not hostinfo:
print "No such host: %s" % host
return 1
session.addHostToChannel(host, channel)
def handle_remove_host_from_channel(options, session, args):
"[admin] Remove a host from a channel"
@ -486,11 +497,19 @@ def handle_remove_host_from_channel(options, session, args):
assert False
host = args[0]
activate_session(session)
id = session.getHost(host)
if not id:
print "%s is not a host" % host
hostinfo = session.getHost(host)
if not hostinfo:
print "No such host: %s" % host
return 1
session.removeHostFromChannel(host, args[1])
hostchannels = dict([(p['name'], p['id']) for p in session.listChannels(hostinfo['id'])])
channel = args[1]
channel_id = hostchannels.get(channel, None)
if not channel_id:
print "Host %s is not a member of channel %s" % (host, channel)
return 1
session.removeHostFromChannel(host, channel)
def handle_add_pkg(options, session, args):
"[admin] Add a package to the listing for tag"
@ -1920,7 +1939,17 @@ def handle_add_target(options, session, args):
activate_session(session)
if not session.hasPerm('admin'):
print "This action requires admin privileges"
return
return 1
chkbuildtag = session.getTag(build_tag)
chkdesttag = session.getTag(dest_tag)
if not chkbuildtag:
print "Build tag does not exist: %s" % build_tag
return 1
if not chkdesttag:
print "Destination tag does not exist: %s" % dest_tag
return 1
session.createBuildTarget(name, build_tag, dest_tag)
def handle_edit_target(options, session, args):