diff options
Diffstat (limited to 'cobbler')
-rw-r--r-- | cobbler/action_litesync.py | 48 | ||||
-rw-r--r-- | cobbler/action_reposync.py | 3 | ||||
-rw-r--r-- | cobbler/action_sync.py | 271 | ||||
-rw-r--r-- | cobbler/api.py | 12 | ||||
-rwxr-xr-x | cobbler/cobbler.py | 36 | ||||
-rw-r--r-- | cobbler/cobbler_msg.py | 1 | ||||
-rw-r--r-- | cobbler/collection.py | 23 | ||||
-rw-r--r-- | cobbler/collection_distros.py | 7 | ||||
-rw-r--r-- | cobbler/collection_profiles.py | 7 | ||||
-rw-r--r-- | cobbler/collection_systems.py | 7 | ||||
-rw-r--r-- | cobbler/settings.py | 3 | ||||
-rw-r--r-- | cobbler/utils.py | 4 |
12 files changed, 207 insertions, 215 deletions
diff --git a/cobbler/action_litesync.py b/cobbler/action_litesync.py index 07cd933..06df597 100644 --- a/cobbler/action_litesync.py +++ b/cobbler/action_litesync.py @@ -24,6 +24,7 @@ import yaml # Howell-Clark version import sub_process import sys +import cexceptions import utils import action_sync import cobbler_msg @@ -48,46 +49,65 @@ class BootLiteSync: self.systems = config.systems() self.settings = config.settings() self.repos = config.repos() - self.sync_module = action_sync.BootSync(self.config) + self.sync = action_sync.BootSync(self.config) def add_single_distro(self, name): + # get the distro record + distro = self.distros.find(name) + if distro is None: + raise cexceptions.CobblerException("error in distro lookup: %s" % name) # generate YAML file in distros/$name in webdir - # copy image files to images/$name in webdir: - # filenames: initrd.img and vmlinuz - # same for tftpboot/images/$name - pass + self.sync.write_distro_file(distro) + # copy image files to images/$name in webdir & tftpboot: + self.sync.copy_single_distro_files(distro) def remove_single_distro(self, name): # delete distro YAML file in distros/$name in webdir + self.sync.rmfile(os.path.join(self.settings.webdir, "distros", name)) # delete contents of images/$name directory in webdir + self.sync.rmtree(os.path.join(self.settings.webdir, "images", name)) # delete contents of images/$name in tftpboot - pass + self.sync.rmtree(os.path.join(self.settings.tftpboot, "images", name)) def add_single_profile(self, name): + # get the profile object: + profile = self.profiles.find(name) + if profile is None: + raise cexceptions.CobblerException("error in profile lookup") # rebuild profile_list YAML file in webdir + self.sync.write_listings() # add profiles/$name YAML file in webdir + self.sync.write_profile_file(profile) # generate kickstart for kickstarts/$name/ks.cfg in webdir - pass + self.sync.validate_kickstart_for_specific_profile(profile) def remove_single_profile(self, name): # rebuild profile_list YAML file in webdir + self.sync.write_listings() # delete profiles/$name file in webdir + self.sync.rmfile(os.path.join(self.settings.webdir, "profiles", name)) # delete contents on kickstarts/$name directory in webdir - pass + self.sync.rmtree(os.path.join(self.settings.webdir, "kickstarts", name)) def add_single_system(self, name): + # get the system object: + system = self.systems.find(name) + if system is None: + raise cexceptions.CobblerException("error in system lookup") # rebuild system_list file in webdir - # create system YAML file in systems/$name in webdir - # create kickstarts_sys/$name/ks.cfg in webdir - # create pxelinux.cfg/$foo where $foo is either the *encoded* IP - # or the MAC or default - pass + self.sync.write_listings() + # wire the PXE and YAML files for the system + self.sync.write_all_system_files(system) def remove_single_system(self, name): # rebuild system_list file in webdir + self.sync.write_listings() # delete system YAML file in systems/$name in webdir + self.sync.rmfile(os.path.join(self.settings.webdir, "systems", name)) # delete contents of kickstarts_sys/$name in webdir + self.sync.rmtree(os.path.join(self.settings.webdir, "kickstarts_sys", name)) # delete pxelinux.cfg/$foo where $foo is either the *encoded* IP # or the MAC or default - pass + filename = self.sync.get_pxe_filename(name) + self.sync.rmfile(os.path.join(self.settings.tftpboot, "pxelinux.cfg", filename)) diff --git a/cobbler/action_reposync.py b/cobbler/action_reposync.py index 276dd71..29bbfe2 100644 --- a/cobbler/action_reposync.py +++ b/cobbler/action_reposync.py @@ -44,13 +44,12 @@ class RepoSync: self.settings = config.settings() self.repos = config.repos() - def run(self,dryrun=False,verbose=True): + def run(self,verbose=True): """ Syncs the current repo configuration file with the filesystem. """ self.verbose = verbose - self.dryrun = dryrun for repo in self.repos: print "considering: %s" % repo repo_path = os.path.join(self.settings.webdir, "repo_mirror", repo.name) diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py index bdb31f7..bec2570 100644 --- a/cobbler/action_sync.py +++ b/cobbler/action_sync.py @@ -46,7 +46,7 @@ class BootSync: self.settings = config.settings() self.repos = config.repos() - def run(self,dryrun=False,verbose=True): + def run(self,verbose=True): """ Syncs the current configuration file with the config tree. Using the Check().run_ functions previously is recommended @@ -56,7 +56,6 @@ class BootSync: # not having a /var/www/cobbler is ok, the app will create it since # no other package has to own it. self.verbose = verbose - self.dryrun = dryrun self.clean_trees() self.copy_koan() self.copy_bootloaders() @@ -297,21 +296,24 @@ class BootSync: NOTE: this has to be done for both tftp and http methods """ # copy is a 4-letter word but tftpboot runs chroot, thus it's required. - for dirtree in [self.settings.tftpboot, self.settings.webdir]: + for d in self.distros: + self.copy_single_distro_files(d) + + def copy_single_distro_files(self, d): + for dirtree in [self.settings.tftpboot, self.settings.webdir]: distros = os.path.join(dirtree, "images") - for d in self.distros: - distro_dir = os.path.join(distros,d.name) - self.mkdir(distro_dir) - kernel = utils.find_kernel(d.kernel) # full path - initrd = utils.find_initrd(d.initrd) # full path - if kernel is None or not os.path.isfile(kernel): - raise cexceptions.CobblerException("sync_kernel", d.kernel, d.name) - if initrd is None or not os.path.isfile(initrd): - raise cexceptions.CobblerException("sync_initrd", d.initrd, d.name) - b_kernel = os.path.basename(kernel) - b_initrd = os.path.basename(initrd) - self.copyfile(kernel, os.path.join(distro_dir, b_kernel)) - self.copyfile(initrd, os.path.join(distro_dir, b_initrd)) + distro_dir = os.path.join(distros,d.name) + self.mkdir(distro_dir) + kernel = utils.find_kernel(d.kernel) # full path + initrd = utils.find_initrd(d.initrd) # full path + if kernel is None or not os.path.isfile(kernel): + raise cexceptions.CobblerException("sync_kernel", d.kernel, d.name) + if initrd is None or not os.path.isfile(initrd): + raise cexceptions.CobblerException("sync_initrd", d.initrd, d.name) + b_kernel = os.path.basename(kernel) + b_initrd = os.path.basename(initrd) + self.copyfile(kernel, os.path.join(distro_dir, b_kernel)) + self.copyfile(initrd, os.path.join(distro_dir, b_initrd)) def validate_kickstarts(self): """ @@ -340,30 +342,33 @@ class BootSync: """ for g in self.profiles: - distro = self.distros.find(g.distro) - kickstart_path = utils.find_kickstart(g.kickstart) - if kickstart_path and os.path.exists(kickstart_path): - # the input is an *actual* file, hence we have to copy it - copy_path = os.path.join( - self.settings.webdir, - "kickstarts", # profile kickstarts go here - g.name - ) - self.mkdir(copy_path) - dest = os.path.join(copy_path, "ks.cfg") - try: - meta = self.blend_options(False, ( - distro.ks_meta, - g.ks_meta, - )) - meta["yum_repo_stanza"] = self.generate_repo_stanza(g) - meta["yum_config_stanza"] = self.generate_config_stanza(g) - meta["kickstart_done"] = self.generate_kickstart_signal(g, is_system=False) - self.apply_template(kickstart_path, meta, dest) - except: - traceback.print_exc() # leave this in, for now... - msg = "err_kickstart2" - raise cexceptions.CobblerException(msg,kickstart_path,dest) + validate_kickstart_for_specific_profile(g) + + def validate_kickstart_for_specific_profile(self,g): + distro = self.distros.find(g.distro) + kickstart_path = utils.find_kickstart(g.kickstart) + if kickstart_path and os.path.exists(kickstart_path): + # the input is an *actual* file, hence we have to copy it + copy_path = os.path.join( + self.settings.webdir, + "kickstarts", # profile kickstarts go here + g.name + ) + self.mkdir(copy_path) + dest = os.path.join(copy_path, "ks.cfg") + try: + meta = self.blend_options(False, ( + distro.ks_meta, + g.ks_meta, + )) + meta["yum_repo_stanza"] = self.generate_repo_stanza(g) + meta["yum_config_stanza"] = self.generate_config_stanza(g) + meta["kickstart_done"] = self.generate_kickstart_signal(g, is_system=False) + self.apply_template(kickstart_path, meta, dest) + except: + traceback.print_exc() # leave this in, for now... + msg = "err_kickstart2" + raise cexceptions.CobblerException(msg,kickstart_path,dest) def generate_kickstart_signal(self, obj, is_system=False): pattern = "wget http://%s/cobbler_track/watcher.py?%s_%s=%s -b" @@ -471,28 +476,12 @@ class BootSync: # and file for each MAC or IP (hex encoded 01-XX-XX-XX-XX-XX-XX) for d in self.distros: - # TODO: add check to ensure all distros have profiles (=warning) - filename = os.path.join(self.settings.webdir,"distros",d.name) - d.kernel_options = self.blend_options(True,( - self.settings.kernel_options, - d.kernel_options - )) - # yaml file: http only - self.write_distro_file(filename,d) + self.write_distro_file(d) for p in self.profiles: # TODO: add check to ensure all profiles have distros (=error) # TODO: add check to ensure all profiles have systems (=warning) - filename = os.path.join(self.settings.webdir,"profiles",p.name) - distro = self.distros.find(p.distro) - if distro is not None: - p.kernel_options = self.blend_options(True,( - self.settings.kernel_options, - distro.kernel_options, - p.kernel_options - )) - # yaml file: http only - self.write_profile_file(filename,p) + self.write_profile_file(p) # Copy default PXE file if it exists; if there's none, ignore # FIXME: Log something inobtrusive ifthe default file is missing @@ -508,37 +497,41 @@ class BootSync: self.copyfile(src, dst) for system in self.systems: - profile = self.profiles.find(system.profile) - if profile is None: - raise cexceptions.CobblerException("orphan_profile2",system.name,system.profile) - distro = self.distros.find(profile.distro) - if distro is None: - raise cexceptions.CobblerException("orphan_distro2",system.profile,profile.distro) - f1 = self.get_pxe_filename(system.name) + write_all_system_files(system) - # tftp only + def write_all_system_files(self,system): + profile = self.profiles.find(system.profile) + if profile is None: + raise cexceptions.CobblerException("orphan_profile2",system.name,system.profile) + distro = self.distros.find(profile.distro) + if distro is None: + raise cexceptions.CobblerException("orphan_distro2",system.profile,profile.distro) + f1 = self.get_pxe_filename(system.name) - if distro.arch in [ "x86", "x86_64", "standard"]: - # pxelinux wants a file named $name under pxelinux.cfg - f2 = os.path.join(self.settings.tftpboot, "pxelinux.cfg", f1) - if distro.arch == "ia64": - # elilo expects files to be named "$name.conf" in the root - # and can not do files based on the MAC address - if system.pxe_address == "" or system.pxe_address is None or not utils.is_ip(system.pxe_address): - raise cexceptions.CobblerException("exc_ia64_noip",system.name) + # tftp only - filename = "%s.conf" % self.get_pxe_filename(system.pxe_address) - f2 = os.path.join(self.settings.tftpboot, filename) + if distro.arch in [ "x86", "x86_64", "standard"]: + # pxelinux wants a file named $name under pxelinux.cfg + f2 = os.path.join(self.settings.tftpboot, "pxelinux.cfg", f1) + if distro.arch == "ia64": + # elilo expects files to be named "$name.conf" in the root + # and can not do files based on the MAC address + if system.pxe_address == "" or system.pxe_address is None or not utils.is_ip(system.pxe_address): + raise cexceptions.CobblerException("exc_ia64_noip",system.name) - f3 = os.path.join(self.settings.webdir, "systems", f1) - if distro.arch in [ "x86", "x86_64", "standard"]: - self.write_pxe_file(f2,system,profile,distro,False) - if distro.arch == "ia64": - self.write_pxe_file(f2,system,profile,distro,True) - self.write_system_file(f3,system) + filename = "%s.conf" % self.get_pxe_filename(system.pxe_address) + f2 = os.path.join(self.settings.tftpboot, filename) + + f3 = os.path.join(self.settings.webdir, "systems", f1) + + if distro.arch in [ "x86", "x86_64", "standard"]: + self.write_pxe_file(f2,system,profile,distro,False) + if distro.arch == "ia64": + self.write_pxe_file(f2,system,profile,distro,True) + self.write_system_file(f3,system) def get_pxe_filename(self,name_input): @@ -638,12 +631,17 @@ class BootSync: self.close_file(fd1) self.close_file(fd2) - def write_distro_file(self,filename,distro): + def write_distro_file(self,distro): """ Create distro information for virt install NOTE: relevant to http only """ + filename = os.path.join(self.settings.webdir,"distros",distro.name) + distro.kernel_options = self.blend_options(True,( + self.settings.kernel_options, + distro.kernel_options + )) fd = self.open_file(filename,"w+") # resolve to current values distro.kernel = utils.find_kernel(distro.kernel) @@ -651,12 +649,21 @@ class BootSync: self.tee(fd,yaml.dump(distro.to_datastruct())) self.close_file(fd) - def write_profile_file(self,filename,profile): + def write_profile_file(self,profile): """ Create profile information for virt install NOTE: relevant to http only """ + filename = os.path.join(self.settings.webdir,"profiles",profile.name) + distro = self.distros.find(profile.distro) + if distro is not None: + profile.kernel_options = self.blend_options(True,( + self.settings.kernel_options, + distro.kernel_options, + profile.kernel_options + )) + # yaml file: http only fd = self.open_file(filename,"w+") # if kickstart path is local, we've already copied it into # the HTTP mirror, so make it something anaconda can get at @@ -677,76 +684,45 @@ class BootSync: self.close_file(fd) def tee(self,fd,text): - """ - For dryrun support: send data to screen and potentially to disk - """ - if self.dryrun: + if self.verbose: print text - if not self.dryrun: - fd.write(text) + fd.write(text) def open_file(self,filename,mode): - """ - For dryrun support: open a file if not in dryrun mode. - """ - if self.dryrun: - return None return open(filename,mode) def close_file(self,fd): - """ - For dryrun support: close a file if not in dryrun mode. - """ - if not self.dryrun: - fd.close() + fd.close() def copyfile(self,src,dst): - """ - For dryrun support: potentially copy a file. - """ - print "%s -> %s" % (src,dst) - if self.dryrun: - return True - try: - return shutil.copyfile(src,dst) - except IOError, ioe: - raise cexceptions.CobblerException("need_perms2",src,dst) + if self.verbose: + print "%s -> %s" % (src,dst) + try: + return shutil.copyfile(src,dst) + except IOError, ioe: + raise cexceptions.CobblerException("need_perms2",src,dst) def copy(self,src,dst): - """ - For dryrun support: potentially copy a file. - """ - print "%s -> %s" % (src,dst) - if self.dryrun: - return True - try: - return shutil.copy(src,dst) - except IOError, ioe: - raise cexceptions.CobblerException("need_perms2",src,dst) + print "%s -> %s" % (src,dst) + try: + return shutil.copy(src,dst) + except IOError, ioe: + raise cexceptions.CobblerException("need_perms2",src,dst) def rmfile(self,path): - """ - For dryrun support. potentially unlink a file. - """ - if self.dryrun: - return True - try: - os.unlink(path) - return True - except OSError, ioe: - if not ioe.errno == errno.ENOENT: # doesn't exist - traceback.print_exc() - raise cexceptions.CobblerException("no_delete",path) - return True + try: + os.unlink(path) + return True + except OSError, ioe: + if not ioe.errno == errno.ENOENT: # doesn't exist + traceback.print_exc() + raise cexceptions.CobblerException("no_delete",path) + return True def rmtree(self,path): - """ - For dryrun support: potentially delete a tree. - """ - print "del %s" % (path) - if self.dryrun: - return True + if self.verbose: + print "del %s" % (path) try: return shutil.rmtree(path) except OSError, ioe: @@ -755,12 +731,8 @@ class BootSync: return True def mkdir(self,path,mode=0777): - """ - For dryrun support: potentially make a directory. - """ - if self.dryrun: + if self.verbose: print "mkdir %s" % (path) - return True try: return os.makedirs(path,mode) except OSError, oe: @@ -771,15 +743,13 @@ class BootSync: def service(self, name, action): """ - Call /sbin/service NAME ACTION, unless its a dryrun + Call /sbin/service NAME ACTION """ cmd = "/sbin/service %s %s" % (name, action) - if self.dryrun: + if self.verbose: print cmd - return 0 - else: - return sub_process.call(cmd, shell=True) + return sub_process.call(cmd, shell=True) def blend_options(self, is_for_kernel, list_of_opts): """ @@ -793,8 +763,9 @@ class BootSync: for template metadata (--ksopts) The output when is_for_kernel is true is a space delimited list. - When is_for_kernel is false, it's just a hash (which Cheetah requires). + When is_for_kernel is false, it's just a hash. """ + # FIXME: needs to be smart enough to remove duplicate options. internal = {} results = [] # for all list of kernel options diff --git a/cobbler/api.py b/cobbler/api.py index dda4052..aa7d42a 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -32,6 +32,8 @@ class BootAPI: """ self._config = config.Config() self.deserialize() + # self.settings = self._config.settings() + # self.syncflag = self.settings.minimize_syncs def clear(self): """ @@ -106,7 +108,7 @@ class BootAPI: check = action_check.BootCheck(self._config) return check.run() - def sync(self,dryrun=True): + def sync(self): """ Take the values currently written to the configuration files in /etc, and /var, and build out the information tree found in @@ -114,15 +116,15 @@ class BootAPI: saved with serialize() will NOT be synchronized with this command. """ sync = action_sync.BootSync(self._config) - return sync.run(dryrun=dryrun) + return sync.run() - def reposync(self,dryrun=True): + def reposync(self): """ Take the contents of /var/lib/cobbler/repos and update them -- or create the initial copy if no contents exist yet. """ - sync = action_reposync.RepoSync(self._config) - return sync.run(dryrun=dryrun) + reposync = action_reposync.RepoSync(self._config) + return reposync.run() def enchant(self,address,profile,systemdef,is_virt): """ diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py index 80d3002..1ba42db 100755 --- a/cobbler/cobbler.py +++ b/cobbler/cobbler.py @@ -166,8 +166,8 @@ class BootCLI: Delete a system: 'cobbler system remove --name=foo' """ commands = { - '--name' : lambda(a): self.api.systems().remove(a), - '--system' : lambda(a): self.api.systems().remove(a), + '--name' : lambda(a): self.api.systems().remove(a, with_delete=self.api.sync_flag), + '--system' : lambda(a): self.api.systems().remove(a, with_delete=self.api.sync_flag), } on_ok = lambda: True return self.apply_args(args,commands,on_ok) @@ -196,8 +196,8 @@ class BootCLI: Delete a profile: 'cobbler profile remove --name=foo' """ commands = { - '--name' : lambda(a): self.api.profiles().remove(a), - '--profile' : lambda(a): self.api.profiles().remove(a) + '--name' : lambda(a): self.api.profiles().remove(a, with_delete=self.api.sync_flag), + '--profile' : lambda(a): self.api.profiles().remove(a, with_delete=self.api.sync_flag) } on_ok = lambda: True return self.apply_args(args,commands,on_ok) @@ -208,8 +208,8 @@ class BootCLI: Delete a distro: 'cobbler distro remove --name='foo' """ commands = { - '--name' : lambda(a): self.api.distros().remove(a), - '--distro' : lambda(a): self.api.distros().remove(a) + '--name' : lambda(a): self.api.distros().remove(a, with_delete=self.api.sync_flag), + '--distro' : lambda(a): self.api.distros().remove(a, with_delete=self.api.sync_flag) } on_ok = lambda: True return self.apply_args(args,commands,on_ok) @@ -322,7 +322,7 @@ class BootCLI: '--ksmeta' : lambda(a) : sys.set_ksmeta(a), '--pxe-address' : lambda(a) : sys.set_pxe_address(a) } - on_ok = lambda: self.api.systems().add(sys) + on_ok = lambda: self.api.systems().add(sys, with_copy=self.api.sync_flag) return self.apply_args(args,commands,on_ok) @@ -347,7 +347,7 @@ class BootCLI: '--ksmeta' : lambda(a) : profile.set_ksmeta(a), '--repos' : lambda(a) : profile.set_repos(a) } - on_ok = lambda: self.api.profiles().add(profile) + on_ok = lambda: self.api.profiles().add(profile, with_copy=self.api.sync_flag) return self.apply_args(args,commands,on_ok) def repo_edit(self,args): @@ -379,7 +379,7 @@ class BootCLI: '--arch' : lambda(a) : distro.set_arch(a), '--ksmeta' : lambda(a) : distro.set_ksmeta(a) } - on_ok = lambda: self.api.distros().add(distro) + on_ok = lambda: self.api.distros().add(distro, with_copy=self.api.sync_flag) return self.apply_args(args,commands,on_ok) @@ -422,26 +422,18 @@ class BootCLI: def sync(self, args): """ - Sync the config file with the system config: 'cobbler sync [--dryrun]' + Sync the config file with the system config: 'cobbler sync' """ - status = None - if args is not None and ("--dryrun" in args or "-n" in args): - status = self.api.sync(dryrun=True) - else: - status = self.api.sync(dryrun=False) - return status + self.api.sync() + return True def reposync(self, args): """ Sync the repo-specific portions of the config with the filesystem. 'cobbler reposync'. Intended to be run on cron. """ - status = None - if args is not None and ("--dryrun" in args or "-n" in args): - status = self.api.reposync(dryrun=True) - else: - status = self.api.reposync(dryrun=False) - return status + self.api.reposync() + return True def check(self,args): """ diff --git a/cobbler/cobbler_msg.py b/cobbler/cobbler_msg.py index 389e692..da3af23 100644 --- a/cobbler/cobbler_msg.py +++ b/cobbler/cobbler_msg.py @@ -110,7 +110,6 @@ _msg_table = { "sync_processing" : "processing: %s", "writing" : "writing file: %s", "mkdir" : "creating: %s", - "dryrun" : "dry run | %s", "copying" : "copying file: %s to %s", "removing" : "removing: %s", "no_initrd" : "cannot find initrd", diff --git a/cobbler/collection.py b/cobbler/collection.py index 3f136e6..617ce09 100644 --- a/cobbler/collection.py +++ b/cobbler/collection.py @@ -75,7 +75,7 @@ class Collection(serializable.Serializable): item = self.factory_produce(self.config,seed_data) self.add(item) - def add(self,ref): + def add(self,ref,with_copy=False): """ Add an object to the collection, if it's valid. Returns True if the object was added to the collection. Returns False if the @@ -84,20 +84,21 @@ class Collection(serializable.Serializable): """ if ref is None or not ref.is_valid(): raise cexceptions.CobblerException("bad_param") + self.listing[ref.name] = ref # perform filesystem operations - lite_sync = action_litesync.BootLiteSync(self.config) - if isinstance(ref, item_system.System): - lite_sync.add_single_system(ref.name) - elif isinstance(ref, item_profile.Profile): - lite_sync.add_single_profile(ref.name) - elif isinstance(ref, item_distro.Distro): - lite_sync.add_single_distro(ref.name) - else: - print "AIEEE ??? %s " % type(ref) + if with_copy: + lite_sync = action_litesync.BootLiteSync(self.config) + if isinstance(ref, item_system.System): + lite_sync.add_single_system(ref.name) + elif isinstance(ref, item_profile.Profile): + lite_sync.add_single_profile(ref.name) + elif isinstance(ref, item_distro.Distro): + lite_sync.add_single_distro(ref.name) + else: + print "AIEEE ??? %s " % type(ref) - self.listing[ref.name] = ref return True diff --git a/cobbler/collection_distros.py b/cobbler/collection_distros.py index cb21a5f..d632ee5 100644 --- a/cobbler/collection_distros.py +++ b/cobbler/collection_distros.py @@ -41,7 +41,7 @@ class Distros(collection.Collection): else: return "/var/lib/cobbler/distros" - def remove(self,name): + def remove(self,name,with_delete=False): """ Remove element named 'name' from the collection """ @@ -50,9 +50,10 @@ class Distros(collection.Collection): if v.distro == name: raise cexceptions.CobblerException("orphan_profile",v.name) if self.find(name): + if with_delete: + lite_sync = action_litesync.BootLiteSync(self.config) + lite_sync.remove_single_profile(name) del self.listing[name] - lite_sync = action_litesync.BootLiteSync(self.config) - lite_sync.remove_single_profile(name) return True raise cexceptions.CobblerException("delete_nothing") diff --git a/cobbler/collection_profiles.py b/cobbler/collection_profiles.py index fb1c37d..cac69fa 100644 --- a/cobbler/collection_profiles.py +++ b/cobbler/collection_profiles.py @@ -39,7 +39,7 @@ class Profiles(collection.Collection): else: return "/var/lib/cobbler/profiles" - def remove(self,name): + def remove(self,name,with_delete=True): """ Remove element named 'name' from the collection """ @@ -48,8 +48,9 @@ class Profiles(collection.Collection): raise cexceptions.CobblerException("orphan_system",v.name) if self.find(name): del self.listing[name] - lite_sync = action_litesync.BootLiteSync(self.config) - lite_sync.remove_single_profile(name) + if with_delete: + lite_sync = action_litesync.BootLiteSync(self.config) + lite_sync.remove_single_profile(name) return True raise cexceptions.CobblerException("delete_nothing") diff --git a/cobbler/collection_systems.py b/cobbler/collection_systems.py index 013ada1..8d90eb5 100644 --- a/cobbler/collection_systems.py +++ b/cobbler/collection_systems.py @@ -43,14 +43,15 @@ class Systems(collection.Collection): else: return "/var/lib/cobbler/systems" - def remove(self,name): + def remove(self,name,with_delete=False): """ Remove element named 'name' from the collection """ if self.find(name): del self.listing[name] - lite_sync = action_litesync.BootLiteSync(self.config) - lite_sync.remove_single_system(name) + if with_delete: + lite_sync = action_litesync.BootLiteSync(self.config) + lite_sync.remove_single_system(name) return True raise cexceptions.CobblerException("delete_nothing") diff --git a/cobbler/settings.py b/cobbler/settings.py index 3195238..af62766 100644 --- a/cobbler/settings.py +++ b/cobbler/settings.py @@ -35,7 +35,8 @@ DEFAULTS = { "standard" : "/usr/lib/syslinux/pxelinux.0", "ia64" : "/var/lib/cobbler/elilo-3.6-ia64.efi" }, - "syslog_port" : 25150 + "syslog_port" : 25150, + "minimize_syncs" : 1 } diff --git a/cobbler/utils.py b/cobbler/utils.py index 84b8686..4333393 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -125,6 +125,8 @@ def find_kernel(path): Given a directory or a filename, find if the path can be made to resolve into a kernel, and return that full path if possible. """ + if path is None: + return None if os.path.isfile(path): filename = os.path.basename(path) if _re_kernel.match(filename): @@ -142,6 +144,8 @@ def find_initrd(path): to resolve into an intird, return that full path if possible. """ # FUTURE: try to match kernel/initrd pairs? + if path is None: + return None if os.path.isfile(path): filename = os.path.basename(path) if _re_initrd.match(filename): |