def main(): config = load_merged_config() for mac, client_config in config['clients'].items(): preseed_path = "/tftp/preseed/{mac}.cfg".format(mac=mac) preseed_alt_path = "/tftp/preseed/{mac}.cfg".format( mac=mac.replace("-", ":")) pxelinux_path = "/tftp/pxelinux.cfg/01-{mac}".format(mac=mac) bootscreen_path = "/tftp/debian-installer/amd64/boot-screens/{mac}.cfg".format( mac=mac) postinstall_path = "/tftp/preseed/{mac}_postinstall.sh".format(mac=mac) client_merged_config = deep_merge(config['client_defaults'], client_config) render_to_files(preseed_template, [preseed_path, preseed_alt_path], mac=mac, dhcp=config['dhcp'], debian_mirror=config['debian_mirror'], public_ip=config['public_ip'], **client_merged_config) render_to_files(pxelinux_template, pxelinux_path, mac=mac) render_to_files(bootscreen_template, bootscreen_path, dhcp=config['dhcp'], public_ip=config['public_ip'], installer_priority=config['installer_priority'], mac=mac) render_to_files(postinstall_template, postinstall_path, dns=config['dns'], **client_merged_config)
def main(): config = load_merged_config() try: os.makedirs(IGNITION_SRC) except FileExistsError: pass os.chdir(IGNITION_SRC) for mac, client_config in config['clients'].items(): yaml_path = '{mac}.yaml'.format(mac=mac) client_merged_config = deep_merge(config['client_defaults'], client_config) client_merged_config['mac'] = mac ## Render the systemd unit files: units = [] for name, unit_config in client_config.get('units', []).items(): if unit_config == None: unit_config = {} unit = {'name': name, **unit_config} if unit.get('enabled', False): unit['enabled'] = "true" unit_template = template_lookup.get_template( 'units/{name}.mako'.format(name=name)) unit['contents'] = unit_template.render(**unit_config).replace( "\n", "\\n").replace("\"", "\\\"") else: unit['enabled'] = "false" unit['contents'] = "## Masked" units.append(unit) client_merged_config['units'] = units ## Render the ignition template: render_to_files(ignition_template, yaml_path, ssh_keys=config['ssh_keys'], dns=config['dns'], dhcp=config['dhcp'], **client_merged_config) os.system("cat -n {yaml_path}".format(yaml_path=yaml_path)) ign_dest = os.path.join(IGNITION_SRC, '{mac}.ign'.format(mac=mac)) cmd = 'fcct --strict --pretty --input {yaml_path} > {ign_dest} ; echo'.format( yaml_path=yaml_path, ign_dest=ign_dest) logger.info(cmd) os.system(cmd) if not os.path.exists(ign_dest): logger.error( 'fcct failed to transform to ignition file: {ign_dest}'.format( yaml_path=yaml_path, ign_dest=ign_dest)) sys.exit(1) logger.info('Created ignition file: {ign_dest}'.format( ign_dest=os.path.join(IGNITION_SRC, ign_dest))) if os.path.getsize(ign_dest) == 0: logger.error('Ignition file is empty : {ign_dest}'.format( ign_dest=os.path.join(IGNITION_SRC, ign_dest))) sys.exit(1)
def main(): config = load_merged_config() for iso, config in config['isos'].items(): iso = "/data/isos/{iso}".format(iso=iso) if not os.path.exists(iso): logger.error("Missing ISO image: {iso}".format(iso=iso)) sys.exit(1) os.makedirs(config['mount']) logger.info("Mounting {iso} to {mount}".format(iso=iso, mount=config['mount'])) os.system("mount -o loop {iso} {mount}".format(iso=iso, mount=config['mount']))
def main(): config = load_merged_config() os.chdir(IGNITION_SRC) for ign_src in [x for x in os.listdir(IGNITION_SRC) if x.endswith(".yaml")]: ign_dest = "{name}.ign".format(name=ign_src.split(".")[0]) cmd="fcct --strict --pretty --input {ign_src} > {ign_dest}".format(ign_src=ign_src, ign_dest=ign_dest) logger.info(cmd) os.system(cmd) if not os.path.exists(ign_dest): logger.error("fcct failed to transform to ignition file: {ign_dest}".format(ign_src=ign_src, ign_dest=ign_dest)) sys.exit(1) logger.info("Created ignition file: {ign_dest}".format(ign_dest=ign_dest))
def main(): config = load_merged_config() for iso, config in config['isos'].items(): path = config['destination'] if not os.path.exists(path): logger.error("Missing ISO image: {path}".format(path=path)) sys.exit(1) try: os.makedirs(config['mount']) except FileExistsError: pass logger.info("Mounting {path} to {mount}".format(path=path, mount=config['mount'])) if os.system("mount -o loop {path} {mount}".format( path=path, mount=config['mount'])) != 0: logger.error("Failed to maount iso: {iso}".format(iso=iso)) sys.exit(1)
def main(): config = load_merged_config() for image, details in (list(config['images'].items()) + list(config['isos'].items())): path = details['destination'] if not os.path.exists(path): logger.info("Downloading {u} to {p} ... ".format(u=details['url'], p=path)) try: os.makedirs(os.path.dirname(path)) except FileExistsError: pass download_file(details['url'], path) if os.path.exists(path): if sha256sum(path) == details['sha256']: logger.info("Found existing image/iso with correct SHA256: {p}".format(p=path)) else: logger.error("Invalid SHA256 for image/iso: {p}".format(p=path)) logger.error("Manually remove the file and try again.") exit(1) else: logger.error("Image/iso not found: {p}".format(p=path)) exit(1)
def main(): config = load_merged_config() for mac, client_config in config['clients'].items(): pxelinux_path = "/data/pxelinux.cfg/01-{mac}".format(mac=mac) bootscreen_path = "/data/debian-installer/amd64/boot-screens/{mac}.cfg".format( mac=mac) client_merged_config = deep_merge(config['client_defaults'], client_config) if client_merged_config.get("vga", False) == True: display_args = "vga=788" else: display_args = "vga=none console=tty0 console=ttyS0" render_to_files(pxelinux_template, pxelinux_path, mac=mac) render_to_files(bootscreen_template, bootscreen_path, dhcp=config['dhcp'], public_ip=config['public_ip'], mac=mac, menu_entries=config['menu_entries'], auto_install=config['auto_install'], display_args=display_args, **client_merged_config)