Modified libvirtwork to use vmmNetwork objects.

Modified the list_networks() API to return the UUIDs for network.

Modified get_network() to take as input a UUID rather than a name, and
return a vmmNetwork object.
This commit is contained in:
Darryl L. Pierce 2011-05-26 14:37:17 -04:00 committed by Cole Robinson
parent 83c25e6ad4
commit 6356d5b8b7
2 changed files with 19 additions and 10 deletions

View File

@ -192,14 +192,15 @@ class NetworkListConfigScreen(ConfigScreen):
ConfigScreen.__init__(self, title)
def get_network_list_page(self, screen, defined=True, created=True):
networks = self.get_libvirt().list_networks(defined, created)
uuids = self.get_libvirt().list_networks(defined, created)
result = None
if len(networks) > 0:
if len(uuids) > 0:
self.__has_networks = True
self.__network_list = Listbox(0)
for name in networks:
self.__network_list.append(name, name)
for uuid in uuids:
network = self.get_libvirt().get_network(uuid)
self.__network_list.append(uuid, network.get_name())
result = self.__network_list
else:
self.__has_networks = False

View File

@ -164,20 +164,28 @@ class LibvirtWorker:
started -- Include only started networks. (default True)
'''
self.__vmmconn.tick()
uuids = self.__vmmconn.list_net_uuids()
result = []
if defined: result.extend(self.__conn.listDefinedNetworks())
if started: result.extend(self.__conn.listNetworks())
for uuid in uuids:
include = False
net = self.__vmmconn.get_net(uuid)
if net.is_active():
if started: include = True
else:
if defined: include = True
if include: result.append(uuid)
return result
def get_network(self, name):
def get_network(self, uuid):
'''Returns the specified network. Raises an exception if the netowrk does not exist.
Keyword arguments:
name -- the name of the network
uuid -- the network's identifier
'''
result = self.__conn.networkLookupByName(name)
if result is None: raise Exception("No such network exists: %s" % name)
result = self.__vmmconn.get_net(uuid)
if result is None: raise Exception("No such network exists: uuid=%s" % uuid)
return result