From 62876ccee3ba679adda926b88564732552459619 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 30 Oct 2008 17:25:45 -0400 Subject: Initial implementation of automount support Add argument handling to crud.Del Make get_list handle LDAP scope --- ipalib/plugins/f_automount.py | 472 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100644 ipalib/plugins/f_automount.py (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py new file mode 100644 index 00000000..78e96ccd --- /dev/null +++ b/ipalib/plugins/f_automount.py @@ -0,0 +1,472 @@ +# Authors: +# Rob Crittenden +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# 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 License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Frontend plugins for automount. + +RFC 2707bis http://www.padl.com/~lukeh/rfc2307bis.txt +""" + +from ipalib import frontend +from ipalib import crud +from ipalib.frontend import Param +from ipalib import api +from ipalib import errors +from ipalib import ipa_types +from ldap import explode_dn + +map_attributes = ['automountMapName', 'description', ] +key_attributes = ['description', 'automountKey', 'automountInformation'] + +def display_entry(entry): + # FIXME: for now delete dn here. In the future pass in the kw to + # output_for_cli() + attr = sorted(entry.keys()) + + for a in attr: + if a != 'dn': + print "%s: %s" % (a, entry[a]) + +def make_automount_dn(mapname): + """ + Construct automount dn from map name. + """ + # FIXME, should this be in b_ldap? + # Experimenting to see what a plugin looks like for a 3rd party who can't + # modify the backend. + import ldap + return 'automountmapname=%s,%s,%s' % ( + ldap.dn.escape_dn_chars(mapname), + api.env.container_accounts, + api.env.basedn, + ) + +class automount(frontend.Object): + """ + Automount object. + """ + takes_params = ( + Param('automountmapname', + cli_name='mapname', + primary_key=True, + doc='A group of related automount objects', + ), + ) +api.register(automount) + + +class automount_addmap(crud.Add): + 'Add a new automount map.' + takes_options = ( + Param('description?', + doc='A description of the automount map'), + ) + + def execute(self, mapname, **kw): + """ + Execute the automount-addmap operation. + + Returns the entry as it will be created in LDAP. + + :param mapname: The map name being added. + :param kw: Keyword arguments for the other LDAP attributes. + """ + assert 'automountmapname' not in kw + assert 'dn' not in kw + ldap = self.api.Backend.ldap + kw['automountmapname'] = mapname + kw['dn'] = make_automount_dn(mapname) + + kw['objectClass'] = ['automountMap'] + + return ldap.create(**kw) + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount map added" + +api.register(automount_addmap) + + +class automount_addkey(crud.Add): + 'Add a new automount key.' + takes_options = ( + Param('automountkey', + cli_name='key', + doc='An entry in an automount map'), + Param('automountinformation', + cli_name='info', + doc='Mount information for this key'), + Param('description?', + doc='A description of the mount'), + ) + + def execute(self, mapname, **kw): + """ + Execute the automount-addkey operation. + + Returns the entry as it will be created in LDAP. + + :param mapname: The map name being added to. + :param kw: Keyword arguments for the other LDAP attributes. + """ + assert 'automountmapname' not in kw + assert 'dn' not in kw + ldap = self.api.Backend.ldap + # use find_entry_dn instead of make_automap_dn so we can confirm that + # the map exists + map_dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + kw['dn'] = "automountkey=%s,%s" % (kw['automountkey'], map_dn) + + kw['objectClass'] = ['automount'] + + return ldap.create(**kw) + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount key added" + +api.register(automount_addkey) + + +class automount_delmap(crud.Del): + 'Delete an automount map.' + def execute(self, mapname, **kw): + """Delete an automount map. This will also remove all of the keys + associated with this map. + + mapname is the automount map to remove + + :param mapname: The map to be removed + :param kw: Not used. + """ + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + keys = api.Command['automount_getkeys'](mapname) + if keys: + for k in keys: + ldap.delete(k.get('dn')) + return ldap.delete(dn) + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount map and associated keys deleted" + +api.register(automount_delmap) + + +class automount_delkey(crud.Del): + 'Delete an automount key.' + takes_options = ( + Param('key', + doc='The automount key to remove'), + ) + def execute(self, mapname, **kw): + """Delete an automount key. + + key is the automount key to remove + + :param mapname: The automount map containing the key to be removed + :param kw: "key" the key to be removed + """ + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + keys = api.Command['automount_getkeys'](mapname) + keydn = None + keyname = kw.get('key').lower() + if keys: + for k in keys: + if k.get('automountkey').lower() == keyname: + keydn = k.get('dn') + break + if not keydn: + raise errors.NotFound + return ldap.delete(keydn) + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount key deleted" + +api.register(automount_delkey) + +class automount_modmap(crud.Mod): + 'Edit an existing automount map.' + takes_options = ( + Param('description?', + doc='A description of the automount map'), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-modmap operation. + + The dn should not be passed as a keyword argument as it is constructed + by this method. + + Returns the entry + + :param mapname: The map name to update. + :param kw: Keyword arguments for the other LDAP attributes. + """ + assert 'automountmapname' not in kw + assert 'dn' not in kw + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + return ldap.update(dn, **kw) + + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount map updated" + +api.register(automount_modmap) + + +class automount_modkey(crud.Mod): + 'Edit an existing automount key.' + takes_options = ( + Param('automountkey', + cli_name='key', + doc='An entry in an automount map'), + Param('automountinformation?', + cli_name='info', + doc='Mount information for this key'), + Param('description?', + doc='A description of the automount map'), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-modkey operation. + + Returns the entry + + :param mapname: The map name to update. + :param kw: Keyword arguments for the other LDAP attributes. + """ + assert 'automountmapname' not in kw + assert 'dn' not in kw + keyname = kw.get('automountkey').lower() + del kw['automountkey'] + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + keys = api.Command['automount_getkeys'](mapname) + keydn = None + if keys: + for k in keys: + if k.get('automountkey').lower() == keyname: + keydn = k.get('dn') + break + if not keydn: + raise errors.NotFound + return ldap.update(keydn, **kw) + + def output_for_cli(self, ret): + """ + Output result of this command to command line interface. + """ + if ret: + print "Automount key updated" +api.register(automount_modkey) + + +class automount_findmap(crud.Find): + 'Search automount maps.' + takes_options = ( + Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + ) + def execute(self, term, **kw): + ldap = self.api.Backend.ldap + + search_fields = map_attributes + + for s in search_fields: + kw[s] = term + + kw['objectclass'] = 'automountMap' + if kw.get('all', False): + kw['attributes'] = ['*'] + else: + kw['attributes'] = map_attributes + return ldap.search(**kw) + def output_for_cli(self, entries): + if not entries: + return + counter = entries[0] + entries = entries[1:] + if counter == 0: + print "No entries found" + return + elif counter == -1: + print "These results are truncated." + print "Please refine your search and try again." + + for e in entries: + display_entry(e) + print "" +api.register(automount_findmap) + + +class automount_findkey(crud.Find): + 'Search automount keys.' + takes_options = ( + Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + ) + def execute(self, term, **kw): + ldap = self.api.Backend.ldap + + search_fields = key_attributes + + for s in search_fields: + kw[s] = term + + kw['objectclass'] = 'automount' + if kw.get('all', False): + kw['attributes'] = ['*'] + else: + kw['attributes'] = key_attributes + return ldap.search(**kw) + def output_for_cli(self, entries): + if not entries: + return + counter = entries[0] + entries = entries[1:] + if counter == 0: + print "No entries found" + return + elif counter == -1: + print "These results are truncated." + print "Please refine your search and try again." + + for e in entries: + display_entry(e) + print "" +api.register(automount_findkey) + + +class automount_showmap(crud.Get): + 'Examine an existing automount map.' + takes_options = ( + Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-showmap operation. + + Returns the entry + + :param mapname: The automount map to retrieve + :param kw: "all" set to True = return all attributes + """ + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + # FIXME: should kw contain the list of attributes to display? + if kw.get('all', False): + return ldap.retrieve(dn) + else: + return ldap.retrieve(dn, map_attributes) + def output_for_cli(self, entry): + if entry: + display_entry(entry) + +api.register(automount_showmap) + + +class automount_showkey(crud.Get): + 'Examine an existing automount key.' + takes_options = ( + Param('key', + doc='The automount key to display'), + Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-showkey operation. + + Returns the entry + + :param mapname: The mapname to examine + :param kw: "key" the key to retrieve + :param kw: "all" set to True = return all attributes + """ + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + keys = api.Command['automount_getkeys'](mapname) + keyname = kw.get('key').lower() + keydn = None + if keys: + for k in keys: + if k.get('automountkey').lower() == keyname: + keydn = k.get('dn') + break + if not keydn: + raise errors.NotFound + # FIXME: should kw contain the list of attributes to display? + if kw.get('all', False): + return ldap.retrieve(keydn) + else: + return ldap.retrieve(keydn, key_attributes) + def output_for_cli(self, entry): + # The automount map name associated with this key is available only + # in the dn. Add it as an attribute to display instead. + if entry and not entry.get('automountmapname'): + elements = explode_dn(entry.get('dn').lower()) + for e in elements: + (attr, value) = e.split('=',1) + if attr == 'automountmapname': + entry['automountmapname'] = value + display_entry(entry) + +api.register(automount_showkey) + + +class automount_getkeys(frontend.Command): + 'Retrieve all keys for an automount map.' + takes_args = ( + Param('automountmapname', + cli_name='mapname', + primary_key=True, + doc='A group of related automount objects', + ), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-getkeys operation. + + Return a list of all automount keys for this mapname + + :param mapname: Retrieve all keys for this mapname + """ + ldap = self.api.Backend.ldap + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + return ldap.get_one_entry(dn, 'objectclass=*', ['automountkey']) + def output_for_cli(self, keys): + if keys: + for k in keys: + print k.get('automountkey') + +api.register(automount_getkeys) -- cgit From e8adb59fd42eddb9f8911f6d888d9a64e0773df9 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 4 Nov 2008 16:21:10 -0500 Subject: Fix some problems uncovered during automation test work --- ipalib/plugins/f_automount.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index 78e96ccd..fba9e12c 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -180,7 +180,8 @@ api.register(automount_delmap) class automount_delkey(crud.Del): 'Delete an automount key.' takes_options = ( - Param('key', + Param('automountkey', + cli_name='key', doc='The automount key to remove'), ) def execute(self, mapname, **kw): @@ -195,7 +196,7 @@ class automount_delkey(crud.Del): dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") keys = api.Command['automount_getkeys'](mapname) keydn = None - keyname = kw.get('key').lower() + keyname = kw.get('automountkey').lower() if keys: for k in keys: if k.get('automountkey').lower() == keyname: @@ -336,6 +337,10 @@ class automount_findkey(crud.Find): takes_options = ( Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), ) + def get_args(self): + return (Param('automountkey', + cli_name='key', + doc='An entry in an automount map'),) def execute(self, term, **kw): ldap = self.api.Backend.ldap @@ -399,7 +404,8 @@ api.register(automount_showmap) class automount_showkey(crud.Get): 'Examine an existing automount key.' takes_options = ( - Param('key', + Param('automountkey', + cli_name='key', doc='The automount key to display'), Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), ) @@ -410,13 +416,13 @@ class automount_showkey(crud.Get): Returns the entry :param mapname: The mapname to examine - :param kw: "key" the key to retrieve + :param kw: "automountkey" the key to retrieve :param kw: "all" set to True = return all attributes """ ldap = self.api.Backend.ldap dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") keys = api.Command['automount_getkeys'](mapname) - keyname = kw.get('key').lower() + keyname = kw.get('automountkey').lower() keydn = None if keys: for k in keys: @@ -463,7 +469,12 @@ class automount_getkeys(frontend.Command): """ ldap = self.api.Backend.ldap dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") - return ldap.get_one_entry(dn, 'objectclass=*', ['automountkey']) + try: + keys = ldap.get_one_entry(dn, 'objectclass=*', ['automountkey']) + except errors.NotFound: + keys = [] + + return keys def output_for_cli(self, keys): if keys: for k in keys: -- cgit From c513743e7c9a611d0b3b0abaf13b79d6237ed6da Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 14 Nov 2008 18:04:57 -0500 Subject: Add autmount-specific location and default entries --- ipalib/plugins/f_automount.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index fba9e12c..7a251572 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -53,7 +53,7 @@ def make_automount_dn(mapname): import ldap return 'automountmapname=%s,%s,%s' % ( ldap.dn.escape_dn_chars(mapname), - api.env.container_accounts, + api.env.container_automount, api.env.basedn, ) @@ -133,7 +133,7 @@ class automount_addkey(crud.Add): ldap = self.api.Backend.ldap # use find_entry_dn instead of make_automap_dn so we can confirm that # the map exists - map_dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + map_dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) kw['dn'] = "automountkey=%s,%s" % (kw['automountkey'], map_dn) kw['objectClass'] = ['automount'] @@ -193,7 +193,7 @@ class automount_delkey(crud.Del): :param kw: "key" the key to be removed """ ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) keys = api.Command['automount_getkeys'](mapname) keydn = None keyname = kw.get('automountkey').lower() @@ -235,7 +235,7 @@ class automount_modmap(crud.Mod): assert 'automountmapname' not in kw assert 'dn' not in kw ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) return ldap.update(dn, **kw) def output_for_cli(self, ret): @@ -274,7 +274,7 @@ class automount_modkey(crud.Mod): keyname = kw.get('automountkey').lower() del kw['automountkey'] ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) keys = api.Command['automount_getkeys'](mapname) keydn = None if keys: @@ -388,7 +388,7 @@ class automount_showmap(crud.Get): :param kw: "all" set to True = return all attributes """ ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) # FIXME: should kw contain the list of attributes to display? if kw.get('all', False): return ldap.retrieve(dn) @@ -420,7 +420,7 @@ class automount_showkey(crud.Get): :param kw: "all" set to True = return all attributes """ ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) keys = api.Command['automount_getkeys'](mapname) keyname = kw.get('automountkey').lower() keydn = None @@ -468,7 +468,7 @@ class automount_getkeys(frontend.Command): :param mapname: Retrieve all keys for this mapname """ ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) try: keys = ldap.get_one_entry(dn, 'objectclass=*', ['automountkey']) except errors.NotFound: -- cgit From fc8ac693726ec33b5c0924f9b8ff5d663705a5a3 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 5 Dec 2008 15:31:18 -0500 Subject: Port plugins to use the new output_for_cli() argument list Fix some errors uncovered by the nosetests --- ipalib/plugins/f_automount.py | 95 ++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index 7a251572..d2a70784 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -34,14 +34,14 @@ from ldap import explode_dn map_attributes = ['automountMapName', 'description', ] key_attributes = ['description', 'automountKey', 'automountInformation'] -def display_entry(entry): +def display_entry(textui, entry): # FIXME: for now delete dn here. In the future pass in the kw to # output_for_cli() attr = sorted(entry.keys()) for a in attr: if a != 'dn': - print "%s: %s" % (a, entry[a]) + textui.print_plain("%s: %s" % (a, entry[a])) def make_automount_dn(mapname): """ @@ -96,12 +96,11 @@ class automount_addmap(crud.Add): kw['objectClass'] = ['automountMap'] return ldap.create(**kw) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, map, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount map added" + textui.print_plain("Automount map %s added" % map) api.register(automount_addmap) @@ -139,12 +138,11 @@ class automount_addkey(crud.Add): kw['objectClass'] = ['automount'] return ldap.create(**kw) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount key added" + textui.print_plain("Automount key added") api.register(automount_addkey) @@ -161,18 +159,17 @@ class automount_delmap(crud.Del): :param kw: Not used. """ ldap = self.api.Backend.ldap - dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap") + dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) keys = api.Command['automount_getkeys'](mapname) if keys: for k in keys: ldap.delete(k.get('dn')) return ldap.delete(dn) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount map and associated keys deleted" + print "Automount map and associated keys deleted" api.register(automount_delmap) @@ -205,12 +202,11 @@ class automount_delkey(crud.Del): if not keydn: raise errors.NotFound return ldap.delete(keydn) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount key deleted" + print "Automount key deleted" api.register(automount_delkey) @@ -238,12 +234,11 @@ class automount_modmap(crud.Mod): dn = ldap.find_entry_dn("automountmapname", mapname, "automountmap", api.env.container_automount) return ldap.update(dn, **kw) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount map updated" + print "Automount map updated" api.register(automount_modmap) @@ -286,12 +281,12 @@ class automount_modkey(crud.Mod): raise errors.NotFound return ldap.update(keydn, **kw) - def output_for_cli(self, ret): + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. """ - if ret: - print "Automount key updated" + print "Automount key updated" + api.register(automount_modkey) @@ -309,26 +304,27 @@ class automount_findmap(crud.Find): kw[s] = term kw['objectclass'] = 'automountMap' + kw['base'] = api.env.container_automount if kw.get('all', False): kw['attributes'] = ['*'] else: kw['attributes'] = map_attributes return ldap.search(**kw) - def output_for_cli(self, entries): - if not entries: - return - counter = entries[0] - entries = entries[1:] + + def output_for_cli(self, textui, result, *args, **options): + counter = result[0] + entries = result[1:] if counter == 0: - print "No entries found" + textui.print_plain("No entries found") return elif counter == -1: - print "These results are truncated." - print "Please refine your search and try again." + textui.print_plain("These results are truncated.") + textui.print_plain("Please refine your search and try again.") for e in entries: - display_entry(e) - print "" + display_entry(textui, e) + textui.print_plain("") + api.register(automount_findmap) @@ -350,26 +346,26 @@ class automount_findkey(crud.Find): kw[s] = term kw['objectclass'] = 'automount' + kw['base'] = api.env.container_automount if kw.get('all', False): kw['attributes'] = ['*'] else: kw['attributes'] = key_attributes return ldap.search(**kw) - def output_for_cli(self, entries): - if not entries: - return - counter = entries[0] - entries = entries[1:] + def output_for_cli(self, textui, result, *args, **options): + counter = result[0] + entries = result[1:] if counter == 0: - print "No entries found" + textui.print_plain("No entries found") return elif counter == -1: - print "These results are truncated." - print "Please refine your search and try again." + textui.print_plain("These results are truncated.") + textui.print_plain("Please refine your search and try again.") for e in entries: - display_entry(e) - print "" + display_entry(textui, e) + textui.print_plain("") + api.register(automount_findkey) @@ -394,9 +390,9 @@ class automount_showmap(crud.Get): return ldap.retrieve(dn) else: return ldap.retrieve(dn, map_attributes) - def output_for_cli(self, entry): - if entry: - display_entry(entry) + def output_for_cli(self, textui, result, *args, **options): + if result: + display_entry(textui, result) api.register(automount_showmap) @@ -436,7 +432,7 @@ class automount_showkey(crud.Get): return ldap.retrieve(keydn) else: return ldap.retrieve(keydn, key_attributes) - def output_for_cli(self, entry): + def output_for_cli(self, textui, result, *args, **options): # The automount map name associated with this key is available only # in the dn. Add it as an attribute to display instead. if entry and not entry.get('automountmapname'): @@ -445,7 +441,7 @@ class automount_showkey(crud.Get): (attr, value) = e.split('=',1) if attr == 'automountmapname': entry['automountmapname'] = value - display_entry(entry) + display_entry(textui, entry) api.register(automount_showkey) @@ -475,9 +471,8 @@ class automount_getkeys(frontend.Command): keys = [] return keys - def output_for_cli(self, keys): - if keys: - for k in keys: - print k.get('automountkey') + def output_for_cli(self, textui, result, *args, **options): + for k in result: + textui.print_plain('%s' % k.get('automountkey')) api.register(automount_getkeys) -- cgit From 039ee0fd56bbca60a79c99cdd489a1590f6f2b78 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Mon, 8 Dec 2008 15:37:36 -0500 Subject: Add a function to show all the maps under a given mapname, def. is auto.master --- ipalib/plugins/f_automount.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index d2a70784..8de6c5ab 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -476,3 +476,35 @@ class automount_getkeys(frontend.Command): textui.print_plain('%s' % k.get('automountkey')) api.register(automount_getkeys) + + +class automount_getmaps(frontend.Command): + 'Retrieve all automount maps' + takes_args = ( + Param('automountmapname?', + cli_name='mapname', + primary_key=True, + doc='A group of related automount objects', + ), + ) + def execute(self, mapname, **kw): + """ + Execute the automount-getmaps operation. + + Return a list of all automount maps. + """ + + ldap = self.api.Backend.ldap + base = api.env.container_automount + "," + api.env.basedn + + if not mapname: + mapname = "auto.master" + search_base = "automountmapname=%s,%s" % (mapname, base) + maps = ldap.get_one_entry(search_base, "objectClass=*", ["*"]) + + return maps + def output_for_cli(self, textui, result, *args, **options): + for k in result: + textui.print_plain('%s: %s' % (k.get('automountinformation'), k.get('automountkey'))) + +api.register(automount_getmaps) -- cgit From c34d2b8923ba0c8dc9a8aa1779a507a64c7c77db Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 10 Dec 2008 13:53:33 -0500 Subject: Add helper for adding Indirect maps. This creates the map and the key pointing to the map. By default the key is associated with the auto.master map but it can be overriden. --- ipalib/plugins/f_automount.py | 57 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index 8de6c5ab..4c392438 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -435,13 +435,13 @@ class automount_showkey(crud.Get): def output_for_cli(self, textui, result, *args, **options): # The automount map name associated with this key is available only # in the dn. Add it as an attribute to display instead. - if entry and not entry.get('automountmapname'): - elements = explode_dn(entry.get('dn').lower()) + if result and not result.get('automountmapname'): + elements = explode_dn(result.get('dn').lower()) for e in elements: (attr, value) = e.split('=',1) if attr == 'automountmapname': - entry['automountmapname'] = value - display_entry(textui, entry) + result['automountmapname'] = value + display_entry(textui, result) api.register(automount_showkey) @@ -508,3 +508,52 @@ class automount_getmaps(frontend.Command): textui.print_plain('%s: %s' % (k.get('automountinformation'), k.get('automountkey'))) api.register(automount_getmaps) + +class automount_addindirectmap(crud.Add): + 'Add a new automap indirect mount point.' + takes_options = ( + Param('parentmap?', + cli_name='parentmap', + default='auto.master', + doc='The parent map to connect this to. Default: auto.master'), + Param('automountkey', + cli_name='key', + doc='An entry in an automount map'), + Param('description?', + doc='A description of the automount map'), + ) + + def execute(self, mapname, **kw): + """ + Execute the automount-addindirectmap operation. + + Returns the key entry as it will be created in LDAP. + + This function creates 2 LDAP entries. It creates an + automountmapname entry and an automountkey entry. + + :param mapname: The map name being added. + :param kw['parentmap'] is the top-level map to add this to. + defaulting to auto.master + :param kw['automountkey'] is the mount point + :param kw['description'] is a textual description of this map + """ + mapkw = {} + if kw.get('description'): + mapkw['description'] = kw.get('description') + newmap = api.Command['automount_addmap'](mapname, **mapkw) + + keykw = {'automountkey': kw['automountkey'], 'automountinformation': mapname} + if kw.get('description'): + keykw['description'] = kw.get('description') + newkey = api.Command['automount_addkey'](kw['parentmap'], **keykw) + + return newkey + def output_for_cli(self, textui, result, map, **options): + """ + Output result of this command to command line interface. + """ + textui.print_plain("Indirect automount map %s added" % map) + +api.register(automount_addindirectmap) + -- cgit From 39068ab7ca4cb2346c3c7079a435fb82ebd29591 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 14 Jan 2009 21:11:14 -0700 Subject: Fixed automount plugins module to where it can at least be imported --- ipalib/plugins/f_automount.py | 76 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 36 deletions(-) (limited to 'ipalib/plugins/f_automount.py') diff --git a/ipalib/plugins/f_automount.py b/ipalib/plugins/f_automount.py index 4c392438..2365ce22 100644 --- a/ipalib/plugins/f_automount.py +++ b/ipalib/plugins/f_automount.py @@ -23,13 +23,9 @@ Frontend plugins for automount. RFC 2707bis http://www.padl.com/~lukeh/rfc2307bis.txt """ -from ipalib import frontend -from ipalib import crud -from ipalib.frontend import Param -from ipalib import api -from ipalib import errors -from ipalib import ipa_types from ldap import explode_dn +from ipalib import crud, errors +from ipalib import api, Str, Flag, Object, Command map_attributes = ['automountMapName', 'description', ] key_attributes = ['description', 'automountKey', 'automountInformation'] @@ -57,12 +53,12 @@ def make_automount_dn(mapname): api.env.basedn, ) -class automount(frontend.Object): +class automount(Object): """ Automount object. """ takes_params = ( - Param('automountmapname', + Str('automountmapname', cli_name='mapname', primary_key=True, doc='A group of related automount objects', @@ -73,8 +69,9 @@ api.register(automount) class automount_addmap(crud.Add): 'Add a new automount map.' + takes_options = ( - Param('description?', + Str('description?', doc='A description of the automount map'), ) @@ -96,6 +93,7 @@ class automount_addmap(crud.Add): kw['objectClass'] = ['automountMap'] return ldap.create(**kw) + def output_for_cli(self, textui, result, map, **options): """ Output result of this command to command line interface. @@ -108,13 +106,13 @@ api.register(automount_addmap) class automount_addkey(crud.Add): 'Add a new automount key.' takes_options = ( - Param('automountkey', + Str('automountkey', cli_name='key', doc='An entry in an automount map'), - Param('automountinformation', + Str('automountinformation', cli_name='info', doc='Mount information for this key'), - Param('description?', + Str('description?', doc='A description of the mount'), ) @@ -138,6 +136,7 @@ class automount_addkey(crud.Add): kw['objectClass'] = ['automount'] return ldap.create(**kw) + def output_for_cli(self, textui, result, *args, **options): """ Output result of this command to command line interface. @@ -177,7 +176,7 @@ api.register(automount_delmap) class automount_delkey(crud.Del): 'Delete an automount key.' takes_options = ( - Param('automountkey', + Str('automountkey', cli_name='key', doc='The automount key to remove'), ) @@ -213,7 +212,7 @@ api.register(automount_delkey) class automount_modmap(crud.Mod): 'Edit an existing automount map.' takes_options = ( - Param('description?', + Str('description?', doc='A description of the automount map'), ) def execute(self, mapname, **kw): @@ -246,13 +245,13 @@ api.register(automount_modmap) class automount_modkey(crud.Mod): 'Edit an existing automount key.' takes_options = ( - Param('automountkey', + Str('automountkey', cli_name='key', doc='An entry in an automount map'), - Param('automountinformation?', + Str('automountinformation?', cli_name='info', doc='Mount information for this key'), - Param('description?', + Str('description?', doc='A description of the automount map'), ) def execute(self, mapname, **kw): @@ -293,7 +292,7 @@ api.register(automount_modkey) class automount_findmap(crud.Find): 'Search automount maps.' takes_options = ( - Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + Flag('all', doc='Retrieve all attributes'), ) def execute(self, term, **kw): ldap = self.api.Backend.ldap @@ -331,10 +330,10 @@ api.register(automount_findmap) class automount_findkey(crud.Find): 'Search automount keys.' takes_options = ( - Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + Flag('all?', doc='Retrieve all attributes'), ) def get_args(self): - return (Param('automountkey', + return (Str('automountkey', cli_name='key', doc='An entry in an automount map'),) def execute(self, term, **kw): @@ -372,7 +371,7 @@ api.register(automount_findkey) class automount_showmap(crud.Get): 'Examine an existing automount map.' takes_options = ( - Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + Flag('all?', doc='Retrieve all attributes'), ) def execute(self, mapname, **kw): """ @@ -400,10 +399,10 @@ api.register(automount_showmap) class automount_showkey(crud.Get): 'Examine an existing automount key.' takes_options = ( - Param('automountkey', + Str('automountkey', cli_name='key', doc='The automount key to display'), - Param('all?', type=ipa_types.Bool(), doc='Retrieve all attributes'), + Flag('all?', doc='Retrieve all attributes'), ) def execute(self, mapname, **kw): """ @@ -446,10 +445,10 @@ class automount_showkey(crud.Get): api.register(automount_showkey) -class automount_getkeys(frontend.Command): +class automount_getkeys(Command): 'Retrieve all keys for an automount map.' takes_args = ( - Param('automountmapname', + Str('automountmapname', cli_name='mapname', primary_key=True, doc='A group of related automount objects', @@ -478,10 +477,10 @@ class automount_getkeys(frontend.Command): api.register(automount_getkeys) -class automount_getmaps(frontend.Command): +class automount_getmaps(Command): 'Retrieve all automount maps' takes_args = ( - Param('automountmapname?', + Str('automountmapname?', cli_name='mapname', primary_key=True, doc='A group of related automount objects', @@ -510,17 +509,23 @@ class automount_getmaps(frontend.Command): api.register(automount_getmaps) class automount_addindirectmap(crud.Add): - 'Add a new automap indirect mount point.' + """ + Add a new automap indirect mount point. + """ + takes_options = ( - Param('parentmap?', + Str('parentmap?', cli_name='parentmap', - default='auto.master', - doc='The parent map to connect this to. Default: auto.master'), - Param('automountkey', + default=u'auto.master', + doc='The parent map to connect this to.', + ), + Str('automountkey', cli_name='key', - doc='An entry in an automount map'), - Param('description?', - doc='A description of the automount map'), + doc='An entry in an automount map', + ), + Str('description?', + doc='A description of the automount map', + ), ) def execute(self, mapname, **kw): @@ -556,4 +561,3 @@ class automount_addindirectmap(crud.Add): textui.print_plain("Indirect automount map %s added" % map) api.register(automount_addindirectmap) - -- cgit