From 32800a792b721d1bbe0d54b9a282e76419a4a037 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 30 May 2008 10:19:08 -0400 Subject: Add two now options, --addattr and --setattr, to allow arbitrary attributes to be added and set when a new user or group is created. Make the user password not mandatory and add new option, -P, to prompt for a password interactively. 449006 --- ipa-admintools/ipa-addgroup | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'ipa-admintools/ipa-addgroup') diff --git a/ipa-admintools/ipa-addgroup b/ipa-admintools/ipa-addgroup index fea84287..89f76300 100644 --- a/ipa-admintools/ipa-addgroup +++ b/ipa-admintools/ipa-addgroup @@ -43,9 +43,12 @@ error was: sys.exit(1) def usage(): - print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] [-v|--verbose] group" + print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] [--addattr attribute=value] [--setattr attribute=value] [-v|--verbose] group" sys.exit(1) +def set_add_usage(which): + print "%s option usage: --%s NAME=VALUE" % (which, which) + def parse_options(): parser = OptionParser() parser.add_option("-d", "--description", dest="desc", @@ -54,6 +57,12 @@ def parse_options(): help="The gid to use for this group. If not included one is automatically set.") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Verbose output of the XML-RPC connection") + parser.add_option("--addattr", dest="addattr", + help="Adds an attribute or values to that attribute, attr=value", + action="append") + parser.add_option("--setattr", dest="setattr", + help="Set an attribute, dropping any existing values that may exist", + action="append") parser.add_option("--usage", action="store_true", help="Program usage") @@ -107,6 +116,29 @@ def main(): group.setValue('cn', cn) group.setValue('description', desc) + if options.setattr: + for s in options.setattr: + s = s.split('=') + if len(s) != 2: + set_add_usage("set") + sys.exit(1) + (attr,value) = s + group.setValue(attr, value) + + if options.addattr: + for a in options.addattr: + a = a.split('=') + if len(a) != 2: + set_add_usage("add") + sys.exit(1) + (attr,value) = a + cvalue = group.getValue(attr) + if cvalue: + if isinstance(cvalue,str): + cvalue = [cvalue] + value = cvalue + [value] + group.setValue(attr, value) + client = ipaclient.IPAClient(verbose=options.verbose) client.add_group(group) print cn + " successfully added" -- cgit