allow setting multiple BIOS attributes at a time (#62764)

* allow setting multiple BIOS attributes at a time

* fix documentation string errors
pull/64157/head
Bill Dodd 5 years ago committed by John R Barker
parent ec1c5585af
commit b4cd9086dc

@ -1419,7 +1419,7 @@ class RedfishUtils(object):
return response return response
return {'ret': True, 'changed': True} return {'ret': True, 'changed': True}
def set_bios_attributes(self, attr): def set_bios_attributes(self, attributes):
result = {} result = {}
key = "Bios" key = "Bios"
@ -1442,19 +1442,27 @@ class RedfishUtils(object):
result['ret'] = True result['ret'] = True
data = response['data'] data = response['data']
# First, check if BIOS attribute exists # Make a copy of the attributes dict
if attr['bios_attr_name'] not in data[u'Attributes']: attrs_to_patch = dict(attributes)
return {'ret': False, 'msg': "BIOS attribute not found"}
# Find out if value is already set to what we want. If yes, return # Check the attributes
if data[u'Attributes'][attr['bios_attr_name']] == attr['bios_attr_value']: for attr in attributes:
return {'ret': True, 'changed': False, 'msg': "BIOS attribute already set"} if attr not in data[u'Attributes']:
return {'ret': False, 'msg': "BIOS attribute %s not found" % attr}
# If already set to requested value, remove it from PATCH payload
if data[u'Attributes'][attr] == attributes[attr]:
del attrs_to_patch[attr]
# Return success w/ changed=False if no attrs need to be changed
if not attrs_to_patch:
return {'ret': True, 'changed': False,
'msg': "BIOS attributes already set"}
# Get the SettingsObject URI
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"] set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"]
# Example: bios_attr = {\"name\":\"value\"} # Construct payload and issue PATCH command
bios_attr = "{\"" + attr['bios_attr_name'] + "\":\"" + attr['bios_attr_value'] + "\"}" payload = {"Attributes": attrs_to_patch}
payload = {"Attributes": json.loads(bios_attr)}
response = self.patch_request(self.root_uri + set_bios_attr_uri, payload) response = self.patch_request(self.root_uri + set_bios_attr_uri, payload)
if response['ret'] is False: if response['ret'] is False:
return response return response

@ -51,17 +51,24 @@ options:
bios_attribute_name: bios_attribute_name:
required: false required: false
description: description:
- name of BIOS attribute to update - name of BIOS attr to update (deprecated - use bios_attributes instead)
default: 'null' default: 'null'
type: str type: str
version_added: "2.8" version_added: "2.8"
bios_attribute_value: bios_attribute_value:
required: false required: false
description: description:
- value of BIOS attribute to update - value of BIOS attr to update (deprecated - use bios_attributes instead)
default: 'null' default: 'null'
type: str type: str
version_added: "2.8" version_added: "2.8"
bios_attributes:
required: false
description:
- dictionary of BIOS attributes to update
default: {}
type: dict
version_added: "2.10"
timeout: timeout:
description: description:
- Timeout in seconds for URL requests to OOB controller - Timeout in seconds for URL requests to OOB controller
@ -90,23 +97,25 @@ EXAMPLES = '''
redfish_config: redfish_config:
category: Systems category: Systems
command: SetBiosAttributes command: SetBiosAttributes
bios_attribute_name: BootMode bios_attributes:
bios_attribute_value: Uefi BootMode: "Uefi"
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
- name: Set BootMode to Legacy BIOS - name: Set multiple BootMode attributes
redfish_config: redfish_config:
category: Systems category: Systems
command: SetBiosAttributes command: SetBiosAttributes
bios_attribute_name: BootMode bios_attributes:
bios_attribute_value: Bios BootMode: "Bios"
OneTimeBootMode: "Enabled"
BootSeqRetry: "Enabled"
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
- name: Enable PXE Boot for NIC1 - name: Enable PXE Boot for NIC1 using deprecated options
redfish_config: redfish_config:
category: Systems category: Systems
command: SetBiosAttributes command: SetBiosAttributes
@ -195,6 +204,7 @@ def main():
password=dict(required=True, no_log=True), password=dict(required=True, no_log=True),
bios_attribute_name=dict(default='null'), bios_attribute_name=dict(default='null'),
bios_attribute_value=dict(default='null'), bios_attribute_value=dict(default='null'),
bios_attributes=dict(type='dict', default={}),
timeout=dict(type='int', default=10), timeout=dict(type='int', default=10),
boot_order=dict(type='list', elements='str', default=[]), boot_order=dict(type='list', elements='str', default=[]),
network_protocols=dict( network_protocols=dict(
@ -216,8 +226,13 @@ def main():
timeout = module.params['timeout'] timeout = module.params['timeout']
# BIOS attributes to update # BIOS attributes to update
bios_attributes = {'bios_attr_name': module.params['bios_attribute_name'], bios_attributes = module.params['bios_attributes']
'bios_attr_value': module.params['bios_attribute_value']} if module.params['bios_attribute_name'] != 'null':
bios_attributes[module.params['bios_attribute_name']] = module.params[
'bios_attribute_value']
module.deprecate(msg='The bios_attribute_name/bios_attribute_value '
'options are deprecated. Use bios_attributes instead',
version='2.10')
# boot order # boot order
boot_order = module.params['boot_order'] boot_order = module.params['boot_order']

Loading…
Cancel
Save