Escape JSON rendered in templates
Dynamic Redfish emulator uses Jinja templates to render JSON documents out of the values it gathers fromm the backend hypervisor. Sometimes these hypervisor-supplied values can contain literals that are special to JSON serialization. Unless escaped properly, such conflicting literals will surely ruin the entire JSON document. This change elicits Jinja and Flask template filters that circumvent this problem. Change-Id: Ie3f2e1b68ab93a701adf666bdca9cf3d227c0c57
This commit is contained in:
parent
4f0cc187ee
commit
cc0bd13f42
@ -7,17 +7,17 @@
|
||||
"@Redfish.Settings": {
|
||||
"@odata.type": "#Settings.v1_0_0.Settings",
|
||||
"SettingsObject": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/BIOS/Settings"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/BIOS/Settings"|format(identity)|tojson }}
|
||||
}
|
||||
},
|
||||
"Actions": {
|
||||
"#Bios.ResetBios": {
|
||||
"target": "/redfish/v1/Systems/{{ identity }}/BIOS/Actions/Bios.ResetBios"
|
||||
"target": {{ "/redfish/v1/Systems/%s/BIOS/Actions/Bios.ResetBios"|format(identity)|tojson }}
|
||||
},
|
||||
"#Bios.ChangePassword": {
|
||||
"target": "/redfish/v1/Systems/{{ identity }}/BIOS/Actions/Bios.ChangePassword"
|
||||
"target": {{ "/redfish/v1/Systems/%s/BIOS/Actions/Bios.ChangePassword"|format(identity)|tojson }}
|
||||
}
|
||||
},
|
||||
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/BIOS"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/BIOS"|format(identity)|tojson }}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@
|
||||
"AttributeRegistry": "BiosAttributeRegistryP89.v1_0_0",
|
||||
"Attributes": {{ bios_pending_attributes }},
|
||||
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/BIOS/Settings",
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/BIOS/Settings"|format(identity)|tojson }},
|
||||
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"error": {
|
||||
"code": "Base.1.0.GeneralError",
|
||||
"message": "{{ message }}",
|
||||
"message": {{ message|string|tojson }},
|
||||
"@Message.ExtendedInfo": [
|
||||
{
|
||||
"@odata.type": "/redfish/v1/$metadata#Message.1.0.0.Message",
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"@odata.type": "#EthernetInterface.v1_0_2.EthernetInterface",
|
||||
"Id": "{{ nic['id'] }}",
|
||||
"Name": "VNIC {{ nic['id'] }}",
|
||||
"PermanentMACAddress": "{{ nic['mac'] }}",
|
||||
"MACAddress": "{{ nic['mac'] }}",
|
||||
"Id": {{ nic['id']|string|tojson }},
|
||||
"Name": {{ "VNIC %s"|format(nic['id'])|tojson }},
|
||||
"PermanentMACAddress": {{ nic['mac']|string|tojson }},
|
||||
"MACAddress": {{ nic['mac']|string|tojson }},
|
||||
"@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/EthernetInterfaces/{{ nic['id'] }}"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/EthernetInterfaces/%s"|format(identity, nic['id'])|tojson }}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
"Members": [
|
||||
{% for nic in nics %}
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/EthernetInterfaces/{{ nic.id }}"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/EthernetInterfaces/%s"|format(identity, nic.id)|tojson }}
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
],
|
||||
"Oem": {},
|
||||
"@odata.context": "/redfish/v1/$metadata#EthernetInterfaceCollection.EthernetInterfaceCollection",
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/EthernetInterfaces"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/EthernetInterfaces"|format(identity)|tojson }}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
{
|
||||
"@odata.type": "#ComputerSystem.v1_1_0.ComputerSystem",
|
||||
"Id": "{{ identity }}",
|
||||
"Name": "{{ identity }}",
|
||||
"UUID": "{{ uuid }}",
|
||||
"Id": {{ identity|string|tojson }},
|
||||
"Name": {{ identity|string|tojson }},
|
||||
"UUID": {{ uuid|string|tojson }},
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK",
|
||||
"HealthRollUp": "OK"
|
||||
},
|
||||
{%- if power_state %}
|
||||
"PowerState": "{{ power_state }}",
|
||||
"PowerState": {{ power_state|string|tojson }},
|
||||
{%- endif %}
|
||||
"Boot": {
|
||||
{%- if boot_source_target %}
|
||||
"BootSourceOverrideEnabled": "Continuous",
|
||||
"BootSourceOverrideTarget": "{{ boot_source_target }}",
|
||||
"BootSourceOverrideTarget": {{ boot_source_target|string|tojson }},
|
||||
"BootSourceOverrideTarget@Redfish.AllowableValues": [
|
||||
"Pxe",
|
||||
"Cd",
|
||||
@ -22,10 +22,10 @@
|
||||
{%- if boot_source_mode %}
|
||||
],
|
||||
{%- if 'uefi' in boot_source_mode.lower() %}
|
||||
"BootSourceOverrideMode": "{{ boot_source_mode }}",
|
||||
"BootSourceOverrideMode": {{ boot_source_mode|string|tojson }},
|
||||
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"
|
||||
{%- else %}
|
||||
"BootSourceOverrideMode": "{{ boot_source_mode }}"
|
||||
"BootSourceOverrideMode": {{ boot_source_mode|string|tojson }}
|
||||
{%- endif %}
|
||||
{%- else %}
|
||||
]
|
||||
@ -55,19 +55,19 @@
|
||||
}
|
||||
},
|
||||
"Bios": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/BIOS"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/BIOS"|format(identity)|tojson }}
|
||||
},
|
||||
"Processors": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/Processors"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/Processors"|format(identity)|tojson }}
|
||||
},
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/Memory"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/Memory"|format(identity)|tojson }}
|
||||
},
|
||||
"EthernetInterfaces": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/EthernetInterfaces"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/EthernetInterfaces"|format(identity)|tojson }}
|
||||
},
|
||||
"SimpleStorage": {
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}/SimpleStorage"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s/SimpleStorage"|format(identity)|tojson }}
|
||||
},
|
||||
"Links": {
|
||||
"Chassis": [
|
||||
@ -77,7 +77,7 @@
|
||||
},
|
||||
"Actions": {
|
||||
"#ComputerSystem.Reset": {
|
||||
"target": "/redfish/v1/Systems/{{ identity }}/Actions/ComputerSystem.Reset",
|
||||
"target": {{ "/redfish/v1/Systems/%s/Actions/ComputerSystem.Reset"|format(identity)|tojson }},
|
||||
"ResetType@Redfish.AllowableValues": [
|
||||
"On",
|
||||
"ForceOff",
|
||||
@ -90,6 +90,6 @@
|
||||
}
|
||||
},
|
||||
"@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem",
|
||||
"@odata.id": "/redfish/v1/Systems/{{ identity }}",
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s"|format(identity)|tojson }},
|
||||
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
"Members": [
|
||||
{% for system in systems %}
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/{{ system }}"
|
||||
"@odata.id": {{ "/redfish/v1/Systems/%s"|format(system)|tojson }}
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user