How to use the cobbler.templar.Templar 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 / 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]):
                    if f == target["boot_files"][file]:
                        # this wasn't really a glob, so just copy it as is
                        filedst = rendered_file
                    else:
                        # this was a glob, so figure out what the destination
                        # file path/name should be
                        tgt_path, tgt_file = os.path.split(f)
                        rnd_path, rnd_file = os.path.split(rendered_file)
github cobbler / cobbler / cobbler / modules / managers / manage_genders.py View on Github external
def write_genders_file(config, profiles_genders, distros_genders, mgmtcls_genders):
    """
    genders file is over-written when manage_genders is set in
    /var/lib/cobbler/settings.
    """

    templar_inst = cobbler.templar.Templar(config)
    try:
        f2 = open(template_file, "r")
    except:
        raise CX(_("error reading template: %s") % template_file)
    template_data = ""
    template_data = f2.read()
    f2.close()

    metadata = {
        "date": time.asctime(time.gmtime()),
        "profiles_genders": profiles_genders,
        "distros_genders": distros_genders,
        "mgmtcls_genders": mgmtcls_genders
    }

    templar_inst.render(template_data, metadata, settings_file, None)
github cobbler / cobbler / bin / tftpd.py View on Github external
except socket.error as e:
            if e[0] in (errno.EPERM, errno.EACCES):
                print("Unable to bind to port %d" % OPTIONS["port"])
                return -1
            else:
                raise

    OPTIONS["sock"].setblocking(0)

    if os.getuid() == 0:
        uid = pwd.getpwnam(OPTIONS["user"])[2]
        os.setreuid(uid, uid)

    # This takes a while, so do it after we open the port, so we
    # don't drop the packet that spawned us
    templar = cobbler.templar.Templar(None)

    io_loop = ioloop.IOLoop.instance()
    io_loop.add_handler(OPTIONS["sock"].fileno(), partial(new_req, OPTIONS["sock"], templar), io_loop.READ)
    # Shove the timeout into OPTIONS, because it's there
    if OPTIONS["idle"] > 0:
        OPTIONS["idle_timer"] = io_loop.add_timeout(time.time() + OPTIONS["idle"], lambda: idle_out())

    logging.info('Starting Eventloop')
    try:
        try:
            io_loop.start()
        except KeyboardInterrupt:
            # Someone hit ^C
            logging.info('Exiting')
    finally:
        OPTIONS["sock"].close()
github cobbler / cobbler / cobbler / modules / managers / manage_bind.py View on Github external
def __init__(self, collection_mgr, logger):
        """
        Constructor
        """
        self.logger = logger
        if self.logger is None:
            self.logger = clogger.Logger()

        self.collection_mgr = collection_mgr
        self.api = collection_mgr.api
        self.distros = collection_mgr.distros()
        self.profiles = collection_mgr.profiles()
        self.systems = collection_mgr.systems()
        self.settings = collection_mgr.settings()
        self.repos = collection_mgr.repos()
        self.templar = templar.Templar(collection_mgr)
        self.settings_file = utils.namedconf_location(self.api)
        self.zonefile_base = utils.zonefile_base(self.api)
github cobbler / cobbler / cobbler / modules / managers / manage_dnsmasq.py View on Github external
def __init__(self, collection_mgr, logger, dhcp=None):
        """
        Constructor
        """
        self.logger = logger
        self.collection_mgr = collection_mgr
        self.api = collection_mgr.api
        self.distros = collection_mgr.distros()
        self.profiles = collection_mgr.profiles()
        self.systems = collection_mgr.systems()
        self.settings = collection_mgr.settings()
        self.repos = collection_mgr.repos()
        self.templar = templar.Templar(collection_mgr)
github cobbler / cobbler / cobbler / modules / managers / manage_tftpd_py.py View on Github external
def __init__(self, collection_mgr, logger):
        """
        Constructor
        """
        self.logger = logger
        if self.logger is None:
            self.logger = clogger.Logger()

        self.collection_mgr = collection_mgr
        self.templar = templar.Templar(collection_mgr)
github cobbler / cobbler / cobbler / actions / sync.py View on Github external
"""
        Constructor
        """
        self.logger = logger
        if logger is None:
            self.logger = clogger.Logger()

        self.verbose = verbose
        self.collection_mgr = collection_mgr
        self.api = collection_mgr.api
        self.distros = collection_mgr.distros()
        self.profiles = collection_mgr.profiles()
        self.systems = collection_mgr.systems()
        self.settings = collection_mgr.settings()
        self.repos = collection_mgr.repos()
        self.templar = templar.Templar(collection_mgr, self.logger)
        self.tftpgen = tftpgen.TFTPGen(collection_mgr, self.logger)
        self.dns = dns
        self.dhcp = dhcp
        self.tftpd = tftpd
        self.bootloc = self.settings.tftpboot_location
        self.tftpgen.verbose = verbose
        self.dns.verbose = verbose
        self.dhcp.verbose = verbose

        self.pxelinux_dir = os.path.join(self.bootloc, "pxelinux.cfg")
        self.grub_dir = os.path.join(self.bootloc, "grub")
        self.images_dir = os.path.join(self.bootloc, "images")
        self.yaboot_bin_dir = os.path.join(self.bootloc, "ppc")
        self.yaboot_cfg_dir = os.path.join(self.bootloc, "etc")
        self.rendered_dir = os.path.join(self.settings.webdir, "rendered")
github cobbler / cobbler / cobbler / modules / managers / manage_in_tftpd.py View on Github external
def __init__(self, collection_mgr, logger):
        """
        Constructor
        """
        self.logger = logger
        if self.logger is None:
            self.logger = clogger.Logger()

        self.collection_mgr = collection_mgr
        self.templar = templar.Templar(collection_mgr)
        self.tftpgen = tftpgen.TFTPGen(collection_mgr, self.logger)
        self.systems = collection_mgr.systems()
        self.bootloc = collection_mgr.settings().tftpboot_location
github cobbler / cobbler / cobbler / modules / managers / manage_ndjbdns.py View on Github external
def __init__(self, config, logger):
        self.logger = logger
        if self.logger is None:
            self.logger = clogger.Logger()

        self.config = config
        self.systems = config.systems()
        self.templar = templar.Templar(config)