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
This commit is contained in:
Pavel Zuna 2010-03-30 18:56:02 +02:00 committed by Martin Nagy
parent 18349dda0f
commit bc5b5a82d9

View File

@ -67,6 +67,7 @@ from ipalib import api, crud, errors, output
from ipalib import Object, Command from ipalib import Object, Command
from ipalib import Flag, Int, Str, StrEnum from ipalib import Flag, Int, Str, StrEnum
from ipalib import _, ngettext from ipalib import _, ngettext
from ipalib.output import Output, standard_entry, standard_list_of_entries
# parent DN # parent DN
_zone_container_dn = api.env.container_dns _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) filter = ldap.make_filter_from_attr('idnsname', term, exact=False)
# select attributes we want to retrieve # select attributes we want to retrieve
if options['all']: if options.get('all', False):
attrs_list = ['*'] attrs_list = ['*']
else: else:
attrs_list = _zone_default_attributes attrs_list = _zone_default_attributes
@ -362,7 +363,7 @@ class dns_show(crud.Retrieve):
dn = _get_zone_dn(ldap, idnsname) dn = _get_zone_dn(ldap, idnsname)
# select attributes we want to retrieve # select attributes we want to retrieve
if options['all']: if options.get('all', False):
attrs_list = ['*'] attrs_list = ['*']
else: else:
attrs_list = _zone_default_attributes 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): def execute(self, zone, idnsname, type, data, **options):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
attr = '%srecord' % type attr = ('%srecord' % type).lower()
# build entry DN # build entry DN
dn = _get_record_dn(ldap, zone, idnsname) 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 ldap = self.api.Backend.ldap2
attr = '%srecord' % type attr = ('%srecord' % type).lower()
# build entry DN # build entry DN
dn = _get_record_dn(ldap, zone, idnsname) 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]) (dn, entry_attrs) = ldap.get_entry(dn, ['idnsname', attr])
entry_attrs['dn'] = dn 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"' % ( output = '"%s %s %s" from zone "%s"' % (
idnsname, type, data, zone, 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): def execute(self, zone, term, **options):
ldap = self.api.Backend.ldap2 ldap = self.api.Backend.ldap2
if 'type' in options: if 'type' in options:
attr = '%srecord' % options['type'] attr = ('%srecord' % options['type']).lower()
else: else:
attr = None attr = None
@ -722,7 +723,7 @@ class dns_find_rr(Command):
filter = ldap.combine_filters((filter, term_filter), ldap.MATCH_ALL) filter = ldap.combine_filters((filter, term_filter), ldap.MATCH_ALL)
# select attributes we want to retrieve # select attributes we want to retrieve
if options['all']: if options.get('all', False):
attrs_list = ['*'] attrs_list = ['*']
elif attr is not None: elif attr is not None:
attrs_list = [attr] 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): def execute(self, zone, idnsname, **options):
# shows all records associated with resource # shows all records associated with resource
@ -803,7 +804,7 @@ class dns_show_rr(Command):
dn = _get_record_dn(ldap, zone, idnsname) dn = _get_record_dn(ldap, zone, idnsname)
# select attributes we want to retrieve # select attributes we want to retrieve
if options['all']: if options.get('all', False):
attrs_list = ['*'] attrs_list = ['*']
else: else:
attrs_list = _record_default_attributes attrs_list = _record_default_attributes