How to use the cobbler.utils.blender function in cobbler

To help you get started, we’ve selected a few cobbler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cobbler / cobbler / cobbler / actions / buildiso.py View on Github external
cfg = open(isolinuxcfg, "w+")
        cfg.write(self.iso_template)

        # iterate through selected profiles
        for profile in which_profiles:
            self.logger.info("processing profile: %s" % profile.name)
            dist = profile.get_conceptual_parent()
            distname = self.make_shorter(dist.name)
            self.copy_boot_files(dist, isolinuxdir, distname)

            cfg.write("\n")
            cfg.write("LABEL %s\n" % profile.name)
            cfg.write("  MENU LABEL %s\n" % profile.name)
            cfg.write("  kernel %s.krn\n" % distname)

            data = utils.blender(self.api, False, profile)

            # SUSE is not using 'text'. Instead 'textmode' is used as kernel option.
            utils.kopts_overwrite(None, dist, data['kernel_options'], self.api.settings())

            if not re.match(r"[a-z]+://.*", data["autoinstall"]):
                data["autoinstall"] = "http://%s:%s/cblr/svc/op/autoinstall/profile/%s" % (
                    data["server"], self.api.settings().http_port, profile.name
                )

            append_line = " append initrd=%s.img" % distname
            if dist.breed == "suse":
                if "proxy" in data and data["proxy"] != "":
                    append_line += " proxy=%s" % data["proxy"]
                if "install" in data["kernel_options"] and data["kernel_options"]["install"] != "":
                    v = data["kernel_options"]["install"]
                    if isinstance(v, list):
