Skip to content

Commit

Permalink
reformat style
Browse files Browse the repository at this point in the history
  • Loading branch information
sever-sever committed Nov 14, 2023
1 parent d720650 commit f95a832
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
20 changes: 11 additions & 9 deletions configure/api/configure_via_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def convert_to_json_commands(input_str):
Returns:
str: A JSON string representing the commands in a structured format.
"""
commands = input_str.strip().split('\n')
commands = input_str.strip().split("\n")
result = []

for command in commands:
Expand Down Expand Up @@ -63,11 +63,13 @@ def configure_vyos(address, key, data, timeout=30):
Exception: If the configuration fails.
"""
headers = {}
url = f'https://{address}/configure'
payload = {'data': data, 'key': key}
url = f"https://{address}/configure"
payload = {"data": data, "key": key}

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.post(url, headers=headers, data=payload, verify=False, timeout=timeout)
response = requests.post(
url, headers=headers, data=payload, verify=False, timeout=timeout
)

if response.status_code == 200:
print("Configuration successful.")
Expand All @@ -77,18 +79,18 @@ def configure_vyos(address, key, data, timeout=30):
print("Response:", response.text)


if __name__ == '__main__':
if __name__ == "__main__":

# Get connection parameters from config.yaml
with open('config.yaml', 'r', encoding='utf-8') as file:
with open("config.yaml", "r", encoding="utf-8") as file:
conf = yaml.load(file, Loader=yaml.FullLoader)

# Set VyOS host address and API key
vyos_host = conf.get('vyos_host')
vyos_api_key = conf.get('vyos_api_key')
vyos_host = conf.get("vyos_host")
vyos_api_key = conf.get("vyos_api_key")

# Read configuration from config_vyos.conf
with open('config_vyos.conf', 'r', encoding='utf-8') as file:
with open("config_vyos.conf", "r", encoding="utf-8") as file:
config_commands = file.read()

config_json = convert_to_json_commands(config_commands)
Expand Down
16 changes: 8 additions & 8 deletions generate/firewall/vyos_basic_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def generate_firewall_rules(config: dict, template: Template) -> str:

if __name__ == "__main__":

with open('config.yaml', 'r', encoding='utf-8') as file:
with open("config.yaml", "r", encoding="utf-8") as file:
conf = yaml.load(file, Loader=yaml.FullLoader)

env = Environment(loader=FileSystemLoader('templates'))
env = Environment(loader=FileSystemLoader("templates"))

network_group_v4 = env.get_template('network_group_v4.j2')
local_v4_rules = env.get_template('local_v4_rules.j2')
output_v4_rules = env.get_template('output_v4_rules.j2')
network_group_v6 = env.get_template('network_group_v6.j2')
local_v6_rules = env.get_template('local_v6_rules.j2')
output_v6_rules = env.get_template('output_v6_rules.j2')
network_group_v4 = env.get_template("network_group_v4.j2")
local_v4_rules = env.get_template("local_v4_rules.j2")
output_v4_rules = env.get_template("output_v4_rules.j2")
network_group_v6 = env.get_template("network_group_v6.j2")
local_v6_rules = env.get_template("local_v6_rules.j2")
output_v6_rules = env.get_template("output_v6_rules.j2")

# IPv4
print(generate_firewall_rules(conf, network_group_v4))
Expand Down
6 changes: 3 additions & 3 deletions generate/ipsec/ipsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def generate_config(config: dict, template: Template) -> str:

if __name__ == "__main__":

with open('config.yaml', 'r', encoding='utf-8') as file:
with open("config.yaml", "r", encoding="utf-8") as file:
conf = yaml.load(file, Loader=yaml.FullLoader)

env = Environment(loader=FileSystemLoader('templates'), trim_blocks=True)
env = Environment(loader=FileSystemLoader("templates"), trim_blocks=True)

ipsec = env.get_template('ipsec.j2')
ipsec = env.get_template("ipsec.j2")
print(generate_config(conf, ipsec))

0 comments on commit f95a832

Please sign in to comment.