ia64/xen-unstable

changeset 13204:d759e9df902f

Implement network.get_VIFs.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 28 12:26:29 2006 +0000 (2006-12-28)
parents ce49c9d78928
children 61788aef85e0
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendNetwork.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendPIF.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Dec 27 16:16:10 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Dec 28 12:26:29 2006 +0000
     1.3 @@ -605,6 +605,16 @@ class XendDomain:
     1.4          finally:
     1.5              self.domains_lock.release()
     1.6  
     1.7 +    def get_all_vms(self):
     1.8 +        self.domains_lock.acquire()
     1.9 +        try:
    1.10 +            result = self.domains.values()
    1.11 +            result += [x for x in self.managed_domains.values() if
    1.12 +                       x not in result]
    1.13 +            return result
    1.14 +        finally:
    1.15 +            self.domains_lock.release()
    1.16 +
    1.17      def get_vm_by_uuid(self, vm_uuid):
    1.18          self.domains_lock.acquire()
    1.19          try:
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Dec 27 16:16:10 2006 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 28 12:26:29 2006 +0000
     2.3 @@ -1967,8 +1967,12 @@ class XendDomainInfo:
     2.4                      config['device'] = 'eth%d' % devid
     2.5                  else:
     2.6                      config['device'] = ''
     2.7 -                    
     2.8 -            config['network'] = '' # Invalid for Xend
     2.9 +
    2.10 +            if not config.has_key('network'):
    2.11 +                config['network'] = \
    2.12 +                    XendNode.instance().bridge_to_network(
    2.13 +                    config.get('bridge')).uuid
    2.14 +
    2.15              config['MTU'] = 1500 # TODO
    2.16              config['io_read_kbs'] = 0.0
    2.17              config['io_write_kbs'] = 0.0
     3.1 --- a/tools/python/xen/xend/XendNetwork.py	Wed Dec 27 16:16:10 2006 +0000
     3.2 +++ b/tools/python/xen/xend/XendNetwork.py	Thu Dec 28 12:26:29 2006 +0000
     3.3 @@ -21,6 +21,7 @@ import re
     3.4  import struct
     3.5  import socket
     3.6  
     3.7 +import XendDomain
     3.8  import XendNode
     3.9  from XendLogging import log
    3.10  
    3.11 @@ -83,7 +84,15 @@ class XendNetwork:
    3.12              XendNode.instance().save_networks()
    3.13  
    3.14      def get_VIF_UUIDs(self):
    3.15 -        return []
    3.16 +        result = []
    3.17 +        vms = XendDomain.instance().get_all_vms()
    3.18 +        for vm in vms:
    3.19 +            vifs = vm.get_vifs()
    3.20 +            for vif in vifs:
    3.21 +                vif_cfg = vm.get_dev_xenapi_config('vif', vif)
    3.22 +                if vif_cfg['network'] == self.uuid:
    3.23 +                    result.append(vif)
    3.24 +        return result
    3.25  
    3.26      def get_PIF_UUIDs(self):
    3.27          return [x.uuid for x in XendNode.instance().pifs.values()
     4.1 --- a/tools/python/xen/xend/XendNode.py	Wed Dec 27 16:16:10 2006 +0000
     4.2 +++ b/tools/python/xen/xend/XendNode.py	Thu Dec 28 12:26:29 2006 +0000
     4.3 @@ -289,6 +289,22 @@ class XendNode:
     4.4      def get_network(self, network_ref):
     4.5          return self.networks[network_ref]
     4.6  
     4.7 +    def bridge_to_network(self, bridge):
     4.8 +        if not bridge:
     4.9 +            rc, bridge = commands.getstatusoutput(
    4.10 +                'brctl show | cut -d "\n" -f 2 | cut -f 1')
    4.11 +            if rc != 0 or not bridge:
    4.12 +                raise Exception(
    4.13 +                    'Could not find default bridge, and none was specified')
    4.14 +
    4.15 +        bridges = Brctl.get_state()
    4.16 +        if bridge not in bridges:
    4.17 +            raise Exception('Bridge %s is not up' % bridge)
    4.18 +        for pif in self.pifs.values():
    4.19 +            if pif.interface_name() in bridges[bridge]:
    4.20 +                return pif.network
    4.21 +        raise Exception('Bridge %s is not connected to a network' % bridge)
    4.22 +
    4.23  
    4.24      #
    4.25      # Getting host information.
     5.1 --- a/tools/python/xen/xend/XendPIF.py	Wed Dec 27 16:16:10 2006 +0000
     5.2 +++ b/tools/python/xen/xend/XendPIF.py	Thu Dec 28 12:26:29 2006 +0000
     5.3 @@ -134,7 +134,7 @@ class XendPIF:
     5.4  
     5.5  
     5.6      def refresh(self, bridges):
     5.7 -        ifname = self._ifname()
     5.8 +        ifname = self.interface_name()
     5.9          rc, _ = _cmd('ip link show %s', ifname)
    5.10          if rc != 0:
    5.11              # Interface does not exist.  If it's a physical interface, then
    5.12 @@ -172,7 +172,7 @@ class XendPIF:
    5.13          log.info('Added network interface %s to bridge %s', ifname, brname)
    5.14  
    5.15  
    5.16 -    def _ifname(self):
    5.17 +    def interface_name(self):
    5.18          if self.vlan:
    5.19              return '%s.%s' % (self.name, self.vlan)
    5.20          else: