bundles: code style improvements
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-02-12 20:37:36 +01:00
parent 2af911c29f
commit f52df58517
Signed by: kunsi
GPG key ID: 12E3D2136B818350
24 changed files with 80 additions and 95 deletions

View file

@ -43,4 +43,3 @@ svc_systemd = {
},
},
}

View file

@ -19,12 +19,12 @@ def get_static_allocations(metadata):
if rnode.metadata.get('location', '') != metadata.get('location', ''):
continue
for identifier, interface in rnode.metadata.get('interfaces', {}).items():
if interface.get('dhcp', False):
for iface_name, iface_config in rnode.metadata.get('interfaces', {}).items():
if iface_config.get('dhcp', False):
try:
allocations[rnode.name] = {
'ipv4': sorted(interface['ips'])[0],
'mac': interface['mac'],
allocations[f'{rnode.name}_{iface_name}'] = {
'ipv4': sorted(iface_config['ips'])[0],
'mac': iface_config['mac'],
}
except KeyError:
pass
@ -41,7 +41,7 @@ def get_static_allocations(metadata):
)
def get_listen_interfaces(metadata):
listen_interfaces = []
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
for _, subnet in node.metadata.get('dhcpd/subnets', {}).items():
listen_interfaces.append(subnet['interface'])
return {
@ -55,15 +55,15 @@ def get_listen_interfaces(metadata):
'iptables/bundle_rules/dhcpd',
)
def iptables(metadata):
iptables = set()
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
iptables.add('iptables -A INPUT -i {} -p udp --dport 67:68 -j ACCEPT'.format(subnet['interface']))
rules = set()
for _, subnet in node.metadata.get('dhcpd/subnets', {}).items():
rules.add('iptables -A INPUT -i {} -p udp --dport 67:68 -j ACCEPT'.format(subnet['interface']))
return {
'iptables': {
'bundle_rules': {
# iptables bundle relies on this being a list.
'dhcpd': sorted(list(iptables)),
'dhcpd': sorted(list(rules)),
},
}
}