Implement network.get_VIFs.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
Ewan Mellor committed 2006-12-28 12:26:29 +00:00
1 parent 6e43af518c
commit 468611d262
5 files changed
+44 -5

No files matched your search

+10
View File
@@ -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:
+6 -2
View File
@@ -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
+10 -1
View File
@@ -21,6 +21,7 @@ import re
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()
+16
View File
@@ -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.
+2 -2
View File
@@ -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:
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.