In order to generate the metadate, the dns plugin needs to have a __json__ method.

Long term, this should be rewritten as a baseldap extension.
From 30fac7c276cdcb4fc9ff911a2c0f27058cbb69fa Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Wed, 6 Oct 2010 19:03:26 -0400
Subject: [PATCH] dns metadata

This is a little bit of a copy and paste approach, as the code for__json__
 was copied from baseldap.  Long term, we want to rewrite this plugin as
an extension of baseldap anyway.
---
 ipalib/plugins/dns.py      |   15 +++++++++++++++
 ipalib/plugins/internal.py |   18 +++++++++++++-----
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index 85a0d82..77bec45 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -187,6 +187,21 @@ class dns(Object):
         ),
     )
 
+    default_attributes = _zone_default_attributes
+
+    json_friendly_attributes = (
+        'default_attributes', 'label', 'name', 'takes_params' )
+
+    def __json__(self):
+        json_dict = dict(
+            (a, getattr(self, a)) for a in self.json_friendly_attributes
+        )
+        if self.primary_key:
+            json_dict['primary_key'] = self.primary_key.name
+        json_dict['methods'] = [m for m in self.methods]
+        return json_dict
+
+
 api.register(dns)
 
 
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 096da18..1550dfe 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -73,20 +73,28 @@ class json_metadata(Command):
     )
 
     def execute(self, objname):
+
         if objname and objname in self.api.Object:
-            return dict(
+
+            meta = dict(
                 result=dict(
                     ((objname, json_serialize(self.api.Object[objname])), )
                 )
             )
-        result=dict(
-            (o.name, json_serialize(o)) for o in self.api.Object()
-            )
-        retval= dict([("metadata",result),("messages",json_serialize(self.messages))])
+            retval= dict([("metadata",meta), ("messages",dict())])
+
+        else:
+            meta=dict(
+                (o.name, json_serialize(o)) for o in self.api.Object()
+                )
+
+            retval= dict([("metadata",meta),
+                          ("messages",json_serialize(self.messages))])
 
         return retval
 
     def output_for_cli(self, textui, result, *args, **options):
+        import pdb; pdb.set_trace()
         print json.dumps(result, default=json_serialize)
 
 api.register(json_metadata)
-- 
1.7.1

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

Reply via email to