set_verbosity()
return params
+def do_get_id(i):
+ if i == "":
+ raise AFSArgumentError("UID/GID identifier is empty string")
+ if not i.isnumeric() and (i[0] != "-" or not i[1:].isnumeric()):
+ raise AFSArgumentError("UID/GID identifier is not numeric")
+ return int(i)
+
+def get_id(switch, params):
+ return do_get_id(params[0])
+
+def get_ids(switch, params):
+ ids = []
+ for i in params:
+ ids.append(do_get_id(i))
+ return ids
+
+def do_get_uid(i):
+ if i == "":
+ raise AFSArgumentError("UID identifier is empty string")
+ if not i.isnumeric():
+ raise AFSArgumentError("UID identifier is a positive integer")
+ return int(i)
+
+def get_uid(switch, params):
+ return do_get_uid(params[0])
+
+def get_uids(switch, params):
+ ids = []
+ for i in params:
+ ids.append(do_get_uid(i))
+ return ids
+
+def do_get_gid(i):
+ if i == "":
+ raise AFSArgumentError("GID identifier is empty string")
+ if i[0] != "-" or not i[1:].isnumeric():
+ raise AFSArgumentError("GID identifier is a positive integer")
+ return int(i)
+
+def get_gid(switch, params):
+ return do_get_gid(params[0])
+
+def get_gids(switch, params):
+ ids = []
+ for i in params:
+ ids.append(do_get_gid(i))
+ return ids
+
###############################################################################
#
# Parse an argument list according to a defined set of switches.
--- /dev/null
+#
+# AFS Server management toolkit: Create groups
+# -*- coding: utf-8 -*-
+#
+
+__copyright__ = """
+Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
+Written by David Howells (dhowells@redhat.com)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public Licence version 2 as
+published by the Free Software Foundation.
+
+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
+GNU General Public Licence for more details.
+
+You should have received a copy of the GNU General Public Licence
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+from afs.argparse import *
+from afs.lib.output import *
+import kafs
+import sys
+
+help = "Create an (empty) Protection Database group entry"
+
+command_arguments = [
+ [ "name", get_strings, "rm", "<group name>+" ],
+ [ "owner", get_string, "os" "<owner of the group>" ],
+ [ "id", get_gids, "om", "<id (negated) for the group>+" ],
+ [ "cell", get_cell, "os", "<cell name>" ],
+ [ "noauth", get_auth, "fn" ],
+ [ "localauth", get_auth, "fn" ],
+ [ "verbose", get_verbose, "fn" ],
+ [ "encrypt", get_dummy, "fn" ],
+ [ "force", get_dummy, "fn" ],
+]
+
+cant_combine_arguments = [
+ ( "cell", "localauth" ),
+ ( "noauth", "localauth" ),
+]
+
+argument_size_limits = {
+ "name" : kafs.PR_MAXNAMELEN,
+}
+
+description = r"""
+Create an (empty) Protection Database group entry
+"""
+
+def main(params):
+ exitcode = 0
+ cell = params["cell"]
+ prcache = cell.get_prcache(params)
+
+ oid = 0
+ if "owner" in params:
+ oid = prcache.name_or_id_to_id(params["owner"])
+
+ names = params["name"]
+ if "id" in params:
+ ids = params["id"]
+ else:
+ ids = []
+
+ for i in range(0, len(names)):
+ name = names[i]
+ try:
+ verbose("Adding group ", name, "\n")
+ if i < len(ids):
+ new_id = int(ids[i])
+ ret = cell.call_pt_server(params, kafs.PR_INewEntry, name, new_id, oid)
+ else:
+ ret = cell.call_pt_server(params, kafs.PR_NewEntry, name, kafs.PRGRP, oid)
+ new_id = ret.id
+ output("Group ", name, " has id ", new_id, "\n")
+ except kafs.AbortPREXIST:
+ error("Entry for name already exists ; unable to create group ", name, "\n")
+ if "force" not in params:
+ break
+ except kafs.AbortPRIDEXIST:
+ error("Entry for id already exists ; unable to create group ", name, " with id ", new_id, "\n")
+ if "force" not in params:
+ break
+ return exitcode