mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
Added a VBD.bootable flag.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
f3ca404628
commit
bdafeefd69
6 files changed
+193
-43
No files matched your search
@@ -1348,6 +1348,7 @@ class XendAPI(object):
|
||||
VBD_attr_rw = ['VM',
|
||||
'VDI',
|
||||
'device',
|
||||
'bootable',
|
||||
'mode',
|
||||
'type',
|
||||
'driver']
|
||||
@@ -1429,6 +1430,10 @@ class XendAPI(object):
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
'device'))
|
||||
def VBD_get_bootable(self, session, vbd_ref):
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
'bootable'))
|
||||
def VBD_get_mode(self, session, vbd_ref):
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
@@ -1454,6 +1459,14 @@ class XendAPI(object):
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
'io_read_kbs'))
|
||||
|
||||
def VBD_set_bootable(self, session, vbd_ref, bootable):
|
||||
bootable = bool(bootable)
|
||||
xd = XendDomain.instance()
|
||||
vm = xd.get_vm_with_dev_uuid('vbd', vbd_ref)
|
||||
vm.set_dev_property('vbd', vbd_ref, 'bootable', bootable)
|
||||
xd.managed_config_save(vm)
|
||||
return xen_api_success_void()
|
||||
|
||||
def VBD_get_all(self, session):
|
||||
xendom = XendDomain.instance()
|
||||
vbds = [d.get_vbds() for d in XendDomain.instance().list('all')]
|
||||
|
||||
@@ -28,7 +28,7 @@ from xen.xend.PrettyPrint import prettyprintstring
|
||||
from xen.xend.XendConstants import DOM_STATE_HALTED
|
||||
|
||||
log = logging.getLogger("xend.XendConfig")
|
||||
log.setLevel(logging.WARN)
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
"""
|
||||
@@ -878,6 +878,13 @@ class XendConfig(dict):
|
||||
controller = domain.getDeviceController(cls)
|
||||
configs = controller.configurations()
|
||||
for config in configs:
|
||||
if sxp.name(config) in ('vbd', 'tap'):
|
||||
# The bootable flag is never written to the
|
||||
# store as part of the device config.
|
||||
uuid = sxp.child_value(sxpr, 'uuid')
|
||||
sxpr.append(
|
||||
'bootable',
|
||||
self['devices'][dev_uuid]['bootable'])
|
||||
sxpr.append(['device', config])
|
||||
|
||||
found = True
|
||||
@@ -948,6 +955,7 @@ class XendConfig(dict):
|
||||
pass
|
||||
|
||||
if dev_type == 'vbd':
|
||||
dev_info['bootable'] = False
|
||||
if dev_info.get('dev', '').startswith('ioemu:'):
|
||||
dev_info['driver'] = 'ioemu'
|
||||
else:
|
||||
@@ -964,13 +972,21 @@ class XendConfig(dict):
|
||||
if param not in target:
|
||||
target[param] = []
|
||||
if dev_uuid not in target[param]:
|
||||
if dev_type == 'vbd' and not target[param]:
|
||||
# Compat hack -- this is the first disk, so mark it
|
||||
# bootable.
|
||||
dev_info['bootable'] = True
|
||||
target[param].append(dev_uuid)
|
||||
elif dev_type in ('tap',):
|
||||
elif dev_type == 'tap':
|
||||
if 'vbd_refs' not in target:
|
||||
target['vbd_refs'] = []
|
||||
if dev_uuid not in target['vbd_refs']:
|
||||
if not target['vbd_refs']:
|
||||
# Compat hack -- this is the first disk, so mark it
|
||||
# bootable.
|
||||
dev_info['bootable'] = True
|
||||
target['vbd_refs'].append(dev_uuid)
|
||||
elif dev_type in ('console',):
|
||||
elif dev_type == 'console':
|
||||
if 'console_refs' not in target:
|
||||
target['console_refs'] = []
|
||||
if dev_uuid not in target['console_refs']:
|
||||
@@ -1009,6 +1025,7 @@ class XendConfig(dict):
|
||||
dev_info['uname'] = cfg_xenapi.get('image', '')
|
||||
dev_info['dev'] = '%s:%s' % (cfg_xenapi.get('device'),
|
||||
old_vbd_type)
|
||||
dev_info['bootable'] = cfg_xenapi.get('bootable', False)
|
||||
dev_info['driver'] = cfg_xenapi.get('driver')
|
||||
dev_info['VDI'] = cfg_xenapi.get('VDI', '')
|
||||
|
||||
|
||||
@@ -1653,48 +1653,45 @@ class XendDomainInfo:
|
||||
blexec = osdep.pygrub_path
|
||||
|
||||
blcfg = None
|
||||
for (devtype, devinfo) in self.info.all_devices_sxpr():
|
||||
if not devtype or not devinfo or devtype not in ('vbd', 'tap'):
|
||||
continue
|
||||
disk = None
|
||||
for param in devinfo:
|
||||
if param[0] == 'uname':
|
||||
disk = param[1]
|
||||
break
|
||||
disks = [x for x in self.info['vbd_refs']
|
||||
if self.info['devices'][x][1]['bootable']]
|
||||
|
||||
if disk is None:
|
||||
continue
|
||||
fn = blkdev_uname_to_file(disk)
|
||||
mounted = devtype == 'tap' and not os.stat(fn).st_rdev
|
||||
if not disks:
|
||||
msg = "Had a bootloader specified, but no disks are bootable"
|
||||
log.error(msg)
|
||||
raise VmError(msg)
|
||||
|
||||
disk = disks[0]
|
||||
|
||||
fn = blkdev_uname_to_file(disk)
|
||||
mounted = devtype == 'tap' and not os.stat(fn).st_rdev
|
||||
if mounted:
|
||||
# This is a file, not a device. pygrub can cope with a
|
||||
# file if it's raw, but if it's QCOW or other such formats
|
||||
# used through blktap, then we need to mount it first.
|
||||
|
||||
log.info("Mounting %s on %s." %
|
||||
(fn, BOOTLOADER_LOOPBACK_DEVICE))
|
||||
|
||||
vbd = {
|
||||
'mode': 'RO',
|
||||
'device': BOOTLOADER_LOOPBACK_DEVICE,
|
||||
}
|
||||
|
||||
from xen.xend import XendDomain
|
||||
dom0 = XendDomain.instance().privilegedDomain()
|
||||
dom0._waitForDeviceUUID(dom0.create_vbd(vbd, fn))
|
||||
fn = BOOTLOADER_LOOPBACK_DEVICE
|
||||
|
||||
try:
|
||||
blcfg = bootloader(blexec, fn, self, False,
|
||||
bootloader_args, kernel, ramdisk, args)
|
||||
finally:
|
||||
if mounted:
|
||||
# This is a file, not a device. pygrub can cope with a
|
||||
# file if it's raw, but if it's QCOW or other such formats
|
||||
# used through blktap, then we need to mount it first.
|
||||
|
||||
log.info("Mounting %s on %s." %
|
||||
log.info("Unmounting %s from %s." %
|
||||
(fn, BOOTLOADER_LOOPBACK_DEVICE))
|
||||
|
||||
vbd = {
|
||||
'mode': 'RO',
|
||||
'device': BOOTLOADER_LOOPBACK_DEVICE,
|
||||
}
|
||||
|
||||
from xen.xend import XendDomain
|
||||
dom0 = XendDomain.instance().privilegedDomain()
|
||||
dom0._waitForDeviceUUID(dom0.create_vbd(vbd, fn))
|
||||
fn = BOOTLOADER_LOOPBACK_DEVICE
|
||||
|
||||
try:
|
||||
blcfg = bootloader(blexec, fn, self, False,
|
||||
bootloader_args, kernel, ramdisk, args)
|
||||
finally:
|
||||
if mounted:
|
||||
log.info("Unmounting %s from %s." %
|
||||
(fn, BOOTLOADER_LOOPBACK_DEVICE))
|
||||
|
||||
dom0.destroyDevice('tap', '/dev/xvdp')
|
||||
|
||||
break
|
||||
dom0.destroyDevice('tap', '/dev/xvdp')
|
||||
|
||||
if blcfg is None:
|
||||
msg = "Had a bootloader specified, but can't find disk"
|
||||
@@ -2137,6 +2134,9 @@ class XendDomainInfo:
|
||||
except KeyError:
|
||||
raise XendError('Invalid property for device: %s' % field)
|
||||
|
||||
def set_dev_property(self, dev_class, dev_uuid, field, value):
|
||||
self.info['devices'][dev_uuid][1][field] = value
|
||||
|
||||
def get_vcpus_util(self):
|
||||
vcpu_util = {}
|
||||
xennode = XendNode.instance()
|
||||
|
||||