Libvirt-Mockup: Add support for getting the boot source target

Prior to this patch the BootSourceOverrideTarget element of the Redfish
template was hardcoded to "Pxe".

Change-Id: Iff300172853e23628da56213081f24c70f0d0959
This commit is contained in:
Lucas Alvares Gomes 2017-02-28 13:41:40 +00:00
parent 01e6453c28
commit 37fcd7ef8f
2 changed files with 15 additions and 5 deletions

View File

@ -28,12 +28,14 @@ app.url_map.strict_slashes = False
LIBVIRT_CONN = None
SET_BOOT_DEVICES_MAP = {
BOOT_DEVICE_MAP = {
'Pxe': 'network',
'Hdd': 'hd',
'Cd': 'cdrom',
}
BOOT_DEVICE_MAP_REV = {v: k for k, v in BOOT_DEVICE_MAP.items()}
def _get_libvirt_domain(domain):
try:
@ -67,17 +69,25 @@ def system_resource(identity):
# domain to be running
total_cpus = 0
# Get the current boot device
boot_source_target = None
tree = ET.fromstring(domain.XMLDesc())
boot_element = tree.find('.//boot')
if boot_element is not None:
boot_source_target = (
BOOT_DEVICE_MAP_REV.get(boot_element.get('dev')))
return flask.render_template(
'system.json', identity=identity, uuid=domain.UUIDString(),
power_state=power_state, total_memory_gb=total_memory_gb,
total_cpus=total_cpus)
total_cpus=total_cpus, boot_source_target=boot_source_target)
elif flask.request.method == 'PATCH':
boot = flask.request.json.get('Boot')
if not boot:
return 'PATCH only works for the Boot element', 400
target = SET_BOOT_DEVICES_MAP.get(boot.get('BootSourceOverrideTarget'))
target = BOOT_DEVICE_MAP.get(boot.get('BootSourceOverrideTarget'))
if not target:
return 'Missing the BootSourceOverrideTarget element', 400

View File

@ -20,8 +20,8 @@
"IndicatorLED": "Off",
"PowerState": "{{ power_state }}",
"Boot": {
"BootSourceOverrideEnabled": "Once",
"BootSourceOverrideTarget": "Pxe",
"BootSourceOverrideEnabled": "Continuous",
"BootSourceOverrideTarget": "{{ boot_source_target }}",
"BootSourceOverrideTarget@Redfish.AllowableValues": [
"Pxe",
"Cd",