diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-12-14 10:57:38 +0000 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-12-14 10:57:38 +0000 |
commit | a7d87ec40695bb2d839c2eeb4150d571adf15e8c (patch) | |
tree | 6b28cd5edb13b6a2a3fb0496814cf0158fbae335 | |
parent | 9b6328746a309888af399c1bcdad2aa9ab6c8a3b (diff) | |
download | pykolab-a7d87ec40695bb2d839c2eeb4150d571adf15e8c.tar.gz |
Add conf command group
21 files changed, 1539 insertions, 0 deletions
diff --git a/pykolab/cli/conf/__init__.py b/pykolab/cli/conf/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pykolab/cli/conf/__init__.py diff --git a/pykolab/cli/conf/cmd_add_role.py b/pykolab/cli/conf/cmd_add_role.py new file mode 100644 index 0000000..7b0076f --- /dev/null +++ b/pykolab/cli/conf/cmd_add_role.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('add_role', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--role', + dest = "role", + action = "store", + default = None, + metavar = "ROLE", + help = _("Add role ROLE.") + ) + +def description(): + return """Add a role.""" + +def execute(*args, **kw): + if conf.role == None: + try: + conf.role = conf.cli_args.pop(0) + except IndexError, errmsg: + print >> sys.stderr, _("Specify a role to add") + sys.exit(1) + + role = confmgmt.add_role(conf.role) diff --git a/pykolab/cli/conf/cmd_file_add_setting.py b/pykolab/cli/conf/cmd_file_add_setting.py new file mode 100644 index 0000000..e90e2e8 --- /dev/null +++ b/pykolab/cli/conf/cmd_file_add_setting.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('file_add_setting', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--file', + dest = "_file", + action = "store", + default = None, + metavar = "FILE", + help = _("Add file FILE") + ) + + my_option_group.add_option( + '--role', + dest = "roles", + action = "append", + default = [], + metavar = "ROLE", + help = _("Exclusively associate the setting for file FILE with role ROLE. May be specified multiple times to associate the file setting with multiple roles.") + ) + + my_option_group.add_option( + '--key', + dest = "key", + action = "store", + default = None, + metavar = "KEY", + help = _("The key or 'name' for the setting.") + ) + + my_option_group.add_option( + '--value', + dest = "value", + action = "store", + default = None, + metavar = "VALUE", + help = _("Set to value VALUE.") + ) + + my_option_group.add_option( + '--function', + dest = "function", + action = "store", + default = None, + metavar = "FUNCTION", + help = _("Set to function FUNCTION.") + ) + +def description(): + return """Add a managed setting with key KEY in file FILE.""" + +def execute(*args, **kw): + if conf._file == None: + print >> sys.stderr, _("Must specify a file.") + sys.exit(1) + + if conf.key == None: + print >> sys.stderr, _("Must specify a key.") + sys.exit(1) + + if conf.value == None and conf.function == None: + print >> sys.stderr, _("Must specify a value of a function to get the values with.") + sys.exit(1) + + if not conf.value == None and not conf.function == None: + print >> sys.stderr, _("Can only specify one of value or function.") + sys.exit(1) + + _file = confmgmt.get_file(conf._file) + + if _file == None: + print >> sys.stderr, _("File %s does not exist.") % (conf._file) + sys.exit(1) + + if conf.key in [x.key for x in _file.settings]: + print >> sys.stderr, _("Setting with key %s already managed in file %s") % (conf.key, conf._file) + sys.exit(1) + + setting = confmgmt.add_setting(conf.key, conf.value, conf.function) + + _file.settings.append(setting) + + for role_name in conf.roles: + role = confmgmt.get_role(role_name) + + if role == None: + log.warning(_("Role %s does not exist.") % (role_name)) + continue + + setting.roles.append(role) + + confmgmt.commit() diff --git a/pykolab/cli/conf/cmd_file_apply_settings.py b/pykolab/cli/conf/cmd_file_apply_settings.py new file mode 100644 index 0000000..cfeb481 --- /dev/null +++ b/pykolab/cli/conf/cmd_file_apply_settings.py @@ -0,0 +1,172 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +from augeas import Augeas +from Cheetah.Template import Template + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('file_apply_settings', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--file', + dest = "_file", + action = "store", + default = None, + metavar = "FILE", + help = _("Add file FILE") + ) + +def description(): + return """Apply managed settings to file FILE.""" + +def execute(*args, **kw): + if conf._file == None: + print >> sys.stderr, _("Must specify a file.") + sys.exit(1) + + _file = confmgmt.get_file(conf._file) + + if _file == None: + print >> sys.stderr, _("File %s is not managed.") % (conf._file) + sys.exit(1) + + if len(_file.settings) < 1: + print >> sys.stderr, _("No managed settings for file %s.") % (conf._file) + sys.exit(1) + + node = confmgmt.get_node(constants.fqdn) + + if node == None: + print >> sys.stderr, _("This node (%s) is not managed.") % (constants.fqdn) + sys.exit(1) + + myaugeas = Augeas() + myaugeas.set('/augeas/load/Postfix_LDAP/lens', '@Postfix_Main') + myaugeas.set('/augeas/load/Postfix_LDAP/incl', "/etc/postfix/ldap/*.cf") + myaugeas.load() + + for role in node.roles: + #print role + for service in role.services: + #print service + for _file in service.files: + #print _file + if _file.path == conf._file: + _cheetah_searchlist = {} + for setting in _file.settings: + #print "node role names", [haystack.name for haystack in node.roles] + #print "setting role names", [needle.name for needle in setting.roles] + #print [needle.name for needle in setting.roles if needle.name in [haystack.name for haystack in node.roles]] + if len(setting.roles) > 0: + if (len([needle.name for needle in setting.roles if needle.name in [haystack.name for haystack in node.roles]]) > 0): + if not setting.function == None: + exec("retval = %s" % (setting.function)) + if isinstance(retval, list): + new_setting = ' '.join(retval) + else: + new_setting = retval + + if _file.tech == 'augeas': + current_value = myaugeas.get('/files%s/%s' % (_file.path, setting.key)) + if not new_setting == current_value: + myaugeas.set('/files%s/%s' % (_file.path, setting.key), new_setting) + elif _file.tech == 'cheetah': + _cheetah_searchlist[setting.key] = new_setting + + else: + if _file.tech == 'augeas': + current_value = myaugeas.get('/files%s/%s' % (_file.path, setting.key)) + if not setting.value == current_value: + myaugeas.set('/files%s/%s' % (_file.path, setting.key), setting.value) + elif _file.tech == 'cheetah': + _cheetah_searchlist[setting.key] = setting.value + else: + if not setting.function == None: + exec("retval = %s" % (setting.function)) + if isinstance(retval, list): + new_setting = ' '.join(retval) + else: + new_setting = retval + + if _file.tech == 'augeas': + current_value = myaugeas.get('/files%s/%s' % (_file.path, setting.key)) + if not new_setting == current_value: + myaugeas.set('/files%s/%s' % (_file.path, setting.key), new_setting) + elif _file.tech == 'cheetah': + _cheetah_searchlist[setting.key] = new_setting + + else: + if _file.tech == 'augeas': + current_value = myaugeas.get('/files%s/%s' % (_file.path, setting.key)) + if not setting.value == current_value: + myaugeas.set('/files%s/%s' % (_file.path, setting.key), setting.value) + elif _file.tech == 'cheetah': + _cheetah_searchlist[setting.key] = setting.value + + if _file.tech == 'cheetah': + _cheetah_searchlist['conf'] = conf + + _file_basename = os.path.basename(_file.path) + if os.path.isfile('/etc/kolab/templates/roundcubemail/%s.tpl' % (_file_basename)): + template_file = '/etc/kolab/templates/roundcubemail/%s.tpl' % (_file_basename) + elif os.path.isfile('/usr/share/kolab/templates/roundcubemail/%s.tpl' % (_file_basename)): + template_file = '/usr/share/kolab/templates/roundcubemail/%s.tpl' % (_file_basename) + elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'roundcubemail', '%s.tpl' % (_file_basename)))): + template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'roundcubemail', '%s.tpl' % (_file_basename))) + + if not template_file == None: + log.debug(_("Using template file %r") % (template_file), level=8) + fp = open(template_file, 'r') + template_definition = fp.read() + fp.close() + + t = Template(template_definition, searchList=[_cheetah_searchlist]) + + print t.__dict__ + print "Settings:", t._CHEETAH_requiredCheetahMethods + + log.debug( + _("Successfully compiled template %r, writing out to %r") % ( + template_file, + '/etc/roundcubemail/%s' % (_file_basename) + ), + level=8 + ) + + fp = open('/etc/roundcubemail/%s.new' % (_file_basename), 'w') + fp.write(t.__str__()) + fp.close() + else: + myaugeas.save() diff --git a/pykolab/cli/conf/cmd_file_list_settings.py b/pykolab/cli/conf/cmd_file_list_settings.py new file mode 100644 index 0000000..9fc9045 --- /dev/null +++ b/pykolab/cli/conf/cmd_file_list_settings.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('file_list_settings', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--file', + dest = "_file", + action = "store", + default = None, + metavar = "FILE", + help = _("List settings for file FILE") + ) + + my_option_group.add_option( + '--values', + dest = "values", + action = "store_true", + default = False, + help = _("Include values when listing settings.") + ) + +def description(): + return """List managed settings for file FILE.""" + +def execute(*args, **kw): + if conf._file == None: + print >> sys.stderr, _("Unwilling to list all settings for all files. Specify a file path with --file.") + sys.exit(1) + + _file = confmgmt.get_file(conf._file) + + if _file == None: + print >> sys.stderr, _("No such file %s") %(conf._file) + sys.exit(1) + + for setting in _file.settings: + if len(setting.roles) > 0: + print "- %s (Roles: %s)" % (setting.key, ', '.join([x.name for x in setting.roles])) + else: + print "- %s" % (setting.key) + + if conf.values: + if not setting.value == None: + print "%-4s Value: %s" % ('', setting.value) + elif not setting.function == None: + print "%-4s Function: %s" % ('', setting.function) diff --git a/pykolab/cli/conf/cmd_file_set_setting.py b/pykolab/cli/conf/cmd_file_set_setting.py new file mode 100644 index 0000000..9bea1bf --- /dev/null +++ b/pykolab/cli/conf/cmd_file_set_setting.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('file_set_setting', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--file', + dest = "_file", + action = "store", + default = None, + metavar = "FILE", + help = _("Add file FILE") + ) + + my_option_group.add_option( + '--role', + dest = "roles", + action = "append", + default = [], + metavar = "ROLE", + help = _("Exclusively associate the setting for file FILE with role ROLE. May be specified multiple times to associate the file setting with multiple roles.") + ) + + my_option_group.add_option( + '--key', + dest = "key", + action = "store", + default = None, + metavar = "KEY", + help = _("The key or 'name' for the setting.") + ) + + my_option_group.add_option( + '--value', + dest = "value", + action = "store", + default = None, + metavar = "VALUE", + help = _("Set to value VALUE.") + ) + + my_option_group.add_option( + '--function', + dest = "function", + action = "store", + default = None, + metavar = "FUNCTION", + help = _("Set to function FUNCTION.") + ) + +def description(): + return """Change the value or function for a managed setting with key KEY in file FILE.""" + +def execute(*args, **kw): + if conf._file == None: + print >> sys.stderr, _("Must specify a file.") + sys.exit(1) + + if conf.key == None: + print >> sys.stderr, _("Must specify a key.") + sys.exit(1) + + if conf.value == None and conf.function == None: + print >> sys.stderr, _("Must specify a value or a function to get the values with.") + sys.exit(1) + + if not conf.value == None and not conf.function == None: + print >> sys.stderr, _("Can only specify one of value or function.") + sys.exit(1) + + _file = confmgmt.get_file(conf._file) + + if _file == None: + print >> sys.stderr, _("File %s does not exist.") % (conf._file) + sys.exit(1) + + if not conf.key in [x.key for x in _file.settings]: + print >> sys.stderr, _("Setting with key %s is not managed in file %s") % (conf.key, conf._file) + sys.exit(1) + + setting = confmgmt.get_setting(conf.key, conf._file) + + if setting == None: + print >> sys.stderr, _("Setting with key %s is not managed in file %s") % (conf.key, conf._file) + sys.exit(1) + + if not conf.value == None: + setting.value = conf.value + elif not conf.function == None: + setting.function = conf.function + + confmgmt.commit() diff --git a/pykolab/cli/conf/cmd_init.py b/pykolab/cli/conf/cmd_init.py new file mode 100644 index 0000000..ec6286d --- /dev/null +++ b/pykolab/cli/conf/cmd_init.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import utils +from pykolab.cli import commands +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('init', execute, group='conf', description=description()) + +def description(): + return """Initialize configuration management.""" + +def execute(*args, **kw): + for environment in [ "development", "testing", "production" ]: + confmgmt.add_environment(environment) + + for role in [ "imap-server", "imap-server-frontend", "imap-server-mupdate", "imap-server-backend" ]: + confmgmt.add_role(role)
\ No newline at end of file diff --git a/pykolab/cli/conf/cmd_list_environments.py b/pykolab/cli/conf/cmd_list_environments.py new file mode 100644 index 0000000..92bee0f --- /dev/null +++ b/pykolab/cli/conf/cmd_list_environments.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_environments', execute, group='conf', description=description()) + +def description(): + return """List environments.""" + +def execute(*args, **kw): + environments = confmgmt.list_environments() + + for environment in environments: + print "- %s" % (environment.name) diff --git a/pykolab/cli/conf/cmd_list_files.py b/pykolab/cli/conf/cmd_list_files.py new file mode 100644 index 0000000..9db5045 --- /dev/null +++ b/pykolab/cli/conf/cmd_list_files.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_files', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--service', + dest = "service", + action = "store", + default = None, + metavar = "SERVICE", + help = _("List only files associated with service SERVICE.") + ) + +def description(): + return """List files (for service SERVICE).""" + +def execute(*args, **kw): + files = confmgmt.list_files() + + if not conf.service == None: + service = confmgmt.get_service(conf.service) + if service == None: + print >> sys.stderr, _("No such service %s") % (conf.service) + sys.exit(1) + + for _file in files: + if not conf.service == None: + if service.name in [x.name for x in _file.services]: + print "- %s" % (_file.path) + else: + print "- %s" % (_file.path) diff --git a/pykolab/cli/conf/cmd_list_nodes.py b/pykolab/cli/conf/cmd_list_nodes.py new file mode 100644 index 0000000..853553d --- /dev/null +++ b/pykolab/cli/conf/cmd_list_nodes.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_nodes', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--environment', + dest = "environment", + action = "store", + default = None, + metavar = "ENVIRONMENT", + help = _("List only nodes in environment ENVIRONMENT.") + ) + +def description(): + return """List nodes (in environment ENVIRONMENT).""" + +def execute(*args, **kw): + nodes = confmgmt.list_nodes() + + if not conf.environment == None: + environment = confmgmt.get_environment(conf.environment) + if environment == None: + print >> sys.stderr, _("No such environment %s") % (conf.environment) + sys.exit(1) + + for node in nodes: + if not conf.environment == None and node.environment == environment: + print "- %s" % (node.fqdn) + else: + print "- %s" % (node.fqdn) diff --git a/pykolab/cli/conf/cmd_list_orphans.py b/pykolab/cli/conf/cmd_list_orphans.py new file mode 100644 index 0000000..e312318 --- /dev/null +++ b/pykolab/cli/conf/cmd_list_orphans.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_orphans', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--purge', + dest = "purge", + action = "store_true", + default = False, + help = _("Purge orphaned objects.") + ) + + my_option_group.add_option( + '--files', + dest = "files", + action = "store_true", + default = False, + help = _("List orphaned files.") + ) + + my_option_group.add_option( + '--roles', + dest = "roles", + action = "store_true", + default = False, + help = _("List orphaned roles.") + ) + + my_option_group.add_option( + '--services', + dest = "services", + action = "store_true", + default = False, + help = _("List orphaned services.") + ) + +def description(): + return """List files, services, settings, roles, etc. that are not associated with anything else.""" + +def execute(*args, **kw): + if conf.files: + files = confmgmt.list_files() + + for _file in files: + if len(_file.services) < 1: + print _("File %s not associated with any services.") % (_file.path) + + if len(_file.settings) < 1: + print _("File %s has no settings associated with it.") % (_file.path) + + if conf.roles: + roles = confmgmt.list_roles() + + for role in roles: + if len(role.nodes) < 1: + print _("Role %s not associated with any nodes.") % (role.name) + + if len(role.services) < 1: + print _("Role %s has no services associated with it.") % (role.name) + + if conf.services: + services = confmgmt.list_services() + + for service in services: + if len(service.roles) < 1: + print _("Service %s not associated with any roles.") % (service.name) diff --git a/pykolab/cli/conf/cmd_list_roles.py b/pykolab/cli/conf/cmd_list_roles.py new file mode 100644 index 0000000..e59ca85 --- /dev/null +++ b/pykolab/cli/conf/cmd_list_roles.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_roles', execute, group='conf', description=description()) + +def description(): + return """List roles.""" + +def execute(*args, **kw): + roles = confmgmt.list_roles() + + for role in roles: + print "- %s" % (role.name) diff --git a/pykolab/cli/conf/cmd_node_add_role.py b/pykolab/cli/conf/cmd_node_add_role.py new file mode 100644 index 0000000..1f73109 --- /dev/null +++ b/pykolab/cli/conf/cmd_node_add_role.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_add_role', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("Add role ROLE to node FQDN") + ) + + my_option_group.add_option( + '--role', + dest = "role", + action = "store", + default = None, + metavar = "ROLE", + help = _("Add role ROLE") + ) + +def description(): + return """Add role to node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + role = confmgmt.get_role(conf.role) + + if node == None: + print >> sys.stderr, _("No such node %s") % (conf.node) + sys.exit(1) + + if role == None: + print >> sys.stderr, _("No such role %s") % (conf.role) + sys.exit(1) + + if role in node.roles: + print >> sys.stderr, _("Node %s already has role %s") % (conf.node, conf.role) + sys.exit(1) + + confmgmt.add_node_role(node, role) diff --git a/pykolab/cli/conf/cmd_node_list_files.py b/pykolab/cli/conf/cmd_node_list_files.py new file mode 100644 index 0000000..00b4e39 --- /dev/null +++ b/pykolab/cli/conf/cmd_node_list_files.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_list_files', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("List services (for node FQDN)") + ) + +def description(): + return """List files with managed settings applicable to node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + + if node == None: + print >> sys.stderr, _("No such node %s") %(conf.node) + sys.exit(1) + + files = confmgmt.get_node_files(conf.node) + + for _file in files: + if _file.tech == "augeas": + print "- %s" % (_file.path) + else: + print "- %s (%s)" % (_file.path, _file.tech) diff --git a/pykolab/cli/conf/cmd_node_list_roles.py b/pykolab/cli/conf/cmd_node_list_roles.py new file mode 100644 index 0000000..075e0fd --- /dev/null +++ b/pykolab/cli/conf/cmd_node_list_roles.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_list_roles', execute, group='conf', description=description(), aliases=['list_node_roles']) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("List roles (for node FQDN)") + ) + +def description(): + return """List roles for node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + + if node == None: + print >> sys.stderr, _("No such node %s") %(conf.node) + sys.exit(1) + + for role in node.roles: + print "- %s" % (role.name) diff --git a/pykolab/cli/conf/cmd_node_list_services.py b/pykolab/cli/conf/cmd_node_list_services.py new file mode 100644 index 0000000..e3491c8 --- /dev/null +++ b/pykolab/cli/conf/cmd_node_list_services.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_list_services', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("List services (for node FQDN)") + ) + +def description(): + return """List services for node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + + if node == None: + print >> sys.stderr, _("No such node %s") %(conf.node) + sys.exit(1) + + for role in node.roles: + for service in role.services: + print "- %s" % (service.name) diff --git a/pykolab/cli/conf/cmd_node_list_settings.py b/pykolab/cli/conf/cmd_node_list_settings.py new file mode 100644 index 0000000..ca336d6 --- /dev/null +++ b/pykolab/cli/conf/cmd_node_list_settings.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_list_settings', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("List settings for node FQDN") + ) + + my_option_group.add_option( + '--file', + dest = "_file", + action = "store", + default = None, + metavar = "FILE", + help = _("List settings for file FILE") + ) + +def description(): + return """List managed settings (for file FILE) applicable to node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + + if node == None: + print >> sys.stderr, _("No such node %s") %(conf.node) + sys.exit(1) + + files = confmgmt.get_node_files(conf.node) + + for _file in files: + print "File %s" % (_file.path) + if conf._file == None or conf._file == _file.path: + for setting in _file.settings: + if len(setting.roles) > 0: + is_my_role_too = False + for _role in setting.roles: + if _role in node.roles: + is_my_role_too = True + + if not is_my_role_too: + continue + + print "%-3s %s" % ('', setting.key) diff --git a/pykolab/cli/conf/cmd_node_remove_role.py b/pykolab/cli/conf/cmd_node_remove_role.py new file mode 100644 index 0000000..58aa605 --- /dev/null +++ b/pykolab/cli/conf/cmd_node_remove_role.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('node_remove_role', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--node', + dest = "node", + action = "store", + default = constants.fqdn, + metavar = "FQDN", + help = _("Remove role ROLE from node FQDN") + ) + + my_option_group.add_option( + '--role', + dest = "role", + action = "store", + default = None, + metavar = "ROLE", + help = _("Remove role ROLE") + ) + +def description(): + return """Remove role from node.""" + +def execute(*args, **kw): + node = confmgmt.get_node(conf.node) + role = confmgmt.get_role(conf.role) + + if node == None: + print >> sys.stderr, _("No such node %s") %(conf.node) + sys.exit(1) + + if role == None: + print >> sys.stderr, _("No such role %s") %(conf.role) + sys.exit(1) + + confmgmt.remove_node_role(node, role) diff --git a/pykolab/cli/conf/cmd_remove_environment.py b/pykolab/cli/conf/cmd_remove_environment.py new file mode 100644 index 0000000..ba54d0d --- /dev/null +++ b/pykolab/cli/conf/cmd_remove_environment.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('remove_environment', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--environment', + dest = "environment", + action = "store", + default = None, + metavar = "ENVIRONMENT", + help = _("Remove environment ENVIRONMENT.") + ) + +def description(): + return """Remove an environment.""" + +def execute(*args, **kw): + if conf.environment == None: + try: + conf.environment = conf.cli_args.pop(0) + except IndexError, errmsg: + print >> sys.stderr, _("Must specify an environment name to delete an environment.") + sys.exit(1) + + environment = confmgmt.get_environment(conf.environment) + + if environment == None: + print >> sys.stderr, _("No environment with name %s exists.") % (conf.environment) + sys.exit(1) + + confmgmt.remove_environment(environment)
\ No newline at end of file diff --git a/pykolab/cli/conf/cmd_remove_role.py b/pykolab/cli/conf/cmd_remove_role.py new file mode 100644 index 0000000..2ac9637 --- /dev/null +++ b/pykolab/cli/conf/cmd_remove_role.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('remove_role', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--role', + dest = "role", + action = "store", + default = None, + metavar = "ROLE", + help = _("Remove role ROLE.") + ) + +def description(): + return """Remove a role.""" + +def execute(*args, **kw): + if conf.role == None: + try: + conf.role = conf.cli_args.pop(0) + except IndexError, errmsg: + print >> sys.stderr, _("Must specify a role name to delete a role.") + sys.exit(1) + + role = confmgmt.get_role(conf.role) + + if role == None: + print >> sys.stderr, _("No role with name %s exists.") % (conf.role) + sys.exit(1) + + confmgmt.remove_role(role) diff --git a/pykolab/cli/conf/cmd_role_add_service.py b/pykolab/cli/conf/cmd_role_add_service.py new file mode 100644 index 0000000..30db5be --- /dev/null +++ b/pykolab/cli/conf/cmd_role_add_service.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> +# +# 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 3 or, at your option, any later version +# +# 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 Library 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. +# + +import sys +import time + +import pykolab + +from pykolab import confmgmt +from pykolab import constants +from pykolab.cli import commands +from pykolab.confmgmt.db import get_db +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('role_add_service', execute, group='conf', description=description()) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( + '--role', + dest = "role", + action = "store", + default = None, + metavar = "ROLE", + help = _("Use role ROLE") + ) + + my_option_group.add_option( + '--service', + dest = "service", + action = "store", + default = None, + metavar = "SERVICE", + help = _("Use service SERVICE") + ) + +def description(): + return """Associate a service with a role.""" + +def execute(*args, **kw): + role = confmgmt.get_role(conf.role) + service = confmgmt.get_service(conf.service) + + if role == None: + print >> sys.stderr, _("No such role %s") % (conf.role) + sys.exit(1) + + if service == None: + print >> sys.stderr, _("No such service %s") % (conf.service) + sys.exit(1) + + confmgmt.add_role_service(role, service) |