direct-io.hg

view tools/python/xen/xend/server/netif.py @ 7547:03612b7f69d5

Don't use XendRoot.get_vif_bridge to provide a default bridge -- instead, pass
no bridge parameter and let the vif-bridge script find one for itself.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Sun Oct 30 13:45:06 2005 +0100 (2005-10-30)
parents 625c75a223fe
children b47b79585772
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 XenSource Ltd
17 #============================================================================
20 """Support for virtual network interfaces.
21 """
23 import os
25 from xen.xend import sxp
26 from xen.xend import XendRoot
28 from xen.xend.server.DevController import DevController
31 xroot = XendRoot.instance()
34 class NetifController(DevController):
35 """Network interface controller. Handles all network devices for a domain.
36 """
38 def __init__(self, vm):
39 DevController.__init__(self, vm)
42 def getDeviceDetails(self, config):
43 """@see DevController.getDeviceDetails"""
45 def _get_config_ipaddr(config):
46 val = []
47 for ipaddr in sxp.children(config, elt='ip'):
48 val.append(sxp.child0(ipaddr))
49 return val
51 script = os.path.join(xroot.network_script_dir,
52 sxp.child_value(config, 'script',
53 xroot.get_vif_script()))
54 bridge = sxp.child_value(config, 'bridge')
55 mac = sxp.child_value(config, 'mac')
56 ipaddr = _get_config_ipaddr(config)
58 devid = self.allocateDeviceID()
60 back = { 'script' : script,
61 'mac' : mac,
62 'handle' : "%i" % devid }
63 if ipaddr:
64 back['ip'] = ' '.join(ipaddr)
65 if bridge:
66 back['bridge'] = bridge
68 front = { 'handle' : "%i" % devid,
69 'mac' : mac }
71 return (devid, back, front)
74 def configuration(self, devid):
75 """@see DevController.configuration"""
77 result = DevController.configuration(self, devid)
79 (script, ip, bridge, mac) = self.readBackend(devid,
80 'script', 'ip', 'bridge',
81 'mac')
83 if script:
84 result.append(['script',
85 script.replace(xroot.network_script_dir + os.sep,
86 "")])
87 if ip:
88 result.append(['ip', ip.split(" ")])
89 if bridge:
90 result.append(['bridge', bridge])
91 if mac:
92 result.append(['mac', mac])
94 return result