From c7ee747ee50dcf14f3de670bb85e2225fc5d3ac8 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 21 Aug 2008 16:56:01 -0400 Subject: Add options to display a subset of delegations and return 2 if none are found. 452027 --- ipa-admintools/ipa-listdelegation | 47 ++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/ipa-admintools/ipa-listdelegation b/ipa-admintools/ipa-listdelegation index 50e80c66..5e0b848d 100644 --- a/ipa-admintools/ipa-listdelegation +++ b/ipa-admintools/ipa-listdelegation @@ -7,7 +7,7 @@ # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 2 only -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# +# import sys try: from optparse import OptionParser @@ -42,12 +42,15 @@ error was: sys.exit(1) aci_fields = ['*', 'aci'] -def usage(): - print "ipa-listdelgation [-v|--verbose]" - sys.exit(1) def parse_options(): parser = OptionParser() + parser.add_option("-s", "--source", dest="source", + help="Source group of delegation") + parser.add_option("-n", "--name", dest="name", + help="Name of delegation") + parser.add_option("-t", "--target", dest="target", + help="Target group of delegation") parser.add_option("--usage", action="store_true", help="Program usage") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", @@ -56,14 +59,18 @@ def parse_options(): args = ipa.config.init_config(sys.argv) options, args = parser.parse_args(args) + if options.usage or len(args) != 1: + parser.error("too many arguments") + return options, args def main(): options, args = parse_options() - if options.usage: - usage() + all = True + if options.name or options.source or options.target: + all = False client = ipaclient.IPAClient(verbose=options.verbose) aci_entry = client.get_aci_entry(aci_fields) @@ -85,18 +92,26 @@ def main(): group_dn_to_cn = ipa.aci.extract_group_cns(aci_list, client) + found = False # the operator.itemgetter(0) lets us sort by the name field for a in sorted(aci_list, key=operator.itemgetter(0)): labels = client.attrs_to_labels(a.attrs) - print "Delegation Name: " + a.name - print "Group " + group_dn_to_cn[a.source_group] - print " can modify these attributes: " - for l in labels: - print "\t" + labels[l] - print " for group " + group_dn_to_cn[a.dest_group] - print - - return 0 + if (all or options.name == a.name or + options.source == group_dn_to_cn[a.source_group] or + options.target == group_dn_to_cn[a.dest_group]): + print "Delegation Name: " + a.name + print "Group " + group_dn_to_cn[a.source_group] + print " can modify these attributes: " + for l in labels: + print "\t" + labels[l] + print " for group " + group_dn_to_cn[a.dest_group] + print + found = True + + if found: + return 0 + else: + return 2 try: if __name__ == "__main__": -- cgit