From f9ba8e880da87af2952b6daef15c720d2c860217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Fri, 6 Mar 2015 13:18:08 +0000 Subject: simple-network.configure: Generate default network config files in a function Use DHCP by defaul in the default interfaces: - for /etc/networ/interfaces: "lo:loopback;eth0:dhcp,hostname=$(hostname)" - for networkd: "e*:dhcp" --- morphlib/exts/simple-network.configure | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure index a058cba7..fbbe6c4e 100755 --- a/morphlib/exts/simple-network.configure +++ b/morphlib/exts/simple-network.configure @@ -42,15 +42,29 @@ class SimpleNetworkConfigurationExtension(cliapp.Application): ''' def process_args(self, args): - network_config = os.environ.get( - "NETWORK_CONFIG", "lo:loopback;eth0:dhcp,hostname=$(hostname)") + network_config = os.environ.get("NETWORK_CONFIG") - self.status(msg="Processing NETWORK_CONFIG=%(nc)s", nc=network_config) + if network_config is None: + self.generate_default_network_config(args) + else: + self.status(msg="Processing NETWORK_CONFIG=%(nc)s", nc=network_config) + + stanzas = self.parse_network_stanzas(network_config) + + self.generate_interfaces_file(args, stanzas) + self.generate_networkd_files(args, stanzas) + + def generate_default_network_config(self, args): + """Generate default network configuration: DHCP in all the interfaces""" + + default_network_config_interfaces = "lo:loopback;eth0:dhcp,hostname=$(hostname)" + default_network_config_networkd = "e*:dhcp" - stanzas = self.parse_network_stanzas(network_config) + stanzas_interfaces = self.parse_network_stanzas(default_network_config_interfaces) + stanzas_networkd = self.parse_network_stanzas(default_network_config_networkd) - self.generate_interfaces_file(args, stanzas) - self.generate_networkd_files(args, stanzas) + self.generate_interfaces_file(args, stanzas_interfaces) + self.generate_networkd_files(args, stanzas_networkd) def generate_interfaces_file(self, args, stanzas): """Generate /etc/network/interfaces file""" -- cgit v1.2.1