summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2008-04-04 17:45:32 -0400
committerMichael DeHaan <mdehaan@redhat.com>2008-04-04 17:45:32 -0400
commitf3a7e9f8a2b85fb936d98aa118bec5189b26140f (patch)
tree3dd8ce63d407bf90d297d2bd31773263cd51524c
parent2d14d31b9aa6b34eaacfad650b99f132c3a103ad (diff)
downloadthird_party-cobbler-f3a7e9f8a2b85fb936d98aa118bec5189b26140f.tar.gz
third_party-cobbler-f3a7e9f8a2b85fb936d98aa118bec5189b26140f.tar.xz
third_party-cobbler-f3a7e9f8a2b85fb936d98aa118bec5189b26140f.zip
Added a "--clobber" option to all add commands that allows the add to function in an "add or edit" mode. Before in Cobbler, add and edit were largely aliases so this was not needed -- now it is. Using --clobber the object will be created if it does not exist, or it will overwrite the existing one (as "edit" does) when it is there. If --clobber is left off, add will refuse to overwrite an existing object. This is a minor break to scripts that are calling cobbler directly but not those to API users -- scripts /should/ be checking return codes.
-rw-r--r--CHANGELOG3
-rw-r--r--cobbler/commands.py14
-rw-r--r--cobbler/modules/cli_distro.py4
-rw-r--r--cobbler/modules/cli_profile.py5
-rw-r--r--cobbler/modules/cli_repo.py4
-rw-r--r--cobbler/modules/cli_system.py3
6 files changed, 30 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 64cfb2f..54bfac6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,8 +10,9 @@ Cobbler CHANGELOG
- added authn_ldap and stub for authz_configfile
- authz_configfile allows filtering ldap/other users by config file
- WebUI now has checkbox on distro/profile for deleting child objects
-- cli has different semantics between "add" and "edit" now
+- cli has different semantics between "add" and "edit" now for safety reasons
- cobbler wants to keep IPs/MACs unique now in configuration (can be disabled)
+- added --clobber option to allow add to overwrite existing objects (for scripts)
- ??? - 0.8.3
- fix WebUI documentation URL
diff --git a/cobbler/commands.py b/cobbler/commands.py
index 6bb0419..2dc627b 100644
--- a/cobbler/commands.py
+++ b/cobbler/commands.py
@@ -241,6 +241,10 @@ class CobblerFunction:
Boilerplate for objects that offer add/edit/delete/remove/copy functionality.
"""
+ clobber = False
+ if "add" in self.args:
+ clobber = options.clobber
+
if "copy" in self.args: # or "rename" in self.args:
if self.options.newname:
obj = obj.make_clone()
@@ -267,10 +271,16 @@ class CobblerFunction:
if "add" in self.args:
if obj.COLLECTION_TYPE == "system":
# duplicate names and netinfo are both bad.
- rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=True, check_for_duplicate_netinfo=True)
+ if not clobber:
+ rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=True, check_for_duplicate_netinfo=True)
+ else:
+ rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=False, check_for_duplicate_netinfo=True)
else:
# duplicate names are bad
- rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=True, check_for_duplicate_netinfo=False)
+ if not clobber:
+ rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=True, check_for_duplicate_netinfo=False)
+ else:
+ rc = collect_fn().add(obj, save=True, with_sync=opt_sync, with_triggers=opt_triggers, check_for_duplicate_names=False, check_for_duplicate_netinfo=False)
else:
# editing or copying (but not renaming), so duplicate netinfo
# CAN be bad, duplicate names are already handled, though
diff --git a/cobbler/modules/cli_distro.py b/cobbler/modules/cli_distro.py
index 9e0637f..8c7b70f 100644
--- a/cobbler/modules/cli_distro.py
+++ b/cobbler/modules/cli_distro.py
@@ -40,6 +40,9 @@ class DistroFunction(commands.CobblerFunction):
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")
+ 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,["remove","report","list"]):
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'")
@@ -48,6 +51,7 @@ class DistroFunction(commands.CobblerFunction):
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"]):
diff --git a/cobbler/modules/cli_profile.py b/cobbler/modules/cli_profile.py
index 9912607..0bf4b8c 100644
--- a/cobbler/modules/cli_profile.py
+++ b/cobbler/modules/cli_profile.py
@@ -36,6 +36,11 @@ class ProfileFunction(commands.CobblerFunction):
return [ "add", "edit", "copy", "rename", "remove", "list", "report" ]
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,["remove","report","list"]):
p.add_option("--distro", dest="distro", help="ex: 'RHEL-5-i386' (REQUIRED)")
diff --git a/cobbler/modules/cli_repo.py b/cobbler/modules/cli_repo.py
index 88e45dd..e8ec04a 100644
--- a/cobbler/modules/cli_repo.py
+++ b/cobbler/modules/cli_repo.py
@@ -37,9 +37,13 @@ class RepoFunction(commands.CobblerFunction):
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")
+ 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,["remove","report","list"]):
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")
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index b173b4b..34c8886 100644
--- a/cobbler/modules/cli_system.py
+++ b/cobbler/modules/cli_system.py
@@ -37,6 +37,9 @@ class SystemFunction(commands.CobblerFunction):
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,["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")