-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removed ABC * fixed config file usage * other config issue * typing error, trying to concat str with Path * update generate subcommand * removed install_file overwrite * added self prefix to vars in dns.py * added additional modules * fixed imports and some errors * removed raised error from heading not found in yamlparser * fixed typo * changed seperator * Updated Path in os file download * changed preseed to ftp dir * fixed directory 2 * Fixed setup commands for ftp * Corrected false statemtn * Added dhcp-boot option to dnsmasq * changed directory * Changed module call order * added language * added boot args, changed local_root to anon_root * Updated jinja template for preseed prompts * Revert "fixed directory 2" This reverts commit f4e4db0. * reverted preseed install dir to tftp * removed outdated flag * Removed invalid flag * fixed tests * fixed some linting errors * more lint fixes * linting again * forgot to commit these * almost done with lints * good enough * type issue * guess this never got pushed --------- Co-authored-by: HenrithicusGreenson <greeht01@pfw.edu>
- Loading branch information
1 parent
f2e1c1d
commit 258031a
Showing
20 changed files
with
156 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
from genisys.modules import base | ||
from typing import Self, Union, List | ||
from pathlib import Path | ||
from jinja2 import Template | ||
import subprocess | ||
from typing_extensions import Self, Union, List | ||
from genisys.modules import base | ||
|
||
class Dnsmasq(base.Module): | ||
"""Creates the nessecary DNS, DHCP, and TFTP configurations to PXE boot clients""" | ||
DNS_DIR = '/etc' | ||
DNS_FILE = 'dnsmasq.conf' | ||
|
||
def __init__(self: Self, config): | ||
"""Pulling DNSMasq config information from the Network header in the config yaml file""" | ||
self.config["network"] = config.getSection("Network") | ||
self.config = {} | ||
self.config["network"] = config.get_section("Network") | ||
#Adding override config to read the last field in our config file | ||
self.config["overrides"] = config.getSection("DNSMasq Overrides") | ||
self.config["overrides"] = config.get_section("DNSMasq Overrides") | ||
|
||
def install_location(self: Self) -> Path: | ||
"""This is where the DNSMasq config file is stored/accessed""" | ||
return Path(DNS_DIR, DNS_FILE) | ||
return Path(self.DNS_DIR, self.DNS_FILE) | ||
|
||
def generate(self: Self) -> str: | ||
configWriter = '' | ||
#The below line deals with the port 53 resolved issue when running dnsmasq after installation | ||
configWriter+="bind-interfaces\n" | ||
config_writer = '' | ||
|
||
# The below line deals with the port 53 resolved issue when running dnsmasq | ||
config_writer+="bind-interfaces\n" | ||
if 'interface' in self.config["network"]: | ||
configWriter+=("interface=" + self.config['network']['interface'] + "\n") | ||
config_writer+=("interface=" + self.config['network']['interface'] + "\n") | ||
if 'no-dhcp' in self.config["network"]: | ||
if self.config['network']['no-dhcp'] == 'false': | ||
if 'dhcp-ranges' in self.config['network'] and 'dhcp-lease' in self.config['network']: | ||
configWriter+=("dhcp-range=" + self.config['network']['dhcp-ranges'] + "," + self.config['network']['dhcp-lease'] + "\n") | ||
configWriter+="enable-tftp\n" | ||
if 'tftp_directory' in self.config['netowrk']: | ||
configWriter+=("tftp-root=" + self.config['network']['tftp_directory'] + "\n") | ||
if not self.config['network']['no-dhcp']: | ||
if 'dhcp-ranges' in self.config['network'] \ | ||
and 'dhcp-lease' in self.config['network']: | ||
config_writer+=(f'dhcp-boot={self.config["network"]["tftp_directory"]}/pxelinux.0\n') | ||
config_writer+=(f'dhcp-range={self.config['network']['dhcp-ranges']},{self.config['network']['dhcp-lease']}\n') | ||
config_writer+="enable-tftp\n" | ||
if 'tftp_directory' in self.config['network']: | ||
config_writer+=("tftp-root=" + self.config['network']['tftp_directory'] + "\n") | ||
if 'dns-servers' in self.config['network']: | ||
configWriter+=("server=" + self.config['network']['dns-servers'] + "\n") | ||
config_writer+=("server=" + self.config['network']['dns-servers'] + "\n") | ||
#adding potential future logic for disabling only dns below | ||
# if 'no-dns' in self.config: | ||
# We add the following string: DNSMASQ_EXCEPT=lo to the file /etc/default/dnsmasq | ||
# We add the following string: DNSMASQ_EXCEPT=lo to the file /etc/default/dnsmasq | ||
if 'authoritative' in self.config['overrides']: | ||
if self.config['overrides']['authoritative'].lower() == 'true': | ||
configWriter+="dhcp-authoritative\n" | ||
if self.config['overrides']['authoritative']: | ||
config_writer+="dhcp-authoritative\n" | ||
else: | ||
configWriter+="#dhcp-authoritative\n" | ||
return configWriter | ||
config_writer+="#dhcp-authoritative\n" | ||
return config_writer | ||
|
||
def setup_commands(self: Self) -> Union[List[str], List[List[str]]]: | ||
return [["systemctl", "restart", "dnsmasq"]] | ||
def validate(self: Self) -> bool: | ||
"""Validates the configuration by attempting to generate the configuration file.""" | ||
try: | ||
self.generate() | ||
#The following logic is supposed to use dnsmasq inbuitl validation dnsmasq --test which returns dnsmasq: syntax check OK. when valid | ||
#For some reason, this code cannot check the output of the command to verify that the config file passed the test | ||
#valid = subprocess.check_output(["sudo", "dnsmasq", "--test"], stdout=subprocess.PIPE) | ||
#validString = valid.stdout.decode('utf-8') | ||
#if validString | ||
return True | ||
except: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.