Merge pull request #19814 from thatch45/mkey_cli

Mkey cli
This commit is contained in:
Thomas S Hatch 2015-01-20 10:22:09 -07:00
commit 89ef86096c
3 changed files with 98 additions and 15 deletions

View File

@ -17,21 +17,23 @@ class SaltKey(parsers.SaltKeyOptionParser):
'''
Execute salt-key
'''
import salt.key
self.parse_args()
multi = False
if self.config.get('zmq_behavior') and self.config.get('transport') == 'raet':
multi = True
if self.config['verify_env']:
verify_env_dirs = []
if not self.config['gen_keys']:
if self.config['transport'] == 'raet':
if self.config['transport'] == 'raet' or multi:
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'accepted'),
os.path.join(self.config['pki_dir'], 'pending'),
os.path.join(self.config['pki_dir'], 'rejected'),
])
elif self.config['transport'] == 'zeromq':
if self.config['transport'] == 'zeromq' or multi:
verify_env_dirs.extend([
self.config['pki_dir'],
os.path.join(self.config['pki_dir'], 'minions'),
@ -56,6 +58,9 @@ class SaltKey(parsers.SaltKeyOptionParser):
self.setup_logfile_logger()
key = salt.key.KeyCLI(self.config)
if multi:
key = salt.key.MultiKeyCLI(self.config)
else:
key = salt.key.KeyCLI(self.config)
if check_user(self.config['user']):
key.run()

View File

@ -13,6 +13,7 @@ import shutil
import fnmatch
import hashlib
import json
import copy
import logging
from salt.ext.six.moves import input
@ -429,6 +430,69 @@ class KeyCLI(object):
self.list_all()
class MultiKeyCLI(KeyCLI):
'''
Manage multiple key backends from the CLI
'''
def __init__(self, opts):
opts['__multi_key'] = True
self.opts = opts
zopts = copy.copy(opts)
ropts = copy.copy(opts)
self.keys = {}
zopts['transport'] = 'zeromq'
self.keys['ZMQ Keys'] = KeyCLI(zopts)
ropts['transport'] = 'raet'
self.keys['RAET Keys'] = KeyCLI(ropts)
def _call_all(self, fun, *args):
'''
Call the given function on all backend keys
'''
for kback in self.keys:
print(kback)
getattr(self.keys[kback], fun)(*args)
def list_status(self, status):
self._call_all('list_status', status)
def list_all(self):
self._call_all('list_all')
def accept(self, match, include_rejected=False):
self._call_all('accept', match, include_rejected)
def accept_all(self, include_rejected=False):
self._call_all('accept_all', include_rejected)
def delete(self, match):
self._call_all('delete', match)
def delete_all(self):
self._call_all('delete_all')
def reject(self, match, include_accepted=False):
self._call_all('reject', match, include_accepted)
def reject_all(self, include_accepted=False):
self._call_all('reject_all', include_accepted)
def print_key(self, match):
self._call_all('print_key', match)
def print_all(self):
self._call_all('print_all')
def finger(self, match):
self._call_all('finger', match)
def finger_all(self):
self._call_all('finger_all')
def prep_signature(self):
self._call_all('prep_signature')
class Key(object):
'''
The object that encapsulates saltkey actions

View File

@ -21,6 +21,9 @@ def output(data):
__opts__.get('color'),
__opts__.get('color_theme'))
strip_colors = __opts__.get('strip_colors', True)
ident = 0
if __opts__.get('__multi_key'):
ident = 4
if __opts__['transport'] == 'zeromq':
acc = 'minions'
pend = 'minions_pre'
@ -33,19 +36,24 @@ def output(data):
rej: color['BLUE'],
'local': color['MAGENTA']}
trans = {pend: u'{0}Unaccepted Keys:{1}'.format(
trans = {pend: u'{0}{1}Unaccepted Keys:{2}'.format(
' ' * ident,
color['LIGHT_RED'],
color['ENDC']),
acc: u'{0}Accepted Keys:{1}'.format(
acc: u'{0}{1}Accepted Keys:{2}'.format(
' ' * ident,
color['LIGHT_GREEN'],
color['ENDC']),
den: u'{0}Denied Keys:{1}'.format(
den: u'{0}{1}Denied Keys:{2}'.format(
' ' * ident,
color['LIGHT_MAGENTA'],
color['ENDC']),
rej: u'{0}Rejected Keys:{1}'.format(
rej: u'{0}{1}Rejected Keys:{2}'.format(
' ' * ident,
color['LIGHT_BLUE'],
color['ENDC']),
'local': u'{0}Local Keys:{1}'.format(
'local': u'{0}{1}Local Keys:{2}'.format(
' ' * ident,
color['LIGHT_MAGENTA'],
color['ENDC'])}
else:
@ -58,16 +66,20 @@ def output(data):
rej: color['BLUE'],
'local': color['MAGENTA']}
trans = {pend: u'{0}Unaccepted Keys:{1}'.format(
trans = {pend: u'{0}{1}Unaccepted Keys:{2}'.format(
' ' * ident,
color['LIGHT_RED'],
color['ENDC']),
acc: u'{0}Accepted Keys:{1}'.format(
acc: u'{0}{1}Accepted Keys:{2}'.format(
' ' * ident,
color['LIGHT_GREEN'],
color['ENDC']),
rej: u'{0}Rejected Keys:{1}'.format(
rej: u'{0}{1}Rejected Keys:{2}'.format(
' ' * ident,
color['LIGHT_BLUE'],
color['ENDC']),
'local': u'{0}Local Keys:{1}'.format(
'local': u'{0}{1}Local Keys:{2}'.format(
' ' * ident,
color['LIGHT_MAGENTA'],
color['ENDC'])}
@ -80,12 +92,14 @@ def output(data):
if strip_colors:
skey = salt.output.strip_esc_sequence(key)
if isinstance(data[status], list):
ret += u'{0}{1}{2}\n'.format(
ret += u'{0}{1}{2}{3}\n'.format(
' ' * ident,
cmap[status],
skey,
color['ENDC'])
if isinstance(data[status], dict):
ret += u'{0}{1}: {2}{3}\n'.format(
ret += u'{0}{1}{2}: {3}{4}\n'.format(
' ' * ident,
cmap[status],
skey,
data[status][key],