2008-10-30 03:20:28 -05:00
|
|
|
# Authors:
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
"""
|
2009-06-16 09:51:44 -05:00
|
|
|
Misc plugins
|
2008-10-30 03:20:28 -05:00
|
|
|
"""
|
|
|
|
|
2008-11-14 23:21:36 -06:00
|
|
|
import re
|
2009-12-09 10:09:53 -06:00
|
|
|
from ipalib import api, LocalOrRemote, _, ngettext
|
|
|
|
from ipalib.output import Output, summary
|
2010-07-26 16:51:18 -05:00
|
|
|
from ipalib import Flag
|
2008-11-14 23:21:36 -06:00
|
|
|
|
2008-11-12 01:46:04 -06:00
|
|
|
# FIXME: We should not let env return anything in_server
|
|
|
|
# when mode == 'production'. This would allow an attacker to see the
|
|
|
|
# configuration of the server, potentially revealing compromising
|
|
|
|
# information. However, it's damn handy for testing/debugging.
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
|
2008-11-14 22:58:39 -06:00
|
|
|
class env(LocalOrRemote):
|
2008-10-30 03:20:28 -05:00
|
|
|
"""Show environment variables"""
|
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = _('%(count)d variables')
|
|
|
|
|
|
|
|
takes_args = (
|
|
|
|
'variables*',
|
|
|
|
)
|
2010-07-26 16:51:18 -05:00
|
|
|
|
|
|
|
takes_options = LocalOrRemote.takes_options + (
|
|
|
|
Flag('all',
|
|
|
|
cli_name='all',
|
2010-10-27 08:11:30 -05:00
|
|
|
doc=_('retrieve and print all attributes from the server. Affects command output.'),
|
2010-07-26 16:51:18 -05:00
|
|
|
exclude='webui',
|
|
|
|
flags=['no_output'],
|
|
|
|
default=True,
|
|
|
|
),
|
|
|
|
)
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
has_output = (
|
|
|
|
Output('result',
|
|
|
|
type=dict,
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Dictionary mapping variable name to value'),
|
2009-12-09 10:09:53 -06:00
|
|
|
),
|
|
|
|
Output('total',
|
|
|
|
type=int,
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Total number of variables env (>= count)'),
|
2010-03-24 06:18:54 -05:00
|
|
|
flags=['no_display'],
|
2009-12-09 10:09:53 -06:00
|
|
|
),
|
|
|
|
Output('count',
|
|
|
|
type=int,
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Number of variables returned (<= total)'),
|
2010-03-24 06:18:54 -05:00
|
|
|
flags=['no_display'],
|
2009-12-09 10:09:53 -06:00
|
|
|
),
|
|
|
|
summary,
|
|
|
|
)
|
2008-11-12 02:47:37 -06:00
|
|
|
|
2008-11-14 22:58:39 -06:00
|
|
|
def __find_keys(self, variables):
|
2008-11-14 23:21:36 -06:00
|
|
|
keys = set()
|
|
|
|
for query in variables:
|
|
|
|
if '*' in query:
|
|
|
|
pat = re.compile(query.replace('*', '.*') + '$')
|
|
|
|
for key in self.env:
|
|
|
|
if pat.match(key):
|
|
|
|
keys.add(key)
|
|
|
|
elif query in self.env:
|
|
|
|
keys.add(query)
|
2009-10-13 12:28:00 -05:00
|
|
|
return keys
|
2008-11-12 01:46:04 -06:00
|
|
|
|
2008-11-14 22:58:39 -06:00
|
|
|
def execute(self, variables, **options):
|
2008-11-12 02:47:37 -06:00
|
|
|
if variables is None:
|
2008-11-14 23:21:36 -06:00
|
|
|
keys = self.env
|
|
|
|
else:
|
|
|
|
keys = self.__find_keys(variables)
|
2009-12-09 10:09:53 -06:00
|
|
|
ret = dict(
|
|
|
|
result=dict(
|
|
|
|
(key, self.env[key]) for key in keys
|
|
|
|
),
|
|
|
|
count=len(keys),
|
|
|
|
total=len(self.env),
|
2008-11-14 23:21:36 -06:00
|
|
|
)
|
2009-12-09 10:09:53 -06:00
|
|
|
if len(keys) > 1:
|
|
|
|
ret['summary'] = self.msg_summary % ret
|
|
|
|
else:
|
|
|
|
ret['summary'] = None
|
|
|
|
return ret
|
2008-10-30 03:20:28 -05:00
|
|
|
|
2008-11-12 01:46:04 -06:00
|
|
|
api.register(env)
|
2008-11-16 20:50:17 -06:00
|
|
|
|
|
|
|
|
|
|
|
class plugins(LocalOrRemote):
|
|
|
|
"""Show all loaded plugins"""
|
|
|
|
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = ngettext(
|
|
|
|
'%(count)d plugin loaded', '%(count)d plugins loaded'
|
|
|
|
)
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
Output('result', dict, 'Dictionary mapping plugin names to bases'),
|
|
|
|
Output('count',
|
|
|
|
type=int,
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('Number of plugins loaded'),
|
2009-12-09 10:09:53 -06:00
|
|
|
),
|
|
|
|
summary,
|
|
|
|
)
|
|
|
|
|
2008-11-16 20:50:17 -06:00
|
|
|
def execute(self, **options):
|
|
|
|
plugins = sorted(self.api.plugins, key=lambda o: o.plugin)
|
2009-12-09 10:09:53 -06:00
|
|
|
return dict(
|
|
|
|
result=dict(
|
|
|
|
(p.plugin, p.bases) for p in plugins
|
|
|
|
),
|
|
|
|
count=len(plugins),
|
2008-11-16 20:50:17 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
api.register(plugins)
|