Heres a new version.
It now works with "cobbler system" and "cobbler profile" and uses Dans
suggestion of api.BootAPI.generate_kickstart()
Michael, thanks for your help and patience.
Dave Hatton
From 421409d130dca66db587312e77d127e6212eb46e Mon Sep 17 00:00:00 2001
From: root <root(a)cobbler.starground.co.uk>
Date: Wed, 13 Aug 2008 19:00:00 +0100
Subject: [PATCH] added getks option to cobbler profile and system
---
cobbler/action_check.py | 5 +++++
cobbler/commands.py | 17 +++++++++++++++++
cobbler/modules/cli_profile.py | 18 +++++++++---------
cobbler/modules/cli_system.py | 23 +++++++++++++----------
4 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/cobbler/action_check.py b/cobbler/action_check.py
index 900ec20..8e91f2e 100644
--- a/cobbler/action_check.py
+++ b/cobbler/action_check.py
@@ -19,6 +19,7 @@ import sub_process
import action_sync
import utils
from utils import _
+
class BootCheck:
def __init__(self,config):
@@ -69,6 +70,7 @@ class BootCheck:
self.check_for_unreferenced_repos(status)
self.check_for_unsynced_repos(status)
self.check_vsftpd_bin(status)
+ self.check_urlgrabber(status)
return status
@@ -305,4 +307,7 @@ class BootCheck:
else:
status.append(_("missing file: %(file)s") % { "file" :
self.settings.dhcpd_conf })
+ def check_urlgrabber(self,status):
+ if not os.system('rpm -q python-urlgrabber.noarch | grep -q "is not
installed"'):
+ status.append(_("urlgrabber package is not installed, yum install
python-urlgrabber.noarch"))
diff --git a/cobbler/commands.py b/cobbler/commands.py
index cbd7cdd..6ea932e 100644
--- a/cobbler/commands.py
+++ b/cobbler/commands.py
@@ -16,6 +16,7 @@ import optparse
from cexceptions import *
from utils import _
import sys
+import api
HELP_FORMAT = "%-20s%s"
@@ -253,6 +254,14 @@ class CobblerFunction:
self.reporting_list_names2(collect_fn(),self.options.name)
return None
+ if "getks" in self.args:
+ if not self.options.name:
+ raise CX(_("name is required"))
+ obj = collect_fn().find(self.options.name)
+ if obj is None:
+ raise CX(_("object not found"))
+ return obj
+
if not self.options.name:
raise CX(_("name is required"))
@@ -280,6 +289,14 @@ class CobblerFunction:
print obj.dump_vars(True)
return True
+ if "getks" in self.args:
+ ba=api.BootAPI()
+ if "system" in self.args:
+ print ba.generate_kickstart(None, self.options.name)
+ if "profile" in self.args:
+ print ba.generate_kickstart(self.options.name, None)
+ return True
+
clobber = False
if "add" in self.args:
clobber = options.clobber
diff --git a/cobbler/modules/cli_profile.py b/cobbler/modules/cli_profile.py
index 25ca635..a1d0275 100644
--- a/cobbler/modules/cli_profile.py
+++ b/cobbler/modules/cli_profile.py
@@ -27,13 +27,13 @@ import cexceptions
class ProfileFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler
profile","<add|copy|edit|find|list|rename|remove|report>
[ARGS|--help]")
+ return commands.HELP_FORMAT % ("cobbler
profile","<add|copy|edit|find|list|rename|remove|report|getks>
[ARGS|--help]")
def command_name(self):
return "profile"
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):
@@ -41,7 +41,7 @@ class ProfileFunction(commands.CobblerFunction):
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("--distro", dest="distro",
help="ex: 'RHEL-5-i386' (REQUIRED)")
p.add_option("--dhcp-tag", dest="dhcp_tag",
help="for use in advanced DHCP configuration")
@@ -58,17 +58,17 @@ class ProfileFunction(commands.CobblerFunction):
if "copy" in args or "rename" in args:
p.add_option("--newname", dest="newname")
- 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","report",
"list"]):
+ if not
self.matches_args(args,["dumpvars","report","getks","list"]):
p.add_option("--owners", dest="owners",
help="specify owners for authz_ownership module")
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,["dumpvars","remove","report","list"]):
+ if not
self.matches_args(args,["dumpvars","remove","report","getks","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'")
@@ -86,7 +86,7 @@ class ProfileFunction(commands.CobblerFunction):
print x.name
return True
- if
self.matches_args(self.args,["report","list","remove","dumpvars"])
or not self.options.inherit:
+ if
self.matches_args(self.args,["report","getks","list","remove","dumpvars"])
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)
@@ -94,7 +94,7 @@ class ProfileFunction(commands.CobblerFunction):
if obj is None:
return True
- if not self.matches_args(self.args,["dumpvars"]):
+ if not self.matches_args(self.args,["dumpvars","getks"]):
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)
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index fbf40cb..816d8bc 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,18 @@ 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")
@@ -85,7 +84,7 @@ class SystemFunction(commands.CobblerFunction):
def run(self):
-
+
if "find" in self.args:
items = self.api.find_system(return_list=True, no_errors=True,
**self.options.__dict__)
for x in items:
@@ -93,11 +92,16 @@ class SystemFunction(commands.CobblerFunction):
return True
obj = self.object_manipulator_start(self.api.new_system,self.api.systems)
+
if obj is None:
return True
+
if self.matches_args(self.args,["dumpvars"]):
return self.object_manipulator_finish(obj, self.api.profiles, self.options)
+ if self.matches_args(self.args,["getks"]):
+ return self.object_manipulator_finish(obj, self.api.profiles, self.options)
+
if self.options.profile: obj.set_profile(self.options.profile)
if self.options.image: obj.set_image(self.options.image)
if self.options.kopts:
obj.set_kernel_options(self.options.kopts,self.options.inplace)
@@ -112,7 +116,6 @@ class SystemFunction(commands.CobblerFunction):
if self.options.virt_cpus: obj.set_virt_cpus(self.options.virt_cpus)
if self.options.virt_path: obj.set_virt_path(self.options.virt_path)
-
if self.options.interface:
my_interface = "intf%s" % self.options.interface
else:
--
1.5.5.1