diff options
Diffstat (limited to 'cobbler/modules')
-rw-r--r-- | cobbler/modules/authn_configfile.py | 76 | ||||
-rw-r--r-- | cobbler/modules/authn_kerberos.py | 81 | ||||
-rw-r--r-- | cobbler/modules/authz_allowall.py | 41 | ||||
-rw-r--r-- | cobbler/modules/cli_distro.py | 95 | ||||
-rw-r--r-- | cobbler/modules/cli_misc.py | 259 | ||||
-rw-r--r-- | cobbler/modules/cli_profile.py | 114 | ||||
-rw-r--r-- | cobbler/modules/cli_repo.py | 97 | ||||
-rw-r--r-- | cobbler/modules/cli_system.py | 120 |
8 files changed, 883 insertions, 0 deletions
diff --git a/cobbler/modules/authn_configfile.py b/cobbler/modules/authn_configfile.py new file mode 100644 index 0000000..ffe87a7 --- /dev/null +++ b/cobbler/modules/authn_configfile.py @@ -0,0 +1,76 @@ +""" +Authentication module that uses /etc/cobbler/auth.conf +Choice of authentication module is in /etc/cobbler/modules.conf + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import ConfigParser +import sys +import os +from rhpl.translate import _, N_, textdomain, utf8 +import md5 +import traceback + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +import cexceptions +import utils + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "authn" + +def __parse_storage(): + + if not os.path.exists("/etc/cobbler/users.digest"): + return [] + fd = open("/etc/cobbler/users.digest") + data = fd.read() + fd.close() + results = [] + lines = data.split("\n") + for line in lines: + try: + line = line.strip() + tokens = line.split(":") + results.append([tokens[0],tokens[1],tokens[2]]) + except: + pass + return results + +def authenticate(api_handle,username,password): + """ + Validate a username/password combo, returning True/False + + Thanks to http://trac.edgewall.org/ticket/845 for supplying + the algorithm info. + """ + + # debugging only (not safe to enable) + # api_handle.logger.debug("backend authenticate (%s,%s)" % (username,password)) + + userlist = __parse_storage() + for (user,realm,actual_blob) in userlist: + if user == username and realm == "Cobbler": + input = ":".join([user,realm,password]) + input_blob = md5.md5(input).hexdigest() + if input_blob.lower() == actual_blob.lower(): + return True + + return False + + diff --git a/cobbler/modules/authn_kerberos.py b/cobbler/modules/authn_kerberos.py new file mode 100644 index 0000000..7f85db6 --- /dev/null +++ b/cobbler/modules/authn_kerberos.py @@ -0,0 +1,81 @@ +""" +Authentication module that uses kerberos. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +# NOTE: this is not using 'straight up' kerberos in that we +# relay passwords through cobblerd for authentication, that may +# be done later. It does of course check against kerberos, +# however. + +# ALSO NOTE: we're calling out to a Perl program to make +# this work. You must install Authen::Simple::Kerberos +# from CPAN and the Kerberos libraries for this to work. +# See the Cobbler Wiki for more info. + +# ALSO ALSO NOTE: set kerberos_realm in /var/lib/cobbler/settings +# to something appropriate or this will never work. CASING +# MATTERS. example.com != EXAMPLE.COM. + +import distutils.sysconfig +import ConfigParser +import sys +import os +from rhpl.translate import _, N_, textdomain, utf8 +import md5 +import traceback +# since sub_process isn't available on older OS's +try: + import sub_process as subprocess +except: + import subprocess + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +import cexceptions +import utils + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "authn" + +def authenticate(api_handle,username,password): + """ + Validate a username/password combo, returning True/False + Uses cobbler_auth_helper + """ + + realm = self.api.settings().kerberos_realm + api_handle.logger.debug("authenticating %s against %s" % (username,realm)) + + rc = subprocess.call([ + "/usr/bin/cobbler_auth_help", + "--method=kerberos", + "--username=%s" % username, + "--password=%s" % password, + "--realm=%s" % realm + ]) + print rc + if rc == 42: + api_handle.logger.debug("authenticated ok") + # authentication ok (FIXME: log) + return True + else: + api_handle.logger.debug("authentication failed") + # authentication failed + return False + + diff --git a/cobbler/modules/authz_allowall.py b/cobbler/modules/authz_allowall.py new file mode 100644 index 0000000..1b05630 --- /dev/null +++ b/cobbler/modules/authz_allowall.py @@ -0,0 +1,41 @@ +""" +Authorization module that allows everything, which is the default +for new cobbler installs. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import ConfigParser +import sys +from rhpl.translate import _, N_, textdomain, utf8 + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +import cexceptions +import utils + + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "authz" + +def authorize(api_handle,user,resource,arg1=None,arg2=None): + """ + Validate a user against a resource. + """ + return True + + diff --git a/cobbler/modules/cli_distro.py b/cobbler/modules/cli_distro.py new file mode 100644 index 0000000..35f5a4b --- /dev/null +++ b/cobbler/modules/cli_distro.py @@ -0,0 +1,95 @@ +""" +Distro CLI module. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import sys + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +from rhpl.translate import _, N_, textdomain, utf8 +import commands +import cexceptions + + +class DistroFunction(commands.CobblerFunction): + + def help_me(self): + return commands.HELP_FORMAT % ("cobbler distro", "<add|edit|copy|list|rename|remove|report> [ARGS|--help]") + + def command_name(self): + return "distro" + + def subcommands(self): + return [ "add", "edit", "copy", "rename", "remove", "list", "report" ] + + def add_options(self, p, args): + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--arch", dest="arch", help="ex: x86, x86_64, ia64") + p.add_option("--breed", dest="breed", help="ex: redhat, debian, suse") + p.add_option("--initrd", dest="initrd", help="absolute path to initrd.img (REQUIRED)") + p.add_option("--kernel", dest="kernel", help="absolute path to vmlinuz (REQUIRED)") + p.add_option("--kopts", dest="kopts", help="ex: 'noipv6'") + p.add_option("--ksmeta", dest="ksmeta", help="ex: 'blippy=7'") + + p.add_option("--name", dest="name", help="ex: 'RHEL-5-i386' (REQUIRED)") + + if self.matches_args(args,["copy","rename"]): + p.add_option("--newname", dest="newname", help="for copy/rename commands") + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--no-sync", action="store_true", dest="nosync", help="suppress sync for speed") + if not self.matches_args(args,["report","list"]): + p.add_option("--no-triggers", action="store_true", dest="notriggers", help="suppress trigger execution") + + if self.matches_args(args,["remove"]): + p.add_option("--recursive", action="store_true", dest="recursive", help="also delete child objects") + + def run(self): + + obj = self.object_manipulator_start(self.api.new_distro,self.api.distros) + if obj is None: + return True + + if self.options.kernel: + obj.set_kernel(self.options.kernel) + if self.options.initrd: + obj.set_initrd(self.options.initrd) + if self.options.kopts: + obj.set_kernel_options(self.options.kopts) + if self.options.ksmeta: + obj.set_ksmeta(self.options.ksmeta) + if self.options.breed: + obj.set_breed(self.options.breed) + + return self.object_manipulator_finish(obj, self.api.distros, self.options) + + + +######################################################## +# MODULE HOOKS + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "cli" + +def cli_functions(api): + return [ + DistroFunction(api) + ] + + diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py new file mode 100644 index 0000000..881787b --- /dev/null +++ b/cobbler/modules/cli_misc.py @@ -0,0 +1,259 @@ +""" +Misc CLI functions. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import sys + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +from rhpl.translate import _, N_, textdomain, utf8 +import commands +from cexceptions import * +HELP_FORMAT = commands.HELP_FORMAT + +# TO DO list +# cobbler check +# cobbler import (--name, --mirror, --available-as) +# cobbler reserialize +# cobbler --type=[profile|system|distro|repo] [--name=list] +# cobbler --type=[profile|system|distro|profile] [--name=report] +# cobbler status +# cobbler reposync --name=$name +# cobbler sync +# cobbler validateks +# elsewhere: repo auto-add + +######################################################## + +class CheckFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler check","") + + def command_name(self): + return "check" + + def add_options(self, p, args): + pass + + def run(self): + status = self.api.check() + if len(status) == 0: + print _("No setup problems found") + print _("Manual review and editing of /var/lib/cobbler/settings is recommended to tailor cobbler to your particular configuration.") + print _("Good luck.") + return True + else: + print _("The following potential problems were detected:") + for i,x in enumerate(status): + print _("#%(number)d: %(problem)s") % { "number" : i, "problem" : x } + return False + +######################################################## + +class ImportFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler import","[ARGS|--help]") + + def command_name(self): + return "import" + + def add_options(self, p, args): + p.add_option("--mirror", dest="mirror", help="local path or rsync location (REQUIRED)") + p.add_option("--name", dest="name", help="name, ex 'RHEL-5', (REQUIRED)") + p.add_option("--available-as", dest="available_as", help="do not mirror, use this as install tree") + p.add_option("--kickstart", dest="kickstart_file", help="use the kickstart file specified as the profile's kickstart file") + p.add_option("--rsync-flags", dest="rsync_flags", help="pass additional flags to rsync") + + def run(self): + if not self.options.mirror: + raise CX(_("mirror is required")) + if not self.options.name: + raise CX(_("name is required")) + return self.api.import_tree( + self.options.mirror, + self.options.name, + network_root=self.options.available_as, + kickstart_file=self.options.kickstart_file, + rsync_flags=self.options.rsync_flags + ) + + +######################################################## + +class ReserializeFunction(commands.CobblerFunction): + + def help_me(self): + return "" # hide + + def command_name(self): + return "reserialize" + + def run(self): + # already deserialized when API is instantiated + # this just saves files in new config format (if any) + return self.api.serialize() + +######################################################## + +class ListFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler list","[ARGS|--help]") + + def command_name(self): + return "list" + + def add_options(self, p, args): + p.add_option("--what", dest="what", default="all", help="all/distros/profiles/systems/repos") + + def run(self): + if self.options.what not in [ "all", "distros", "profiles", "systems", "repos" ]: + raise CX(_("invalid value for --what")) + if self.options.what in [ "all" ]: + self.list_tree(self.api.distros(),0) + self.list_tree(self.api.repos(),0) + if self.options.what in [ "distros"]: + self.list_list(self.api.distros()) + if self.options.what in [ "profiles"]: + self.list_list(self.api.profiles()) + if self.options.what in [ "systems" ]: + self.list_list(self.api.systems()) + if self.options.what in [ "repos"]: + self.list_list(self.api.repos()) + +######################################################## + +class ReportFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler report","[ARGS|--help]") + + def command_name(self): + return "report" + + def add_options(self, p, args): + p.add_option("--what", dest="what", default="all", help="distros/profiles/systems/repos") + p.add_option("--name", dest="name", help="report on just this object") + + def run(self): + if self.options.what not in [ "all", "distros", "profiles", "systems", "repos" ]: + raise CX(_("Invalid value for --what")) + + if self.options.what in [ "all", "distros" ]: + if self.options.name: + self.reporting_list_names2(self.api.distros(),self.options.name) + else: + self.reporting_print_sorted(self.api.distros()) + + if self.options.what in [ "all", "profiles" ]: + if self.options.name: + self.reporting_list_names2(self.api.profiles(),self.options.name) + else: + self.reporting_print_sorted(self.api.profiles()) + + if self.options.what in [ "all", "systems" ]: + if self.options.name: + self.reporting_list_names2(self.api.systems(),self.options.name) + else: + self.reporting_print_sorted(self.api.systems()) + + if self.options.what in [ "all", "repos" ]: + if self.options.name: + self.reporting_list_names2(self.api.repos(),self.options.name) + else: + self.reporting_print_sorted(self.api.repos()) + return True + +## FIXME: add legacy command translator to keep things simple +## cobbler system report foo --> cobbler report --what=systems --name=foo +## cobbler system report --> cobbler report --what=systems +## ditto for "cobbler list" + +######################################################## + +class StatusFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler status","[ARGS|--help]") + + def command_name(self): + return "status" + + def run(self): + return self.api.status("text") # no other output modes supported yet + +######################################################## + +class SyncFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler sync","") + + def command_name(self): + return "sync" + + def run(self): + return self.api.sync() + +######################################################## + +class RepoSyncFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler reposync","[ARGS|--help]") + + def command_name(self): + return "reposync" + + def add_options(self, p, args): + p.add_option("--only", dest="only", help="update only this repository name") + + def run(self): + return self.api.reposync(self.options.only) + +######################################################## + +class ValidateKsFunction(commands.CobblerFunction): + + def help_me(self): + return HELP_FORMAT % ("cobbler validateks","") + + def command_name(self): + return "validateks" + + def run(self): + return self.api.validateks() + +######################################################## +# MODULE HOOKS + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "cli" + +def cli_functions(api): + return [ + CheckFunction(api), ImportFunction(api), ReserializeFunction(api), + ListFunction(api), ReportFunction(api), StatusFunction(api), + SyncFunction(api), RepoSyncFunction(api), ValidateKsFunction(api) + ] + return [] + + diff --git a/cobbler/modules/cli_profile.py b/cobbler/modules/cli_profile.py new file mode 100644 index 0000000..e9d1d23 --- /dev/null +++ b/cobbler/modules/cli_profile.py @@ -0,0 +1,114 @@ +""" +Profile CLI module. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import sys + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +from rhpl.translate import _, N_, textdomain, utf8 +import commands +import cexceptions + + +class ProfileFunction(commands.CobblerFunction): + + def help_me(self): + return commands.HELP_FORMAT % ("cobbler profile","<add|edit|copy|list|rename|remove|report> [ARGS|--help]") + + def command_name(self): + return "profile" + + def subcommands(self): + return [ "add", "edit", "copy", "rename", "remove", "list", "report" ] + + def add_options(self, p, args): + if not self.matches_args(args,["remove","report","list"]): + + p.add_option("--distro", dest="distro", help="ex: 'RHEL-5-i386' (REQUIRED)") + p.add_option("--dhcp-tag", dest="dhcp_tag", help="for use in advanced DHCP configuration") + p.add_option("--inherit", dest="inherit", help="inherit from this profile name, defaults to no") + p.add_option("--kickstart", dest="kickstart", help="absolute path to kickstart template (RECOMMENDED)") + p.add_option("--ksmeta", dest="ksmeta", help="ex: 'blippy=7'") + p.add_option("--kopts", dest="kopts", help="ex: 'noipv6'") + p.add_option("--name", dest="name", help="a name for the profile (REQUIRED)") + + if "copy" in args or "rename" in args: + p.add_option("--newname", dest="newname") + + if not self.matches_args(args,["remove","report", "list"]): + p.add_option("--no-sync", action="store_true", dest="nosync", help="suppress sync for speed") + if not self.matches_args(args,["report", "list"]): + p.add_option("--no-triggers", action="store_true", dest="notriggers", help="suppress trigger execution") + + if self.matches_args(args,["remove"]): + p.add_option("--recursive", action="store_true", dest="recursive", help="also delete child objects") + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--repos", dest="repos", help="names of cobbler repos") + p.add_option("--server-override", dest="server_override", help="overrides value in settings file") + p.add_option("--virt-bridge", dest="virt_bridge", help="ex: 'virbr0'") + p.add_option("--virt-cpus", dest="virt_cpus", help="integer (default: 1)") + p.add_option("--virt-file-size", dest="virt_file_size", help="size in GB") + p.add_option("--virt-path", dest="virt_path", help="path, partition, or volume") + p.add_option("--virt-ram", dest="virt_ram", help="size in MB") + p.add_option("--virt-type", dest="virt_type", help="ex: 'xenpv', 'qemu'") + + def run(self): + + + if self.matches_args(self.args,["report","list","remove"]) or not self.options.inherit: + obj = self.object_manipulator_start(self.api.new_profile,self.api.profiles,subobject=False) + else: + obj = self.object_manipulator_start(self.api.new_profile,self.api.profiles,subobject=True) + + if obj is None: + return True + + if self.options.inherit: obj.set_parent(self.options.inherit) + if self.options.distro: obj.set_distro(self.options.distro) + if self.options.kickstart: obj.set_kickstart(self.options.kickstart) + if self.options.kopts: obj.set_kernel_options(self.options.kopts) + if self.options.ksmeta: obj.set_ksmeta(self.options.ksmeta) + if self.options.virt_file_size: obj.set_virt_file_size(self.options.virt_file_size) + if self.options.virt_ram: obj.set_virt_ram(self.options.virt_ram) + if self.options.virt_bridge: obj.set_virt_bridge(self.options.virt_bridge) + if self.options.virt_type: obj.set_virt_type(self.options.virt_type) + if self.options.virt_cpus: obj.set_virt_cpus(self.options.virt_cpus) + if self.options.repos: obj.set_repos(self.options.repos) + if self.options.virt_path: obj.set_virt_path(self.options.virt_path) + if self.options.dhcp_tag: obj.set_dhcp_tag(self.options.dhcp_tag) + if self.options.server_override: obj.set_server(self.options.server) + + return self.object_manipulator_finish(obj, self.api.profiles, self.options) + + + +######################################################## +# MODULE HOOKS + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "cli" + +def cli_functions(api): + return [ + ProfileFunction(api) + ] + + diff --git a/cobbler/modules/cli_repo.py b/cobbler/modules/cli_repo.py new file mode 100644 index 0000000..96afa6f --- /dev/null +++ b/cobbler/modules/cli_repo.py @@ -0,0 +1,97 @@ +""" +Repo CLI module. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import sys + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +from rhpl.translate import _, N_, textdomain, utf8 +import commands +import cexceptions + + +class RepoFunction(commands.CobblerFunction): + + def help_me(self): + return commands.HELP_FORMAT % ("cobbler repo","<add|edit|copy|list|rename|remove|report> [ARGS|--help]") + + def command_name(self): + return "repo" + + def subcommands(self): + return [ "add", "edit", "copy", "rename", "remove", "list", "report" ] + + def add_options(self, p, args): + + if not self.matches_args(args,["remove","report","list"]): + + p.add_option("--arch", dest="arch", help="overrides repo arch if required") + p.add_option("--createrepo-flags", dest="createrepo_flags", help="additional flags for createrepo") + p.add_option("--keep-updated", dest="keep_updated", help="update on each reposync, yes/no") + + p.add_option("--name", dest="name", help="ex: 'Fedora-8-updates-i386' (REQUIRED)") + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--mirror", dest="mirror", help="source to mirror (REQUIRED)") + p.add_option("--priority", dest="priority", help="set priority") + p.add_option("--rpm-list", dest="rpm_list", help="just mirror these rpms") + p.add_option("--yumopts", dest="yumopts", help="ex: pluginvar=abcd") + + if self.matches_args(args,["copy","rename"]): + + p.add_option("--newname", dest="newname", help="used for copy/edit") + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--no-sync", action="store_true", dest="nosync", help="suppress sync for speed") + if not self.matches_args(args,["report","list"]): + p.add_option("--no-triggers", action="store_true", dest="notriggers", help="suppress trigger execution") + + + def run(self): + + obj = self.object_manipulator_start(self.api.new_repo,self.api.repos) + if obj is None: + return True + + if self.options.arch: obj.set_arch(self.options.arch) + if self.options.createrepo_flags: obj.set_createrepo_flags(self.options.createrepo_flags) + if self.options.rpm_list: obj.set_rpm_list(self.options.rpm_list) + if self.options.keep_updated: obj.set_keep_updated(self.options.keep_updated) + if self.options.priority: obj.set_priority(self.options.priority) + if self.options.mirror: obj.set_mirror(self.options.mirror) + if self.options.yumopts: obj.set_yumopts(self.options.yumopts) + + return self.object_manipulator_finish(obj, self.api.repos, self.options) + + + +######################################################## +# MODULE HOOKS + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "cli" + +def cli_functions(api): + return [ + RepoFunction(api) + ] + return [] + + diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py new file mode 100644 index 0000000..c463b8c --- /dev/null +++ b/cobbler/modules/cli_system.py @@ -0,0 +1,120 @@ +""" +System CLI module. + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +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., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import distutils.sysconfig +import sys + +plib = distutils.sysconfig.get_python_lib() +mod_path="%s/cobbler" % plib +sys.path.insert(0, mod_path) + +from rhpl.translate import _, N_, textdomain, utf8 +import commands +import cexceptions + + +class SystemFunction(commands.CobblerFunction): + + def help_me(self): + return commands.HELP_FORMAT % ("cobbler system","<add|edit|copy|list|rename|remove|report> [ARGS|--help]") + + def command_name(self): + return "system" + + def subcommands(self): + return [ "add", "edit", "copy", "rename", "remove", "report", "list" ] + + def add_options(self, p, args): + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--dhcp-tag", dest="dhcp_tag", help="for use in advanced DHCP configurations") + p.add_option("--gateway", dest="gateway", help="for static IP / templating usage") + p.add_option("--hostname", dest="hostname", help="ex: server.example.org") + p.add_option("--interface", dest="interface", help="edit this interface # (0-7, default 0)") + p.add_option("--ip", dest="ip", help="ex: 192.168.1.55, (RECOMMENDED)") + p.add_option("--kickstart", dest="kickstart", help="override profile kickstart template") + p.add_option("--kopts", dest="kopts", help="ex: 'noipv6'") + p.add_option("--ksmeta", dest="ksmeta", help="ex: 'blippy=7'") + p.add_option("--mac", dest="mac", help="ex: 'AA:BB:CC:DD:EE:FF', (RECOMMENDED)") + + p.add_option("--name", dest="name", help="a name for the system (REQUIRED)") + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--netboot-enabled", dest="netboot_enabled", help="PXE on (1) or off (0)") + + if self.matches_args(args,["copy","rename"]): + p.add_option("--newname", dest="newname", help="for use with copy/edit") + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--no-sync", action="store_true", dest="nosync", help="suppress sync for speed") + if not self.matches_args(args,["report","list"]): + p.add_option("--no-triggers", action="store_true", dest="notriggers", help="suppress trigger execution") + + + if not self.matches_args(args,["remove","report","list"]): + p.add_option("--profile", dest="profile", help="name of cobbler profile (REQUIRED)") + p.add_option("--server-override", dest="server_override", help="overrides server value in settings file") + p.add_option("--subnet", dest="subnet", help="for static IP / templating usage") + p.add_option("--virt-bridge", dest="virt_bridge", help="ex: virbr0") + p.add_option("--virt-path", dest="virt_path", help="path, partition, or volume") + p.add_option("--virt-type", dest="virt_type", help="ex: xenpv, qemu, xenfv") + + + def run(self): + + obj = self.object_manipulator_start(self.api.new_system,self.api.systems) + if obj is None: + return True + + if self.options.profile: obj.set_profile(self.options.profile) + if self.options.kopts: obj.set_kernel_options(self.options.kopts) + if self.options.ksmeta: obj.set_ksmeta(self.options.ksmeta) + if self.options.kickstart: obj.set_kickstart(self.options.kickstart) + if self.options.netboot_enabled: obj.set_netboot_enabled(self.options.netboot_enabled) + if self.options.server_override: obj.set_server(self.options.server_override) + if self.options.virt_path: obj.set_virt_path(self.options.virt_path) + if self.options.virt_type: obj.set_virt_type(self.options.virt_type) + + if self.options.interface: + my_interface = "intf%s" % self.options.interface + else: + my_interface = "intf0" + + if self.options.hostname: obj.set_hostname(self.options.hostname, my_interface) + if self.options.mac: obj.set_mac_address(self.options.mac, my_interface) + if self.options.ip: obj.set_ip_address(self.options.ip, my_interface) + if self.options.subnet: obj.set_subnet(self.options.subnet, my_interface) + if self.options.gateway: obj.set_gateway(self.options.gateway, my_interface) + if self.options.dhcp_tag: obj.set_dhcp_tag(self.options.dhcp_tag, my_interface) + if self.options.virt_bridge: obj.set_virt_bridge(self.options.virt_bridge, my_interface) + + return self.object_manipulator_finish(obj, self.api.systems, self.options) + + + +######################################################## +# MODULE HOOKS + +def register(): + """ + The mandatory cobbler module registration hook. + """ + return "cli" + +def cli_functions(api): + return [ + SystemFunction(api) + ] + + |