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:
parent
01e6453c28
commit
37fcd7ef8f
@ -28,12 +28,14 @@ app.url_map.strict_slashes = False
|
|||||||
|
|
||||||
LIBVIRT_CONN = None
|
LIBVIRT_CONN = None
|
||||||
|
|
||||||
SET_BOOT_DEVICES_MAP = {
|
BOOT_DEVICE_MAP = {
|
||||||
'Pxe': 'network',
|
'Pxe': 'network',
|
||||||
'Hdd': 'hd',
|
'Hdd': 'hd',
|
||||||
'Cd': 'cdrom',
|
'Cd': 'cdrom',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOT_DEVICE_MAP_REV = {v: k for k, v in BOOT_DEVICE_MAP.items()}
|
||||||
|
|
||||||
|
|
||||||
def _get_libvirt_domain(domain):
|
def _get_libvirt_domain(domain):
|
||||||
try:
|
try:
|
||||||
@ -67,17 +69,25 @@ def system_resource(identity):
|
|||||||
# domain to be running
|
# domain to be running
|
||||||
total_cpus = 0
|
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(
|
return flask.render_template(
|
||||||
'system.json', identity=identity, uuid=domain.UUIDString(),
|
'system.json', identity=identity, uuid=domain.UUIDString(),
|
||||||
power_state=power_state, total_memory_gb=total_memory_gb,
|
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':
|
elif flask.request.method == 'PATCH':
|
||||||
boot = flask.request.json.get('Boot')
|
boot = flask.request.json.get('Boot')
|
||||||
if not boot:
|
if not boot:
|
||||||
return 'PATCH only works for the Boot element', 400
|
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:
|
if not target:
|
||||||
return 'Missing the BootSourceOverrideTarget element', 400
|
return 'Missing the BootSourceOverrideTarget element', 400
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
"IndicatorLED": "Off",
|
"IndicatorLED": "Off",
|
||||||
"PowerState": "{{ power_state }}",
|
"PowerState": "{{ power_state }}",
|
||||||
"Boot": {
|
"Boot": {
|
||||||
"BootSourceOverrideEnabled": "Once",
|
"BootSourceOverrideEnabled": "Continuous",
|
||||||
"BootSourceOverrideTarget": "Pxe",
|
"BootSourceOverrideTarget": "{{ boot_source_target }}",
|
||||||
"BootSourceOverrideTarget@Redfish.AllowableValues": [
|
"BootSourceOverrideTarget@Redfish.AllowableValues": [
|
||||||
"Pxe",
|
"Pxe",
|
||||||
"Cd",
|
"Cd",
|
||||||
|
Loading…
Reference in New Issue
Block a user