ia64/xen-unstable

view tools/python/xen/xend/server/netif.py @ 7185:d79ab87e27b8

Cope with missing configuration information inside the configuration method.
This allows us to better recover if the store has been deleted.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Mon Oct 03 16:40:27 2005 +0100 (2005-10-03)
parents 82e8a1d7230f
children 03612b7f69d5
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 xroot.get_vif_bridge())
56 mac = sxp.child_value(config, 'mac')
57 ipaddr = _get_config_ipaddr(config)
59 devid = self.allocateDeviceID()
61 back = { 'script' : script,
62 'mac' : mac,
63 'bridge' : bridge,
64 'handle' : "%i" % devid }
65 if ipaddr:
66 back['ip'] = ' '.join(ipaddr)
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