github cobbler / cobbler / cobbler / power_manager.py View on Github external
COBBLER_POWER_PASS will be used.
        @param str password power management password
        @param Logger logger logger
        @return bool/None if power operation is 'status', return if system is on;
                otherwise, return None
        @raise CX if there are errors
        """

        if logger is None:
            logger = self.logger

        power_command = get_power_command(system.power_type)
        if not power_command:
            utils.die(logger, "no power type set for system")

        meta = utils.blender(self.api, False, system)
        meta["power_mode"] = power_operation

        logger.info("cobbler power configuration is:")
        logger.info("      type   : %s" % system.power_type)
        logger.info("      address: %s" % system.power_address)
        logger.info("      user   : %s" % system.power_user)
        logger.info("      id     : %s" % system.power_id)
        logger.info("      options: %s" % system.power_options)
        logger.info("identity_file: %s" % system.power_identity_file)

        # if no username/password data, check the environment
        if not system.power_user and not user:
            user = os.environ.get("COBBLER_POWER_USER", "")
        if not system.power_pass and not password:
            password = os.environ.get("COBBLER_POWER_PASS", "")
github cobbler / cobbler / cobbler / remote.py View on Github external
def get_file_for_koan(self, name, token=None, **rest):
        """
        This is a legacy function for 2.6.6 releases.
        :param name: Name of the file to get.
        :param token: Auth token to authenticate against the api.
        :param rest: This is dropped in this method since it is not needed here.
        :return: The desired file or '~'.
        """
        self._log("get_file_for_koan", name=name, token=token)
        obj = self.api.find_file(name=name)
        if obj is not None:
            return self.xmlrpc_hacks(utils.blender(self.api, True, obj))
        return self.xmlrpc_hacks({})
github cobbler / cobbler / cobbler / modules / managers / manage_in_tftpd.py View on Github external
def write_boot_files_distro(self, distro):
        # collapse the object down to a rendered datastructure
        # the second argument set to false means we don't collapse
        # dicts/arrays into a flat string
        target = utils.blender(self.collection_mgr.api, False, distro)

        # Create metadata for the templar function
        # Right now, just using local_img_path, but adding more
        # cobbler variables here would probably be good
        metadata = {}
        metadata["local_img_path"] = os.path.join(self.bootloc, "images", distro.name)
        # Create the templar instance.  Used to template the target directory
        templater = templar.Templar(self.collection_mgr)

        # Loop through the dict of boot files,
        # executing a cp for each one
        self.logger.info("processing boot_files for distro: %s" % distro.name)
        for file in list(target["boot_files"].keys()):
            rendered_file = templater.render(file, metadata, None)
            try:
                for f in glob.glob(target["boot_files"][file]):
github cobbler / cobbler / cobbler / remote.py View on Github external
def get_mgmtclass_as_rendered(self, name, token=None, **rest):
        """
        Get management class after passing through Cobbler's inheritance engine

        @param str name management class name
        @param str token authentication token
        """

        self._log("get_mgmtclass_as_rendered", name=name, token=token)
        obj = self.api.find_mgmtclass(name=name)
        if obj is not None:
            return self.xmlrpc_hacks(utils.blender(self.api, True, obj))
        return self.xmlrpc_hacks({})
github cobbler / cobbler / cobbler / tftpgen.py View on Github external
if system:
            if format == "grub":
                if system.netboot_enabled:
                    template = os.path.join(self.settings.boot_loader_conf_template_dir, "grubsystem.template")
                    buffer += 'set system="{system}"\n'.format(system=system.name)
                else:
                    local = os.path.join(self.settings.boot_loader_conf_template_dir, "grublocal.template")
                    if os.path.exists(local):
                        template = local
            else:   # pxe
                if system.netboot_enabled:
                    template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem.template")

                    if arch == "ppc" or arch == "ppc64":
                        # to inherit the distro and system's boot_loader values correctly
                        blended_system = utils.blender(self.api, False, system)
                        if blended_system["boot_loader"] == "pxelinux":
                            template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_ppc.template")
                        else:
                            template = os.path.join(self.settings.boot_loader_conf_template_dir, "yaboot_ppc.template")
                    elif arch.startswith("arm"):
                        template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_arm.template")
                    elif distro and distro.os_version.startswith("esxi"):
                        # ESXi uses a very different pxe method, using more files than
                        # a standard automatic installation file and different options -
                        # so giving it a dedicated PXE template makes more sense than
                        # shoe-horning it into the existing templates
                        template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxesystem_esxi.template")
                else:
                    # local booting on ppc requires removing the system-specific dhcpd.conf filename
                    if arch is not None and (arch == "ppc" or arch == "ppc64"):
                        # Disable yaboot network booting for all interfaces on the system
github cobbler / cobbler / cobbler / tftpgen.py View on Github external
management_interface = None
        if system is not None:
            blended = utils.blender(self.api, False, system)
            # find the first management interface
            try:
                for intf in list(system.interfaces.keys()):
                    if system.interfaces[intf]["management"]:
                        management_interface = intf
                        break
            except:
                # just skip this then
                pass
        elif profile is not None:
            blended = utils.blender(self.api, False, profile)
        else:
            blended = utils.blender(self.api, False, image)

        append_line = ""
        kopts = blended.get("kernel_options", dict())
        kopts = utils.revert_strip_none(kopts)

        # SUSE and other distro specific kernel additions or modificatins
        utils.kopts_overwrite(system, distro, kopts, self.settings)

        # since network needs to be configured again (it was already in netboot) when kernel boots
        # and we choose to do it dinamically, we need to set 'ksdevice' to one of
        # the interfaces' MAC addresses in ppc systems.
        # ksdevice=bootif is not useful in yaboot, as the "ipappend" line is a pxe feature.
        if system and arch and (arch == "ppc" or arch == "ppc64"):
            for intf in list(system.interfaces.keys()):
                # use first interface with defined IP and MAC, since these are required
                # fields in a DHCP entry
github cobbler / cobbler / cobbler / actions / buildiso.py View on Github external
cfg.write("\nMENU SEPARATOR\n")

        # iterate through all selected systems
        for system in which_systems:
            self.logger.info("processing system: %s" % system.name)
            profile = system.get_conceptual_parent()
            dist = profile.get_conceptual_parent()
            distname = self.make_shorter(dist.name)
            self.copy_boot_files(dist, isolinuxdir, distname)

            cfg.write("\n")
            cfg.write("LABEL %s\n" % system.name)
            cfg.write("  MENU LABEL %s\n" % system.name)
            cfg.write("  kernel %s.krn\n" % distname)

            data = utils.blender(self.api, False, system)
            if not re.match(r"[a-z]+://.*", data["autoinstall"]):
                data["autoinstall"] = "http://%s:%s/cblr/svc/op/autoinstall/system/%s" % (
                    data["server"], self.api.settings().http_port, system.name
                )

            append_line = " append initrd=%s.img" % distname
            if dist.breed == "suse":
                if "proxy" in data and data["proxy"] != "":
                    append_line += " proxy=%s" % data["proxy"]
                if "install" in data["kernel_options"] and data["kernel_options"]["install"] != "":
                    append_line += " install=%s" % data["kernel_options"]["install"]
                    del data["kernel_options"]["install"]
                else:
                    append_line += " install=http://%s:%s/cblr/links/%s" % (
                        data["server"], self.api.settings().http_port, dist.name
                    )
github cobbler / cobbler / cobbler / action_reposync.py View on Github external
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, pipes.quote(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