summaryrefslogtreecommitdiffstats
path: root/cobbler/modules
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-11-27 17:16:27 -0500
committerMichael DeHaan <mdehaan@redhat.com>2007-11-27 17:16:27 -0500
commitcb02309cc41fbae69e3ff3efcb3e3feb763189ff (patch)
tree2d0efcd9120408d75c376e2b663bc3eb29a6e11e /cobbler/modules
parent035fa440a9b40b079d81a5cb1b46114cdabd0462 (diff)
downloadthird_party-cobbler-cb02309cc41fbae69e3ff3efcb3e3feb763189ff.tar.gz
third_party-cobbler-cb02309cc41fbae69e3ff3efcb3e3feb763189ff.tar.xz
third_party-cobbler-cb02309cc41fbae69e3ff3efcb3e3feb763189ff.zip
Changes to make "cobbler ___ report [___]" and "cobbler ___ list" work like they used to, which means adding a few subcommands, abstracting away the list logic, and writing some minor code to make the trailing names look like --name=x to please optparse.
Diffstat (limited to 'cobbler/modules')
-rw-r--r--cobbler/modules/cli_distro.py11
-rw-r--r--cobbler/modules/cli_misc.py69
-rw-r--r--cobbler/modules/cli_profile.py17
-rw-r--r--cobbler/modules/cli_repo.py13
-rw-r--r--cobbler/modules/cli_system.py18
5 files changed, 51 insertions, 77 deletions
diff --git a/cobbler/modules/cli_distro.py b/cobbler/modules/cli_distro.py
index 094961b..3cfa716 100644
--- a/cobbler/modules/cli_distro.py
+++ b/cobbler/modules/cli_distro.py
@@ -27,24 +27,27 @@ import cexceptions
class DistroFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler distro", "<add|edit|copy|rename|remove> [ARGS|--help]")
+ 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" ]
+ return [ "add", "edit", "copy", "rename", "remove", "list", "report" ]
def add_options(self, p, args):
- if not "remove" in 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 "copy" in args or "rename" in args:
+
+ if self.matches_args(args,["copy","rename"]):
p.add_option("--newname", dest="newname", help="for copy/rename commands")
def run(self):
diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py
index b3f6dfa..cf7adcb 100644
--- a/cobbler/modules/cli_misc.py
+++ b/cobbler/modules/cli_misc.py
@@ -121,35 +121,16 @@ class ListFunction(commands.CobblerFunction):
if self.options.what not in [ "all", "distros", "profiles", "systems", "repos" ]:
raise CX(_("invalid value for --what"))
if self.options.what in [ "all" ]:
- self.__tree(self.api.distros(),0)
- self.__tree(self.api.repos(),0)
+ self.list_tree(self.api.distros(),0)
+ self.list_tree(self.api.repos(),0)
if self.options.what in [ "distros"]:
- self.__list(self.api.distros())
+ self.list_list(self.api.distros())
if self.options.what in [ "profiles"]:
- self.__list(self.api.profiles())
+ self.list_list(self.api.profiles())
if self.options.what in [ "systems" ]:
- self.__list(self.api.systems())
+ self.list_list(self.api.systems())
if self.options.what in [ "repos"]:
- self.__list(self.api.repos())
-
- def __list(self, collection):
- names = [ x.name for x in collection]
- names.sort() # sorted() is 2.4 only
- for name in names:
- str = _(" %(name)s") % { "name" : name }
- print str
- return True
-
- def __tree(self,collection,level):
- for item in collection:
- print _("%(indent)s%(type)s %(name)s") % {
- "indent" : " " * level,
- "type" : item.TYPE_NAME,
- "name" : item.name
- }
- kids = item.get_children()
- if kids is not None and len(kids) > 0:
- self.__tree(kids,level+1)
+ self.list_list(self.api.repos())
########################################################
@@ -165,55 +146,33 @@ class ReportFunction(commands.CobblerFunction):
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 __list_names2(self, collection, name):
- obj = collection.find(name=name)
- if obj is not None:
- print obj.printable()
- return True
-
- def __sorter(self, a, b):
- return cmp(a.name, b.name)
-
- def __print_sorted(self, collection):
- collection = [x for x in collection]
- collection.sort(self.__sorter)
- for x in collection:
- print x.printable()
- return True
-
- def __list_names2(self, collection, name):
- obj = collection.find(name=name)
- if obj is not None:
- print obj.printable()
- return True
-
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.__list_names2(self.api.distros(),self.options.name)
+ self.reporting_list_names2(self.api.distros(),self.options.name)
else:
- self.__print_sorted(self.api.distros())
+ self.reporting_print_sorted(self.api.distros())
if self.options.what in [ "all", "profiles" ]:
if self.options.name:
- self.__list_names2(self.api.profiles(),self.options.name)
+ self.reporting_list_names2(self.api.profiles(),self.options.name)
else:
- self.__print_sorted(self.api.profiles())
+ self.reporting_print_sorted(self.api.profiles())
if self.options.what in [ "all", "systems" ]:
if self.options.name:
- self.__list_names2(self.api.systems(),self.options.name)
+ self.reporting_list_names2(self.api.systems(),self.options.name)
else:
- self.__print_sorted(self.api.systems())
+ self.reporting_print_sorted(self.api.systems())
if self.options.what in [ "all", "repos" ]:
if self.options.name:
- self.__list_names2(self.api.repos(),self.options.name)
+ self.reporting_list_names2(self.api.repos(),self.options.name)
else:
- self.__print_sorted(self.api.repos())
+ self.reporting_print_sorted(self.api.repos())
return True
## FIXME: add legacy command translator to keep things simple
diff --git a/cobbler/modules/cli_profile.py b/cobbler/modules/cli_profile.py
index 63c4270..8189e7c 100644
--- a/cobbler/modules/cli_profile.py
+++ b/cobbler/modules/cli_profile.py
@@ -27,16 +27,17 @@ import cexceptions
class ProfileFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler profile","<add|edit|copy|rename|remove> [ARGS|--help]")
+ 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" ]
+ return [ "add", "edit", "copy", "rename", "remove", "list", "report" ]
def add_options(self, p, args):
- if not "remove" in 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")
@@ -44,9 +45,11 @@ class ProfileFunction(commands.CobblerFunction):
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 "remove" in args:
+
+ 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'")
@@ -59,10 +62,10 @@ class ProfileFunction(commands.CobblerFunction):
def run(self):
- if self.options.inherit:
- obj = self.object_manipulator_start(self.api.new_profile,self.api.profiles,subobject=True)
+ 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=False)
+ obj = self.object_manipulator_start(self.api.new_profile,self.api.profiles,subobject=True)
if obj is None:
return True
diff --git a/cobbler/modules/cli_repo.py b/cobbler/modules/cli_repo.py
index 3dd8f64..f1c61b3 100644
--- a/cobbler/modules/cli_repo.py
+++ b/cobbler/modules/cli_repo.py
@@ -27,23 +27,28 @@ import cexceptions
class RepoFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler repo","<add|edit|copy|rename|remove> [ARGS|--help]")
+ 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" ]
+ return [ "add", "edit", "copy", "rename", "remove", "list", "report" ]
def add_options(self, p, args):
- if not "remove" in 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("--rpm-list", dest="rpm_list", help="just mirror these rpms")
p.add_option("--keep-updated", dest="keep_updated", help="update on each reposync, yes/no")
p.add_option("--mirror", dest="mirror", help="source to mirror (REQUIRED)")
+
p.add_option("--name", dest="name", help="ex: 'Fedora-8-updates-i386' (REQUIRED)")
- if "copy" in args or "rename" in args:
+
+ if self.matches_args(args,["copy","rename"]):
+
p.add_option("--newname", dest="newname", help="used for copy/edit")
def run(self):
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index 1e39669..dc7e6bc 100644
--- a/cobbler/modules/cli_system.py
+++ b/cobbler/modules/cli_system.py
@@ -27,17 +27,17 @@ import cexceptions
class SystemFunction(commands.CobblerFunction):
def help_me(self):
- return commands.HELP_FORMAT % ("cobbler system","<add|edit|copy|rename|remove> [ARGS|--help]")
+ 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" ]
-
+ return [ "add", "edit", "copy", "rename", "remove", "report", "list" ]
def add_options(self, p, args):
- if not "remove" in 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")
@@ -46,12 +46,16 @@ class SystemFunction(commands.CobblerFunction):
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 "remove" in args:
+
+ 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 "copy" in args or "rename" in args:
+
+ if self.matches_args(args,["copy","rename"]):
p.add_option("--newname", dest="newname", help="for use with copy/edit")
- if not "remove" in args:
+
+ 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")