diff options
author | sshedi <53473811+sshedi@users.noreply.github.com> | 2021-08-09 22:19:13 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 11:49:13 -0500 |
commit | 049d62b658b06e729291def6b7b6f9520827d0ba (patch) | |
tree | 7c7166cc75742c66c58087609acb4d7ea9ab61f3 /cloudinit/net | |
parent | 00dbaf1e9ab0e59d81662f0f3561897bef499a3f (diff) | |
download | vyos-cloud-init-049d62b658b06e729291def6b7b6f9520827d0ba.tar.gz vyos-cloud-init-049d62b658b06e729291def6b7b6f9520827d0ba.zip |
photon: refactor hostname handling and add networkd activator (#958)
Diffstat (limited to 'cloudinit/net')
-rw-r--r-- | cloudinit/net/activators.py | 27 | ||||
-rw-r--r-- | cloudinit/net/networkd.py | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/cloudinit/net/activators.py b/cloudinit/net/activators.py index 84aaafc9..11149548 100644 --- a/cloudinit/net/activators.py +++ b/cloudinit/net/activators.py @@ -8,6 +8,7 @@ from cloudinit import subp from cloudinit import util from cloudinit.net.eni import available as eni_available from cloudinit.net.netplan import available as netplan_available +from cloudinit.net.networkd import available as networkd_available from cloudinit.net.network_state import NetworkState from cloudinit.net.sysconfig import NM_CFG_FILE @@ -213,12 +214,38 @@ class NetplanActivator(NetworkActivator): return _alter_interface(NetplanActivator.NETPLAN_CMD, 'all') +class NetworkdActivator(NetworkActivator): + @staticmethod + def available(target=None) -> bool: + """Return true if ifupdown can be used on this system.""" + return networkd_available(target=target) + + @staticmethod + def bring_up_interface(device_name: str) -> bool: + """ Return True is successful, otherwise return False """ + cmd = ['ip', 'link', 'set', 'up', device_name] + return _alter_interface(cmd, device_name) + + @staticmethod + def bring_up_all_interfaces(network_state: NetworkState) -> bool: + """ Return True is successful, otherwise return False """ + cmd = ['systemctl', 'restart', 'systemd-networkd', 'systemd-resolved'] + return _alter_interface(cmd, 'all') + + @staticmethod + def bring_down_interface(device_name: str) -> bool: + """ Return True is successful, otherwise return False """ + cmd = ['ip', 'link', 'set', 'down', device_name] + return _alter_interface(cmd, device_name) + + # This section is mostly copied and pasted from renderers.py. An abstract # version to encompass both seems overkill at this point DEFAULT_PRIORITY = [ IfUpDownActivator, NetworkManagerActivator, NetplanActivator, + NetworkdActivator, ] diff --git a/cloudinit/net/networkd.py b/cloudinit/net/networkd.py index 2dffce59..63e3a07f 100644 --- a/cloudinit/net/networkd.py +++ b/cloudinit/net/networkd.py @@ -246,7 +246,7 @@ class Renderer(renderer.Renderer): def available(target=None): - expected = ['systemctl'] + expected = ['ip', 'systemctl'] search = ['/usr/bin', '/bin'] for p in expected: if not subp.which(p, search=search, target=target): |