Joint effort between me and Rob in getting this to work.

I've tested it with the following data:

[ayo...@ipa freeipa]$ cat ../bulk_request.json
{"method":"bulk","params":[[
        {"method":"json_metadata","params":[[],{}]},
{"method":"user_find","params":[[],{"whoami":" true","all":"true"}]},
        {"method":"user_show","params":[["admin"],{"all":true}],"id":4}
        ],{}],"id":1}


Called this way:

curl -H "Content-Type:application/json" -H "Accept:applicaton/json" -H "Accept-Language:en" --negotiate -u : --cacert /etc/ipa/ca.crt -d @../bulk_request.json -X POST http://localhost:8888/ipa/json



This needs a test, but that will be a follow on patch.
From 55c3fb0b401c068b90a0a30a2db457429c1fc35c Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Fri, 22 Oct 2010 15:08:29 -0400
Subject: [PATCH] bulk

Allows the user to send multiple commands bundled together
---
 ipalib/plugins/bulk.py     |   41 +++++++++++++++++++++++++++++++++++++++++
 ipalib/plugins/internal.py |    3 ++-
 2 files changed, 43 insertions(+), 1 deletions(-)
 create mode 100644 ipalib/plugins/bulk.py

diff --git a/ipalib/plugins/bulk.py b/ipalib/plugins/bulk.py
new file mode 100644
index 0000000000000000000000000000000000000000..be28aadbba1c97301c81e09762457b492fa74ae0
--- /dev/null
+++ b/ipalib/plugins/bulk.py
@@ -0,0 +1,41 @@
+from ipalib import api, errors
+from ipalib import Command
+from ipalib import Str, List
+from ipalib.output import Output
+from ipalib import output
+from ipalib.text import _
+
+
+class bulk(Command):
+
+    takes_args = (
+        List('methods?',
+             doc=_('Nested Methods to execute'),
+             ),
+        )
+
+    has_output = (
+        Output('count', int, doc=_('')),
+        Output('results', list, doc=_(''))
+    )
+
+
+    def execute(self, *args, **options):
+        results=[]
+        for arg in args[0]:
+            try:
+                a = arg['params'][0]
+                kw = arg['params'][1]
+                newkw = {}
+                for k in kw:
+                    newkw[str(k)] = kw[k]
+                result = api.Command[arg['method']](*a, **newkw)
+                result['error']=None
+            except Exception, e:
+                result = dict()
+                result['error'] = unicode(e)
+            results.append(result)
+        return dict(count=len(results) , results=results) 
+
+
+api.register(bulk)
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index e950796b5db3ab0f969bd688fa2990a1487bb9a5..0835ad6ea841db1c341a4a9ad683dee741b8cc4c 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -24,8 +24,9 @@ import json
 
 from ipalib import api, errors
 from ipalib import Command
-from ipalib import Str
+from ipalib import Str, List
 from ipalib.output import Output
+from ipalib import output
 from ipalib.text import _
 from ipalib.util import json_serialize
 
-- 
1.7.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to