Merge pull request #2252 from UtahDave/add_loopback_to_ip_addrs

Allow deleting minions by glob.
This commit is contained in:
Thomas S Hatch 2012-10-15 18:09:17 -07:00
commit ae56e3b778

View File

@ -7,6 +7,7 @@ import os
import shutil import shutil
import sys import sys
import logging import logging
import glob
# Import salt modules # Import salt modules
import salt.crypt import salt.crypt
import salt.utils import salt.utils
@ -281,6 +282,7 @@ class Key(object):
Delete a key Delete a key
''' '''
# Don't ask for verification if yes is not set # Don't ask for verification if yes is not set
del_ = []
yes = self.opts.get('yes', True) yes = self.opts.get('yes', True)
(minions_accepted, (minions_accepted,
minions_pre, minions_pre,
@ -290,48 +292,25 @@ class Key(object):
else: else:
# If a key is explicitly passed then don't ask for verification # If a key is explicitly passed then don't ask for verification
yes = True yes = True
pre = os.path.join(minions_pre, delete) del_.extend(glob.glob(os.path.join(minions_pre, delete)))
acc = os.path.join(minions_accepted, delete) del_.extend(glob.glob(os.path.join(minions_accepted, delete)))
rej = os.path.join(minions_rejected, delete) del_.extend(glob.glob(os.path.join(minions_rejected, delete)))
if os.path.exists(pre): if del_:
rm_ = True rm_ = True
if not yes: if not yes:
msg = ('The following pending key is set to be removed: {0}' msg = 'The following keys are going to be deleted:\n'
'\n[n/Y]').format(delete) #for key in sorted(del_):
veri = raw_input(msg) for key in sorted(set(del_)):
# Default to Yes msg += '{0}\n'.format(key)
veri = raw_input('{0}[n/Y]'.format(msg))
if veri.lower().startswith('n'): if veri.lower().startswith('n'):
rm_ = False rm_ = False
if rm_: if rm_:
os.remove(pre) for key in del_:
self._log('Removed pending key {0}'.format(delete), os.remove(key)
level='info') filepath, filename = os.path.split(key)
if os.path.exists(acc): self._log('Removed pending key {0}'.format(filename),
rm_ = True level='info')
if not yes:
msg = ('The following accepted key is set to be removed: {0}'
'\n[n/Y]').format(delete)
veri = raw_input(msg)
# Default to Yes
if veri.lower().startswith('n'):
rm_ = False
if rm_:
os.remove(acc)
self._log('Removed accepted key {0}'.format(delete),
level='info')
if os.path.exists(rej):
rm_ = True
if not yes:
msg = ('The following rejected key is set to be removed: {0}'
'\n[n/Y]').format(delete)
veri = raw_input(msg)
# Default to Yes
if veri.lower().startswith('n'):
rm_ = False
if rm_:
os.remove(rej)
self._log('Removed rejected key {0}'.format(delete),
level='info')
def _delete_all(self): def _delete_all(self):
''' '''