Move initDomain out of image.py and into XendDomainInfo. The only thing that

needed any of the state of image.py was the bootloader code, which says there,
but all the rest was doing something that belonged more properly in
XendDomainInfo, with all the other generic domain initialisation code.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@ewan committed 2005-09-22 17:52:07 +01:00
1 parent 8259cb8841
commit 251888ee61
2 files changed
+41 -55

No files matched your search

+35 -21
View File
@@ -706,32 +706,14 @@ class XendDomainInfo:
"""
# todo - add support for scheduling params?
try:
# Initial domain create.
if 'image' not in self.info:
raise VmError('Missing image in configuration')
self.image = ImageHandler.create(self, self.info['image'],
self.image = ImageHandler.create(self,
self.info['image'],
self.info['device'])
log.debug('XendDomainInfo.construct: '
'calling initDomain(%s %s %s %s %s)',
str(self.domid),
str(self.info['memory_KiB']),
str(self.info['ssidref']),
str(self.info['cpu']),
str(self.info['cpu_weight']))
self.setDomid(self.image.initDomain(self.domid,
self.info['memory_KiB'],
self.info['ssidref'],
self.info['cpu'],
self.info['cpu_weight'],
self.info['bootloader']))
self.info['start_time'] = time.time()
log.debug('init_domain> Created domain=%d name=%s memory=%d',
self.domid, self.info['name'], self.info['memory_KiB'])
self.initDomain()
# Create domain devices.
self.construct_image()
@@ -745,6 +727,38 @@ class XendDomainInfo:
self.destroy()
raise
def initDomain(self):
log.debug('XendDomainInfo.initDomain: %s %s %s %s)',
str(self.domid),
str(self.info['memory_KiB']),
str(self.info['ssidref']),
str(self.info['cpu_weight']))
self.domid = xc.domain_create(dom = self.domid or 0,
ssidref = self.info['ssidref'])
if self.domid <= 0:
raise VmError('Creating domain failed: name=%s' %
self.vm.getName())
if self.info['bootloader']:
self.image.handleBootloading()
xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
m = self.image.getDomainMemory(self.info['memory_KiB'])
xc.domain_setmaxmem(self.domid, m)
xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
cpu = self.info['cpu']
if cpu is not None and cpu != -1:
xc.domain_pincpu(self.domid, 0, 1 << cpu)
self.info['start_time'] = time.time()
log.debug('init_domain> Created domain=%d name=%s memory=%d',
self.domid, self.info['name'], self.info['memory_KiB'])
def configure_vcpus(self, vcpus):
d = {}
for v in range(0, vcpus):
+6 -34
View File
@@ -36,9 +36,6 @@ MAX_GUEST_CMDLINE = 1024
class ImageHandler:
"""Abstract base class for image handlers.
initDomain() is called to initialise the domain memory and parse
the configuration.
createImage() is called to configure and build the domain from its
kernel image and ramdisk etc.
@@ -132,6 +129,12 @@ class ImageHandler:
("image/cmdline", self.cmdline),
("image/ramdisk", self.ramdisk))
def handleBootloading():
self.unlink(self.kernel)
self.unlink(self.ramdisk)
def unlink(self, f):
if not f: return
try:
@@ -139,37 +142,6 @@ class ImageHandler:
except OSError, ex:
log.warning("error removing bootloader file '%s': %s", f, ex)
def initDomain(self, dom, memory, ssidref, cpu, cpu_weight, bootloading):
"""Initial domain create.
@param memory In KiB
@return domain id
"""
mem_kb = self.getDomainMemory(memory)
dom = xc.domain_create(dom = dom or 0, ssidref = ssidref)
# if bootloader, unlink here. But should go after buildDomain() ?
if bootloading:
self.unlink(self.kernel)
self.unlink(self.ramdisk)
if dom <= 0:
raise VmError('Creating domain failed: name=%s' %
self.vm.getName())
if cpu is None:
cpu = -1;
log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, mem_kb, ssidref, dom)
xc.domain_setcpuweight(dom, cpu_weight)
xc.domain_setmaxmem(dom, mem_kb)
try:
xc.domain_memory_increase_reservation(dom, mem_kb, 0, 0)
except:
xc.domain_destroy(dom)
raise
if cpu != -1:
xc.domain_pincpu(dom, 0, 1<<int(cpu))
return dom
def createImage(self):
"""Entry point to create domain memory image.
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.