Add options to display a subset of delegations and return 2 if none are found.

452027
This commit is contained in:
Rob Crittenden authored and Rob Crittenden committed 2008-08-22 17:57:09 -04:00
1 parent 2846083979
commit c7ee747ee5
1 file changed
+30 -15
+30 -15
View File
@@ -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
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
return 0
if found:
return 0
else:
return 2
try:
if __name__ == "__main__":