Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 96c4915

Browse files
committed
VirtualNetworkInterface: Add set_source helper
Also track TYPE_DIRECT
1 parent fcd8ba7 commit 96c4915

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

virtinst/VirtualNetworkInterface.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class VirtualNetworkInterface(VirtualDevice.VirtualDevice):
103103
TYPE_VIRTUAL = "network"
104104
TYPE_USER = "user"
105105
TYPE_ETHERNET = "ethernet"
106-
network_types = [TYPE_BRIDGE, TYPE_VIRTUAL, TYPE_USER, TYPE_ETHERNET]
106+
TYPE_DIRECT = "direct"
107+
network_types = [TYPE_BRIDGE, TYPE_VIRTUAL, TYPE_USER, TYPE_ETHERNET,
108+
TYPE_DIRECT]
107109

108110
def get_network_type_desc(net_type):
109111
"""
@@ -182,12 +184,26 @@ def get_source(self):
182184
return self.network
183185
if self.type == self.TYPE_BRIDGE:
184186
return self.bridge
185-
if self.type == self.TYPE_ETHERNET:
187+
if self.type == self.TYPE_ETHERNET or self.type == self.TYPE_DIRECT:
186188
return self.source_dev
187189
if self.type == self.TYPE_USER:
188190
return None
189191
return self.network or self.bridge or self.source_dev
190192

193+
def set_source(self, newsource):
194+
"""
195+
Conveninece function, try to set the relevant <source> value
196+
per the network type
197+
"""
198+
if self.type == self.TYPE_VIRTUAL:
199+
self.network = newsource
200+
elif self.type == self.TYPE_BRIDGE:
201+
self.bridge = newsource
202+
elif self.type == self.TYPE_ETHERNET or self.type == self.TYPE_DIRECT:
203+
self.source_dev = newsource
204+
return
205+
source = property(get_source, set_source)
206+
191207
def _get_virtualport(self):
192208
return self._virtualport
193209
virtualport = property(_get_virtualport)

0 commit comments

Comments
 (0)