diff options
-rw-r--r-- | API.txt | 4 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | ipalib/plugins/automount.py | 97 |
3 files changed, 79 insertions, 24 deletions
@@ -119,7 +119,7 @@ arg: Str('automountlocationcn', cli_name='automountlocation', label=Gettext('Loc arg: IA5Str('automountmapautomountmapname', cli_name='automountmap', label=Gettext('Map', domain='ipa', localedir=None), query=True, required=True) option: Flag('continue', autofill=True, cli_name='continue', default=False) option: IA5Str('automountkey', cli_name='key', label=Gettext('Key', domain='ipa', localedir=None)) -option: IA5Str('automountinformation', cli_name='info', label=Gettext('Mount information', domain='ipa', localedir=None)) +option: IA5Str('automountinformation?', cli_name='info', label=Gettext('Mount information', domain='ipa', localedir=None)) output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly description of action performed') output: Output('result', <type 'dict'>, 'list of deletions that failed') output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user") @@ -162,7 +162,7 @@ arg: Str('automountlocationcn', cli_name='automountlocation', label=Gettext('Loc arg: IA5Str('automountmapautomountmapname', cli_name='automountmap', label=Gettext('Map', domain='ipa', localedir=None), query=True, required=True) option: Flag('rights', autofill=True, default=False, label=Gettext('Rights', domain='ipa', localedir=None)) option: IA5Str('automountkey', cli_name='key', label=Gettext('Key', domain='ipa', localedir=None)) -option: IA5Str('automountinformation', cli_name='info', label=Gettext('Mount information', domain='ipa', localedir=None)) +option: IA5Str('automountinformation?', cli_name='info', label=Gettext('Mount information', domain='ipa', localedir=None)) option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output']) option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output']) option: Str('version?', exclude='webui', flags=['no_option', 'no_output']) @@ -79,4 +79,4 @@ IPA_DATA_VERSION=20100614120000 # # ######################################################## IPA_API_VERSION_MAJOR=2 -IPA_API_VERSION_MINOR=3 +IPA_API_VERSION_MINOR=4 diff --git a/ipalib/plugins/automount.py b/ipalib/plugins/automount.py index 504e183bf..11cea5c90 100644 --- a/ipalib/plugins/automount.py +++ b/ipalib/plugins/automount.py @@ -174,6 +174,7 @@ from ipalib import Object, Command from ipalib import Flag, Str, IA5Str from ipalib.plugins.baseldap import * from ipalib import _, ngettext +import ldap as _ldap import os @@ -604,11 +605,13 @@ class automountkey(LDAPObject): num_parents = 2 label = _('Automount Keys') already_exists_msg = _('The key,info pair must be unique. A key named %(key)s with info %(info)s already exists') + key_already_exists_msg = _('key named %(key)s already exists') object_not_found_msg = _('The automount key %(key)s with info %(info)s does not exist') def get_dn(self, *keys, **kwargs): # all commands except for create send pk in keys, too # create cannot due to validation in frontend.py + ldap = self.backend if len(keys) == self.num_parents: try: pkey = kwargs[self.primary_key.name] @@ -625,6 +628,37 @@ class automountkey(LDAPObject): pkey, parent_dn ) + # If we're doing an add then just return the dn we created, there + # is no need to check for it. + if kwargs.get('add_operation', False): + return dn + # We had an older mechanism where description consisted of + # 'automountkey automountinformation' so we could support multiple + # direct maps. This made showing keys nearly impossible since it + # required automountinfo to show, which if you had you didn't need + # to look at the key. We still support existing entries but now + # only create this type of dn when the key is /- + # + # First we look with the information given, then try to search for + # the right entry. + try: + (dn, entry_attrs) = ldap.get_entry( + dn, ['*'], normalize=self.normalize_dn + ) + except errors.NotFound: + if kwargs.get('automountinformation', False): + sfilter = '(&(automountkey=%s)(automountinformation=%s))' % \ + (kwargs['automountkey'], kwargs['automountinformation']) + else: + sfilter = '(automountkey=%s)' % kwargs['automountkey'] + basedn = 'automountmapname=%s,cn=%s,%s' % (parent_keys[1], parent_keys[0], self.container_dn) + attrs_list = ['*'] + (entries, truncated) = ldap.find_entries(sfilter, attrs_list, + basedn, _ldap.SCOPE_ONELEVEL) + if len(entries) > 1: + raise errors.NotFound(reason=_('More than one entry with key %(key)s found, use --info to select specific entry.') % dict(key=pkey)) + dn = entries[0][0] + return dn def handle_not_found(self, *keys): @@ -641,23 +675,39 @@ class automountkey(LDAPObject): pkey = keys[-1] key = pkey.split(self.rdn_separator)[0] info = self.rdn_separator.join(pkey.split(self.rdn_separator)[1:]) - raise errors.DuplicateEntry( - message=self.already_exists_msg % { - 'key': key, 'info': info, - } - ) + if info: + raise errors.DuplicateEntry( + message=self.already_exists_msg % { + 'key': key, 'info': info, + } + ) + else: + raise errors.DuplicateEntry( + message=self.key_already_exists_msg % { + 'key': key, + } + ) - def get_pk(self, key, info): - return self.rdn_separator.join((key,info)) + def get_pk(self, key, info=None): + if info: + return self.rdn_separator.join((key,info)) + else: + return key def check_key_uniqueness(self, location, map, **keykw): + info = None key = keykw.get('automountkey') - info = keykw.get('automountinformation') - if key is None or info is None: + if key is None: return - entries = self.methods.find(location, map, **keykw)['result'] + entries = self.methods.find(location, map, automountkey=key)['result'] if len(entries) > 0: + if key == u'/-': + info = keykw.get('automountinformation') + entries = self.methods.find(location, map, **keykw)['result'] + if len(entries) > 0: + self.handle_duplicate_entry(location, map, self.get_pk(key, info)) + else: return self.handle_duplicate_entry(location, map, self.get_pk(key, info)) api.register(automountkey) @@ -676,9 +726,13 @@ class automountkey_add(LDAPCreate): yield key def execute(self, *keys, **options): - options[self.obj.primary_key.name] = self.obj.get_pk( - options['automountkey'], - options['automountinformation']) + key = options['automountkey'] + info = options.get('automountinformation', None) + if key == '/-': + options[self.obj.primary_key.name] = self.obj.get_pk(key, info) + else: + options[self.obj.primary_key.name] = self.obj.get_pk(key, None) + options['add_operation'] = True return super(automountkey_add, self).execute(*keys, **options) api.register(automountkey_add) @@ -724,7 +778,7 @@ class automountkey_del(LDAPDelete): label=_('Key'), doc=_('Automount key name.'), ), - IA5Str('automountinformation', + IA5Str('automountinformation?', cli_name='info', label=_('Mount information'), ), @@ -736,10 +790,10 @@ class automountkey_del(LDAPDelete): def execute(self, *keys, **options): keys += (self.obj.get_pk(options['automountkey'], - options['automountinformation']), ) + options.get('automountinformation', None)),) options[self.obj.primary_key.name] = self.obj.get_pk( options['automountkey'], - options['automountinformation']) + options.get('automountinformation', None)) return super(automountkey_del, self).execute(*keys, **options) api.register(automountkey_del) @@ -769,10 +823,10 @@ class automountkey_mod(LDAPUpdate): def execute(self, *keys, **options): keys += (self.obj.get_pk(options['automountkey'], - options['automountinformation']), ) + options.get('automountinformation', None)), ) options[self.obj.primary_key.name] = self.obj.get_pk( options['automountkey'], - options['automountinformation']) + options.get('automountinformation', None)) return super(automountkey_mod, self).execute(*keys, **options) api.register(automountkey_mod) @@ -796,7 +850,7 @@ class automountkey_show(LDAPRetrieve): label=_('Key'), doc=_('Automount key name.'), ), - IA5Str('automountinformation', + IA5Str('automountinformation?', cli_name='info', label=_('Mount information'), ), @@ -808,10 +862,11 @@ class automountkey_show(LDAPRetrieve): def execute(self, *keys, **options): keys += (self.obj.get_pk(options['automountkey'], - options['automountinformation']), ) + options.get('automountinformation', None)), ) options[self.obj.primary_key.name] = self.obj.get_pk( options['automountkey'], - options['automountinformation']) + options.get('automountinformation', None)) + return super(automountkey_show, self).execute(*keys, **options) api.register(automountkey_show) |