diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | cobbler.spec | 3 | ||||
-rw-r--r-- | cobbler/api.py | 12 | ||||
-rwxr-xr-x | cobbler/cobbler.py | 6 | ||||
-rw-r--r-- | cobbler/commands.py | 3 | ||||
-rw-r--r-- | cobbler/item_image.py | 4 | ||||
-rw-r--r-- | cobbler/modules/cli_image.py | 24 | ||||
-rw-r--r-- | config/cobbler_bash | 64 | ||||
-rw-r--r-- | setup.py | 2 |
11 files changed, 112 insertions, 9 deletions
@@ -38,6 +38,7 @@ Patches and other contributions from: Al Tobey <tobert@gmail.com> Ronald van den Blink <ronald@a61.nl> Thomas Uhde <thomas.uhde@KabelDeutschland.de> + John L. Villalovos <john@sodarock.com> Tim Verhoeven <tim.verhoeven.be@gmail.com> [...send patches to get your name here...] @@ -27,6 +27,7 @@ Cobbler CHANGELOG - s390x import, added support for s390x "pseudo-PXE" trees - added support for tracking image objects and virtual ISO images - support for multiple copies of the same kernel option in kopts +- add cobbler bash completion script - Mon Jun 09 2008 - 1.0.2 - Fix mkdir invocation diff --git a/MANIFEST.in b/MANIFEST.in index 3216946f..501ff838 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -12,6 +12,7 @@ include config/auth.conf include config/settings include config/users.digest include config/users.conf +include config/cobbler_bash recursive-include templates *.template recursive-include kickstarts *.ks include docs/cobbler.1.gz diff --git a/cobbler.spec b/cobbler.spec index f9786752..da9dfcf5 100644 --- a/cobbler.spec +++ b/cobbler.spec @@ -116,6 +116,9 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT %{_bindir}/cobbler %{_bindir}/cobblerd +%defattr(644,root,root) +%config(noreplace) /etc/bash_completion.d/cobbler_bash + %defattr(-,root,root) %dir /etc/cobbler %config(noreplace) /etc/cobbler/*.ks diff --git a/cobbler/api.py b/cobbler/api.py index cd21000c..d1c5ecf8 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -57,6 +57,7 @@ class BootAPI: """ self.__dict__ = BootAPI.__shared_state + self.perms_ok = False if not BootAPI.__has_loaded: # NOTE: we do not log all API actions, because @@ -65,7 +66,13 @@ class BootAPI: # the logs, so we'll do that logging at CLI # level (and remote.py web service level) instead. - self.logger = self.__setup_logger("api") + try: + self.logger = self.__setup_logger("api") + except CX: + # return to CLI/other but perms are not valid + # perms_ok is False + return + self.logger_remote = self.__setup_logger("remote") BootAPI.__has_loaded = True @@ -85,7 +92,8 @@ class BootAPI: ) self.kickgen = kickgen.KickGen(self._config) self.logger.debug("API handle initialized") - + self.perms_ok = True + def __setup_logger(self,name): return utils.setup_logger(name) diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py index 97569d09..ff47917e 100755 --- a/cobbler/cobbler.py +++ b/cobbler/cobbler.py @@ -35,13 +35,17 @@ class BootCLI: def __init__(self): self.api = api.BootAPI() - self.loader = commands.FunctionLoader() + self.loader = commands.FunctionLoader(self.api) climods = self.api.get_modules_in_category("cli") for mod in climods: for fn in mod.cli_functions(self.api): self.loader.add_func(fn) def run(self,args): + if not self.api.perms_ok: + print "Insufficient permissions. Use cobbler aclsetup to grant access to non-roo tusers." + sys.exit(1) + return self.loader.run(args) #################################################### diff --git a/cobbler/commands.py b/cobbler/commands.py index 7ddb712f..985e7e93 100644 --- a/cobbler/commands.py +++ b/cobbler/commands.py @@ -27,10 +27,11 @@ class FunctionLoader: The F'n Loader controls processing of cobbler commands. """ - def __init__(self): + def __init__(self, api): """ When constructed the loader has no functions. """ + self.api = api self.functions = {} def add_func(self, obj): diff --git a/cobbler/item_image.py b/cobbler/item_image.py index db40a777..67aefe4a 100644 --- a/cobbler/item_image.py +++ b/cobbler/item_image.py @@ -120,9 +120,9 @@ class Image(item.Item): without a kickstart is *usually* not a good idea). """ if self.file is None or self.file == '': - raise CX(_("no file specified")) + raise CX(_("image has file specified")) if self.name is None or self.name == '': - raise CX(_("no name specified")) + raise CX(_("image has no name specified")) return True # FIXME: add virt parameters here as needed diff --git a/cobbler/modules/cli_image.py b/cobbler/modules/cli_image.py index ea4edd93..aa6a2162 100644 --- a/cobbler/modules/cli_image.py +++ b/cobbler/modules/cli_image.py @@ -58,6 +58,18 @@ class ImageFunction(commands.CobblerFunction): p.add_option("--no-triggers", action="store_true", dest="notriggers", help="suppress trigger execution") if not self.matches_args(args,["dumpvars","remove","report","list"]): p.add_option("--owners", dest="owners", help="specify owners for authz_ownership module") + if not self.matches_args(args,["dumpvars","remove","report","list"]): + # virt ram + # virt cpus + # virt bridge + p.add_option("--virt-cpus", dest="virt_cpus", help="specify VCPU count") + p.add_option("--virt-bridge", dest="virt_bridge", help="ex: virbr0") + p.add_option("--virt-file-size", dest="virt_file_size", help="size in GB (not for use with non-ISO virt-images), ex: 5") + p.add_option("--virt-path", dest="virt_path", help="virt install location") + p.add_option("--virt-type", dest="virt_type", help="virt install type (ISOs only)") + p.add_option("--virt-ram", dest="virt_ram", help="ex: 1024") + p.add_option("--xml-file", dest="xml_file", help="associate a virt-image XML template (needed for VM cloning)") + def run(self): @@ -75,9 +87,15 @@ class ImageFunction(commands.CobblerFunction): return self.object_manipulator_finish(obj, self.api.images, self.options) if self.options.file: obj.set_file(self.options.file) - - if self.options.owners: - obj.set_owners(self.options.owners) + if self.options.owners: obj.set_owners(self.options.owners) + if self.options.virt_bridge: obj.set_file(self.options.virt_bridge) + if self.options.virt_path: obj.set_virt_path(self.options.virt_path) + if self.options.virt_file_size: obj.set_virt_file_size(self.options.virt_file_size) + if self.options.virt_bridge: obj.set_virt_bridge(self.options.virt_bridge) + if self.options.virt_cpus: obj.set_virt_cpus(self.options.virt_cpus) + if self.options.virt_ram: obj.set_virt_ram(self.options.virt_ram) + if self.options.virt_type: obj.set_virt_type(self.options.virt_type) + if self.options.xml_file: obj.set_xml_file(self.options.xml_file) return self.object_manipulator_finish(obj, self.api.images, self.options) diff --git a/config/cobbler_bash b/config/cobbler_bash new file mode 100644 index 00000000..c4f78649 --- /dev/null +++ b/config/cobbler_bash @@ -0,0 +1,64 @@ +#!/bin/bash +# The #! is here so vim will do syntax highlighting. emacs: -*- sh -*- +# +# bash completion file for cobbler +# +# Copyright 2008 John L. Villalovos <john@sodarock.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; either version 2 of the License, 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 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., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Version History: +# 0.1: Initial version to do some basic command line completion + +_cobbler() +{ + local cur prev + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $cur in + --*) + COMPREPLY=( $( compgen -W 'help' -- $cur ) ) + return 0 + ;; + -*) + COMPREPLY=( $( compgen -W '-h' -- $cur ) ) + return 0 + ;; + esac + + _count_args + + case $args in + 1) + COMPREPLY=( $( compgen -W 'buildiso check distro import list \ + profile replicate repo report reposync status sync system \ + validateks' -- $cur ) ) + ;; + *) + case $prev in + distro|profile|repo|system) + COMPREPLY=( $( compgen -W 'add edit copy list rename remove report' -- $cur ) ) + ;; + *) + _filedir + ;; + esac + ;; + esac +} +complete -F _cobbler cobbler @@ -12,6 +12,7 @@ Cobbler is a network boot and update server. Cobbler supports PXE, provisioning if __name__ == "__main__": # docspath="share/doc/koan-%s/" % VERSION + bashpath = "/etc/bash_completion.d/" manpath = "share/man/man1/" cobpath = "/var/lib/cobbler/" backpath = "/var/lib/cobbler/backup/" @@ -81,6 +82,7 @@ if __name__ == "__main__": (etcpath, ['config/users.conf']), (initpath, ['config/cobblerd']), (etcpath, ['config/settings']), + (bashpath, ['config/cobbler_bash']), # backups for upgrades (backpath, []), |