def create_project_file(config): """ Creates a coregen project with settings for this device Args: config (dictionary): configuration dictionary Returns: (string): filename to the project file Raises: Nothing """ core_dir = get_coregen_dir(config, absolute = True) cp_fn = os.path.join(core_dir, COREGEN_PROJECT_NAME) fp = open(cp_fn, "w") #Open up the template dictionary fn = COREGEN_TEMPLATE fn = os.path.join(os.path.dirname(__file__), fn) template = json.load(open(fn, "r")) template["device"] = utils.get_device(config) template["devicefamily"] = utils.get_family(config) template["package"] = utils.get_package(config) template["speedgrade"] = utils.get_speed_grade(config) template["workingdirectory"] = get_coregen_temp_dir(config, absolute = True) for t in template: fp.write("SET %s = %s%s" % (t, template[t], os.linesep)) fp.close() return cp_fn
def create_project_file(config): """ Creates a coregen project with settings for this device Args: config (dictionary): configuration dictionary Returns: (string): filename to the project file Raises: Nothing """ core_dir = get_coregen_dir(config, absolute=True) cp_fn = os.path.join(core_dir, COREGEN_PROJECT_NAME) fp = open(cp_fn, "w") #Open up the template dictionary fn = COREGEN_TEMPLATE fn = os.path.join(os.path.dirname(__file__), fn) template = json.load(open(fn, "r")) template["device"] = utils.get_device(config) template["devicefamily"] = utils.get_family(config) template["package"] = utils.get_package(config) template["speedgrade"] = utils.get_speed_grade(config) template["workingdirectory"] = get_coregen_temp_dir(config, absolute=True) for t in template: fp.write("SET %s = %s%s" % (t, template[t], os.linesep)) fp.close() return cp_fn
def run(self): """ Returns None if there are no errors, otherwise returns a list of things to correct prior to running application 'for real'. (The CLI usage is "cobbler check" before "cobbler sync") """ status = [] self.checked_family = utils.get_family() self.check_name(status) self.check_selinux(status) if self.settings.manage_dhcp: mode = self.collection_mgr.api.get_sync().dhcp.what() if mode == "isc": self.check_dhcpd_bin(status) self.check_dhcpd_conf(status) self.check_service(status, "dhcpd") elif mode == "dnsmasq": self.check_dnsmasq_bin(status) self.check_service(status, "dnsmasq") if self.settings.manage_dns: mode = self.collection_mgr.api.get_sync().dns.what() if mode == "bind": self.check_bind_bin(status) self.check_service(status, "named") elif mode == "dnsmasq" and not self.settings.manage_dhcp: self.check_dnsmasq_bin(status) self.check_service(status, "dnsmasq") mode = self.collection_mgr.api.get_sync().tftpd.what() if mode == "in_tftpd": self.check_tftpd_bin(status) self.check_tftpd_dir(status) self.check_tftpd_conf(status) elif mode == "tftpd_py": self.check_ctftpd_bin(status) self.check_ctftpd_dir(status) self.check_ctftpd_conf(status) self.check_service(status, "cobblerd") self.check_bootloaders(status) self.check_for_wget_curl(status) self.check_rsync_conf(status) self.check_httpd(status) self.check_iptables(status) self.check_yum(status) self.check_debmirror(status) self.check_for_ksvalidator(status) self.check_for_default_password(status) self.check_for_unreferenced_repos(status) self.check_for_unsynced_repos(status) self.check_for_cman(status) return status
def __init__(self, collection_mgr, logger=None): """ Constructor """ # self.collection_mgr = collection_mgr # self.api = collection_mgr.api # self.settings = collection_mgr.settings() if logger is None: logger = clogger.Logger() self.logger = logger self.family = utils.get_family() if self.family == "debian": self.hardlink = "/usr/bin/hardlink" self.hardlink_args = "-f -p -o -t -v /var/www/cobbler/ks_mirror /var/www/cobbler/repo_mirror" else: self.hardlink = "/usr/sbin/hardlink" self.hardlink_args = "-c -v /var/www/cobbler/ks_mirror /var/www/cobbler/repo_mirror" self.hardlink_cmd = "%s %s" % (self.hardlink, self.hardlink_args)
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) # add any repo metadata we can use mdoptions = [] if os.path.isfile("%s/.origin/repomd.xml" % (dirname)): if not HAS_YUM: utils.die(self.logger, "yum is required to use this feature") rmd = yum.repoMDObject.RepoMD( '', "%s/.origin/repomd.xml" % (dirname)) if "group" in rmd.repoData: groupmdfile = rmd.getData("group").location[1] mdoptions.append("-g %s" % groupmdfile) if "prestodelta" in rmd.repoData: # need createrepo >= 0.9.7 to add deltas if utils.get_family() in ("redhat", "suse"): cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo" createrepo_ver = utils.subprocess_get(self.logger, cmd) if createrepo_ver >= "0.9.7": mdoptions.append("--deltas") else: self.logger.error( "this repo has presto metadata; you must upgrade createrepo to >= 0.9.7 first and then need to resync the repo through cobbler." ) blended = utils.blender(self.api, False, repo) flags = blended.get("createrepo_flags", "(ERROR: FLAGS)") try: # BOOKMARK cmd = "createrepo %s %s %s" % (" ".join(mdoptions), flags, dirname) utils.subprocess_call(self.logger, cmd) except: utils.log_exc(self.logger) self.logger.error("createrepo failed.") del fnames[:] # we're in the right place
def regen_ss_file(): # this is only used for Kerberos auth at the moment. # it identifies XMLRPC requests from Apache that have already # been cleared by Kerberos. ssfile = "/var/lib/cobbler/web.ss" fd = open("/dev/urandom") data = fd.read(512) fd.close() fd = os.open(ssfile, os.O_CREAT | os.O_RDWR, 0600) os.write(fd, binascii.hexlify(data)) os.close(fd) http_user = "******" family = utils.get_family() if family == "debian": http_user = "******" elif family == "suse": http_user = "******" os.lchown("/var/lib/cobbler/web.ss", pwd.getpwnam(http_user)[2], -1) return 1
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) # add any repo metadata we can use mdoptions = [] if os.path.isfile("%s/.origin/repomd.xml" % (dirname)): if not HAS_YUM: utils.die(self.logger, "yum is required to use this feature") rmd = yum.repoMDObject.RepoMD("", "%s/.origin/repomd.xml" % (dirname)) if "group" in rmd.repoData: groupmdfile = rmd.getData("group").location[1] mdoptions.append("-g %s" % groupmdfile) if "prestodelta" in rmd.repoData: # need createrepo >= 0.9.7 to add deltas if utils.get_family() in ("redhat", "suse"): cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo" createrepo_ver = utils.subprocess_get(self.logger, cmd) if utils.compare_versions_gt(createrepo_ver, "0.9.7"): mdoptions.append("--deltas") else: self.logger.error( "this repo has presto metadata; you must upgrade createrepo to >= 0.9.7 first and then need to resync the repo through cobbler." ) blended = utils.blender(self.api, False, repo) flags = blended.get("createrepo_flags", "(ERROR: FLAGS)") try: # BOOKMARK cmd = "createrepo %s %s %s" % (" ".join(mdoptions), flags, dirname) utils.subprocess_call(self.logger, cmd) except: utils.log_exc(self.logger) self.logger.error("createrepo failed.") del fnames[:] # we're in the right place
def _regen_ss_file(self): """ The 'web.ss' file is regenerated each time cobblerd restarts and is used to agree on shared secret interchange between cobblerd and the cli. This enables root users to avoid entering username/pass if on the cobbler server. """ fd = open("/dev/urandom") data = fd.read(512) fd.close() ssfile = "/var/lib/cobbler/web.ss" fd = os.open(ssfile, os.O_CREAT | os.O_RDWR, 0600) os.write(fd, binascii.hexlify(data)) os.close(fd) http_user = "******" family = get_family() if family == "debian": http_user = "******" elif family == "suse": http_user = "******" os.lchown(ssfile, pwd.getpwnam(http_user)[2], -1)
def test_get_family(self): config = utils.read_config(self.env) config["device"] = "xc6slx9-tqg144-3" family = utils.get_family(config) self.assertEqual("spartan6", family)
def customize_core(config, coregen_filename): """ Reads in the xco from the the core directory and customize it for this Architecture Args: config (dictionary): configuration dictionary coregen_filename (string): filename of the coregen file to work on Returns: (string): filename to the custom core path Raises: Nothing """ #Open the coregen file fp = open(coregen_filename) core_in = fp.read() fp.close() #open a reference to the output file c_fn = os.path.split(coregen_filename)[1] c_fn = os.path.join(get_coregen_dir(config, absolute = True), c_fn) #Open up the template dictionary fn = COREGEN_TEMPLATE fn = os.path.join(os.path.dirname(__file__), fn) template = json.load(open(fn, "r")) template["device"] = utils.get_device(config) template["devicefamily"] = utils.get_family(config) template["package"] = utils.get_package(config) template["speedgrade"] = utils.get_speed_grade(config) template["workingdirectory"] = get_coregen_temp_dir(config, absolute = True) #print "Open: %s" % c_fn fp = open(c_fn, "w") #Break this into lines core_in_lines = core_in.splitlines() for line in core_in_lines: line = line.strip() if re.search('BEGIN.*Project.*Options', line, re.I): #print "\tFound the beginning of the project" fp.write("%s%s" % (line, os.linesep)) #Copy all the objects into the new file for key in template: fp.write("SET %s = %s%s" % (key, template[key], os.linesep)) continue if "CRC" in line: #Don't write the CRC continue #if line.startswith("#"): #print "line: %s" % line items = line.split(' ') if "set" == items[0].lower(): #print "Line: %s" % line #Now we have a line we might need to modify if items[1].lower() in template.keys(): #Skip it, cause we already wrote what we wanted into the new xco continue fp.write("%s%s" % (line, os.linesep)) fp.close()
def customize_core(config, coregen_filename): """ Reads in the xco from the the core directory and customize it for this Architecture Args: config (dictionary): configuration dictionary coregen_filename (string): filename of the coregen file to work on Returns: (string): filename to the custom core path Raises: Nothing """ #Open the coregen file fp = open(coregen_filename) core_in = fp.read() fp.close() #open a reference to the output file c_fn = os.path.split(coregen_filename)[1] c_fn = os.path.join(get_coregen_dir(config, absolute=True), c_fn) #Open up the template dictionary fn = COREGEN_TEMPLATE fn = os.path.join(os.path.dirname(__file__), fn) template = json.load(open(fn, "r")) template["device"] = utils.get_device(config) template["devicefamily"] = utils.get_family(config) template["package"] = utils.get_package(config) template["speedgrade"] = utils.get_speed_grade(config) template["workingdirectory"] = get_coregen_temp_dir(config, absolute=True) #print "Open: %s" % c_fn fp = open(c_fn, "w") #Break this into lines core_in_lines = core_in.splitlines() for line in core_in_lines: line = line.strip() if re.search('BEGIN.*Project.*Options', line, re.I): #print "\tFound the beginning of the project" fp.write("%s%s" % (line, os.linesep)) #Copy all the objects into the new file for key in template: fp.write("SET %s = %s%s" % (key, template[key], os.linesep)) continue if "CRC" in line: #Don't write the CRC continue #if line.startswith("#"): #print "line: %s" % line items = line.split(' ') if "set" == items[0].lower(): #print "Line: %s" % line #Now we have a line we might need to modify if items[1].lower() in template.keys(): #Skip it, cause we already wrote what we wanted into the new xco continue fp.write("%s%s" % (line, os.linesep)) fp.close()