# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167308789 0
# Node ID d759e9df902f4a4b0be5b25cd9cb8ef08e5d5174
# Parent ce49c9d789281c40bbc9d451acca2f539d51b7b1
Implement network.get_VIFs.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
tools/python/xen/xend/XendDomain.py | 10 ++++++++++
tools/python/xen/xend/XendDomainInfo.py | 8 ++++++--
tools/python/xen/xend/XendNetwork.py | 11 ++++++++++-
tools/python/xen/xend/XendNode.py | 16 ++++++++++++++++
tools/python/xen/xend/XendPIF.py | 4 ++--
5 files changed, 44 insertions(+), 5 deletions(-)
diff -r ce49c9d78928 -r d759e9df902f tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py Wed Dec 27 16:16:10 2006 +0000
+++ b/tools/python/xen/xend/XendDomain.py Thu Dec 28 12:26:29 2006 +0000
@@ -605,6 +605,16 @@ class XendDomain:
finally:
self.domains_lock.release()
+ def get_all_vms(self):
+ self.domains_lock.acquire()
+ try:
+ result = self.domains.values()
+ result += [x for x in self.managed_domains.values() if
+ x not in result]
+ return result
+ finally:
+ self.domains_lock.release()
+
def get_vm_by_uuid(self, vm_uuid):
self.domains_lock.acquire()
try:
diff -r ce49c9d78928 -r d759e9df902f tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Wed Dec 27 16:16:10 2006 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py Thu Dec 28 12:26:29 2006 +0000
@@ -1967,8 +1967,12 @@ class XendDomainInfo:
config['device'] = 'eth%d' % devid
else:
config['device'] = ''
-
- config['network'] = '' # Invalid for Xend
+
+ if not config.has_key('network'):
+ config['network'] = \
+ XendNode.instance().bridge_to_network(
+ config.get('bridge')).uuid
+
config['MTU'] = 1500 # TODO
config['io_read_kbs'] = 0.0
config['io_write_kbs'] = 0.0
diff -r ce49c9d78928 -r d759e9df902f tools/python/xen/xend/XendNetwork.py
--- a/tools/python/xen/xend/XendNetwork.py Wed Dec 27 16:16:10 2006 +0000
+++ b/tools/python/xen/xend/XendNetwork.py Thu Dec 28 12:26:29 2006 +0000
@@ -21,6 +21,7 @@ import struct
import struct
import socket
+import XendDomain
import XendNode
from XendLogging import log
@@ -83,7 +84,15 @@ class XendNetwork:
XendNode.instance().save_networks()
def get_VIF_UUIDs(self):
- return []
+ result = []
+ vms = XendDomain.instance().get_all_vms()
+ for vm in vms:
+ vifs = vm.get_vifs()
+ for vif in vifs:
+ vif_cfg = vm.get_dev_xenapi_config('vif', vif)
+ if vif_cfg['network'] == self.uuid:
+ result.append(vif)
+ return result
def get_PIF_UUIDs(self):
return [x.uuid for x in XendNode.instance().pifs.values()
diff -r ce49c9d78928 -r d759e9df902f tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Wed Dec 27 16:16:10 2006 +0000
+++ b/tools/python/xen/xend/XendNode.py Thu Dec 28 12:26:29 2006 +0000
@@ -289,6 +289,22 @@ class XendNode:
def get_network(self, network_ref):
return self.networks[network_ref]
+ def bridge_to_network(self, bridge):
+ if not bridge:
+ rc, bridge = commands.getstatusoutput(
+ 'brctl show | cut -d "\n" -f 2 | cut -f 1')
+ if rc != 0 or not bridge:
+ raise Exception(
+ 'Could not find default bridge, and none was specified')
+
+ bridges = Brctl.get_state()
+ if bridge not in bridges:
+ raise Exception('Bridge %s is not up' % bridge)
+ for pif in self.pifs.values():
+ if pif.interface_name() in bridges[bridge]:
+ return pif.network
+ raise Exception('Bridge %s is not connected to a network' % bridge)
+
#
# Getting host information.
diff -r ce49c9d78928 -r d759e9df902f tools/python/xen/xend/XendPIF.py
--- a/tools/python/xen/xend/XendPIF.py Wed Dec 27 16:16:10 2006 +0000
+++ b/tools/python/xen/xend/XendPIF.py Thu Dec 28 12:26:29 2006 +0000
@@ -134,7 +134,7 @@ class XendPIF:
def refresh(self, bridges):
- ifname = self._ifname()
+ ifname = self.interface_name()
rc, _ = _cmd('ip link show %s', ifname)
if rc != 0:
# Interface does not exist. If it's a physical interface, then
@@ -172,7 +172,7 @@ class XendPIF:
log.info('Added network interface %s to bridge %s', ifname, brname)
- def _ifname(self):
+ def interface_name(self):
if self.vlan:
return '%s.%s' % (self.name, self.vlan)
else:
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|