From b6a47783b6fadbc5e4b52c013efe1b93f4b8c1af Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 31 Mar 2019 19:03:10 +0200 Subject: [PATCH] Set iface mode to manual when no address is specified Also dhcp is allowed as address to enable dhcp mode --- genconfdrv/genconfdrv.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/genconfdrv/genconfdrv.py b/genconfdrv/genconfdrv.py index 86347b5..df68caf 100755 --- a/genconfdrv/genconfdrv.py +++ b/genconfdrv/genconfdrv.py @@ -47,12 +47,16 @@ class ConfigDrive: ]) if address: - if "/" not in address: + if address == "dhcp": + address = None + method = "dhcp" + elif "/" in address: + address = ipaddress.ip_interface(address) + method = "static" + else: raise ValueError("IP Interface is not a subnet") - address = ipaddress.ip_interface(address) - method = "static" else: - method = "dhcp" + method = "manual" self._interfaces.extend([ "", @@ -275,8 +279,8 @@ def main(): parser.add_argument("-i", "--networks", "--net", default=[], nargs="+", help="Specify all networks, in format of interface[:address[:gateway[:route-gateway[:...]]]]. " "Both : and ; can be used as delimiter (but only one per net config). " - "Address MUST be a network in CIDR notation. Additional " - "routes can be added in the form of cidr-gateway, e.g. " + "Address MUST be a network in CIDR notation or dhcp for DHCP mode. " + "Additional routes can be added in the form of cidr-gateway, e.g. " "10.0.0.0/8-10.0.0.1") parser.add_argument("-u", "--disable-upgrades", action="store_true", default=False) parser.add_argument("-v", "--verbose", action="store_true", default=False)