mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Added code to detect 'shared' physical NICs
This commit is contained in:
parent
a389933464
commit
eb68f9321f
@ -20,7 +20,8 @@
|
||||
import gobject
|
||||
import libvirt
|
||||
import logging
|
||||
import os
|
||||
import os, sys
|
||||
import traceback
|
||||
from time import time
|
||||
import logging
|
||||
from socket import gethostbyaddr, gethostname
|
||||
@ -92,8 +93,11 @@ class vmmConnection(gobject.GObject):
|
||||
# Find info about all current present media
|
||||
for path in self.hal_iface.FindDeviceByCapability("net"):
|
||||
self._device_added(path)
|
||||
except Exception, e:
|
||||
logging.error("Unable to connect to HAL to list network devices: '%s'", e)
|
||||
except:
|
||||
(type, value, stacktrace) = sys.exc_info ()
|
||||
logging.error("Unable to connect to HAL to list network devices: '%s'" + \
|
||||
str(type) + " " + str(value) + "\n" + \
|
||||
traceback.format_exc (stacktrace))
|
||||
self.bus = None
|
||||
self.hal_iface = None
|
||||
|
||||
@ -104,7 +108,28 @@ class vmmConnection(gobject.GObject):
|
||||
name = obj.GetPropertyString("net.interface")
|
||||
mac = obj.GetPropertyString("net.address")
|
||||
|
||||
dev = vmmNetDevice(self.config, self, name, mac, False)
|
||||
# Now magic to determine if the device is part of a bridge
|
||||
shared = False
|
||||
bridge = None
|
||||
try:
|
||||
# XXX Linux specific - needs porting for other OS - patches
|
||||
# welcomed...
|
||||
sysfspath = obj.GetPropertyString("linux.sysfs_path")
|
||||
brportpath = os.path.join(sysfspath, "brport")
|
||||
|
||||
if os.path.exists(brportpath):
|
||||
shared = True
|
||||
brlinkpath = os.path.join(brportpath, "bridge")
|
||||
dest = os.readlink(brlinkpath)
|
||||
(head,tail) = os.path.split(dest)
|
||||
bridge = tail
|
||||
except:
|
||||
(type, value, stacktrace) = sys.exc_info ()
|
||||
logging.error("Unable to determine if device is shared:" +
|
||||
str(type) + " " + str(value) + "\n" + \
|
||||
traceback.format_exc (stacktrace))
|
||||
|
||||
dev = vmmNetDevice(self.config, self, name, mac, shared, bridge)
|
||||
self.netdevs[path] = dev
|
||||
self.emit("netdev-added", dev.get_name())
|
||||
|
||||
@ -159,8 +184,8 @@ class vmmConnection(gobject.GObject):
|
||||
def get_net(self, uuid):
|
||||
return self.nets[uuid]
|
||||
|
||||
def get_net_device(self, name):
|
||||
return self.netdevs[name]
|
||||
def get_net_device(self, path):
|
||||
return self.netdevs[path]
|
||||
|
||||
def close(self):
|
||||
if self.vmm == None:
|
||||
@ -176,11 +201,8 @@ class vmmConnection(gobject.GObject):
|
||||
def list_net_uuids(self):
|
||||
return self.nets.keys()
|
||||
|
||||
def list_net_device_names(self):
|
||||
names = []
|
||||
for path in self.netdevs:
|
||||
names.append(self.netdevs[path].get_name())
|
||||
return names
|
||||
def list_net_device_paths(self):
|
||||
return self.netdevs.keys()
|
||||
|
||||
def get_host_info(self):
|
||||
return self.hostinfo
|
||||
|
@ -955,8 +955,10 @@ class vmmCreate(gobject.GObject):
|
||||
|
||||
def populate_device_model(self, model):
|
||||
model.clear()
|
||||
br = virtinst.util.default_bridge()
|
||||
model.append([br])
|
||||
for name in self.connection.list_net_device_paths():
|
||||
net = self.connection.get_net_device(name)
|
||||
if net.is_shared():
|
||||
model.append([net.get_bridge()])
|
||||
|
||||
def change_os_type(self, box):
|
||||
model = box.get_model()
|
||||
|
@ -21,13 +21,14 @@ import gobject
|
||||
class vmmNetDevice(gobject.GObject):
|
||||
__gsignals__ = {}
|
||||
|
||||
def __init__(self, config, connection, name, mac, shared):
|
||||
def __init__(self, config, connection, name, mac, shared, bridge=None):
|
||||
self.__gobject_init__()
|
||||
|
||||
self.conn = connection
|
||||
self.name = name
|
||||
self.mac = mac
|
||||
self.shared = shared
|
||||
self.bridge = bridge
|
||||
|
||||
def get_connection(self):
|
||||
return self.conn
|
||||
@ -38,6 +39,9 @@ class vmmNetDevice(gobject.GObject):
|
||||
def is_shared(self):
|
||||
return self.shared
|
||||
|
||||
def get_bridge(self):
|
||||
return self.bridge
|
||||
|
||||
def get_mac(self):
|
||||
return self.mac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user