summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2015-03-06 13:18:08 (GMT)
committerJavier Jardón <javier.jardon@codethink.co.uk>2015-03-16 17:59:54 (GMT)
commitf9ba8e880da87af2952b6daef15c720d2c860217 (patch)
tree8c616c85261caa99a8dbba5710aaf764bed1f5d8
parent993a41a841ab2758f3941a2b1fbea262cae924a0 (diff)
downloadmorph-f9ba8e880da87af2952b6daef15c720d2c860217.tar.gz
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"
-rwxr-xr-xmorphlib/exts/simple-network.configure26
1 files changed, 20 insertions, 6 deletions
diff --git a/morphlib/exts/simple-network.configure b/morphlib/exts/simple-network.configure
index a058cba..fbbe6c4 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"""