ns2 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ns2/__init__.py +0 -0
- ns2/core.py +0 -0
- ns2/dbus/__init__.py +0 -0
- ns2/dbus/dbus.py +13 -0
- ns2/lib/__init__.py +0 -0
- ns2/lib/accounts.py +130 -0
- ns2/lib/commands.py +32 -0
- ns2/lib/firewalld.py +167 -0
- ns2/lib/introspection/org.fedoraproject.FirewallD1.config.xml +3 -0
- ns2/lib/introspection/org.fedoraproject.FirewallD1.xml +763 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.AccessPoint.xml +106 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.AgentManager.xml +43 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Checkpoint.xml +36 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Connection.Active.xml +185 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml +21 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml +20 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml +21 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml +36 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bond.xml +40 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml +41 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml +20 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Generic.xml +27 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Hsr.xml +51 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml +107 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml +31 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ipvlan.xml +38 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Loopback.xml +8 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Lowpan.xml +27 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml +109 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml +39 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Modem.xml +62 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml +34 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsBridge.xml +21 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsInterface.xml +11 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsPort.xml +21 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ppp.xml +11 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml +35 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Team.xml +48 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Tun.xml +65 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Veth.xml +18 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml +45 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vrf.xml +18 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml +139 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml +109 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WifiP2P.xml +76 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WireGuard.xml +38 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wired.xml +53 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml +131 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wpan.xml +20 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Device.xml +407 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.DnsManager.xml +40 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.IP4Config.xml +125 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.IP6Config.xml +95 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.PPP.xml +34 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.SecretAgent.xml +94 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml +224 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.xml +233 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml +42 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml +204 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml +35 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.WifiP2PPeer.xml +91 -0
- ns2/lib/introspection/org.freedesktop.NetworkManager.xml +598 -0
- ns2/lib/lib.py +0 -0
- ns2/lib/network_delay.py +92 -0
- ns2/lib/networking.py +528 -0
- ns2/lib/ntl.py +188 -0
- ns2/lib/pam_client.py +37 -0
- ns2/lib/ping_data_collector.py +37 -0
- ns2/lib/snmp.py +511 -0
- ns2/lib/socket.py +132 -0
- ns2/lib/socket_client.py +62 -0
- ns2/lib/systemd.py +151 -0
- ns2/lib/test.py +374 -0
- ns2/lib/udp_client.py +227 -0
- ns2/lib/udp_server.py +167 -0
- ns2/snmp/__init__.py +0 -0
- ns2/snmp/ns_dbus_service.py +38 -0
- ns2/snmp/pam_interface.py +19 -0
- ns2/snmp/snmp_interface.py +66 -0
- ns2/ui/__init__.py +0 -0
- ns2/ui/assets/NOVUS_LOGO.svg +105 -0
- ns2/ui/assets/favicon.png +0 -0
- ns2/ui/firewalld_page.py +375 -0
- ns2/ui/fpga_page.py +24 -0
- ns2/ui/login.py +65 -0
- ns2/ui/main.py +200 -0
- ns2/ui/networking_page.py +406 -0
- ns2/ui/ntp.py +105 -0
- ns2/ui/root.py +31 -0
- ns2/ui/snmp_page.py +353 -0
- ns2/ui/terminal.py +65 -0
- ns2/ui/tests_page.py +116 -0
- ns2/ui/theme.py +25 -0
- ns2/utils.py +5 -0
- ns2-0.2.6.dist-info/METADATA +78 -0
- ns2-0.2.6.dist-info/RECORD +98 -0
- ns2-0.2.6.dist-info/WHEEL +4 -0
- ns2-0.2.6.dist-info/entry_points.txt +3 -0
ns2/lib/systemd.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from dbus_next.signature import Variant
|
|
5
|
+
from dbus_next.aio.proxy_object import ProxyInterface
|
|
6
|
+
from dbus_next.aio import MessageBus
|
|
7
|
+
from dbus_next import Message
|
|
8
|
+
|
|
9
|
+
async def systemd_start(bus: MessageBus, service: str):
|
|
10
|
+
async def on_job_removed(id, job_path, unit, result):
|
|
11
|
+
job_dict = {"id":id,
|
|
12
|
+
"job_path":job_path,
|
|
13
|
+
"unit":unit,
|
|
14
|
+
"method": "start",
|
|
15
|
+
|
|
16
|
+
"result":result}
|
|
17
|
+
if job_path == job and not job_future.done():
|
|
18
|
+
if result != 'done':
|
|
19
|
+
job_future.set_exception(Exception(f"Job failed: {result}"))
|
|
20
|
+
else:
|
|
21
|
+
job_future.set_result(job_dict)
|
|
22
|
+
|
|
23
|
+
job_future = asyncio.Future()
|
|
24
|
+
systemd = await getSystemdManager(bus)
|
|
25
|
+
systemd.on_job_removed(on_job_removed)
|
|
26
|
+
try:
|
|
27
|
+
job = await systemd.call_start_unit(service, 'replace')
|
|
28
|
+
print(await job_future)
|
|
29
|
+
|
|
30
|
+
finally:
|
|
31
|
+
systemd.off_job_removed(on_job_removed)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async def systemd_stop(bus: MessageBus, service: str):
|
|
35
|
+
async def on_job_removed(id, job_path, unit, result):
|
|
36
|
+
job_dict = {"id":id,
|
|
37
|
+
"job_path":job_path,
|
|
38
|
+
"unit":unit,
|
|
39
|
+
"method": "stop",
|
|
40
|
+
"result":result}
|
|
41
|
+
if job_path == job and not job_future.done():
|
|
42
|
+
if result != 'done':
|
|
43
|
+
job_future.set_exception(Exception(f"Job failed: {result}"))
|
|
44
|
+
else:
|
|
45
|
+
job_future.set_result(job_dict)
|
|
46
|
+
|
|
47
|
+
job_future = asyncio.Future()
|
|
48
|
+
systemd = await getSystemdManager(bus)
|
|
49
|
+
systemd.on_job_removed(on_job_removed)
|
|
50
|
+
try:
|
|
51
|
+
job = await systemd.call_stop_unit(service, 'replace')
|
|
52
|
+
print(await job_future)
|
|
53
|
+
|
|
54
|
+
finally:
|
|
55
|
+
systemd.off_job_removed(on_job_removed)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def systemd_restart(bus: MessageBus, service: str):
|
|
60
|
+
async def on_job_removed(id, job_path, unit, result):
|
|
61
|
+
job_dict = {"id":id,
|
|
62
|
+
"job_path":job_path,
|
|
63
|
+
"unit":unit,
|
|
64
|
+
"method": "restart",
|
|
65
|
+
"result":result}
|
|
66
|
+
if job_path == job and not job_future.done():
|
|
67
|
+
if result != 'done':
|
|
68
|
+
job_future.set_exception(Exception(f"Job failed: {result}"))
|
|
69
|
+
else:
|
|
70
|
+
job_future.set_result(job_dict)
|
|
71
|
+
|
|
72
|
+
job_future = asyncio.Future()
|
|
73
|
+
systemd = await getSystemdManager(bus)
|
|
74
|
+
systemd.on_job_removed(on_job_removed)
|
|
75
|
+
try:
|
|
76
|
+
job = await systemd.call_restart_unit(service, 'replace')
|
|
77
|
+
print(await job_future)
|
|
78
|
+
|
|
79
|
+
finally:
|
|
80
|
+
systemd.off_job_removed(on_job_removed)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def getUnitInterface(bus: MessageBus, unit:str) -> ProxyInterface:
|
|
84
|
+
unitPath = await getUnitPath(bus, unit)
|
|
85
|
+
introspection = await bus.introspect('org.freedesktop.systemd1', unitPath)
|
|
86
|
+
obj = bus.get_proxy_object('org.freedesktop.systemd1', unitPath, introspection)
|
|
87
|
+
return obj.get_interface('org.freedesktop.systemd1.Manager')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
async def getSystemdManager(bus: MessageBus) -> ProxyInterface:
|
|
91
|
+
introspection = await bus.introspect('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
|
|
92
|
+
obj = bus.get_proxy_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1', introspection)
|
|
93
|
+
return obj.get_interface('org.freedesktop.systemd1.Manager')
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
async def getUnitPropertiesInterface(bus: MessageBus, unit:str) -> ProxyInterface:
|
|
97
|
+
unitPath = await getUnitPath(bus, unit)
|
|
98
|
+
introspection = await bus.introspect('org.freedesktop.systemd1', unitPath)
|
|
99
|
+
obj = bus.get_proxy_object('org.freedesktop.systemd1', unitPath, introspection)
|
|
100
|
+
return obj.get_interface('org.freedesktop.DBus.Properties')
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async def getUnitPath(bus: MessageBus, service: str) -> str:
|
|
105
|
+
rsp = await bus.call(
|
|
106
|
+
Message(
|
|
107
|
+
destination='org.freedesktop.systemd1',
|
|
108
|
+
path='/org/freedesktop/systemd1',
|
|
109
|
+
interface='org.freedesktop.systemd1.Manager',
|
|
110
|
+
member='GetUnit',
|
|
111
|
+
signature='s',
|
|
112
|
+
body=[service]
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
unitPath = rsp.body[0]
|
|
117
|
+
|
|
118
|
+
return unitPath
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
async def getUnitProperties(bus: MessageBus, unitPath: str) -> dict:
|
|
123
|
+
|
|
124
|
+
rsp = await bus.call(
|
|
125
|
+
Message(
|
|
126
|
+
destination='org.freedesktop.systemd1',
|
|
127
|
+
path=unitPath,
|
|
128
|
+
interface='org.freedesktop.DBus.Properties',
|
|
129
|
+
member='GetAll',
|
|
130
|
+
signature='s',
|
|
131
|
+
body=['org.freedesktop.systemd1.Unit']
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
unitProps = rsp.body[0]
|
|
135
|
+
return unitProps
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def getServiceState(bus: MessageBus, service: str) -> str:
|
|
139
|
+
path = await getUnitPath(bus, service)
|
|
140
|
+
props = await getUnitProperties(bus, path)
|
|
141
|
+
return props.get("ActiveState", Variant('s', 'StateNotFound')).value
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
async def isActive(bus: MessageBus, service: str) -> bool:
|
|
146
|
+
state = await getServiceState(bus, service)
|
|
147
|
+
print(f'{service} is active: {state}')
|
|
148
|
+
if state == 'active':
|
|
149
|
+
return True
|
|
150
|
+
else:
|
|
151
|
+
return False
|
ns2/lib/test.py
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from dataclasses import dataclass, fields
|
|
3
|
+
import os
|
|
4
|
+
from pprint import pprint
|
|
5
|
+
import time
|
|
6
|
+
from typing import Any, Optional, Type, TypeVar
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
from dbus_next import BusType
|
|
10
|
+
from dbus_next.signature import Variant, SignatureTree, SignatureType
|
|
11
|
+
from dbus_next.aio import MessageBus
|
|
12
|
+
|
|
13
|
+
from ns.utils import INTROSPECTION_DIR
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def GetNetworkManager(bus: MessageBus):
|
|
17
|
+
file_name = 'org.freedesktop.NetworkManager.xml'
|
|
18
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
19
|
+
introspection = f.read()
|
|
20
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager', introspection)
|
|
21
|
+
return obj.get_interface('org.freedesktop.NetworkManager')
|
|
22
|
+
|
|
23
|
+
def GetDevice(bus: MessageBus, path : str):
|
|
24
|
+
file_name = 'org.freedesktop.NetworkManager.Device.xml'
|
|
25
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
26
|
+
introspection = f.read()
|
|
27
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
|
|
28
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Device')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def GetActiveConnection(bus: MessageBus, path : str):
|
|
32
|
+
file_name = 'org.freedesktop.NetworkManager.Connection.Active.xml'
|
|
33
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
34
|
+
introspection = f.read()
|
|
35
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
|
|
36
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Connection.Active')
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def GetIp4Config(bus: MessageBus, path : str):
|
|
40
|
+
file_name = 'org.freedesktop.NetworkManager.IP4Config.xml'
|
|
41
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
42
|
+
introspection = f.read()
|
|
43
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
|
|
44
|
+
return obj.get_interface('org.freedesktop.NetworkManager.IP4Config')
|
|
45
|
+
|
|
46
|
+
def GetIp6Config(bus: MessageBus, path : str):
|
|
47
|
+
file_name = 'org.freedesktop.NetworkManager.IP6Config.xml'
|
|
48
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
49
|
+
introspection = f.read()
|
|
50
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
|
|
51
|
+
return obj.get_interface('org.freedesktop.NetworkManager.IP6Config')
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def GetSettingsManager(bus: MessageBus):
|
|
55
|
+
file_name = 'org.freedesktop.NetworkManager.Settings.xml'
|
|
56
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
57
|
+
introspection = f.read()
|
|
58
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', "/org/freedesktop/NetworkManager/Settings", introspection)
|
|
59
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Settings')
|
|
60
|
+
|
|
61
|
+
def GetConnection(bus: MessageBus, path : str):
|
|
62
|
+
file_name = 'org.freedesktop.NetworkManager.Settings.Connection.xml'
|
|
63
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
64
|
+
introspection = f.read()
|
|
65
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspection)
|
|
66
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Settings.Connection')
|
|
67
|
+
|
|
68
|
+
#def UnpackSettings(settings: dict):
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
introspections = None
|
|
72
|
+
bus = None
|
|
73
|
+
|
|
74
|
+
async def GetProperties(proxy):
|
|
75
|
+
data = (await proxy.get_all())[0]
|
|
76
|
+
for f in fields(proxy):
|
|
77
|
+
if f.name in data:
|
|
78
|
+
prop_data = data[f.name]
|
|
79
|
+
if isinstance(prop_data, tuple) and len(prop_data) == 2:
|
|
80
|
+
setattr(proxy, f.name, prop_data[1])
|
|
81
|
+
else:
|
|
82
|
+
setattr(proxy, f.name, prop_data)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
async def getAllProperties(cls :dataclass, router, path: str = ''):
|
|
87
|
+
prox = Proxy(Properties(cls(path)), router)
|
|
88
|
+
all_properties = (await prox.get_all())[0]
|
|
89
|
+
if all_properties:
|
|
90
|
+
return cls.from_dict(all_properties)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def from_dict(obj, instance, data: dict[str, tuple[str, Any]]):
|
|
96
|
+
"""Convert from dict of {'Prop': ('s', value)} or similar into structured props."""
|
|
97
|
+
for f in fields(obj):
|
|
98
|
+
if f.name in data:
|
|
99
|
+
prop_data = data[f.name]
|
|
100
|
+
if isinstance(prop_data, tuple) and len(prop_data) == 2:
|
|
101
|
+
#filtered[f.name] = prop_data[1]
|
|
102
|
+
setattr(instance, f.name, prop_data[1])
|
|
103
|
+
else:
|
|
104
|
+
print("from dict ERROR")
|
|
105
|
+
#filtered[f.name] = prop_data
|
|
106
|
+
setattr(instance, f.name, prop_data)
|
|
107
|
+
#return cls(**filtered)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def load_introspection():
|
|
112
|
+
introspections = {}
|
|
113
|
+
|
|
114
|
+
for file_name in os.listdir("introspection"):
|
|
115
|
+
if file_name.endswith(".xml"):
|
|
116
|
+
print(file_name)
|
|
117
|
+
with open(str(INTROSPECTION_DIR /file_name), "r") as f:
|
|
118
|
+
introspections[file_name] = f.read()
|
|
119
|
+
|
|
120
|
+
return introspections
|
|
121
|
+
|
|
122
|
+
def get_network_manager():
|
|
123
|
+
global introspections, bus
|
|
124
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager', introspections['org.freedesktop.NetworkManager.xml'])
|
|
125
|
+
nm = obj.get_interface('org.freedesktop.NetworkManager')
|
|
126
|
+
return nm
|
|
127
|
+
|
|
128
|
+
def get_network_device(path):
|
|
129
|
+
global introspections, bus
|
|
130
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspections['org.freedesktop.NetworkManager.Device.xml'])
|
|
131
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Device')
|
|
132
|
+
|
|
133
|
+
def get_active_connection(path):
|
|
134
|
+
global introspections, bus
|
|
135
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', path, introspections['org.freedesktop.NetworkManager.Connection.Active.xml'])
|
|
136
|
+
return obj.get_interface('org.freedesktop.NetworkManager.Connection.Active')
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def get_settings_manager():
|
|
140
|
+
global introspections, bus
|
|
141
|
+
obj = bus.get_proxy_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Settings', introspections['org.freedesktop.NetworkManager.Settings.xml'])
|
|
142
|
+
nm = obj.get_interface('org.freedesktop.NetworkManager.Settings')
|
|
143
|
+
return nm
|
|
144
|
+
|
|
145
|
+
#def nm_settings_to_dict(settings: dict):
|
|
146
|
+
# new_dict = {}
|
|
147
|
+
# for key, value in settings.items():
|
|
148
|
+
# new_dict[key] = value
|
|
149
|
+
# for k, v in value.items():
|
|
150
|
+
# if isinstance(v.value, list):
|
|
151
|
+
# if k == "address-data":
|
|
152
|
+
# addresses = []
|
|
153
|
+
# for addr in v.value:
|
|
154
|
+
# addresses.append(f"{addr.get("address").value}/{addr.get("prefix").value}")
|
|
155
|
+
# new_dict[key][k] = addresses
|
|
156
|
+
# else:
|
|
157
|
+
# new_dict[key][k] = v.value
|
|
158
|
+
#
|
|
159
|
+
# return new_dict
|
|
160
|
+
#
|
|
161
|
+
#def dict_to_nm_settings(settings: dict):
|
|
162
|
+
# new_dict = {}
|
|
163
|
+
# for key, value in settings.items():
|
|
164
|
+
# new_dict[key] = value
|
|
165
|
+
# for k, v in value.items():
|
|
166
|
+
# if isinstance(v.value, list):
|
|
167
|
+
# if k == "address-data":
|
|
168
|
+
# addresses = []
|
|
169
|
+
# for addr in v.value:
|
|
170
|
+
# addresses.append(f"{addr.get("address").value}/{addr.get("prefix").value}")
|
|
171
|
+
# new_dict[key][k] = addresses
|
|
172
|
+
# else:
|
|
173
|
+
# new_dict[key][k] = v.value
|
|
174
|
+
#
|
|
175
|
+
# return new_dict
|
|
176
|
+
|
|
177
|
+
async def help_me():
|
|
178
|
+
global introspections, bus
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
print(__name__)
|
|
182
|
+
|
|
183
|
+
bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
nm = GetNetworkManager(bus)
|
|
188
|
+
|
|
189
|
+
sm = GetSettingsManager(bus)
|
|
190
|
+
|
|
191
|
+
connections = await sm.call_list_connections()
|
|
192
|
+
|
|
193
|
+
pprint(connections)
|
|
194
|
+
|
|
195
|
+
devices = await nm.call_get_devices()
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
for device_path in devices:
|
|
199
|
+
|
|
200
|
+
device = GetDevice(bus, device_path)
|
|
201
|
+
|
|
202
|
+
interface = await device.get_interface()
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if interface == 'enp3s0':
|
|
206
|
+
|
|
207
|
+
ip4_config_path = await device.get_ip4_config()
|
|
208
|
+
|
|
209
|
+
ip4_config = GetIp4Config(bus, ip4_config_path)
|
|
210
|
+
|
|
211
|
+
address_data = await ip4_config.get_address_data()
|
|
212
|
+
gateway = await ip4_config.get_gateway()
|
|
213
|
+
print(gateway)
|
|
214
|
+
pprint(address_data)
|
|
215
|
+
|
|
216
|
+
active_connection_path = await device.get_active_connection()
|
|
217
|
+
#print(active_connection_path)
|
|
218
|
+
if len(active_connection_path) > 1:
|
|
219
|
+
activeConnection = GetActiveConnection(bus, active_connection_path)
|
|
220
|
+
|
|
221
|
+
connection_path = await activeConnection.get_connection()
|
|
222
|
+
|
|
223
|
+
#print(connection_path)
|
|
224
|
+
|
|
225
|
+
connection = GetConnection(bus, connection_path)
|
|
226
|
+
|
|
227
|
+
current_settings = await connection.call_get_settings()
|
|
228
|
+
|
|
229
|
+
pprint(current_settings)
|
|
230
|
+
|
|
231
|
+
if False:
|
|
232
|
+
current_settings['ipv4']['method'] = Variant('s', 'auto')
|
|
233
|
+
current_settings['ipv4']['address-data'] = Variant('aa{sv}', [
|
|
234
|
+
{
|
|
235
|
+
'address': Variant('s', '10.1.10.106'),
|
|
236
|
+
'prefix': Variant('u', 24)
|
|
237
|
+
}
|
|
238
|
+
])
|
|
239
|
+
current_settings['ipv4']['gateway'] = Variant('s', '10.1.10.1')
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
# Remove if exists, do nothing if it doesn't
|
|
243
|
+
current_settings['ipv4'].pop('addresses', None)
|
|
244
|
+
current_settings['ipv4'].pop('routes', None) # Also remove deprecated routes
|
|
245
|
+
|
|
246
|
+
await connection.call_update2(current_settings, 0x1, {})
|
|
247
|
+
|
|
248
|
+
await device.call_reapply(current_settings, 0, 0)
|
|
249
|
+
|
|
250
|
+
pprint(current_settings)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
#conn = await open_dbus_connection(bus="SYSTEM")
|
|
259
|
+
|
|
260
|
+
#router = DBusRouter(conn)
|
|
261
|
+
|
|
262
|
+
# the introspection xml would normally be included in your project, but
|
|
263
|
+
# this is convenient for development
|
|
264
|
+
# introspection = await bus.introspect('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Devices/2')
|
|
265
|
+
#
|
|
266
|
+
# #print(introspection.tostring())
|
|
267
|
+
#
|
|
268
|
+
# with open("test.xml", 'a') as f:
|
|
269
|
+
# f.write(introspection.tostring())
|
|
270
|
+
#
|
|
271
|
+
# with open("./introspection/org.freedesktop.NetworkManager.Device.xml", "r") as f:
|
|
272
|
+
# device_intro = f.read()
|
|
273
|
+
#
|
|
274
|
+
# with open("./introspection/org.freedesktop.NetworkManager.xml", 'r') as f:
|
|
275
|
+
# nm_intro = f.read()
|
|
276
|
+
|
|
277
|
+
# introspections = load_introspection()
|
|
278
|
+
#
|
|
279
|
+
# #obj = bus.get_proxy_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager', nm_intro)
|
|
280
|
+
# #nm = obj.get_interface('org.freedesktop.NetworkManager')
|
|
281
|
+
# #properties = obj.get_interface('org.freedesktop.DBus.Properties')
|
|
282
|
+
#
|
|
283
|
+
# nm = get_network_manager()
|
|
284
|
+
#
|
|
285
|
+
# sm = get_settings_manager()
|
|
286
|
+
#
|
|
287
|
+
# #connections = await sm.call_list_connections()
|
|
288
|
+
# #print(connections)
|
|
289
|
+
#
|
|
290
|
+
# print(await nm.get_all())
|
|
291
|
+
#
|
|
292
|
+
# device_paths = await nm.call_get_devices()
|
|
293
|
+
# print(device_paths)
|
|
294
|
+
#
|
|
295
|
+
##
|
|
296
|
+
# for device in device_paths:
|
|
297
|
+
# dev = get_network_device(device)
|
|
298
|
+
#
|
|
299
|
+
#
|
|
300
|
+
# print( await dev.get_udi())
|
|
301
|
+
#
|
|
302
|
+
#
|
|
303
|
+
#
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
# call methods on the interface (this causes the media player to play)
|
|
307
|
+
# await player.call_play()
|
|
308
|
+
#
|
|
309
|
+
# volume = await player.get_volume()
|
|
310
|
+
# print(f'current volume: {volume}, setting to 0.5')
|
|
311
|
+
#
|
|
312
|
+
#print(introspection)
|
|
313
|
+
#
|
|
314
|
+
#introspection.to_xml()
|
|
315
|
+
#
|
|
316
|
+
#with open("NetworkManager.xml", 'x') as f:
|
|
317
|
+
# f.write(introspection.tostring())
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
#nm = Proxy(NetworkManager(), router)
|
|
322
|
+
#device_paths = await nm.GetDevices()
|
|
323
|
+
#
|
|
324
|
+
#for path in device_paths[0]:
|
|
325
|
+
#
|
|
326
|
+
#
|
|
327
|
+
#
|
|
328
|
+
# deviceProxy = Proxy(Device(path), router) # holds methods
|
|
329
|
+
# properties = await deviceProxy.get_all() # gets all props
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
#print(await deviceProxy.GetAppliedConnection(flags=0))
|
|
336
|
+
#devicePropsProxy = Proxy(Properties(Device(path)), router) # holds properties
|
|
337
|
+
|
|
338
|
+
#print(await devicePropsProxy.get_all()) # gets all props
|
|
339
|
+
|
|
340
|
+
#await deviceProxy.SomeMethod() # calls some method
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
#print(await dev.get("Interface"))
|
|
346
|
+
#
|
|
347
|
+
#deviceProperties = (await dev.get_all())[0]
|
|
348
|
+
#
|
|
349
|
+
#devProps = DeviceProperties.from_dict(deviceProperties)
|
|
350
|
+
#
|
|
351
|
+
#print(devProps.ActiveConnection)
|
|
352
|
+
|
|
353
|
+
#
|
|
354
|
+
# if device.Interface == 'wlp1s0':
|
|
355
|
+
#
|
|
356
|
+
# print(device.AvailableConnections)
|
|
357
|
+
#
|
|
358
|
+
# print(device.Ip4Config)
|
|
359
|
+
#
|
|
360
|
+
#
|
|
361
|
+
# config_prox = Proxy(Properties(IP4Config(device.Ip4Config)), router)
|
|
362
|
+
#
|
|
363
|
+
# all_config_data = (await config_prox.get_all())[0]
|
|
364
|
+
#
|
|
365
|
+
# cfg = IP4ConfigProperties.from_dict(all_config_data)
|
|
366
|
+
#
|
|
367
|
+
# print(cfg.AddressData)
|
|
368
|
+
#
|
|
369
|
+
|
|
370
|
+
#print(res2)
|
|
371
|
+
|
|
372
|
+
#await conn.close()
|
|
373
|
+
|
|
374
|
+
asyncio.run(help_me())
|