bitkeeper revision 1.1713.3.6 (42b2dc47kgG53fAZb70R3lHX96n7dw)

xsobj.py:
  Handle attribute lookups for non-existing attributes.
  Use setAttr consistently.
  Fix access to data in convertFromDB.
console.py:
  Cleanup whitespace.
channel.py:
  Cleanup saveToDB.
blkif.py:
  Save dev_handle in DB.
image.py:
  Cleanup exportToDB.
XendDomainInfo.py:
  Cleanup {save,export}toDB use.
  Cleanup whitespace.
  Change id type to be int.
  Output store_mfn in sxpr.
  Use id variable name consistently for domain id's.
  Add eventChannel comment.
  On restore, the uuid must be known.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
cl349@firebug.cl.cam.ac.uk committed 2005-06-17 14:20:55 +00:00
1 parent 4ddc54b2db
commit 99a2107ffa
6 files changed
+64 -58

No files matched your search

+38 -39
View File
@@ -157,7 +157,7 @@ class XendDomainInfo:
db = parentdb.addChild(uuid)
vm = cls(db)
vm.construct(config)
vm.saveDB(sync=True)
vm.saveToDB(sync=True)
return vm
create = classmethod(create)
@@ -193,7 +193,7 @@ class XendDomainInfo:
recreate = classmethod(recreate)
def restore(cls, parentdb, config, uuid=None):
def restore(cls, parentdb, config, uuid):
"""Create a domain and a VM object to do a restore.
@param parentdb: parent db
@@ -202,16 +202,20 @@ class XendDomainInfo:
"""
db = parentdb.addChild(uuid)
vm = cls(db)
dom = xc.domain_create()
vm.setdom(dom)
vm.dom_construct(vm.id, config)
vm.saveDB(sync=True)
id = xc.domain_create()
vm.setdom(id)
try:
vm.restore = True
vm.construct(config)
finally:
vm.restore = False
vm.exportToDB(save=True, sync=True)
return vm
restore = classmethod(restore)
__exports__ = [
DBVar('id', ty='str'),
DBVar('id', ty='int'),
DBVar('name', ty='str'),
DBVar('uuid', ty='str'),
DBVar('config', ty='sxpr'),
@@ -267,14 +271,17 @@ class XendDomainInfo:
def setDB(self, db):
self.db = db
def saveDB(self, save=False, sync=False):
def saveToDB(self, save=False, sync=False):
self.db.saveDB(save=save, sync=sync)
def exportToDB(self, save=False, sync=False):
if self.channel:
self.channel.saveToDB(self.db.addChild("channel"))
self.channel.saveToDB(self.db.addChild("channel"), save=save)
if self.store_channel:
self.store_channel.saveToDB(self.db.addChild("store_channel"))
self.store_channel.saveToDB(self.db.addChild("store_channel"),
save=save)
if self.image:
self.image.exportToDB(save=save, sync=sync)
self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
def importFromDB(self):
@@ -316,7 +323,7 @@ class XendDomainInfo:
self.state = state
self.state_updated.notifyAll()
self.state_updated.release()
self.saveDB()
self.saveToDB()
def state_wait(self, state):
self.state_updated.acquire()
@@ -325,14 +332,14 @@ class XendDomainInfo:
self.state_updated.release()
def __str__(self):
s = "domain"
s = "<domain"
s += " id=" + str(self.id)
s += " name=" + self.name
s += " memory=" + str(self.memory)
console = self.getConsole()
if console:
s += " console=" + str(console.console_port)
s += ""
s += ">"
return s
__repr__ = __str__
@@ -422,15 +429,19 @@ class XendDomainInfo:
sxpr.append(self.channel.sxpr())
if self.store_channel:
sxpr.append(self.store_channel.sxpr())
if self.store_mfn:
sxpr.append(['store_mfn', self.store_mfn])
console = self.getConsole()
if console:
sxpr.append(console.sxpr())
if self.restart_count:
sxpr.append(['restart_count', self.restart_count])
if self.restart_state:
sxpr.append(['restart_state', self.restart_state])
if self.restart_time:
sxpr.append(['restart_time', str(self.restart_time)])
devs = self.sxpr_devices()
if devs:
sxpr.append(devs)
@@ -546,7 +557,7 @@ class XendDomainInfo:
"""
self.create_channel()
self.image.createImage()
self.image.exportToDB()
self.exportToDB()
#if self.store_channel:
# self.db.introduceDomain(self.id,
# self.store_mfn,
@@ -558,7 +569,7 @@ class XendDomainInfo:
if self.dom_get(self.id):
return
self.id = None
self.saveDB(sync=True)
self.saveToDB(sync=True)
try:
# Todo: eventually will have to wait for devices to signal
# destruction before can delete the db.
@@ -614,7 +625,7 @@ class XendDomainInfo:
"""
self.cleanup()
self.destroy_domain()
self.saveDB()
self.saveToDB()
return 0
def is_terminated(self):
@@ -649,14 +660,13 @@ class XendDomainInfo:
cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
except:
raise VmError('invalid cpu')
dom = self.image.initDomain(self.id, self.memory, cpu, self.cpu_weight)
id = self.image.initDomain(self.id, self.memory, cpu, self.cpu_weight)
log.debug('init_domain> Created domain=%d name=%s memory=%d',
dom, self.name, self.memory)
if not self.restore:
self.setdom(dom)
id, self.name, self.memory)
self.setdom(id)
def openChannel(self, key, local, remote):
"""Create a channel to the domain.
"""Create a control channel to the domain.
If saved info is available recreate the channel.
@param key db key for the saved data (if any)
@@ -670,6 +680,11 @@ class XendDomainInfo:
return chan
def eventChannel(self, key):
"""Create an event channel to the domain.
If saved info is available recreate the channel.
@param key db key for the saved data (if any)
"""
db = self.db.addChild(key)
return EventChannel.restoreFromDB(db, 0, self.id)
@@ -832,11 +847,12 @@ class XendDomainInfo:
self.state = STATE_VM_OK
self.shutdown_pending = None
self.restart_check()
self.exportToDB()
self.restart_state = STATE_RESTART_BOOTING
if self.bootloader:
self.config = self.bootloader_config()
self.construct(self.config)
self.saveDB()
self.saveToDB()
finally:
self.restart_state = None
@@ -910,23 +926,6 @@ class XendDomainInfo:
backend = blkif.getBackend(0)
backend.connect(recreate=self.recreate)
def dom_construct(self, dom, config):
"""Construct a vm for an existing domain.
@param dom: domain id
@param config: domain configuration
"""
d = dom_get(dom)
if not d:
raise VmError("Domain not found: %d" % dom)
try:
self.restore = True
self.setdom(dom)
self.memory = d['mem_kb']/1024
self.construct(config)
finally:
self.restore = False
def configure_fields(self):
"""Process the vm configuration fields using the registered handlers.
"""
+2 -2
View File
@@ -96,8 +96,8 @@ class ImageHandler:
self.db = vm.db.addChild('/image')
self.config = config
def exportToDB(self, save=False):
self.db.exportToDB(self, fields=self.__exports__, save=save)
def exportToDB(self, save=False, sync=False):
self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
def importFromDB(self):
self.db.importFromDB(self, fields=self.__exports__)
+1
View File
@@ -167,6 +167,7 @@ class BlkDev(Dev):
DBVar('params', ty='str'),
DBVar('node', ty='str'),
DBVar('device', ty='long'),
DBVar('dev_handle', ty='long'),
DBVar('start_sector', ty='long'),
DBVar('nr_sectors', ty='long'),
]
+4 -4
View File
@@ -81,7 +81,7 @@ class EventChannel(dict):
evtchn_close(self.dom1, self.port1)
evtchn_close(self.dom2, self.port2)
def saveToDB(self, db):
def saveToDB(self, db, save=False):
"""Save the event channel to the db so it can be restored later,
using restoreFromDB() on the class.
@@ -91,7 +91,7 @@ class EventChannel(dict):
db['dom2'] = str(self.dom2)
db['port1'] = str(self.port1)
db['port2'] = str(self.port2)
db.saveDB()
db.saveDB(save=save)
def sxpr(self):
return ['event-channel',
@@ -339,7 +339,7 @@ class Channel:
# Make sure the port will deliver all the messages.
self.port.register(TYPE_WILDCARD)
def saveToDB(self, db):
def saveToDB(self, db, save=False):
"""Save the channel ports to the db so the channel can be restored later,
using restoreFromDB() on the factory.
@@ -348,7 +348,7 @@ class Channel:
if self.closed: return
db['local_port'] = str(self.getLocalPort())
db['remote_port'] = str(self.getRemotePort())
db.saveDB()
db.saveDB(save=save)
def getKey(self):
"""Get the channel key.
+2 -1
View File
@@ -214,7 +214,8 @@ class ConsoleDev(Dev, protocol.ServerFactory):
self.unix_listener = reactor.listenUNIX(path, self)
if xroot.get_xend_http_server():
interface = xroot.get_console_address()
self.tcp_listener = reactor.listenTCP(self.console_port, self, interface=interface)
self.tcp_listener = reactor.listenTCP(
self.console_port, self, interface=interface)
finally:
self.lock.release()
+17 -12
View File
@@ -1,6 +1,8 @@
import string
import types
from xen.xend.XendLogging import log
from xen.xend import sxp
from xsnode import XenNode
from xen.util.mac import macToString, macFromString
@@ -14,14 +16,19 @@ def hasAttr(obj, attr):
return hasattr(obj, attr)
def getAttr(obj, attr):
if isinstance(obj, dict):
return dict.get(attr)
else:
return getattr(obj, attr, None)
try:
if isinstance(obj, dict):
return obj.get(attr)
else:
return getattr(obj, attr, None)
except AttributeError:
return None
except LookupError:
return None
def setAttr(obj, attr, val):
if isinstance(obj, dict):
dict[attr] = val
obj[attr] = val
else:
setattr(obj, attr, val)
@@ -53,8 +60,8 @@ class DBConverter:
convertToDB = classmethod(convertToDB)
def convertFromDB(cls, val, ty=None):
return cls.getConverter(ty).fromDB(val)
def convertFromDB(cls, data, ty=None):
return cls.getConverter(ty).fromDB(data.getData())
convertFromDB = classmethod(convertFromDB)
@@ -201,9 +208,8 @@ class DBVar:
setAttr(o, self.attr, val)
def getDB(self, db):
try:
data = getattr(db, self.path)
except AttributeError:
data = getAttr(db, self.path)
if data is None:
return None
return DBConverter.convertFromDB(data, ty=self.ty)
@@ -214,8 +220,7 @@ class DBVar:
return
data = DBConverter.convertToDB(val, ty=self.ty)
#print 'DBVar>setDB>', self.path, 'data=', data
setattr(db, self.path, data)
setAttr(db, self.path, data)
class DBMap(dict):
"""A persistent map. Extends dict with persistence.
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.