The attached patch adds a "getks" option to "cobbler system".
This renders the finished kickstart file for a specified system on the
console or terminal winder using the elinks ascii browser.
eg: cobbler system getks --name teapot
I find this very useful for checking the kickstart genrerated by cobbler
in an environment where I can't use http.
I hope others find this useful and it can be added to the base cobbler
system.
Regards
Dave Hatton
From d1f278517ae9042ee2d941bc5bb3d7008ac4068a Mon Sep 17 00:00:00 2001
From: root <root(a)cobbler.starground.co.uk>
Date: Mon, 11 Aug 2008 18:49:53 +0100
Subject: [PATCH] added getks option to cobbler system
---
cobbler/action_check.py | 4 ++++
cobbler/commands.py | 7 +++++++
cobbler/modules/cli_misc.py | 32 +++++++++++++++++++++++++++++++-
cobbler/modules/cli_system.py | 14 +++++++-------
4 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/cobbler/action_check.py b/cobbler/action_check.py
index a85344d..fe0d322 100644
--- a/cobbler/action_check.py
+++ b/cobbler/action_check.py
@@ -69,6 +69,7 @@ class BootCheck:
self.check_for_unreferenced_repos(status)
self.check_for_unsynced_repos(status)
self.check_vsftpd_bin(status)
+ self.check_elinks(status)
return status
@@ -302,4 +303,7 @@ class BootCheck:
else:
status.append(_("missing file: %(file)s") % { "file" :
self.settings.dhcpd_conf })
+ def check_elinks(self,status):
+ if not os.path.exists("/usr/bin/elinks"):
+ status.append(_("elinks package is not installed, needed for cobbler
system render, yum install elinks?"))
diff --git a/cobbler/commands.py b/cobbler/commands.py
index cbd7cdd..1507abe 100644
--- a/cobbler/commands.py
+++ b/cobbler/commands.py
@@ -16,6 +16,7 @@ import optparse
from cexceptions import *
from utils import _
import sys
+import os
HELP_FORMAT = "%-20s%s"
@@ -253,6 +254,12 @@ class CobblerFunction:
self.reporting_list_names2(collect_fn(),self.options.name)
return None
+ if "getks" in self.args:
+ if self.options.name:
+ os.system("/usr/bin/elinks --localhost 1
http://localhost/cblr/svc/op/ks/system/" + self.options.name)
+ else:
+ raise CX(_("Please specify a system name using --name"))
+
if not self.options.name:
raise CX(_("name is required"))
diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py
index f92094a..ec9948f 100644
--- a/cobbler/modules/cli_misc.py
+++ b/cobbler/modules/cli_misc.py
@@ -14,6 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import distutils.sysconfig
import sys
+import os
plib = distutils.sysconfig.get_python_lib()
mod_path="%s/cobbler" % plib
@@ -198,6 +199,34 @@ class ReportFunction(commands.CobblerFunction):
########################################################
+class GetksFunction(commands.CobblerFunction):
+
+ def help_me(self):
+ return HELP_FORMAT % ("cobbler getks","[ARGS|--help]")
+
+ def command_name(self):
+ return "getks"
+
+ def add_options(self, p, args):
+ p.add_option("--what", dest="what",
default="all", help="systems")
+ p.add_option("--name", dest="name",
help="report on just this object")
+
+ def run(self):
+ if self.options.what not in [ "all", "systems" ]:
+ raise CX(_("Invalid value for --what"))
+
+ if self.options.what in [ "all", "systems" ]:
+ if self.options.name:
+ os.system("/usr/bin/elinks --localhost 1
http://localhost/cblr/svc/op/ks/system/" + self.options.name)
+ else:
+ raise CX(_("Please specify a system name using --name"))
+
+ return True
+
+
+
+########################################################
+
class StatusFunction(commands.CobblerFunction):
def help_me(self):
@@ -345,7 +374,8 @@ def cli_functions(api):
CheckFunction(api), ImportFunction(api), ReserializeFunction(api),
ListFunction(api), ReportFunction(api), StatusFunction(api),
SyncFunction(api), RepoSyncFunction(api), ValidateKsFunction(api),
- ReplicateFunction(api), AclFunction(api)
+ ReplicateFunction(api), AclFunction(api),
+ GetksFunction(api)
]
return []
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index fbf40cb..62a0c5b 100644
--- a/cobbler/modules/cli_system.py
+++ b/cobbler/modules/cli_system.py
@@ -27,20 +27,20 @@ import cexceptions
class SystemFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler
system","<add|copy|edit|find|list|rename|remove|report>
[ARGS|--help]")
+ return commands.HELP_FORMAT % ("cobbler
system","<add|copy|edit|find|list|rename|remove|report|getks>
[ARGS|--help]")
def command_name(self):
return "system"
def subcommands(self):
- return [ "add", "copy", "dumpvars",
"edit", "find", "list", "remove",
"rename", "report" ]
+ return [ "add", "copy", "dumpvars",
"edit", "find", "list", "remove",
"rename", "report", "getks"]
def add_options(self, p, args):
if self.matches_args(args,["add"]):
p.add_option("--clobber", dest="clobber",
help="allow add to overwrite existing objects", action="store_true")
- if not
self.matches_args(args,["dumpvars","remove","report","list"]):
+ if not
self.matches_args(args,["dumpvars","remove","report","getks","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")
@@ -58,19 +58,19 @@ class SystemFunction(commands.CobblerFunction):
p.add_option("--name", dest="name",
help="a name for the system (REQUIRED)")
- if not
self.matches_args(args,["dumpvars","remove","report","list"]):
+ if not
self.matches_args(args,["dumpvars","remove","report","getks","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,["dumpvars","find","remove","report","list"]):
+ if not
self.matches_args(args,["dumpvars","find","remove","report","getks","list"]):
p.add_option("--no-sync", action="store_true",
dest="nosync", help="suppress sync for speed")
- if not
self.matches_args(args,["dumpvars","find","report","list"]):
+ if not
self.matches_args(args,["dumpvars","find","report","getks","list"]):
p.add_option("--no-triggers", action="store_true",
dest="notriggers", help="suppress trigger execution")
- if not
self.matches_args(args,["dumpvars","remove","report","list"]):
+ if not
self.matches_args(args,["dumpvars","remove","report","getks","list"]):
p.add_option("--owners", dest="owners",
help="specify owners for authz_ownership module")
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")
--
1.5.5.1