Network¶
Network interface and NetworkManager connection management — IP addressing, link state, MAC handling, and NM connection profiles for test network setup.
sts.network.interface
¶
Network interface discovery and management.
NetworkInterface
pydantic-model
¶
Bases: NetworkDevice
Network interface representation.
Example
iface = NetworkInterface()
iface.discover() # Discovers first available interface
iface = NetworkInterface(name='eth0')
iface.discover() # Discovers other values
iface = NetworkInterface(mac='F0:DE:F1:0D:D3:C9')
iface.discover() # Discovers other values
Show JSON schema:
{
"additionalProperties": false,
"description": "Network interface representation.\n\nExample:\n ```python\n iface = NetworkInterface()\n iface.discover() # Discovers first available interface\n iface = NetworkInterface(name='eth0')\n iface.discover() # Discovers other values\n iface = NetworkInterface(mac='F0:DE:F1:0D:D3:C9')\n iface.discover() # Discovers other values\n ```",
"properties": {
"path": {
"anyOf": [
{
"type": "string"
},
{
"format": "path",
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Path"
},
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Name"
},
"ip": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Ip"
},
"port": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Port"
},
"mac": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Mac"
},
"driver": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Driver"
},
"pci_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Pci Id"
}
},
"title": "NetworkInterface",
"type": "object"
}
Fields:
-
path(PathOrStr | None) -
name(str | None) -
ip(str | None) -
port(int | None) -
mac(str | None) -
driver(str | None) -
pci_id(str | None)
Validators:
-
_derive_fields
Source code in sts_libs/src/sts/network/interface.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
ip_addresses
property
¶
Get IP addresses assigned to this interface.
discover()
¶
Discover interface properties from the system.
Runs subprocess commands to find name, MAC, driver, and PCI ID. Call after construction when system discovery is needed.
Source code in sts_libs/src/sts/network/interface.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
down()
¶
Bring interface down.
Source code in sts_libs/src/sts/network/interface.py
195 196 197 198 199 200 201 202 | |
get_all()
classmethod
¶
Get all network interfaces with valid MAC addresses.
Source code in sts_libs/src/sts/network/interface.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
get_by_ip(ip)
classmethod
¶
Get interface by IP address.
Source code in sts_libs/src/sts/network/interface.py
245 246 247 248 249 250 251 252 | |
get_by_mac(mac)
classmethod
¶
Get interface by MAC address.
Source code in sts_libs/src/sts/network/interface.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_ip_version(addr)
staticmethod
¶
Get IP version (4 or 6), or None if invalid.
Source code in sts_libs/src/sts/network/interface.py
178 179 180 181 182 183 184 | |
is_valid_mac(mac)
staticmethod
¶
Check if MAC address is valid.
Source code in sts_libs/src/sts/network/interface.py
128 129 130 131 | |
standardize_mac(mac)
staticmethod
¶
Standardize MAC address to colon-separated uppercase format.
Example
NetworkInterface.standardize_mac('F0-DE-F1-0D-D3-C9')
'F0:DE:F1:0D:D3:C9'
Source code in sts_libs/src/sts/network/interface.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
up()
¶
Bring interface up.
Source code in sts_libs/src/sts/network/interface.py
186 187 188 189 190 191 192 193 | |
sts.network.nm
¶
NetworkManager connection management via nmcli.
NetworkConnection
pydantic-model
¶
Bases: StsBaseModel
NetworkManager connection representation.
Example
conn = NetworkConnection()
conn.discover() # Discovers first available connection
conn = NetworkConnection(name='eth0')
conn.discover() # Discovers other values
Show JSON schema:
{
"additionalProperties": false,
"description": "NetworkManager connection representation.\n\nExample:\n ```python\n conn = NetworkConnection()\n conn.discover() # Discovers first available connection\n conn = NetworkConnection(name='eth0')\n conn.discover() # Discovers other values\n ```",
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Name"
},
"uuid": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Uuid"
},
"interface": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Interface"
},
"conn_type": {
"default": "ethernet",
"enum": [
"ethernet",
"wifi",
"bond",
"bridge",
"team",
"vlan"
],
"title": "Conn Type",
"type": "string"
}
},
"title": "NetworkConnection",
"type": "object"
}
Fields:
-
name(str | None) -
uuid(str | None) -
interface(str | None) -
conn_type(ConnectionType)
Source code in sts_libs/src/sts/network/nm.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
delete()
¶
Delete connection.
Source code in sts_libs/src/sts/network/nm.py
127 128 129 130 131 132 133 134 | |
discover()
¶
Discover connection properties from NetworkManager.
Runs nmcli commands to find name, UUID, and interface. Call after construction when NM discovery is needed.
Source code in sts_libs/src/sts/network/nm.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
down()
¶
Deactivate connection.
Source code in sts_libs/src/sts/network/nm.py
118 119 120 121 122 123 124 125 | |
exists()
¶
Check if connection exists in NetworkManager.
Source code in sts_libs/src/sts/network/nm.py
97 98 99 100 101 102 103 104 105 106 107 | |
modify(setting, value)
¶
Modify connection setting (e.g. ipv4.method).
Source code in sts_libs/src/sts/network/nm.py
136 137 138 139 140 141 142 143 | |
set_ip(ip, prefix=24)
¶
Set IP address, switch to manual mode, and reactivate.
Source code in sts_libs/src/sts/network/nm.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
up()
¶
Activate connection.
Source code in sts_libs/src/sts/network/nm.py
109 110 111 112 113 114 115 116 | |
NetworkManager
¶
NetworkManager operations.
Example
nm = NetworkManager()
conn = nm.get_connection('eth0')
conn.up()
Source code in sts_libs/src/sts/network/nm.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
add_connection(name=None, interface=None, conn_type='ethernet', **settings)
¶
Add new connection.
Setting keys are converted to nmcli format via _convert_setting_name
(e.g. ipv4_method becomes ipv4.method).
Source code in sts_libs/src/sts/network/nm.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
get_connection(name_or_uuid=None)
¶
Get connection by name or UUID, or the first available if not specified.
Source code in sts_libs/src/sts/network/nm.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
get_connection_by_interface(interface=None)
¶
Get connection by interface, or the first available if not specified.
Source code in sts_libs/src/sts/network/nm.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
reload()
staticmethod
¶
Reload NetworkManager configuration.
Source code in sts_libs/src/sts/network/nm.py
176 177 178 179 180 | |