On 4/14/2010 5:36 PM, Rob Crittenden wrote:
Pavel Zůna wrote:
On 4/13/2010 10:51 PM, Rob Crittenden wrote:
Pavel Zuna wrote:
The DNS plugin is getting old, tired and already looking forward to his
pension in the Carribean. It will be replaced soon by a younger,
faster,
safer, shorter (in terms of code) and more maintainable version.
Until that happens, here's some medicine for the old guy:

- proper output definitions: the DNS plugin was created before we
had the has_output attribute in place

- --all: this is related to the output definitions as
Command.get_options() adds the --all and --raw options automatically
if has_output contains entries

- dns-add-rr overwritting: missing .lower() caused records to be
overwritten every time a new one was added from the CLI

Pavel

This looks ok but I wonder why you are defining your own Output
definition instead of using the standard? The only difference seems to
be that your custom one doesn't have a summary.

rob
Because the standard output definitions with entries make Command
plugins automatically add the --all and --raw options. dns-*-rr
commands aren't comfortable with it.

Can you be more specific? What doesn't work?

rob
There were conflicts with --all being defined explicitly by some of the commands. Also, dns-del-rr didn't expect any options and raised an exception when it received the automatically added --all/--raw.

Anyway, I fixed those issues, so that we can use the standard definitions from ipalib/output.py. I guess I got lazy before or just wasn't thinking about it too much. :) Modified patch attached.

Pavel
From 6073a12c78c4702916c7de4c5115a7ea1c62cdca Mon Sep 17 00:00:00 2001
From: Pavel Zuna <pz...@redhat.com>
Date: Tue, 30 Mar 2010 18:56:02 +0200
Subject: [PATCH] Fix DNS plugin: proper output definitions, --all, dns-add-rr 
overwritting

The DNS plugin is getting old, tired and already looking forward to his
pension in the Carribean. It will be replaced soon by a younger, faster,
safer, shorter (in terms of code) and more maintainable version.
Until that happens, here's some medicine for the old guy:
- proper output definitions: the DNS plugin was created before we
  had the has_output attribute in place
- --all: this is related to the output definitions as
  Command.get_options() adds the --all and --raw options automatically
  if has_output contains entries
- dns-add-rr overwritting: missing .lower() caused records to be
  overwritten everytime a new one was added from the CLI
---
 ipalib/plugins/dns.py |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index 5f6949a..4c81a8e 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -67,6 +67,7 @@ from ipalib import api, crud, errors, output
 from ipalib import Object, Command
 from ipalib import Flag, Int, Str, StrEnum
 from ipalib import _, ngettext
+from ipalib.output import Output, standard_entry, standard_list_of_entries
 
 # parent DN
 _zone_container_dn = api.env.container_dns
@@ -310,7 +311,7 @@ class dns_find(crud.Search):
         filter = ldap.make_filter_from_attr('idnsname', term, exact=False)
 
         # select attributes we want to retrieve
-        if options['all']:
+        if options.get('all', False):
             attrs_list = ['*']
         else:
             attrs_list = _zone_default_attributes
@@ -362,7 +363,7 @@ class dns_show(crud.Retrieve):
         dn = _get_zone_dn(ldap, idnsname)
 
         # select attributes we want to retrieve
-        if options['all']:
+        if options.get('all', False):
             attrs_list = ['*']
         else:
             attrs_list = _zone_default_attributes
@@ -492,11 +493,11 @@ class dns_add_rr(Command):
         ),
     )
 
-    has_output = output.standard_entry
+    has_output = standard_entry
 
     def execute(self, zone, idnsname, type, data, **options):
         ldap = self.api.Backend.ldap2
-        attr = '%srecord' % type
+        attr = ('%srecord' % type).lower()
 
         # build entry DN
         dn = _get_record_dn(ldap, zone, idnsname)
@@ -593,11 +594,11 @@ class dns_del_rr(Command):
         ),
     )
 
-    has_output = output.standard_entry
+    has_output = standard_entry
 
-    def execute(self, zone, idnsname, type, data):
+    def execute(self, zone, idnsname, type, data, **options):
         ldap = self.api.Backend.ldap2
-        attr = '%srecord' % type
+        attr = ('%srecord' % type).lower()
 
         # build entry DN
         dn = _get_record_dn(ldap, zone, idnsname)
@@ -635,9 +636,9 @@ class dns_del_rr(Command):
         (dn, entry_attrs) = ldap.get_entry(dn, ['idnsname', attr])
         entry_attrs['dn'] = dn
 
-        return dict(result=result, value=idnsname)
+        return dict(result=entry_attrs, value=idnsname)
 
-    def output_for_cli(self, textui, result, zone, idnsname, type, data):
+    def output_for_cli(self, textui, result, zone, idnsname, type, data, 
**options):
         output = '"%s %s %s" from zone "%s"' % (
             idnsname, type, data, zone,
         )
@@ -683,12 +684,12 @@ class dns_find_rr(Command):
         ),
     )
 
-    has_output = output.standard_list_of_entries
+    has_output = standard_list_of_entries
 
     def execute(self, zone, term, **options):
         ldap = self.api.Backend.ldap2
         if 'type' in options:
-            attr = '%srecord' % options['type']
+            attr = ('%srecord' % options['type']).lower()
         else:
             attr = None
 
@@ -722,7 +723,7 @@ class dns_find_rr(Command):
             filter = ldap.combine_filters((filter, term_filter), 
ldap.MATCH_ALL)
 
         # select attributes we want to retrieve
-        if options['all']:
+        if options.get('all', False):
             attrs_list = ['*']
         elif attr is not None:
             attrs_list = [attr]
@@ -793,7 +794,7 @@ class dns_show_rr(Command):
         ),
     )
 
-    has_output = output.standard_entry
+    has_output = standard_entry
 
     def execute(self, zone, idnsname, **options):
         # shows all records associated with resource
@@ -803,7 +804,7 @@ class dns_show_rr(Command):
         dn = _get_record_dn(ldap, zone, idnsname)
 
         # select attributes we want to retrieve
-        if options['all']:
+        if options.get('all', False):
             attrs_list = ['*']
         else:
             attrs_list = _record_default_attributes
-- 
1.6.6

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

Reply via email to