From 5371ae2361bed672938bf927ea5257bcf49cc453 Mon Sep 17 00:00:00 2001 From: brent s Date: Mon, 11 Nov 2019 21:42:58 -0500 Subject: [PATCH] stubbing network out --- aif.xsd | 1 + aif/network/__init__.py | 18 +++++++++++++----- aif/network/_common.py | 14 ++------------ aif/network/net.py | 19 +++++++++++++++++++ aif/network/networkmanager.py | 23 +++++++++++++++++++++++ aif/network/networkmanager_fallback.py | 1 + docs/MANUAL.adoc | 8 ++++++++ 7 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 aif/network/net.py diff --git a/aif.xsd b/aif.xsd index bba465d..2024912 100644 --- a/aif.xsd +++ b/aif.xsd @@ -270,6 +270,7 @@ WPA3? EAP, eduroam (https://github.com/rst0git/netctl-eduroam-config/blob/master/eduroam), etc. --> + diff --git a/aif/network/__init__.py b/aif/network/__init__.py index 20a8caa..4ebacdd 100644 --- a/aif/network/__init__.py +++ b/aif/network/__init__.py @@ -3,14 +3,22 @@ try: except ImportError: pass # GI isn't supported, so we don't even use a fallback. +from . import netctl + # TODO: use DBus interface for systemd but fallback to subprocess? # http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html # https://www.youtube.com/watch?v=ZUX9Fx8Rwzg # https://www.youtube.com/watch?v=lBQgMGPxqNo # https://github.com/facebookincubator/pystemd has some unit/service examples -# try: -# from . import networkd -# except ImportError: -# from . import networkd_fallback as networkd +try: + from . import networkd +except ImportError: + from . import networkd_fallback as networkd -from . import netctl + +try: + from . import networkmanager +except ImportError: + from . import networkmanager_fallback + +from . import net diff --git a/aif/network/_common.py b/aif/network/_common.py index a8686f5..bcacaa5 100644 --- a/aif/network/_common.py +++ b/aif/network/_common.py @@ -1,13 +1,3 @@ import gi -gi.require_version('NM', '2.0') -from gi.repository import NM, GLib - -NM.ensure_init([None]) - - -def addBDPlugin(plugin_name): - plugins = NM.get_available_plugin_names() - plugins.append(plugin_name) - plugins = list(set(plugins)) # Deduplicate - spec = NM.plugin_specs_from_names(plugins) - return(NM.ensure_init(spec)) +gi.require_version('NM', '1.0') +from gi.repository import GObject, NM, GLib diff --git a/aif/network/net.py b/aif/network/net.py new file mode 100644 index 0000000..cadfe6f --- /dev/null +++ b/aif/network/net.py @@ -0,0 +1,19 @@ +class Network(object): + def __init__(self, network_xml): + self.xml = network_xml + self.hostname = self.xml.attrib['hostname'] + self.provider = self.xml.attrib.get('provider', 'netctl') + handler = None + if self.provider == 'netctl': + from . import netctl as handler + elif self.provider == 'nm': + from . import networkmanager as handler + elif self.provider == 'systemd': + from . import networkd as handler + self.provider = handler + if not self.provider: + raise RuntimeError('Could not determine handler') + self.connections = [] + + def _initConns(self): + pass diff --git a/aif/network/networkmanager.py b/aif/network/networkmanager.py index e69de29..23a8350 100644 --- a/aif/network/networkmanager.py +++ b/aif/network/networkmanager.py @@ -0,0 +1,23 @@ +from . import _common + +_NM = _common.NM + + +class Connection(object): + def __init__(self, iface_xml): + self.xml = iface_xml + self.connection_type = None + self.provider_type = 'NetworkManager' + self.client = _NM.Client.new() + + +class Ethernet(Connection): + def __init__(self, iface_xml): + super().__init__(iface_xml) + self.connection_type = 'ethernet' + + +class Wireless(Connection): + def __init__(self, iface_xml): + super().__init__(iface_xml) + self.connection_type = 'wireless' diff --git a/aif/network/networkmanager_fallback.py b/aif/network/networkmanager_fallback.py index e69de29..2933cb5 100644 --- a/aif/network/networkmanager_fallback.py +++ b/aif/network/networkmanager_fallback.py @@ -0,0 +1 @@ +import subprocess diff --git a/docs/MANUAL.adoc b/docs/MANUAL.adoc index f7d85d5..2ed63ed 100644 --- a/docs/MANUAL.adoc +++ b/docs/MANUAL.adoc @@ -85,6 +85,14 @@ TIP: Your distro's package manager should have most if not all of these availabl NOTE: Some versions may be higher than actually needed. +//// +Need to revamp. Recommended vs. fallback plus required for both + +Recommended: +pygobject-introspection +libblockdev +libnm +//// === Necessary These are needed for using AIF-NG.