This commit is contained in:
BoHung Chiu 2022-08-25 14:42:44 +08:00
parent aa87513628
commit 574b9f6708
1 changed files with 19 additions and 0 deletions

View File

@ -30,12 +30,17 @@ def main():
if ethernets_block == None:
no_ethernets_block = True
else:
need_remove_interfaces = []
for interface in ethernets_block:
interface_block = ethernets_block[interface]
interface_addresses = interface_block.get('addresses')
if interface_addresses != None:
if len(interface_addresses) != 0:
addresses[interface] = interface_addresses
elif interface == '':
need_remove_interfaces.append(interface)
for interface in need_remove_interfaces:
del netplan_config_yaml['network']['ethernets'][interface]
if len(addresses) != 0:
print("You alreay configure some addresses for interfaces!")
for interface in addresses:
@ -46,6 +51,12 @@ def main():
if ans.lower() != "y":
sys.exit()
default_interfaces = list(set(subprocess.Popen("ip -o -4 route show to default | awk '{print $5}'", shell=True, stdout=subprocess.PIPE).stdout.read().decode().strip().split("\n")))
if '' in default_interfaces:
default_interfaces.remove('')
if len(default_interfaces) == 0:
default_interfaces.extend(subprocess.Popen("ls /sys/class/net/|xargs", shell=True, stdout=subprocess.PIPE).stdout.read().decode().strip().split(" "))
if 'lo' in default_interfaces:
default_interfaces.remove('lo')
if len(default_interfaces) == 0:
if len(args) > 2:
default_interfaces = args[2]
@ -74,7 +85,15 @@ def main():
print("Invalid ipaddress!")
new_addr = ""
addresses[interface] = [new_addr + '/24']
new_gateway4 = input(f"New gateway4 for interface {interface}: (can leave blank by default 254)")
gateway4[interface] = re.sub('[\\d]+$', '254', new_addr)
if new_gateway4 != "":
try:
ipaddress.IPv4Address(new_gateway4)
gateway4[interface] = new_gateway4
except:
print("Invalid gateway4 ipaddress!")
print(f"Change to default: {gateway4[interface]}")
change_flag = True
else:
change_flag = True