def autostart(self, vm): self.conn = self.__get_conn() if self.conn.get_type() == "Xen": autostart_args = [ "/bin/ln", "-s", "/etc/xen/%s" % vm, "/etc/xen/auto" ] else: # When using KVM, we need to make sure the autostart # directory exists mkdir_args = [ "/bin/mkdir", "-p", "/etc/libvirt/qemu/autostart" ] sub_process.call(mkdir_args,shell=False,close_fds=True) # We aren't using virsh autostart because we want # the command to work even when the VM isn't running autostart_args = [ "/bin/ln", "-s", "/etc/libvirt/qemu/%s.xml" % vm, "/etc/libvirt/qemu/autostart/%s.xml" % vm ] return sub_process.call(autostart_args,shell=False,close_fds=True)
def run_triggers(ref, globber): """ Runs all the trigger scripts in a given directory. ref can be a certmaster object, if not None, the name will be passed to the script. If ref is None, the script will be called with no argumenets. Globber is a wildcard expression indicating which triggers to run. Example: "/var/lib/certmaster/triggers/blah/*" """ log = logger.Logger().logger triggers = glob.glob(globber) triggers.sort() for file in triggers: log.debug("Executing trigger: %s" % file) try: if file.find(".rpm") != -1: # skip .rpmnew files that may have been installed # in the triggers directory continue if ref: rc = sub_process.call([file, ref], shell=False) else: rc = sub_process.call([file], shell=False) except: log.warning("Warning: failed to execute trigger: %s" % file) continue if rc != 0: raise codes.CMException, "certmaster trigger failed: %(file)s returns %(code)d" % { "file" : file, "code" : rc }
def __init__(self, logfile="/var/log/cobbler/cobbler.log"): # Main logfile is append mode, other logfiles not. if not os.path.exists(logfile): self.logfile = open(logfile, "a") sub_process.call("chown apache %s" % logfile, shell=True) self.logfile.close() if logfile.find("tasks") != -1: self.logfile = open(logfile, "w+") else: self.logfile = open(logfile, "a")
def createrepo_walker(self, repo, dirname, fnames): """ Used to run createrepo on a copied Yum mirror. """ if os.path.exists(dirname) or repo['breed'] == 'rsync': utils.remove_yum_olddata(dirname) try: cmd = "createrepo %s %s" % (repo.createrepo_flags, dirname) print _("- %s") % cmd sub_process.call(cmd, shell=True, close_fds=True) except: print _("- createrepo failed. Is it installed?") del fnames[:] # we're in the right place
def deploy(api, system, virt_host=None, virt_group=None): """ Deploy the current system to the virtual host or virtual group """ if virt_host is None and virt_group is not None: virt_host = __find_host(api, virt_group) if virt_host is None and system.virt_group == "": virt_host = __find_host(api, system.virt_group) if system.virt_host != "": virt_host = system.virt_host if virt_host is None: raise CX("No host specified for deployment.") virt_host = api.find_system(virt_host) if virt_host is None: raise CX("Unable to find cobbler system record for virt-host (%s)" % virt_host) if virt_host.hostname == "": raise CX("Hostname for cobbler system (%s) not set" % virt_host.name) me = api.settings().server cmd = ["/usr/bin/ssh", virt_host.hostname, "koan", "--server", me, "--virt", "--system", system.name] print "- %s" % " ".join(cmd) rc = sub_process.call(cmd, shell=False) if rc != 0: raise CX("remote deployment failed") return virt_host.name
def scp_it(self,from_path,to_path): from_path = "%s:%s" % (self.host, from_path) cmd = "scp %s %s" % (from_path, to_path) print _("- %s") % cmd rc = sub_process.call(cmd, shell=True, close_fds=True) if rc !=0: raise CX(_("scp failed"))
def __command(self, service_name, command): filename = os.path.join("/etc/rc.d/init.d/",service_name) if os.path.exists(filename): return sub_process.call(["/sbin/service", service_name, command]) else: raise codes.FuncException("Service not installed: %s" % service_name)
def rsync_sync(self, repo): """ Handle copying of rsync:// and rsync-over-ssh repos. """ repo_mirror = repo.mirror if not repo.mirror_locally: raise CX(_("rsync:// urls must be mirrored locally, yum cannot access them directly")) if repo.rpm_list != "": print _("- warning: --rpm-list is not supported for rsync'd repositories") # FIXME: don't hardcode dest_path = os.path.join("/var/www/cobbler/repo_mirror", repo.name) spacer = "" if not repo.mirror.startswith("rsync://") and not repo.mirror.startswith("/"): spacer = "-e ssh" if not repo.mirror.endswith("/"): repo.mirror = "%s/" % repo.mirror cmd = "rsync -rltDv %s --delete --delete-excluded --exclude-from=/etc/cobbler/rsync.exclude %s %s" % (spacer, repo.mirror, dest_path) print _("- %s") % cmd rc = sub_process.call(cmd, shell=True, close_fds=True) if rc !=0: raise CX(_("cobbler reposync failed")) print _("- walking: %s") % dest_path os.path.walk(dest_path, self.createrepo_walker, repo) self.create_local_file(dest_path, repo)
def __command(self, service_name, command): service_name = service_name.strip() # remove useless spaces filename = os.path.join("/etc/init.d/",service_name) if os.path.exists(filename): return sub_process.call(["/sbin/service", service_name, command], close_fds=True, env={ 'LANG':'C' }) else: raise codes.FuncException("Service not installed: %s" % service_name)
def __command(self, service_name, command): service_name = service_name.strip() # remove useless spaces filename = os.path.join("/etc/rc.d/init.d/",service_name) if os.path.exists(filename): return sub_process.call(["/sbin/service", service_name, command], close_fds=True) else: raise codes.FuncException("Service not installed: %s" % service_name)
def is_selinux_enabled(): if not os.path.exists("/usr/sbin/selinuxenabled"): return False args = "/usr/sbin/selinuxenabled" selinuxenabled = sub_process.call(args,close_fds=True) if selinuxenabled == 0: return True else: return False
def __init__(self, logfile="/var/log/cobbler/cobbler.log"): self.logfile = None # Main logfile is append mode, other logfiles not. if not os.path.exists(logfile): self.logfile = open(logfile, "a") sub_process.call("chown apache %s" % logfile, shell=True) self.logfile.close() try: if logfile.find("tasks") != -1: self.logfile = open(logfile, "w+") else: self.logfile = open(logfile, "a") except IOError: # You likely don't have write access, this logger will just print # things to stdout. pass
def subprocess_call(cmd, ignore_rc=False): """ Wrapper around subprocess.call(...) """ print "- %s" % cmd rc = sub_process.call(cmd) if rc != 0 and not ignore_rc: raise InfoException, "command failed (%s)" % rc return rc
def modacl(self,isadd,isuser,who): webdir = self.settings.webdir snipdir = self.settings.snippetsdir tftpboot = utils.tftpboot_location() PROCESS_DIRS = { webdir : "rwx", "/var/log/cobbler" : "rwx", "/var/lib/cobbler" : "rwx", "/etc/cobbler" : "rwx", tftpboot : "rwx", "/var/lib/cobbler/triggers" : "rwx" } if not snipdir.startswith("/var/lib/cobbler/"): PROCESS_DIRS[snipdir] = "r" cmd = "-R" if isadd: cmd = "%s -m" % cmd else: cmd = "%s -x" % cmd if isuser: cmd = "%s u:%s" % (cmd,who) else: cmd = "%s g:%s" % (cmd,who) for d in PROCESS_DIRS: how = PROCESS_DIRS[d] if isadd: cmd2 = "%s:%s" % (cmd,how) else: cmd2 = cmd cmd2 = "%s %s" % (cmd2,d) print "- setfacl -d %s" % cmd2 rc = sub_process.call("setfacl -d %s" % cmd2,shell=True,close_fds=True) if not rc == 0: raise CX(_("command failed")) print "- setfacl %s" % cmd2 rc = sub_process.call("setfacl %s" % cmd2,shell=True,close_fds=True) if not rc == 0: raise CX(_("command failed"))
def check_service(self, status, which, notes=""): if notes != "": notes = " (NOTE: %s)" % notes rc = 0 if self.checked_dist == "redhat" or self.checked_dist == "suse": if os.path.exists("/etc/rc.d/init.d/%s" % which): rc = sub_process.call("/sbin/service %s status > /dev/null 2>/dev/null" % which, shell=True, close_fds=True) if rc != 0: status.append(_("service %s is not running%s") % (which,notes)) return False elif self.checked_dist == "debian": if os.path.exists("/etc/init.d/%s" % which): rc = sub_process.call("/etc/init.d/%s status /dev/null 2>/dev/null" % which, shell=True, close_fds=True) if rc != 0: status.append(_("service %s is not running%s") % which,notes) return False else: status.append(_("Unknown distribution type, cannot check for running service %s" % which)) return False return True
def run_this(self, cmd, args): """ A simple wrapper around subprocess calls. """ my_cmd = cmd % args print _("- %s") % my_cmd rc = sub_process.call(my_cmd,shell=True,close_fds=True) if rc != 0: raise CX(_("Command failed"))
def kill(self,pid,signal="TERM"): if pid == "0": raise codes.FuncException("Killing pid group 0 not permitted") if signal == "": # this is default /bin/kill behaviour, # it claims, but enfore it anyway signal = "-TERM" if signal[0] != "-": signal = "-%s" % signal rc = sub_process.call(["/bin/kill",signal, pid], executable="/bin/kill", shell=False) print rc return rc
def kill(self, pid, signal="TERM"): if pid == "0": raise codes.FuncException("Killing pid group 0 not permitted") if signal == "": # this is default /bin/kill behaviour, # it claims, but enfore it anyway signal = "-TERM" if signal[0] != "-": signal = "-%s" % signal rc = sub_process.call(["/bin/kill", signal, pid], executable="/bin/kill", shell=False) print rc return rc
def subprocess_call(cmd,ignore_rc=0): """ Wrapper around subprocess.call(...) """ print "- %s" % cmd if not ANCIENT_PYTHON: rc = sub_process.call(cmd) else: cmd = string.join(cmd, " ") print "cmdstr=(%s)" % cmd rc = os.system(cmd) if rc != 0 and not ignore_rc: raise InfoException, "command failed (%s)" % rc return rc
def run_triggers(api,ref,globber,additional=[]): """ Runs all the trigger scripts in a given directory. ref can be a cobbler object, if not None, the name will be passed to the script. If ref is None, the script will be called with no argumenets. Globber is a wildcard expression indicating which triggers to run. Example: "/var/lib/cobbler/triggers/blah/*" As of Cobbler 1.5.X, this also runs cobbler modules that match the globbing paths. """ # Python triggers first, before shell modules = api.get_modules_in_category(globber) for m in modules: arglist = [] if ref: arglist.append(ref.name) for x in additional: arglist.append(x) rc = m.run(api, arglist) if rc != 0: raise CX("cobbler trigger failed: %s" % m.__name__) # now do the old shell triggers, which are usually going to be slower, but are easier to write # and support any language triggers = glob.glob(globber) triggers.sort() for file in triggers: try: if file.startswith(".") or file.find(".rpm") != -1: # skip dotfiles or .rpmnew files that may have been installed # in the triggers directory continue arglist = [ file ] if ref: arglist.append(ref.name) for x in additional: arglist.append(x) rc = sub_process.call(arglist, shell=False, close_fds=True) except: print _("Warning: failed to execute trigger: %s" % file) continue if rc != 0: raise CX(_("cobbler trigger failed: %(file)s returns %(code)d") % { "file" : file, "code" : rc })
def install(self, server_name, target_name, system=False, virt_name=None, virt_path=None, graphics=False): """ Install a new virt system by way of a named cobbler profile. """ # Example: # install("bootserver.example.org", "fc7webserver", True) # install("bootserver.example.org", "client.example.org", True, "client-disk0", "HostVolGroup00") conn = self.__get_conn() if conn is None: raise codes.FuncException("no connection") if not os.path.exists("/usr/bin/koan"): raise codes.FuncException("no /usr/bin/koan") target = "profile" if system: target = "system" koan_args = [ "/usr/bin/koan", "--virt", "--%s=%s" % (target, target_name), "--server=%s" % server_name ] if virt_name: koan_args.append("--virt-name=%s" % virt_name) if virt_path: koan_args.append("--virt-path=%s" % virt_path) if not graphics: koan_args.append("--nogfx") rc = sub_process.call(koan_args, shell=False, close_fds=True) if rc == 0: return 0 else: raise codes.FuncException("koan returned %d" % rc)
def cabextract(src,dst,api=None): """ Extract a cab file, used for importing off of Windows based cds """ try: if not os.path.isdir(dst): raise CX(_("Error in cabextract: the destination (%s) must be a directory") % dst) cmd = [ "/usr/bin/cabextract", "-d", dst, src ] rc = sub_process.call(cmd, shell=False, close_fds=True) return rc except: if not os.access(src,os.R_OK): raise CX(_("Cannot read: %s") % src) if not os.path.samefile(src,dst): # accomodate for the possibility that we already copied # the file as a symlink/hardlink raise
def install(self, server_name, target_name, system=False, virt_name=None, virt_path=None, graphics=False): """ Install a new virt system by way of a named cobbler profile. """ # Example: # install("bootserver.example.org", "fc7webserver", True) # install("bootserver.example.org", "client.example.org", True, "client-disk0", "HostVolGroup00") conn = self.__get_conn() if conn is None: raise codes.FuncException("no connection") if not os.path.exists("/usr/bin/koan"): raise codes.FuncException("no /usr/bin/koan") target = "profile" if system: target = "system" koan_args = [ "/usr/bin/koan", "--virt", "--%s=%s" % (target, target_name), "--server=%s" % server_name ] if virt_name: koan_args.append("--virt-name=%s" % virt_name) if virt_path: koan_args.append("--virt-path=%s" % virt_path) if not graphics: koan_args.append("--nogfx") rc = sub_process.call(koan_args,shell=False,close_fds=True) if rc == 0: return 0 else: raise codes.FuncException("koan returned %d" % rc)
def nfsmount(input_path): # input: nfs://user@server:/foo/bar/x.img as string # output: (dirname where mounted, last part of filename) as 2-element tuple input_path = input_path[6:] # FIXME: move this function to util.py so other modules can use it # we have to mount it first segments = input_path.split("/") # discard nfs:// prefix filename = segments[-1] dirpath = "/".join(segments[:-1]) tempdir = tempfile.mkdtemp(suffix=".mnt", prefix="koan_", dir="/tmp") mount_cmd = ["/bin/mount", "-t", "nfs", "-o", "ro", dirpath, tempdir] print "- running: %s" % " ".join(mount_cmd) rc = sub_process.call(mount_cmd) if not rc == 0: shutil.rmtree(tempdir, ignore_errors=True) raise koan.InfoException("nfs mount failed: %s" % dirpath) # NOTE: option for a blocking install might be nice, so we could do this # automatically, if supported by python-virtinst print "after install completes, you may unmount and delete %s" % tempdir return (tempdir, filename)
def general_operation(api, hostname, guestname, operation): # map English phrases into virsh commands if operation == "uninstall": vops = [ "destroy", "undefine" ] elif operation in [ "start", "shutdown", "reboot" ]: vops = [ operation ] elif operation == "unplug": vops = [ "destroy" ] else: raise CX("unknown operation: %s" % operation) # run over SSH for v in vops: cmd = [ "/usr/bin/ssh", hostname, "virsh", v, guestname ] print "- %s" % " ".join(cmd) rc = sub_process.call(cmd, shell=False) if rc != 0: raise CX("remote command failed failed")
def update_permissions(self, repo_path): """ Verifies that permissions and contexts after an rsync are as expected. Sending proper rsync flags should prevent the need for this, though this is largely a safeguard. """ # all_path = os.path.join(repo_path, "*") cmd1 = "chown -R root:apache %s" % repo_path sub_process.call(cmd1, shell=True, close_fds=True) cmd2 = "chmod -R 755 %s" % repo_path sub_process.call(cmd2, shell=True, close_fds=True) if self.config.api.is_selinux_enabled(): cmd3 = "chcon --reference /var/www %s >/dev/null 2>/dev/null" % repo_path sub_process.call(cmd3, shell=True, close_fds=True)
def run(self,iso=None,tempdir=None,profiles=None,systems=None,distro=None,standalone=None,source=None,exclude_dns=None): # the distro option is for stand-alone builds only if not standalone and distro is not None: raise CX(_("The --distro option should only be used when creating a standalone ISO")) # if building standalone, we only want --distro, # profiles/systems are disallowed if standalone: if profiles is not None or systems is not None: raise CX(_("When building a standalone ISO, use --distro only instead of --profiles/--systems")) elif distro is None: raise CX(_("When building a standalone ISO, you must specify a --distro")) if source != None and not os.path.exists(source): raise CX(_("The source specified (%s) does not exist" % source)) # if iso is none, create it in . as "kickstart.iso" if iso is None: iso = "kickstart.iso" if tempdir is None: tempdir = os.path.join(os.getcwd(), "buildiso") else: if not os.path.isdir(tempdir): raise CX(_("The --tempdir specified is not a directory")) (tempdir_head,tempdir_tail) = os.path.split(os.path.normpath(tempdir)) if tempdir_tail != "buildiso": tempdir = os.path.join(tempdir, "buildiso") print _("- using/creating tempdir: %s") % tempdir if not os.path.exists(tempdir): os.makedirs(tempdir) else: shutil.rmtree(tempdir) os.makedirs(tempdir) # if base of tempdir does not exist, fail # create all profiles unless filtered by "profiles" imagesdir = os.path.join(tempdir, "images") isolinuxdir = os.path.join(tempdir, "isolinux") print _("- building tree for isolinux") if not os.path.exists(imagesdir): os.makedirs(imagesdir) if not os.path.exists(isolinuxdir): os.makedirs(isolinuxdir) print _("- copying miscellaneous files") isolinuxbin = "/usr/lib/syslinux/isolinux.bin" menu = "/var/lib/cobbler/menu.c32" chain = "/usr/lib/syslinux/chain.c32" files = [ isolinuxbin, menu, chain ] for f in files: if not os.path.exists(f): raise CX(_("Required file not found: %s") % f) else: utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)), self.api) if standalone: self.generate_standalone_iso(imagesdir,isolinuxdir,distro,source) else: self.generate_netboot_iso(imagesdir,isolinuxdir,profiles,systems,exclude_dns) cmd = "mkisofs -quiet -o %s -r -b isolinux/isolinux.bin -c isolinux/boot.cat" % iso cmd = cmd + " -no-emul-boot -boot-load-size 4" cmd = cmd + " -boot-info-table -V Cobbler\ Install -R -J -T %s" % tempdir print _("- running: %s") % cmd rc = sub_process.call(cmd, shell=True, close_fds=True) if rc: raise CX(_("mkisofs failed")) print _("ISO build complete") print _("You may wish to delete: %s") % tempdir print _("The output file is: %s") % iso
def call_iptables(args): return sub_process.call(["/sbin/iptables"] + args.split(), executable="/sbin/iptables", shell=False)
def generate_standalone_iso(self,imagesdir,isolinuxdir,distname,filesource): # Get the distro object for the requested distro # and then get all of its descendants (profiles/sub-profiles/systems) distro = self.api.find_distro(distname) if distro is None: raise CX("distro %s was not found, aborting" % distname) descendants = distro.get_descendants() if filesource is None: # Try to determine the source from the distro kernel path print _("- trying to locate source for distro") found_source = False (source_head, source_tail) = os.path.split(distro.kernel) while source_tail != '': if source_head == os.path.join(self.api.settings().webdir, "ks_mirror"): filesource = os.path.join(source_head, source_tail) found_source = True print _(" found source in %s" % filesource) break (source_head, source_tail) = os.path.split(source_head) # Can't find the source, raise an error if not found_source: raise CX(_(" Error, no installation source found. When building a standalone ISO, you must specify a --source if the distro install tree is not hosted locally")) print _("- copying kernels and initrds - for standalone distro") # tempdir/isolinux/$distro/vmlinuz, initrd.img # FIXME: this will likely crash on non-Linux breeds f1 = os.path.join(isolinuxdir, "vmlinuz") f2 = os.path.join(isolinuxdir, "initrd.img") if not os.path.exists(distro.kernel): raise CX("path does not exist: %s" % distro.kernel) if not os.path.exists(distro.initrd): raise CX("path does not exist: %s" % distro.initrd) shutil.copyfile(distro.kernel, f1) shutil.copyfile(distro.initrd, f2) cmd = "rsync -rlptgu --exclude=boot.cat --exclude=TRANS.TBL --exclude=isolinux/ %s/ %s/../" % (filesource, isolinuxdir) print _("- copying distro %s files (%s)" % (distname,cmd)) rc = sub_process.call(cmd, shell=True, close_fds=True) if rc: raise CX(_("rsync of files failed")) print _("- generating a isolinux.cfg") isolinuxcfg = os.path.join(isolinuxdir, "isolinux.cfg") cfg = open(isolinuxcfg, "w+") cfg.write(HEADER) # fixme, use template for descendant in descendants: data = utils.blender(self.api, True, descendant) cfg.write("\n") cfg.write("LABEL %s\n" % descendant.name) cfg.write(" MENU LABEL %s\n" % descendant.name) cfg.write(" kernel vmlinuz\n") data["kickstart"] = "cdrom:/isolinux/ks-%s.cfg" % descendant.name append_line = " append initrd=initrd.img" append_line = append_line + " ks=%s " % data["kickstart"] append_line = append_line + " %s\n" % data["kernel_options"] cfg.write(append_line) if descendant.COLLECTION_TYPE == 'profile': kickstart_data = self.api.kickgen.generate_kickstart_for_profile(descendant.name) elif descendant.COLLECTION_TYPE == 'system': kickstart_data = self.api.kickgen.generate_kickstart_for_system(descendant.name) cdregex = re.compile("url .*\n", re.IGNORECASE) kickstart_data = cdregex.sub("cdrom\n", kickstart_data) ks_name = os.path.join(isolinuxdir, "ks-%s.cfg" % descendant.name) ks_file = open(ks_name, "w+") ks_file.write(kickstart_data) ks_file.close() print _("- done writing config") cfg.write("\n") cfg.write("MENU END\n") cfg.close() return
def process_comps_file(self, comps_path, distro): """ When importing Fedora/EL certain parts of the install tree can also be used as yum repos containing packages that might not yet be available via updates in yum. This code identifies those areas. """ processed_repos = {} masterdir = "repodata" if not os.path.exists(os.path.join(comps_path, "repodata")): # older distros... masterdir = "base" # print _("- scanning: %(path)s (distro: %(name)s)") % { "path" : comps_path, "name" : distro.name } # figure out what our comps file is ... print _("- looking for %(p1)s/%(p2)s/*comps*.xml") % { "p1" : comps_path, "p2" : masterdir } files = glob.glob("%s/%s/*comps*.xml" % (comps_path, masterdir)) if len(files) == 0: print _("- no comps found here: %s") % os.path.join(comps_path, masterdir) return # no comps xml file found # pull the filename from the longer part comps_file = files[0].split("/")[-1] try: # store the yum configs on the filesystem so we can use them later. # and configure them in the kickstart post, etc # print "- possible source repo match" counter = len(distro.source_repos) # find path segment for yum_url (changing filesystem path to http:// trailing fragment) seg = comps_path.rfind("ks_mirror") urlseg = comps_path[seg+10:] # print "- segment: %s" % urlseg # write a yum config file that shows how to use the repo. if counter == 0: dotrepo = "%s.repo" % distro.name else: dotrepo = "%s-%s.repo" % (distro.name, counter) fname = os.path.join(self.settings.webdir, "ks_mirror", "config", "%s-%s.repo" % (distro.name, counter)) repo_url = "http://@@http_server@@/cobbler/ks_mirror/config/%s-%s.repo" % (distro.name, counter) repo_url2 = "http://@@http_server@@/cobbler/ks_mirror/%s" % (urlseg) distro.source_repos.append([repo_url,repo_url2]) # NOTE: the following file is now a Cheetah template, so it can be remapped # during sync, that's why we have the @@http_server@@ left as templating magic. # repo_url2 is actually no longer used. (?) # print _("- url: %s") % repo_url config_file = open(fname, "w+") config_file.write("[core-%s]\n" % counter) config_file.write("name=core-%s\n" % counter) config_file.write("baseurl=http://@@http_server@@/cobbler/ks_mirror/%s\n" % (urlseg)) config_file.write("enabled=1\n") config_file.write("gpgcheck=0\n") config_file.write("priority=1\n") config_file.close() # don't run creatrepo twice -- this can happen easily for Xen and PXE, when # they'll share same repo files. if not processed_repos.has_key(comps_path): utils.remove_yum_olddata(comps_path) #cmd = "createrepo --basedir / --groupfile %s %s" % (os.path.join(comps_path, masterdir, comps_file), comps_path) cmd = "createrepo -c cache --groupfile %s %s" % (os.path.join(comps_path, masterdir, comps_file), comps_path) print _("- %s") % cmd sub_process.call(cmd,shell=True,close_fds=True) processed_repos[comps_path] = 1 # for older distros, if we have a "base" dir parallel with "repodata", we need to copy comps.xml up one... p1 = os.path.join(comps_path, "repodata", "comps.xml") p2 = os.path.join(comps_path, "base", "comps.xml") if os.path.exists(p1) and os.path.exists(p2): print _("- cp %(p1)s %(p2)s") % { "p1" : p1, "p2" : p2 } shutil.copyfile(p1,p2) except: print _("- error launching createrepo, ignoring...") traceback.print_exc()
def __send_ssh(self, command, **kwargs): ssh_args = ['/usr/bin/ssh', 'root@%s' % self.hostname] for arg in command: ssh_args.append(arg) return sub_process.call(ssh_args, **kwargs)
def __test_setup(): # this contains some code from remote.py that has been modified # slightly to add in some extra parameters for these checks. # it can probably be combined into something like a test_utils # module later. api = cobbler_api.BootAPI() fake = open("/tmp/cobbler.fake","w+") fake.write("") fake.close() distro = api.new_distro() distro.set_name("distro0") distro.set_kernel("/tmp/cobbler.fake") distro.set_initrd("/tmp/cobbler.fake") api.add_distro(distro) repo = api.new_repo() repo.set_name("repo0") if not os.path.exists("/tmp/empty"): os.mkdir("/tmp/empty",770) repo.set_mirror("/tmp/empty") files = glob.glob("rpm-build/*.rpm") if len(files) == 0: raise Exception("Tests must be run from the cobbler checkout directory.") sub_process.call("cp rpm-build/*.rpm /tmp/empty",shell=True,close_fds=True) api.add_repo(repo) fd = open("/tmp/cobbler_t1","w+") fd.write("$profile_name") fd.close() fd = open("/tmp/cobbler_t2","w+") fd.write("$system_name") fd.close() profile = api.new_profile() profile.set_name("profile0") profile.set_distro("distro0") profile.set_kickstart("/var/lib/cobbler/kickstarts/sample.ks") profile.set_repos(["repo0"]) profile.set_mgmt_classes(["alpha","beta"]) profile.set_ksmeta({"tree":"look_for_this1","gamma":3}) profile.set_template_files("/tmp/cobbler_t1=/tmp/t1-rendered") api.add_profile(profile) system = api.new_system() system.set_name("system0") system.set_hostname("hostname0") system.set_gateway("192.168.1.1") system.set_profile("profile0") system.set_dns_name("hostname0","eth0") system.set_ksmeta({"tree":"look_for_this2"}) system.set_template_files({"/tmp/cobbler_t2":"/tmp/t2-rendered"}) api.add_system(system) image = api.new_image() image.set_name("image0") image.set_file("/tmp/cobbler.fake") api.add_image(image) # perhaps an artifact of the test process? os.system("rm -rf /var/www/cobbler/repo_mirror/repo0") api.reposync(name="repo0")
def reboot(self, when='now', message=''): return sub_process.call(["/sbin/shutdown", '-r', when, message])
def pkill(self, name, level=""): # example killall("thunderbird","-9") rc = sub_process.call(["/usr/bin/pkill", name, level], executable="/usr/bin/pkill", shell=False) return rc