From 12c0947bad9393522bdc77b97fbb90c9713d00a7 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 12 Aug 2016 16:38:53 +1200 Subject: [PATCH] hacking that might be enough to let you turn dhcp on for an interface --- console_conf/controllers/network.py | 14 +++++++++++++- console_conf/ui/views/network.py | 4 ++-- .../ui/views/network_configure_interface.py | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/console_conf/controllers/network.py b/console_conf/controllers/network.py index 72761fe0..f5175a91 100644 --- a/console_conf/controllers/network.py +++ b/console_conf/controllers/network.py @@ -14,10 +14,13 @@ # along with this program. If not, see . import logging +import time +import netifaces import yaml from subiquitycore.controller import BaseController +from subiquitycore.utils import run_command from console_conf.models import NetworkModel from console_conf.ui.views import NetworkView, NetworkConfigureInterfaceView @@ -42,9 +45,18 @@ class NetworkController(BaseController): def network_finish(self, config): log.debug("network config: \n%s", yaml.dump(config)) + #self.ui.frame.body = + if self.opts.dry_run: + pass + else: + with open('/etc/netplan/01-console-conf.yaml', 'w') as w: + w.write(yaml.dump(config)) + run_command(['systemctl', 'restart', 'systemd-networkd']) + while 'default' not in netifaces.gateways(): + time.sleep(0.1) self.signal.emit_signal('menu:identity:main') def network_configure_interface(self, interface): self.ui.set_header("Network interface {}".format(interface)) self.ui.set_body(NetworkConfigureInterfaceView( - self.model, self.signal, interface)) + self.model, self.signal, self.model.config.ethernets[interface])) diff --git a/console_conf/ui/views/network.py b/console_conf/ui/views/network.py index c71c100e..76f3a97d 100644 --- a/console_conf/ui/views/network.py +++ b/console_conf/ui/views/network.py @@ -86,12 +86,12 @@ class NetworkView(BaseView): t = addr.with_prefixlen if addr.version == 4: if iface.dhcp4: - t += " (dhcp)" + t += " (from dhcp4)" else: t += " (static)" elif addr.version == 6: if iface.dhcp6: - t += " (dhcp)" + t += " (from dhcp6)" else: t += " (static)" col_2.append(Text(t)) diff --git a/console_conf/ui/views/network_configure_interface.py b/console_conf/ui/views/network_configure_interface.py index a02764a2..2ccfa21b 100644 --- a/console_conf/ui/views/network_configure_interface.py +++ b/console_conf/ui/views/network_configure_interface.py @@ -13,9 +13,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from urwid import Text, Pile, ListBox +from urwid import Text, Pile, ListBox, CheckBox from subiquitycore.view import BaseView -from subiquitycore.ui.buttons import done_btn, menu_btn +from subiquitycore.ui.buttons import done_btn, menu_btn, cancel_btn from subiquitycore.ui.utils import Color, Padding import logging @@ -27,7 +27,11 @@ class NetworkConfigureInterfaceView(BaseView): self.model = model self.signal = signal self.iface = iface + self.dhcp4_box = CheckBox("Use DHCP for IPv4", state=iface.dhcp4) + self.dhcp6_box = CheckBox("Use DHCP for IPv6", state=iface.dhcp6) body = [ + Padding.center_79(self.dhcp4_box), + Padding.center_79(self.dhcp6_box), ## Padding.center_79(self._build_gateway_ipv4_info()), ## Padding.center_79(self._build_manual_ipv4_button()), ## Padding.line_break(""), @@ -86,11 +90,18 @@ class NetworkConfigureInterfaceView(BaseView): def _build_buttons(self): done = done_btn(on_press=self.done) + cancel = cancel_btn(on_press=self.cancel) buttons = [ Color.button(done, focus_map='button focus'), + Color.button(cancel), ] return Pile(buttons) def done(self, result): + self.iface.dhcp4 = self.dhcp4_box.get_state() + self.iface.dhcp6 = self.dhcp6_box.get_state() + self.signal.prev_signal() + + def cancel(self, result): self.signal.prev_signal()