ia64/xen-unstable

changeset 7162:70d5bfbf23d4

Move XendVnet from using DBMap etc to using xstransact. This is the last
dependency upon xsnode, xsobj, and xsresource, so these can all go.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Sun Oct 02 18:22:22 2005 +0100 (2005-10-02)
parents a73ab0ddf990
children d443f03f8be0
files tools/python/xen/xend/XendVnet.py tools/python/xen/xend/xenstore/__init__.py
line diff
     1.1 --- a/tools/python/xen/xend/XendVnet.py	Sun Oct 02 18:21:01 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendVnet.py	Sun Oct 02 18:22:22 2005 +0100
     1.3 @@ -13,6 +13,7 @@
     1.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     1.5  #============================================================================
     1.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     1.7 +# Copyright (C) 2005 XenSource Ltd
     1.8  #============================================================================
     1.9  
    1.10  """Handler for vnet operations.
    1.11 @@ -22,7 +23,8 @@ from xen.util import Brctl
    1.12  from xen.xend import sxp
    1.13  from xen.xend.XendError import XendError
    1.14  from xen.xend.XendLogging import log
    1.15 -from xen.xend.xenstore import XenNode, DBMap, DBVar
    1.16 +from xen.xend.xenstore.xstransact import xstransact
    1.17 +
    1.18  
    1.19  def vnet_cmd(cmd):
    1.20      out = None
    1.21 @@ -39,39 +41,40 @@ class XendVnetInfo:
    1.22      
    1.23      vifctl_ops = {'up': 'vif.add', 'down': 'vif.del'}
    1.24  
    1.25 -    __exports__ = [
    1.26 -        DBVar('id',     ty='str'),
    1.27 -        DBVar('dbid',   ty='str'),
    1.28 -        DBVar('config', ty='sxpr'),
    1.29 -       ]
    1.30 -    
    1.31 -    def __init__(self, db, config=None):
    1.32 +    def __init__(self, dbpath, config=None):
    1.33          if config:
    1.34 -            self.id = sxp.child_value(config, 'id')
    1.35 -            self.id = str(self.id)
    1.36 +            self.id = str(sxp.child_value(config, 'id'))
    1.37              self.dbid = self.id.replace(':', '-')
    1.38 -            self.db = db.addChild(self.dbid)
    1.39 +            self.dbpath = dbpath + '/' + self.dbid
    1.40              self.config = config
    1.41          else:
    1.42 -            self.db = db
    1.43 +            self.dbpath = dbpath
    1.44              self.importFromDB()
    1.45 -            config = self.config
    1.46              
    1.47 -        self.bridge = sxp.child_value(config, 'bridge')
    1.48 +        self.bridge = sxp.child_value(self.config, 'bridge')
    1.49          if not self.bridge:
    1.50              self.bridge = "vnet%s" % self.id
    1.51 -        self.vnetif = sxp.child_value(config, 'vnetif')
    1.52 +        self.vnetif = sxp.child_value(self.config, 'vnetif')
    1.53          if not self.vnetif:
    1.54              self.vnetif = "vnif%s" % self.id
    1.55  
    1.56 -    def saveToDB(self, save=False, sync=False):
    1.57 -        self.db.saveDB(save=save, sync=sync)
    1.58  
    1.59      def exportToDB(self, save=False, sync=False):
    1.60 -        self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
    1.61 +        to_store = {
    1.62 +            'id' : self.id,
    1.63 +            'dbid' : self.dbid,
    1.64 +            'config' : sxp.to_string
    1.65 +            }
    1.66 +        xstransact.Write(self.dbpath, to_store)
    1.67 +
    1.68  
    1.69      def importFromDB(self):
    1.70 -        self.db.importFromDB(self, fields=self.__exports__)
    1.71 +        (self.id, self.dbid, c) = xstransact.Gather(self.dbpath,
    1.72 +                                                    ('id', str),
    1.73 +                                                    ('dbid', str),
    1.74 +                                                    ('config', str))
    1.75 +        self.config = sxp.from_string(c)
    1.76 +
    1.77  
    1.78      def sxpr(self):
    1.79          return self.config
    1.80 @@ -88,7 +91,7 @@ class XendVnetInfo:
    1.81          Brctl.vif_bridge_rem({'bridge': self.bridge, 'vif': self.vnetif})
    1.82          Brctl.bridge_del(self.bridge)
    1.83          val = vnet_cmd(['vnet.del', self.id])
    1.84 -        self.db.delete()
    1.85 +        xstransact.Remove(self.dbpath)
    1.86          return val
    1.87  
    1.88      def vifctl(self, op, vif, vmac):
    1.89 @@ -107,18 +110,17 @@ class XendVnet:
    1.90      def __init__(self):
    1.91          # Table of vnet info indexed by vnet id.
    1.92          self.vnet = {}
    1.93 -        self.db = DBMap(db=XenNode(self.dbpath))
    1.94 -        self.db.readDB()
    1.95 -        for vnetdb in self.db.values():
    1.96 +        listing = xstransact.List(self.dbpath)
    1.97 +        for entry in listing:
    1.98              try:
    1.99 -                info = XendVnetInfo(vnetdb)
   1.100 +                info = XendVnetInfo(self.dbpath + '/' + entry)
   1.101                  self.vnet[info.id] = info
   1.102                  info.configure()
   1.103              except XendError, ex:
   1.104                  log.warning("Failed to configure vnet %s: %s", str(info.id), str(ex))
   1.105              except Exception, ex:
   1.106                  log.exception("Vnet error")
   1.107 -                vnetdb.delete()
   1.108 +                xstransact.Remove(self.dbpath + '/' + entry)
   1.109  
   1.110      def vnet_of_bridge(self, bridge):
   1.111          """Get the vnet for a bridge (if any).
   1.112 @@ -155,9 +157,9 @@ class XendVnet:
   1.113  
   1.114          @param config: config
   1.115          """
   1.116 -        info = XendVnetInfo(self.db, config=config)
   1.117 +        info = XendVnetInfo(self.dbpath, config=config)
   1.118          self.vnet[info.id] = info
   1.119 -        info.saveToDB()
   1.120 +        info.exportToDB()
   1.121          info.configure()
   1.122  
   1.123      def vnet_delete(self, id):
     2.1 --- a/tools/python/xen/xend/xenstore/__init__.py	Sun Oct 02 18:21:01 2005 +0100
     2.2 +++ b/tools/python/xen/xend/xenstore/__init__.py	Sun Oct 02 18:22:22 2005 +0100
     2.3 @@ -14,5 +14,3 @@
     2.4  #============================================================================
     2.5  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     2.6  #============================================================================
     2.7 -from xsnode import *
     2.8 -from xsobj import *
     3.1 --- a/tools/python/xen/xend/xenstore/xsnode.py	Sun Oct 02 18:21:01 2005 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,477 +0,0 @@
     3.4 -#============================================================================
     3.5 -# This library is free software; you can redistribute it and/or
     3.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
     3.7 -# License as published by the Free Software Foundation.
     3.8 -#
     3.9 -# This library is distributed in the hope that it will be useful,
    3.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.12 -# Lesser General Public License for more details.
    3.13 -#
    3.14 -# You should have received a copy of the GNU Lesser General Public
    3.15 -# License along with this library; if not, write to the Free Software
    3.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.17 -#============================================================================
    3.18 -# Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    3.19 -#============================================================================
    3.20 -import errno
    3.21 -import os
    3.22 -import os.path
    3.23 -import select
    3.24 -import socket
    3.25 -import sys
    3.26 -import threading
    3.27 -import time
    3.28 -
    3.29 -from xen.lowlevel import xs
    3.30 -from xen.xend import sxp
    3.31 -from xen.xend.PrettyPrint import prettyprint
    3.32 -
    3.33 -SELECT_TIMEOUT = 2.0
    3.34 -
    3.35 -def getEventPath(event):
    3.36 -    if event and event.startswith("/"):
    3.37 -        event = event[1:]
    3.38 -    return os.path.join("/event", event)
    3.39 -
    3.40 -def getEventIdPath(event):
    3.41 -    return os.path.join(getEventPath(event), "@eid")
    3.42 -
    3.43 -class Subscription:
    3.44 -
    3.45 -    def __init__(self, path, fn, sid):
    3.46 -        self.path = path
    3.47 -        self.watcher = None
    3.48 -        self.fn = fn
    3.49 -        self.sid = sid
    3.50 -
    3.51 -    def getPath(self):
    3.52 -        return self.path
    3.53 -
    3.54 -    def getSid(self):
    3.55 -        return self.sid
    3.56 -
    3.57 -    def watch(self, watcher):
    3.58 -        self.watcher = watcher
    3.59 -        watcher.addSubs(self)
    3.60 -
    3.61 -    def unwatch(self):
    3.62 -        watcher = self.watcher
    3.63 -        if watcher:
    3.64 -            self.watcher = None
    3.65 -            watcher.delSubs(self)
    3.66 -        return watcher
    3.67 -
    3.68 -    def notify(self, token, path, val):
    3.69 -        try:
    3.70 -            self.fn(self, token, path, val)
    3.71 -        except SystemExit:
    3.72 -            raise
    3.73 -        except Exception, ex:
    3.74 -            pass
    3.75 -
    3.76 -class Watcher:
    3.77 -
    3.78 -    def __init__(self, store, path):
    3.79 -        self.path = path
    3.80 -        store.mkdirs(self.path)
    3.81 -        self.xs = None
    3.82 -        self.subscriptions = []
    3.83 -
    3.84 -    def fileno(self):
    3.85 -        if self.xs:
    3.86 -            return self.xs.fileno()
    3.87 -        else:
    3.88 -            return -1
    3.89 -
    3.90 -    def getPath(self):
    3.91 -        return self.path
    3.92 -
    3.93 -    def getToken(self):
    3.94 -        return self.path
    3.95 -
    3.96 -    def addSubs(self, subs):
    3.97 -        self.subscriptions.append(subs)
    3.98 -        self.watch()
    3.99 -
   3.100 -    def delSubs(self, subs):
   3.101 -        self.subscriptions.remove(subs)
   3.102 -        if len(self.subscriptions) == 0:
   3.103 -            self.unwatch()
   3.104 -
   3.105 -    def watch(self):
   3.106 -        if self.xs: return
   3.107 -        self.xs = xs.open()
   3.108 -        self.xs.watch(path=self.getPath(), token=self.getToken())
   3.109 -
   3.110 -    def unwatch(self):
   3.111 -        if self.xs:
   3.112 -## Possibly crashes xenstored.
   3.113 -##            try:
   3.114 -##                self.xs.unwatch(path=self.getPath(), token=self.getToken())
   3.115 -##            except Exception, ex:
   3.116 -##                print 'Watcher>unwatch>', ex
   3.117 -            try:
   3.118 -                self.xs.close()
   3.119 -            except Exception, ex:
   3.120 -                pass
   3.121 -            self.xs = None
   3.122 -            
   3.123 -    def watching(self):
   3.124 -        return self.xs is not None
   3.125 -
   3.126 -    def getNotification(self):
   3.127 -        p = self.xs.read_watch()
   3.128 -        self.xs.acknowledge_watch(p[1])
   3.129 -        return p
   3.130 -
   3.131 -    def notify(self):
   3.132 -        try:
   3.133 -            (path, token) = self.getNotification()
   3.134 -            if path.endswith("@eid"):
   3.135 -                pass
   3.136 -            else:
   3.137 -                val = self.xs.read(path)
   3.138 -                for subs in self.subscriptions:
   3.139 -                    subs.notify(token, path, val)
   3.140 -        except SystemExit:
   3.141 -            raise
   3.142 -        except Exception, ex:
   3.143 -            raise
   3.144 -
   3.145 -class EventWatcher(Watcher):
   3.146 -
   3.147 -    def __init__(self, store, path, event):
   3.148 -        Watcher.__init__(self, store, path)
   3.149 -        self.event = event
   3.150 -        self.eidPath = getEventIdPath(event)
   3.151 -        if not store.exists(self.eidPath):
   3.152 -            store.write(self.eidPath, str(0))
   3.153 -
   3.154 -    def getEvent(self):
   3.155 -        return self.event
   3.156 -
   3.157 -    def getToken(self):
   3.158 -        return self.event
   3.159 -
   3.160 -class XenStore:
   3.161 -
   3.162 -    xs = None
   3.163 -    watchThread = None
   3.164 -    subscription_id = 1
   3.165 -    
   3.166 -    def __init__(self):
   3.167 -        self.subscriptions = {}
   3.168 -        self.watchers = {}
   3.169 -        self.write("/", "")
   3.170 -
   3.171 -    def getxs(self):
   3.172 -        if self.xs is None:
   3.173 -            ex = None
   3.174 -            for i in range(0,20):
   3.175 -                try:
   3.176 -                    self.xs = xs.open()
   3.177 -                    ex = None
   3.178 -                    break
   3.179 -                except SystemExit:
   3.180 -                    raise
   3.181 -                except Exception, ex:
   3.182 -                    print >>sys.stderr, "Exception connecting to xenstored:", ex
   3.183 -                    print >>sys.stderr, "Trying again..."
   3.184 -                    time.sleep(1)
   3.185 -            else:
   3.186 -                raise ex
   3.187 -            
   3.188 -        #todo would like to reconnect if xs conn closes (e.g. daemon restart).
   3.189 -        return self.xs
   3.190 -
   3.191 -    def dump(self, path="/", out=sys.stdout):
   3.192 -        print 'dump>', path
   3.193 -        val = ['node']
   3.194 -        val.append(['path',  path])
   3.195 -##         perms = ['perms']
   3.196 -##         for p in self.getPerms(path):
   3.197 -##             l = ['perm']
   3.198 -##             l.append('dom', p.get['dom'])
   3.199 -##             for k in ['read', 'write', 'create', 'owner']:
   3.200 -##                 v = p.get(k)
   3.201 -##                 l.append([k, v])
   3.202 -##             perms.append(l)
   3.203 -##         val.append(perms)
   3.204 -        data = self.read(path)
   3.205 -        if data:
   3.206 -            val.append(['data',  data])
   3.207 -        children = ['children']
   3.208 -        for x in self.lsPaths(path):
   3.209 -            print 'dump>', 'child=', x
   3.210 -            children.append(self.dump(x))
   3.211 -        if len(children) > 1:
   3.212 -            val.append(children)
   3.213 -        prettyprint(val, out=out)
   3.214 -        return val
   3.215 -
   3.216 -    def getPerms(self, path):
   3.217 -        return self.getxs().get_permissions(path)
   3.218 -
   3.219 -    def ls(self, path="/"):
   3.220 -        return self.getxs().ls(path)
   3.221 -
   3.222 -    def lsPaths(self, path="/"):
   3.223 -        return [ os.path.join(path, x) for x in self.ls(path) ]
   3.224 -
   3.225 -    def lsr(self, path="/", list=None):
   3.226 -        if list is None:
   3.227 -            list = []
   3.228 -        list.append(path)
   3.229 -        for x in self.lsPaths(path):
   3.230 -            list.append(x)
   3.231 -            self.lsr(x, list=list)
   3.232 -        return list
   3.233 -
   3.234 -    def rm(self, path):
   3.235 -        try:
   3.236 -            #for x in self.lsPaths():
   3.237 -            #    self.getxs().rm(x)
   3.238 -            self.getxs().rm(path)
   3.239 -        except:
   3.240 -            pass
   3.241 -
   3.242 -    def exists(self, path):
   3.243 -        try:
   3.244 -            self.getxs().ls(path)
   3.245 -            return True
   3.246 -        except RuntimeError, ex:
   3.247 -            if ex.args[0] == errno.ENOENT:
   3.248 -                return False
   3.249 -            else:
   3.250 -                raise RuntimeError(ex.args[0],
   3.251 -                                   ex.args[1] +
   3.252 -                                   (', in exists(%s)' % (str(path))))
   3.253 -
   3.254 -    def mkdirs(self, path):
   3.255 -        if self.exists(path):
   3.256 -            return
   3.257 -        elts = path.split("/")
   3.258 -        p = "/"
   3.259 -        for x in elts:
   3.260 -            if x == "": continue
   3.261 -            p = os.path.join(p, x)
   3.262 -            if not self.exists(p):
   3.263 -                self.getxs().write(p, "")
   3.264 -
   3.265 -    def read(self, path):
   3.266 -        try:
   3.267 -            return self.getxs().read(path)
   3.268 -        except RuntimeError, ex:
   3.269 -            if ex.args[0] == errno.EISDIR:
   3.270 -                return None
   3.271 -            else:
   3.272 -                raise
   3.273 -
   3.274 -    def create(self, path):
   3.275 -        self.write(path, "")
   3.276 -
   3.277 -    def write(self, path, data):
   3.278 -        try:
   3.279 -            self.getxs().write(path, data)
   3.280 -        except RuntimeError, ex:
   3.281 -            raise RuntimeError(ex.args[0],
   3.282 -                               ex.args[1] +
   3.283 -                               (', while writing %s : %s' % (str(path),
   3.284 -                                                             str(data))))
   3.285 -
   3.286 -    def begin(self):
   3.287 -        self.getxs().transaction_start()
   3.288 -
   3.289 -    def commit(self, abandon=False):
   3.290 -        self.getxs().transaction_end(abort=abandon)
   3.291 -
   3.292 -    def watch(self, path, fn):
   3.293 -        watcher = self.watchers.get(path)
   3.294 -        if not watcher:
   3.295 -            watcher = self.addWatcher(Watcher(self, path))
   3.296 -        return self.addSubscription(watcher, fn)
   3.297 -        
   3.298 -    def unwatch(self, sid):
   3.299 -        s = self.subscriptions.get(sid)
   3.300 -        if not s: return
   3.301 -        del self.subscriptions[s.sid]
   3.302 -        watcher = s.unwatch()
   3.303 -        if watcher and not watcher.watching():
   3.304 -            try:
   3.305 -                del self.watchers[watcher.getPath()]
   3.306 -            except:
   3.307 -                pass
   3.308 -
   3.309 -    def subscribe(self, event, fn):
   3.310 -        path = getEventPath(event)
   3.311 -        watcher = self.watchers.get(path)
   3.312 -        if not watcher:
   3.313 -            watcher = self.addWatcher(EventWatcher(self, path, event))
   3.314 -        return self.addSubscription(watcher, fn)
   3.315 -
   3.316 -    unsubscribe = unwatch
   3.317 -
   3.318 -    def sendEvent(self, event, data):
   3.319 -        eventPath = getEventPath(event)
   3.320 -        eidPath = getEventIdPath(event)
   3.321 -        try:
   3.322 -            #self.begin(eventPath)
   3.323 -            self.mkdirs(eventPath)
   3.324 -            eid = 1
   3.325 -            if self.exists(eidPath):
   3.326 -                try:
   3.327 -                    eid = int(self.read(eidPath))
   3.328 -                    eid += 1
   3.329 -                except Exception, ex:
   3.330 -                    pass
   3.331 -            self.write(eidPath, str(eid))
   3.332 -            self.write(os.path.join(eventPath, str(eid)), data)
   3.333 -        finally:
   3.334 -            #self.commit()
   3.335 -            pass
   3.336 -
   3.337 -    def addWatcher(self, watcher):
   3.338 -        self.watchers[watcher.getPath()] = watcher
   3.339 -        self.watchStart()
   3.340 -        return watcher
   3.341 -
   3.342 -    def addSubscription(self, watcher, fn):
   3.343 -        self.subscription_id += 1
   3.344 -        subs = Subscription(watcher.getPath(), fn, self.subscription_id)
   3.345 -        self.subscriptions[subs.sid] = subs
   3.346 -        subs.watch(watcher)
   3.347 -        return subs.sid
   3.348 -
   3.349 -    def watchStart(self):
   3.350 -        if self.watchThread: return
   3.351 -        self.watchThread = threading.Thread(name="Watcher",
   3.352 -                                            target=self.watchMain)
   3.353 -        self.watchThread.setDaemon(True)
   3.354 -        self.watchThread.start()
   3.355 -        
   3.356 -    def watchMain(self):
   3.357 -        try:
   3.358 -            while True:
   3.359 -                if self.watchThread is None: return
   3.360 -                if not self.watchers:
   3.361 -                    return
   3.362 -                rd = self.watchers.values()
   3.363 -                try:
   3.364 -                    (srd, swr, ser) = select.select(rd, [], [], SELECT_TIMEOUT)
   3.365 -                    for watcher in srd:
   3.366 -                        watcher.notify()
   3.367 -                except socket.error, ex:
   3.368 -                    if ex.args[0] in (EAGAIN, EINTR):
   3.369 -                        pass
   3.370 -                    else:
   3.371 -                        raise
   3.372 -        finally:
   3.373 -            self.watchThread = None
   3.374 -
   3.375 -def getXenStore():
   3.376 -    global xenstore
   3.377 -    try:
   3.378 -        return xenstore
   3.379 -    except:
   3.380 -        xenstore = XenStore()
   3.381 -        return xenstore
   3.382 -
   3.383 -def sendEvent(event, val):
   3.384 -    getXenStore.sendEvent(event, val)
   3.385 -
   3.386 -def subscribe(event, fn):
   3.387 -    return getXenStore().subscribe(event, fn)
   3.388 -
   3.389 -def unsubscribe(sid):
   3.390 -    getXenStore().unsubscribe(sid)
   3.391 -
   3.392 -class XenNode:
   3.393 -
   3.394 -    def __init__(self, path="/", create=True):
   3.395 -        self.store = getXenStore()
   3.396 -        self.path = path
   3.397 -        if not self.store.exists(path):
   3.398 -            if create:
   3.399 -                self.store.create(path)
   3.400 -            else:
   3.401 -                raise ValueError("path does not exist: '%s'" % path)
   3.402 -
   3.403 -    def getStore(self):
   3.404 -        return self.store
   3.405 -
   3.406 -    def relPath(self, path=""):
   3.407 -        if not path:
   3.408 -            return self.path
   3.409 -        if path and path.startswith("/"):
   3.410 -            path = path[1:]
   3.411 -        return os.path.join(self.path, path)
   3.412 -
   3.413 -    def delete(self, path=""):
   3.414 -        self.store.rm(self.relPath(path))
   3.415 -
   3.416 -    def exists(self, path=""):
   3.417 -        return self.store.exists(self.relPath(path))
   3.418 -
   3.419 -    def getNode(self, path="", create=True):
   3.420 -        if path == "":
   3.421 -            return self
   3.422 -        else:
   3.423 -            return XenNode(self.relPath(path=path), create=create)
   3.424 -
   3.425 -    getChild = getNode
   3.426 -
   3.427 -    def getData(self, path=""):
   3.428 -        path = self.relPath(path)
   3.429 -        try:
   3.430 -            return self.store.read(path)
   3.431 -        except:
   3.432 -            return None
   3.433 -
   3.434 -    def setData(self, data, path=""):
   3.435 -        return self.store.write(self.relPath(path), data)
   3.436 -
   3.437 -    def getLock(self):
   3.438 -        return None
   3.439 -
   3.440 -    def lock(self, lockid):
   3.441 -        return None
   3.442 -
   3.443 -    def unlock(self, lockid):
   3.444 -        return None
   3.445 -
   3.446 -    def deleteChild(self, name):
   3.447 -        self.delete(name)
   3.448 -
   3.449 -    def deleteChildren(self):
   3.450 -        for name in self.ls():
   3.451 -            self.deleteChild(name)
   3.452 -
   3.453 -    def getChildren(self):
   3.454 -        return [ self.getNode(name) for name in self.ls() ]
   3.455 -
   3.456 -    def ls(self):
   3.457 -        return self.store.ls(self.path)
   3.458 -
   3.459 -    def watch(self, fn, path=""):
   3.460 -        """Watch a path for changes. The path is relative
   3.461 -        to the node and defaults to the node itself.
   3.462 -        """
   3.463 -        return self.store.watch(self.relPath(path), fn)
   3.464 -
   3.465 -    def unwatch(self, sid):
   3.466 -        return self.store.unwatch(sid)
   3.467 -
   3.468 -    def subscribe(self, event, fn):
   3.469 -        return self.store.subscribe(event, fn)
   3.470 -
   3.471 -    def unsubscribe(self, sid):
   3.472 -        self.store.unsubscribe(sid)
   3.473 -
   3.474 -    def sendEvent(self, event, data):
   3.475 -        return self.store.sendEvent(event, data)
   3.476 -
   3.477 -    def __repr__(self):
   3.478 -        return "<XenNode %s>" % self.path
   3.479 -
   3.480 -
     4.1 --- a/tools/python/xen/xend/xenstore/xsobj.py	Sun Oct 02 18:21:01 2005 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,537 +0,0 @@
     4.4 -#============================================================================
     4.5 -# This library is free software; you can redistribute it and/or
     4.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
     4.7 -# License as published by the Free Software Foundation.
     4.8 -#
     4.9 -# This library is distributed in the hope that it will be useful,
    4.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.12 -# Lesser General Public License for more details.
    4.13 -#
    4.14 -# You should have received a copy of the GNU Lesser General Public
    4.15 -# License along with this library; if not, write to the Free Software
    4.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.17 -#============================================================================
    4.18 -# Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    4.19 -#============================================================================
    4.20 -import string
    4.21 -import types
    4.22 -
    4.23 -from xen.xend.XendLogging import log
    4.24 -
    4.25 -from xen.xend import sxp
    4.26 -from xsnode import XenNode
    4.27 -from xen.util.mac import macToString, macFromString
    4.28 -
    4.29 -VALID_KEY_CHARS = string.ascii_letters + string.digits + "_-@"
    4.30 -
    4.31 -def hasAttr(obj, attr):
    4.32 -    if isinstance(obj, dict):
    4.33 -        return obj.contains(attr)
    4.34 -    else:
    4.35 -        return hasattr(obj, attr)
    4.36 -
    4.37 -def getAttr(obj, attr):
    4.38 -    try:
    4.39 -        if isinstance(obj, dict):
    4.40 -            return obj.get(attr)
    4.41 -        else:
    4.42 -            return getattr(obj, attr, None)
    4.43 -    except AttributeError:
    4.44 -        return None
    4.45 -    except LookupError:
    4.46 -        return None
    4.47 -
    4.48 -def setAttr(obj, attr, val):
    4.49 -    if isinstance(obj, dict):
    4.50 -        obj[attr] = val
    4.51 -    else:
    4.52 -        setattr(obj, attr, val)
    4.53 -
    4.54 -class DBConverter:
    4.55 -    """Conversion of values to and from strings in xenstore.
    4.56 -    """
    4.57 -
    4.58 -    converters = {}
    4.59 -
    4.60 -    def checkType(cls, ty):
    4.61 -        if ty is None or ty in cls.converters:
    4.62 -            return
    4.63 -        raise ValueError("invalid converter type: '%s'" % ty)
    4.64 -
    4.65 -    checkType = classmethod(checkType)
    4.66 -    
    4.67 -    def getConverter(cls, ty=None):
    4.68 -        if ty is None:
    4.69 -            ty = "str"
    4.70 -        conv = cls.converters.get(ty)
    4.71 -        if not conv:
    4.72 -            raise ValueError("no converter for type: '%s'" % ty)
    4.73 -        return conv
    4.74 -
    4.75 -    getConverter = classmethod(getConverter)
    4.76 -
    4.77 -    def exportTypeToDB(cls, db, path, val, ty=None):
    4.78 -        return cls.getConverter(ty).exportToDB(db, path, val)
    4.79 -
    4.80 -    exportTypeToDB = classmethod(exportTypeToDB)
    4.81 -
    4.82 -    def importTypeFromDB(cls, db, path, ty=None):
    4.83 -        return cls.getConverter(ty).importFromDB(db, path)
    4.84 -
    4.85 -    importTypeFromDB = classmethod(importTypeFromDB)
    4.86 -
    4.87 -    # Must define in subclass.
    4.88 -    name = None
    4.89 -
    4.90 -    def __init__(self):
    4.91 -        self.register()
    4.92 -    
    4.93 -    def register(self):
    4.94 -        if not self.name:
    4.95 -            raise ValueError("invalid converter name: '%s'" % self.name)
    4.96 -        self.converters[self.name] = self
    4.97 -
    4.98 -    def exportToDB(self, db, path, val):
    4.99 -        if val is None:
   4.100 -            return
   4.101 -        try:
   4.102 -            data = self.toDB(val)
   4.103 -        except Exception, ex:
   4.104 -            raise
   4.105 -        setattr(db, path, data)
   4.106 -
   4.107 -    def importFromDB(self, db, path):
   4.108 -        data = getAttr(db, path)
   4.109 -        if data is None:
   4.110 -            val = None
   4.111 -        else:
   4.112 -            try:
   4.113 -                val = self.fromDB(data.getData())
   4.114 -            except Exception, ex:
   4.115 -                raise
   4.116 -        return val
   4.117 -        
   4.118 -    def toDB(self, val):
   4.119 -        raise NotImplementedError()
   4.120 -
   4.121 -    def fromDB(self, val):
   4.122 -        raise NotImplementedError()
   4.123 -
   4.124 -class StrConverter(DBConverter):
   4.125 -
   4.126 -    name = "str"
   4.127 -    
   4.128 -    def toDB(self, val):
   4.129 -        # Convert True/False to 1/0, otherwise they convert to
   4.130 -        # 'True' and 'False' rather than '1' and '0', even though
   4.131 -        # isinstance(True/False, int) is true.
   4.132 -        if isinstance(val, bool):
   4.133 -            val = int(val)
   4.134 -        return str(val)
   4.135 -
   4.136 -    def fromDB(self, data):
   4.137 -        return data
   4.138 -
   4.139 -StrConverter()
   4.140 -    
   4.141 -class BoolConverter(DBConverter):
   4.142 -
   4.143 -    name = "bool"
   4.144 -
   4.145 -    def toDB(self, val):
   4.146 -        return str(int(bool(val)))
   4.147 -
   4.148 -    def fromDB(self, data):
   4.149 -        return bool(int(data))
   4.150 -
   4.151 -BoolConverter()
   4.152 -
   4.153 -class SxprConverter(DBConverter):
   4.154 -
   4.155 -    name = "sxpr"
   4.156 -    
   4.157 -    def toDB(self, val):
   4.158 -        return sxp.to_string(val)
   4.159 -
   4.160 -    def fromDB(self, data):
   4.161 -        return sxp.from_string(data)
   4.162 -    
   4.163 -SxprConverter()
   4.164 -
   4.165 -class IntConverter(DBConverter):
   4.166 -
   4.167 -    name = "int"
   4.168 -    
   4.169 -    def toDB(self, val):
   4.170 -        return str(int(val))
   4.171 -
   4.172 -    def fromDB(self, data):
   4.173 -        return int(data)
   4.174 -    
   4.175 -IntConverter()
   4.176 -    
   4.177 -class FloatConverter(DBConverter):
   4.178 -
   4.179 -    name = "float"
   4.180 -    
   4.181 -    def toDB(self, val):
   4.182 -        return str(float(val))
   4.183 -
   4.184 -    def fromDB(self, data):
   4.185 -        return float(data)
   4.186 -    
   4.187 -FloatConverter()
   4.188 -    
   4.189 -class LongConverter(DBConverter):
   4.190 -
   4.191 -    name = "long"
   4.192 -    
   4.193 -    def toDB(self, val):
   4.194 -        return str(long(val))
   4.195 -
   4.196 -    def fromDB(self, data):
   4.197 -        return long(data)
   4.198 -    
   4.199 -LongConverter()
   4.200 -
   4.201 -class MacConverter(DBConverter):
   4.202 -
   4.203 -    name = "mac"
   4.204 -    
   4.205 -    def toDB(self, val):
   4.206 -        return macToString(val)
   4.207 -
   4.208 -    def fromDB(self, data):
   4.209 -        return macFromString(data)
   4.210 -    
   4.211 -MacConverter()
   4.212 -
   4.213 -class DBVar:
   4.214 -
   4.215 -    def __init__(self, var, ty=None, path=None):
   4.216 -        DBConverter.checkType(ty)
   4.217 -        if path is None:
   4.218 -            path = var
   4.219 -        self.var = var
   4.220 -        self.ty = ty
   4.221 -        self.path = path
   4.222 -        varpath = filter(bool, self.var.split())
   4.223 -        self.attrpath = varpath[:-1]
   4.224 -        self.attr = varpath[-1]
   4.225 -
   4.226 -    def exportToDB(self, db, obj):
   4.227 -        val = self.getObj(obj)
   4.228 -        DBConverter.exportTypeToDB(db, self.path, val, ty=self.ty)
   4.229 -
   4.230 -    def importFromDB(self, db, obj):
   4.231 -        val = DBConverter.importTypeFromDB(db, self.path, ty=self.ty)
   4.232 -        self.setObj(obj, val)
   4.233 -
   4.234 -    def getObj(self, obj):
   4.235 -        o = obj
   4.236 -        for x in self.attrpath:
   4.237 -            o = getAttr(o, x)
   4.238 -            if o is None:
   4.239 -                return None
   4.240 -        return getAttr(o, self.attr)
   4.241 -
   4.242 -    def setObj(self, obj, val):
   4.243 -        o = obj
   4.244 -        for x in self.attrpath:
   4.245 -            o = getAttr(o, x)
   4.246 -        # Don't set obj attr if val is None.
   4.247 -        if val is None and hasAttr(o, self.attr):
   4.248 -            return
   4.249 -        setAttr(o, self.attr, val)
   4.250 -
   4.251 -class DBMap(dict):
   4.252 -    """A persistent map. Extends dict with persistence.
   4.253 -    Set and get values using the usual map syntax:
   4.254 -
   4.255 -    m[k],     m.get(k)
   4.256 -    m[k] = v
   4.257 -
   4.258 -    Also supports being treated as an object with attributes.
   4.259 -    When 'k' is a legal identifier you may also use
   4.260 -
   4.261 -    m.k,     getattr(m, k)
   4.262 -    m.k = v, setattr(m, k)
   4.263 -    k in m,  hasattr(m, k)
   4.264 -
   4.265 -    When setting you can pass in a normal value, for example
   4.266 -
   4.267 -    m.x = 3
   4.268 -
   4.269 -    Getting works too:
   4.270 -
   4.271 -    m.x ==> 3
   4.272 -
   4.273 -    while m['x'] will return the map for x.
   4.274 -
   4.275 -    m['x'].getData() ==> 3
   4.276 -    
   4.277 -    To get values from subdirs use get() to get the subdir first:
   4.278 -
   4.279 -    get(m, 'foo').x
   4.280 -    m['foo'].x
   4.281 -
   4.282 -    instead of m.foo.x, because m.foo will return the data for field foo,
   4.283 -    not the directory.
   4.284 -
   4.285 -    You can assign values into a subdir by passing a map:
   4.286 -
   4.287 -    m.foo = {'x': 1, 'y':2 }
   4.288 -
   4.289 -    You can also use paths as keys:
   4.290 -
   4.291 -    m['foo/x'] = 1
   4.292 -
   4.293 -    sets field x in subdir foo.
   4.294 -    
   4.295 -    """
   4.296 -
   4.297 -    __db__          = None
   4.298 -    __data__        = None
   4.299 -    __perms__       = None
   4.300 -    __parent__      = None
   4.301 -    __name__        = ""
   4.302 -
   4.303 -    __transaction__ = False
   4.304 -
   4.305 -    # True if value set since saved (or never saved).
   4.306 -    __dirty__       = True
   4.307 -
   4.308 -    def __init__(self, parent=None, name="", db=None):
   4.309 -        if parent is None:
   4.310 -            self.__name__ = name
   4.311 -        else:
   4.312 -            if not isinstance(parent, DBMap):
   4.313 -                raise ValueError("invalid parent")
   4.314 -            self.__parent__ = parent
   4.315 -            self.__name__ = name
   4.316 -            db = self.__parent__.getChildDB(name)
   4.317 -        self.setDB(db)
   4.318 -
   4.319 -    def getName(self):
   4.320 -        return self.__name__
   4.321 -
   4.322 -    def getPath(self):
   4.323 -        return self.__db__ and self.__db__.relPath()
   4.324 -
   4.325 -    def watch(self, fn, path=""):
   4.326 -        return self.__db__.watch(fn, path=path)
   4.327 -
   4.328 -    def unwatch(self, sid):
   4.329 -        return self.__db__.unwatch(sid)
   4.330 -
   4.331 -    def subscribe(self, event, fn):
   4.332 -        return self.__db__.subscribe(event, fn)
   4.333 -
   4.334 -    def unsubscribe(self, sid):
   4.335 -        return self.__db__.unsubscribe(sid)
   4.336 -
   4.337 -    def sendEvent(self, event, val):
   4.338 -        return self.__db__.sendEvent(event, val)
   4.339 -        
   4.340 -    def transactionBegin(self):
   4.341 -        # Begin a transaction.
   4.342 -        pass
   4.343 -
   4.344 -    def transactionCommit(self):
   4.345 -        # Commit writes to db.
   4.346 -        pass
   4.347 -
   4.348 -    def transactionFail(self):
   4.349 -        # Fail a transaction.
   4.350 -        # We have changed values, what do we do?
   4.351 -        pass
   4.352 -
   4.353 -    def checkName(self, k):
   4.354 -        if k == "":
   4.355 -            raise ValueError("invalid key, empty string")
   4.356 -        for c in k:
   4.357 -            if c in VALID_KEY_CHARS: continue
   4.358 -            raise ValueError("invalid key char '%s'" % c)
   4.359 -
   4.360 -    def _setData(self, v):
   4.361 -        #print 'DBMap>_setData>', self.getPath(), 'data=', v
   4.362 -        if v != self.__data__:
   4.363 -            self.__dirty__ = True
   4.364 -        self.__data__ = v
   4.365 -
   4.366 -    def setData(self, v):
   4.367 -        if isinstance(v, dict):
   4.368 -            for (key, val) in v.items():
   4.369 -                self[key] = val
   4.370 -        else:
   4.371 -            self._setData(v)
   4.372 -
   4.373 -    def getData(self):
   4.374 -        return self.__data__
   4.375 -
   4.376 -    def _set(self, k, v):
   4.377 -        dict.__setitem__(self, k, v)
   4.378 -
   4.379 -    def _get(self, k):
   4.380 -        try:
   4.381 -            return dict.__getitem__(self, k)
   4.382 -        except:
   4.383 -            return None
   4.384 -
   4.385 -    def _del(self, k, v):
   4.386 -        try:
   4.387 -            dict.__delitem__(self, k)
   4.388 -        except:
   4.389 -            pass
   4.390 -
   4.391 -    def _contains(self, k):
   4.392 -        return dict.__contains__(self, k)
   4.393 -        
   4.394 -    def __setitem__(self, k, v, save=False):
   4.395 -        node = self.addChild(k)
   4.396 -        node.setData(v)
   4.397 -        if save:
   4.398 -            node.saveDB()
   4.399 -
   4.400 -    def __getitem__(self, k):
   4.401 -        if self._contains(k):
   4.402 -            v = self._get(k)
   4.403 -        else:
   4.404 -            v = self.readChildDB(k)
   4.405 -            self._set(k, v)
   4.406 -        return v
   4.407 -
   4.408 -    def __delitem__(self, k):
   4.409 -        self._del(k)
   4.410 -        self.deleteChildDB(k)
   4.411 -
   4.412 -    def __repr__(self):
   4.413 -        if len(self):
   4.414 -            return dict.__repr__(self)
   4.415 -        else:
   4.416 -            return repr(self.__data__)
   4.417 -
   4.418 -    def __setattr__(self, k, v):
   4.419 -        if k.startswith("__"):
   4.420 -            object.__setattr__(self, k, v)
   4.421 -        else:
   4.422 -            self.__setitem__(k, v, save=True)
   4.423 -        return v
   4.424 -    
   4.425 -    def __getattr__(self, k):
   4.426 -        if k.startswith("__"):
   4.427 -            v = object.__getattr__(self, k)
   4.428 -        else:
   4.429 -            try:
   4.430 -                v = self.__getitem__(k).getData()
   4.431 -            except LookupError, ex:
   4.432 -                raise AttributeError(ex.args)
   4.433 -        return v
   4.434 -
   4.435 -    def __delattr__(self, k):
   4.436 -        return self.__delitem__(k)
   4.437 -
   4.438 -    def delete(self):
   4.439 -        dict.clear(self)
   4.440 -        self.__data__ = None
   4.441 -        if self.__db__:
   4.442 -            self.__db__.delete()
   4.443 -
   4.444 -    def clear(self):
   4.445 -        dict.clear(self)
   4.446 -        if self.__db__:
   4.447 -            self.__db__.deleteChildren()
   4.448 -
   4.449 -    def getChild(self, k):
   4.450 -        return self._get(k)
   4.451 -
   4.452 -    def getChildDB(self, k):
   4.453 -        self.checkName(k)
   4.454 -        return self.__db__ and self.__db__.getChild(k)
   4.455 -
   4.456 -    def deleteChildDB(self, k):
   4.457 -        if self.__db__:
   4.458 -            self.__db__.deleteChild(k)
   4.459 -
   4.460 -    def _addChild(self, k):
   4.461 -        kid = self._get(k)
   4.462 -        if kid is None:
   4.463 -            kid = DBMap(parent=self, name=k, db=self.getChildDB(k))
   4.464 -            self._set(k, kid)
   4.465 -        return kid
   4.466 -
   4.467 -    def addChild(self, path):
   4.468 -        l = path.split("/")
   4.469 -        n = self
   4.470 -        for x in l:
   4.471 -            if x == "": continue
   4.472 -            n = n._addChild(x)
   4.473 -        return n
   4.474 -
   4.475 -    def setDB(self, db):
   4.476 -        if (db is not None) and not isinstance(db, XenNode):
   4.477 -            raise ValueError("invalid db")
   4.478 -        self.__db__ = db
   4.479 -        for (k, v) in self.items():
   4.480 -            if v is None: continue
   4.481 -            if isinstance(v, DBMap):
   4.482 -                v._setDB(self.addChild(k), restore)
   4.483 -
   4.484 -    def readDB(self):
   4.485 -        if self.__db__ is None:
   4.486 -            return
   4.487 -        self.__data__ = self.__db__.getData()
   4.488 -        l = self.__db__.ls()
   4.489 -        if l:
   4.490 -            for k in l:
   4.491 -                n = self.addChild(k)
   4.492 -                n.readDB()
   4.493 -        self.__dirty__ = False
   4.494 -
   4.495 -    def readChildDB(self, k):
   4.496 -        if self.__db__ and (k in self.__db__.ls()):
   4.497 -            n = self.addChild(k)
   4.498 -            n.readDB()
   4.499 -        raise LookupError("invalid key '%s'" % k)
   4.500 -
   4.501 -    def saveDB(self, sync=False, save=False):
   4.502 -        """Save unsaved data to db.
   4.503 -        If save or sync is true, saves whether dirty or not.
   4.504 -        If sync is true, removes db entries not in the map.
   4.505 -        """
   4.506 -        
   4.507 -        if self.__db__ is None:
   4.508 -            #print 'DBMap>saveDB>',self.getPath(), 'no db'
   4.509 -            return
   4.510 -        # Write data.
   4.511 -        #print 'DBMap>saveDB>', self.getPath(), 'dirty=', self.__dirty__, 'data=', self.__data__
   4.512 -        if ((self.__data__ is not None)
   4.513 -            and (sync or save or self.__dirty__)):
   4.514 -            self.__db__.setData(self.__data__)
   4.515 -            self.__dirty__ = False
   4.516 -        else:
   4.517 -            #print 'DBMap>saveDB>', self.getPath(), 'not written'
   4.518 -            pass
   4.519 -        # Write children.
   4.520 -        for (name, node) in self.items():
   4.521 -            if not isinstance(node, DBMap): continue
   4.522 -            node.saveDB(sync=sync, save=save)
   4.523 -        # Remove db nodes not in children.
   4.524 -        ###if sync:
   4.525 -        ###    for name in self.__db__.ls():
   4.526 -        ###        if name not in self:
   4.527 -        ###            self.__db__.delete(name)
   4.528 -
   4.529 -    def importFromDB(self, obj, fields):
   4.530 -        """Set fields in obj from db fields.
   4.531 -        """
   4.532 -        for f in fields:
   4.533 -            f.importFromDB(self, obj)
   4.534 -
   4.535 -    def exportToDB(self, obj, fields, save=False, sync=False):
   4.536 -        """Set fields in db from obj fields.
   4.537 -        """
   4.538 -        for f in fields:
   4.539 -            f.exportToDB(self, obj)
   4.540 -        self.saveDB(save=save, sync=sync)
     5.1 --- a/tools/python/xen/xend/xenstore/xsresource.py	Sun Oct 02 18:21:01 2005 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,149 +0,0 @@
     5.4 -#============================================================================
     5.5 -# This library is free software; you can redistribute it and/or
     5.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
     5.7 -# License as published by the Free Software Foundation.
     5.8 -#
     5.9 -# This library is distributed in the hope that it will be useful,
    5.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.12 -# Lesser General Public License for more details.
    5.13 -#
    5.14 -# You should have received a copy of the GNU Lesser General Public
    5.15 -# License along with this library; if not, write to the Free Software
    5.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.17 -#============================================================================
    5.18 -# Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    5.19 -#============================================================================
    5.20 -# HTTP interface onto xenstore (read-only).
    5.21 -# Mainly intended for testing.
    5.22 -
    5.23 -import os
    5.24 -import os.path
    5.25 -
    5.26 -from xen.web.httpserver import HttpServer, UnixHttpServer
    5.27 -from xen.web.SrvBase import SrvBase
    5.28 -from xen.web.SrvDir import SrvDir
    5.29 -from xen.xend.Args import FormFn
    5.30 -from xen.xend.xenstore import XenNode
    5.31 -
    5.32 -def pathurl(req):
    5.33 -    url = req.prePathURL()
    5.34 -    if not url.endswith('/'):
    5.35 -        url += '/'
    5.36 -    return url
    5.37 -    
    5.38 -def writelist(req, l):
    5.39 -    req.write('(')
    5.40 -    for k in l:
    5.41 -       req.write(' ' + k)
    5.42 -    req.write(')')
    5.43 -
    5.44 -def lsData(dbnode, req, url):
    5.45 -    v = dbnode.getData()
    5.46 -    if v is None:
    5.47 -        req.write('<p>No data')
    5.48 -    else:
    5.49 -        req.write('<p>Data: <pre>')
    5.50 -        req.write(str(v))
    5.51 -        req.write('</pre>')
    5.52 -    v = dbnode.getLock()
    5.53 -    if v is None:
    5.54 -        req.write("<p>Unlocked")
    5.55 -    else:
    5.56 -        req.write("<p>Lock = %s" % v)
    5.57 -
    5.58 -def lsChildren(dbnode, req, url):
    5.59 -    l = dbnode.ls()
    5.60 -    if l:
    5.61 -        req.write('<p>Children: <ul>')
    5.62 -        for key in l:
    5.63 -            child = dbnode.getChild(key)
    5.64 -            data = child.getData()
    5.65 -            if data is None: data = ""
    5.66 -            req.write('<li><a href="%(url)s%(key)s">%(key)s</a> %(data)s</li>'
    5.67 -                      % { "url": url, "key": key, "data": data })
    5.68 -        req.write('</ul>')
    5.69 -    else:
    5.70 -        req.write('<p>No children')
    5.71 -        
    5.72 -
    5.73 -class DBDataResource(SrvBase):
    5.74 -    """Resource for the node data.
    5.75 -    """
    5.76 -
    5.77 -    def __init__(self, dbnode):
    5.78 -        SrvBase.__init__(self)
    5.79 -        self.dbnode = dbnode
    5.80 -
    5.81 -    def render_GET(self, req):
    5.82 -        req.write('<html><head></head><body>')
    5.83 -        self.print_path(req)
    5.84 -        req.write("<pre>")
    5.85 -        req.write(self.getData() or self.getNoData())
    5.86 -        req.write("</pre>")
    5.87 -        req.write('</body></html>')
    5.88 -
    5.89 -    def getContentType(self):
    5.90 -        # Use content-type from metadata.
    5.91 -        return "text/plain"
    5.92 -
    5.93 -    def getData(self):
    5.94 -        v = self.dbnode.getData()
    5.95 -        if v is None: return v
    5.96 -        return str(v)
    5.97 -
    5.98 -    def getNoData(self):
    5.99 -        return ""
   5.100 -
   5.101 -class DBNodeResource(SrvDir):
   5.102 -    """Resource for a DB node.
   5.103 -    """
   5.104 -
   5.105 -    def __init__(self, dbnode):
   5.106 -        SrvDir.__init__(self)
   5.107 -        self.dbnode = dbnode
   5.108 -
   5.109 -    def get(self, x):
   5.110 -        val = None
   5.111 -        if x == "__data__":
   5.112 -            val = DBDataResource(self.dbnode)
   5.113 -        else:
   5.114 -            if self.dbnode.exists(x):
   5.115 -                child = self.dbnode.getChild(x, create=False)
   5.116 -            else:
   5.117 -                child = None
   5.118 -            if child is not None:
   5.119 -                val = DBNodeResource(child)
   5.120 -        return val
   5.121 -
   5.122 -    def render_POST(self, req):
   5.123 -        return self.perform(req)
   5.124 -
   5.125 -    def ls(self, req, use_sxp=0):
   5.126 -        if use_sxp:
   5.127 -            writelist(req, self.dbnode.getChildren())
   5.128 -        else:
   5.129 -            url = pathurl(req)
   5.130 -            req.write("<fieldset>")
   5.131 -            lsData(self.dbnode, req, url)
   5.132 -            lsChildren(self.dbnode, req, url)
   5.133 -            req.write("</fieldset>")
   5.134 -
   5.135 -    def form(self, req):
   5.136 -        url = req.prePathURL()
   5.137 -        pass
   5.138 -        
   5.139 -class DBRootResource(DBNodeResource):
   5.140 -    """Resource for the root of a DB.
   5.141 -    """
   5.142 -
   5.143 -    def __init__(self):
   5.144 -        DBNodeResource.__init__(self, XenNode())
   5.145 -
   5.146 -def main(argv):
   5.147 -    root = SrvDir()
   5.148 -    root.putChild('xenstore', DBRootResource())
   5.149 -    interface = ''
   5.150 -    port = 8003
   5.151 -    server = HttpServer(root=root, interface=interface, port=port)
   5.152 -    server.run()