Add new Storage controllers

Adds new resource StorageController to Storage introduced in Redfish
v1.9 to allow StorageControllers be their own resource.

Refactor BIOS code to reuse the same code for apply time handling
for both BIOS and now StorageController.

Change-Id: I32554dc94096662dae163b1043e97386318daf7f
This commit is contained in:
Aija Jauntēva
2022-07-25 10:12:29 -04:00
parent 10578574e8
commit 4dd5976c47
14 changed files with 502 additions and 84 deletions

View File

@@ -0,0 +1,6 @@
---
features:
- |
Adds ``controllers`` property of ``Storage`` class that was introduced in
Redfish v1.9 to replace ``storage_controllers`` deprecated in Redfish
v1.13.

View File

@@ -167,9 +167,10 @@ class SettingsField(base.CompositeField):
:param connector: A Connector instance
:param value: Value representing JSON whose structure is specific
to each resource and the caller must format it correctly
:returns: Response object
"""
connector.patch(self.resource_uri, data=value)
return connector.patch(self.resource_uri, data=value)
@property
def resource_uri(self):

View File

@@ -19,7 +19,6 @@ import logging
from sushy import exceptions
from sushy.resources import base
from sushy.resources import common
from sushy.resources import constants as res_cons
from sushy.resources import settings
from sushy import utils
@@ -147,25 +146,9 @@ class Bios(base.ResourceBase):
set by the system.
"""
payload = {'Attributes': value}
if (not apply_time
and (maint_window_start_time or maint_window_duration)):
raise ValueError('"apply_time" missing when passing maintenance '
'window settings')
if apply_time:
prop = '@Redfish.SettingsApplyTime'
payload[prop] = {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': res_cons.ApplyTime(apply_time).value,
}
if maint_window_start_time and not maint_window_duration:
raise ValueError('"maint_window_duration" missing')
if not maint_window_start_time and maint_window_duration:
raise ValueError('"maint_window_start_time" missing')
if maint_window_start_time and maint_window_duration:
payload[prop]['MaintenanceWindowStartTime'] =\
maint_window_start_time.isoformat()
payload[prop]['MaintenanceWindowDurationInSeconds'] =\
maint_window_duration
payload = utils.process_apply_time_input(
payload, apply_time, maint_window_start_time,
maint_window_duration)
self._settings.commit(self._conn,
payload)
utils.cache_clear(self, force_refresh=False,

View File

@@ -0,0 +1,150 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# This is referred from Redfish standard schema.
# http://redfish.dmtf.org/schemas/v1/StorageController.v1_6_0.json
import logging
from sushy.resources import base
from sushy.resources import common
from sushy.resources import constants as res_cons
from sushy.resources import settings
from sushy.resources.system.storage import constants
from sushy.taskmonitor import TaskMonitor
from sushy import utils
LOG = logging.getLogger(__name__)
class StorageController(base.ResourceBase):
"""Storage controller"""
identity = base.Field('Id', required=True)
"""The storage controller identity"""
name = base.Field('Name', required=True)
"""The name of the storage controller"""
status = common.StatusField('Status')
"""Describes the status and health of the resource and its children."""
identifiers = common.IdentifiersListField('Identifiers', default=[])
"""The Durable names for the storage controller."""
speed_gbps = base.Field('SpeedGbps')
"""The maximum speed of the storage controller's device interface."""
controller_protocols = base.MappedListField(
'SupportedControllerProtocols', res_cons.Protocol)
"""The protocols by which this storage controller can be communicated to"""
device_protocols = base.MappedListField('SupportedDeviceProtocols',
res_cons.Protocol)
"""The protocols that can be used to communicate with attached devices"""
raid_types = base.MappedListField('SupportedRAIDTypes', constants.RAIDType)
"""The set of RAID types supported by the storage controller."""
_settings = settings.SettingsField()
"""Future intended state for settings that can't be updated immediately."""
@property
@utils.cache_it
def pending_settings(self):
"""Pending Storage Controller settings resource"""
return StorageController(
self._conn, self._settings.resource_uri,
registries=None,
redfish_version=self.redfish_version, root=self.root)
@property
def supported_apply_times(self):
"""List of supported BIOS update apply times
:returns: List of supported update apply time names
"""
return self._settings._supported_apply_times
def update(self, payload, apply_time=None, maint_window_start_time=None,
maint_window_duration=None):
"""Updates writable properties
Supports updating properties that require reboot.
:param payload: dictionary with properties to update
:param apply_time: When to update the attributes. Optional.
A :py:class:`sushy.ApplyTime` value.
:param maint_window_start_time: The start time of a maintenance window,
datetime. Required when updating during maintenance window and
default maintenance window not set by the system.
:param maint_window_duration: Duration of maintenance time since
maintenance window start time in seconds. Required when updating
during maintenance window and default maintenance window not
set by the system.
:returns: TaskMonitor if async task or None
"""
payload = utils.process_apply_time_input(
payload, apply_time, maint_window_start_time,
maint_window_duration)
r = self._settings.commit(self._conn, payload)
utils.cache_clear(self, force_refresh=False,
only_these=['pending_settings'])
if r.status_code == 202:
return TaskMonitor.from_response(
self._conn, r, self._settings.resource_uri,
self.redfish_version, self.registries)
class ControllerCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return StorageController
@property
@utils.cache_it
def summary(self):
"""Summary of storage controllers
:returns: dictionary of controller id-s and their status in format
.. code-block:: python
{'RAID.Integrated.1-1': {'Health': sushy.Health.OK,
'State': sushy.State.ENABLED}}
"""
controllers = {}
for controller in self.get_members():
controllers[controller.identity] = {
'Health': controller.status.health,
'State': controller.status.state,
}
return controllers
def __init__(self, connector, path, redfish_version=None, registries=None,
root=None):
"""A class representing a ControllerCollection
:param connector: A Connector instance
:param path: The canonical path to the Controller collection resource
:param redfish_version: The version of Redfish. Used to construct
the object according to schema of the given version.
:param registries: Dict of Redfish Message Registry objects to be
used in any resource that needs registries to parse messages
:param root: Sushy root object. Empty for Sushy root itself.
"""
super(ControllerCollection, self).__init__(
connector, path, redfish_version=redfish_version,
registries=registries,
root=root)

View File

@@ -19,6 +19,7 @@ from sushy.resources import base
from sushy.resources import common
from sushy.resources import constants as res_cons
from sushy.resources.system.storage import constants
from sushy.resources.system.storage import controller
from sushy.resources.system.storage import drive
from sushy.resources.system.storage import volume
from sushy import utils
@@ -134,7 +135,25 @@ class Storage(base.ResourceBase):
storage_controllers = StorageControllersListField('StorageControllers',
default=[])
"""The storage devices associated with this resource."""
"""The storage devices associated with this resource.
Deprecated since Redfish v1.13 to allow storage controllers be their own
resource. Use `controllers` where available.
"""
@property
@utils.cache_it
def controllers(self):
"""The storage controllers allocated to this storage subsystem.
Replaces `storage_controllers` since Redfish v1.9 to allow storage
controllers be their own resource.
"""
return controller.ControllerCollection(
self._conn,
utils.get_sub_resource_path_by(self, "Controllers"),
redfish_version=self.redfish_version,
registries=self.registries, root=self.root)
class StorageCollection(base.ResourceCollectionBase):

View File

@@ -1,5 +1,5 @@
{
"@odata.type": "#Storage.v1_4_0.Storage",
"@odata.type": "#Storage.v1_10_1.Storage",
"Id": "1",
"Name": "Local Storage Controller",
"Description": "Integrated RAID Controller",
@@ -9,6 +9,9 @@
"Health": "OK",
"HealthRollup": "OK"
},
"Controllers": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers"
},
"StorageControllers": [
{
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1#/StorageControllers/0",

View File

@@ -0,0 +1,50 @@
{
"@Redfish.Settings": {
"@odata.context": "/redfish/v1/$metadata#Settings.Settings",
"@odata.type": "#Settings.v1_3_3.Settings",
"SettingsObject": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1/Settings"
},
"SupportedApplyTimes": [
"Immediate",
"OnReset"
]
},
"@odata.context": "/redfish/v1/$metadata#StorageController.StorageController",
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1",
"@odata.type": "#StorageController.v1_2_0.StorageController",
"Description": "Integrated RAID Controller",
"FirmwareVersion": "1.0.0.7",
"Id": "1",
"Identifiers": [
{
"@odata.type": "#Resource.v1_1_0.Identifier",
"DurableNameFormat": "NAA",
"DurableName": "345C59DBD970859C"
}
],
"Identifiers@odata.count": 1,
"Manufacturer": "Contoso",
"Model": "12Gbs Integrated RAID",
"Name": "Contoso Integrated RAID",
"SpeedGbps": 12,
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
},
"SupportedControllerProtocols": [
"PCIe"
],
"SupportedControllerProtocols@odata.count": 1,
"SupportedDeviceProtocols": [
"SAS",
"SATA"
],
"SupportedDeviceProtocols@odata.count": 2,
"SupportedRAIDTypes": [
"RAID0",
"RAID1"
],
"SupportedRAIDTypes@odata.count": 2
}

View File

@@ -0,0 +1,13 @@
{
"@odata.context": "/redfish/v1/$metadata#StorageControllerCollection.StorageControllerCollection",
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers",
"@odata.type": "#StorageControllerCollection.StorageControllerCollection",
"Description": "Collection Of Storage controllers",
"Members": [
{
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1"
}
],
"Members@odata.count": 1,
"Name": "Storage controller Collection"
}

View File

@@ -0,0 +1,8 @@
{
"@odata.context": "/redfish/v1/$metadata#StorageController.StorageController",
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1",
"@odata.type": "#StorageController.v1_2_0.StorageController",
"Id": "1",
"Name": "Local Storage Controller",
"Description": "Integrated RAID Controller"
}

View File

@@ -0,0 +1,140 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
import json
from unittest import mock
import sushy
from sushy.resources.system.storage import controller
from sushy import taskmonitor
from sushy.tests.unit import base
class ControllerTestCase(base.TestCase):
def setUp(self):
super(ControllerTestCase, self).setUp()
self.conn = mock.Mock()
with open('sushy/tests/unit/json_samples/'
'storage_controller.json') as f:
self.json_doc = json.load(f)
with open('sushy/tests/unit/json_samples/'
'storage_controller_settings.json') as f:
self.settings_json = json.load(f)
self.conn.get.return_value.json.side_effect = [
self.json_doc, self.settings_json]
self.controller = controller.StorageController(
self.conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.controller._parse_attributes(self.json_doc)
self.assertEqual('1', self.controller.identity)
self.assertEqual('Contoso Integrated RAID', self.controller.name)
self.assertEqual(sushy.Health.OK, self.controller.status.health)
self.assertEqual(sushy.State.ENABLED, self.controller.status.state)
identifiers = self.controller.identifiers
self.assertIsInstance(identifiers, list)
self.assertEqual(1, len(identifiers))
identifier = identifiers[0]
self.assertEqual(sushy.DurableNameFormat.NAA,
identifier.durable_name_format)
self.assertEqual('345C59DBD970859C', identifier.durable_name)
self.assertEqual(12, self.controller.speed_gbps)
self.assertEqual([sushy.Protocol.PCIe],
self.controller.controller_protocols)
self.assertEqual([sushy.Protocol.SAS, sushy.Protocol.SATA],
self.controller.device_protocols)
self.assertEqual([sushy.RAIDType.RAID0, sushy.RAIDType.RAID1],
self.controller.raid_types)
self.assertEqual('1', self.controller.pending_settings.identity)
self.assertEqual([sushy.ApplyTime.IMMEDIATE, sushy.ApplyTime.ON_RESET],
self.controller.supported_apply_times)
def test_update(self):
mock_response = mock.Mock()
mock_response.status_code = http_client.ACCEPTED
mock_response.headers = {'Content-Length': 42,
'Location': '/Task/545',
'Retry-After': 20,
'Allow': 'DELETE'}
mock_response.content = None
self.controller._conn.patch.return_value = mock_response
tm = self.controller.update(
{'ControllerRates': {'ConsistencyCheckRatePercent': 30}},
apply_time=sushy.ApplyTime.ON_RESET)
self.controller._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1/Settings',
data={'ControllerRates': {'ConsistencyCheckRatePercent': 30},
'@Redfish.SettingsApplyTime': {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': 'OnReset'}})
self.assertIsInstance(tm, taskmonitor.TaskMonitor)
self.assertEqual('/Task/545', tm.task_monitor_uri)
class ControllerCollectionTestCase(base.TestCase):
def setUp(self):
super(ControllerCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('sushy/tests/unit/json_samples/'
'storage_controller_collection.json') as f:
self.json_doc = json.load(f)
with open('sushy/tests/unit/json_samples/'
'storage_controller.json') as f:
self.json_doc_ctrl = json.load(f)
self.conn.get.return_value.json.return_value = self.json_doc
self.ctrl_col = controller.ControllerCollection(
self.conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.ctrl_col._parse_attributes(self.json_doc)
self.assertEqual((
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1',),
self.ctrl_col.members_identities)
@mock.patch.object(controller, 'StorageController', autospec=True)
def test_get_member(self, mock_controller):
self.ctrl_col.get_member(
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1')
mock_controller.assert_called_once_with(
self.ctrl_col._conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1',
redfish_version=self.ctrl_col.redfish_version, registries=None,
root=self.ctrl_col.root)
@mock.patch.object(controller, 'StorageController', autospec=True)
def test_get_members(self, mock_controller):
members = self.ctrl_col.get_members()
mock_controller.assert_called_once_with(
self.ctrl_col._conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Controllers/1',
redfish_version=self.ctrl_col.redfish_version, registries=None,
root=self.ctrl_col.root)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))
def test_summary(self):
self.conn.get.return_value.json.return_value = self.json_doc_ctrl
self.assertEqual({'1': {'Health': sushy.Health.OK,
'State': sushy.State.ENABLED}},
self.ctrl_col.summary)

View File

@@ -16,6 +16,7 @@ from unittest import mock
import sushy
from sushy.resources import constants as res_cons
from sushy.resources.system.storage import controller
from sushy.resources.system.storage import drive
from sushy.resources.system.storage import storage
from sushy.resources.system.storage import volume
@@ -43,6 +44,12 @@ class StorageTestCase(base.TestCase):
self.conn = mock.Mock()
with open('sushy/tests/unit/json_samples/storage.json') as f:
self.json_doc = json.load(f)
with open('sushy/tests/unit/json_samples/'
'storage_controller_collection.json') as f:
self.json_doc_ctrl_col = json.load(f)
with open('sushy/tests/unit/json_samples/'
'storage_controller.json') as f:
self.json_doc_ctrl = json.load(f)
self.conn.get.return_value.json.return_value = self.json_doc
@@ -136,6 +143,16 @@ class StorageTestCase(base.TestCase):
self.assertEqual([sushy.RAIDType.RAID0, sushy.RAIDType.RAID1],
controller.raid_types)
def test_controllers(self):
self.conn.get.return_value.json.side_effect = [
self.json_doc_ctrl_col,
self.json_doc_ctrl]
controllers = self.storage.controllers
self.assertIsInstance(controllers, controller.ControllerCollection)
self.assertEqual(1, len(controllers.get_members()))
controller1 = controllers.get_members()[0]
self.assertEqual('1', controller1.identity)
def test_drives_after_refresh(self):
self.storage.refresh()
self.conn.get.return_value.json.reset_mock()

View File

@@ -118,23 +118,7 @@ class BiosTestCase(base.TestCase):
parser.parse('2020-09-01T04:30:00-06:00')},
attributes.get('maintenance_window'))
def test_set_attribute(self):
self.sys_bios.set_attribute('ProcTurboMode', 'Disabled')
self.sys_bios._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
data={'Attributes': {'ProcTurboMode': 'Disabled'}})
def test_set_attribute_apply_time(self):
self.sys_bios.set_attribute('ProcTurboMode', 'Disabled',
res_cons.ApplyTime.ON_RESET)
self.sys_bios._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
data={'Attributes': {'ProcTurboMode': 'Disabled'},
'@Redfish.SettingsApplyTime': {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': 'OnReset'}})
def test_set_attribute_apply_time_with_maintenance_window(self):
self.sys_bios.set_attribute(
'ProcTurboMode', 'Disabled',
res_cons.ApplyTime.IN_MAINTENANCE_WINDOW_ON_RESET,
@@ -166,26 +150,6 @@ class BiosTestCase(base.TestCase):
self.assertTrue(self.conn.get.called)
def test_set_attributes(self):
self.sys_bios.set_attributes({'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'})
self.sys_bios._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
data={'Attributes': {'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'}})
def test_set_attributes_apply_time(self):
self.sys_bios.set_attributes({'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'},
res_cons.ApplyTime.IMMEDIATE)
self.sys_bios._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
data={'Attributes': {'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'},
'@Redfish.SettingsApplyTime': {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': 'Immediate'}})
def test_set_attributes_apply_time_with_maintenance_window(self):
self.sys_bios.set_attributes(
{'ProcTurboMode': 'Disabled', 'UsbControl': 'UsbDisabled'},
res_cons.ApplyTime.AT_MAINTENANCE_WINDOW_START,
@@ -201,30 +165,6 @@ class BiosTestCase(base.TestCase):
'MaintenanceWindowStartTime': '2020-09-01T04:30:00',
'MaintenanceWindowDurationInSeconds': 600}})
def test_set_attributes_apply_time_missing(self):
self.assertRaises(ValueError,
self.sys_bios.set_attributes,
{'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'},
maint_window_start_time=datetime.datetime.now(),
maint_window_duration=600)
def test_set_attributes_maint_window_start_time_missing(self):
self.assertRaises(ValueError,
self.sys_bios.set_attributes,
{'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'},
res_cons.ApplyTime.AT_MAINTENANCE_WINDOW_START,
maint_window_duration=600)
def test_set_attributes_maint_window_duration_missing(self):
self.assertRaises(ValueError,
self.sys_bios.set_attributes,
{'ProcTurboMode': 'Disabled',
'UsbControl': 'UsbDisabled'},
res_cons.ApplyTime.AT_MAINTENANCE_WINDOW_START,
datetime.datetime.now())
def test_set_attributes_on_refresh(self):
self.conn.get.reset_mock()
# make it to instantiate pending attributes

View File

@@ -13,10 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import json
from unittest import mock
import sushy
from sushy import exceptions
from sushy.resources import base as resource_base
from sushy.resources.system import system
@@ -244,3 +245,47 @@ class CacheTestCase(base.TestCase):
expected = {'UserName': 'admin', 'Password': '***',
'nested': {'answer': 42, 'password': '***'}}
self.assertEqual(expected, utils.sanitize(orig))
class ProcessApplyTimeTestCase(base.TestCase):
def test_process_apply_time_input(self):
payload = utils.process_apply_time_input(
{'test': 'value'},
sushy.ApplyTime.ON_RESET, None, None)
self.assertEqual(
{'@Redfish.SettingsApplyTime': {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': 'OnReset'},
'test': 'value'}, payload)
def test_process_apply_time_input_maintenance_window(self):
payload = utils.process_apply_time_input(
{'test': 'value'},
sushy.ApplyTime.AT_MAINTENANCE_WINDOW_START,
datetime.datetime(2020, 9, 1, 4, 30, 0),
600)
self.assertEqual(
{'@Redfish.SettingsApplyTime': {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': 'AtMaintenanceWindowStart',
'MaintenanceWindowDurationInSeconds': 600,
'MaintenanceWindowStartTime': '2020-09-01T04:30:00'},
'test': 'value'}, payload)
def test_process_apply_time_missing(self):
self.assertRaises(
ValueError, utils.process_apply_time_input,
{'test': 'value'}, None, datetime.datetime(2020, 9, 1, 4, 30, 0),
600)
def test_process_apply_time_maint_window_start_time_missing(self):
self.assertRaises(
ValueError, utils.process_apply_time_input, {'test': 'value'},
sushy.ApplyTime.AT_MAINTENANCE_WINDOW_START, None, 600)
def test_process_apply_time_maint_window_duration_missing(self):
self.assertRaises(
ValueError, utils.process_apply_time_input, {'test': 'value'},
sushy.ApplyTime.AT_MAINTENANCE_WINDOW_START,
datetime.datetime.now(), None)

View File

@@ -19,6 +19,7 @@ import logging
import threading
from sushy import exceptions
from sushy.resources import constants as res_cons
LOG = logging.getLogger(__name__)
@@ -352,3 +353,45 @@ def sanitize(item):
for key, value in item.items()}
else:
return item
def process_apply_time_input(
payload, apply_time, maint_window_start_time, maint_window_duration):
"""Validates apply time input for asynchronous operations
:param payload: Payload for which to process apply time settings
:param apply_time: When to update the attribute. Optional.
An :py:class:`sushy.ApplyTime` value.
:param maint_window_start_time: The start time of a maintenance window,
datetime. Required when updating during maintenance window and
default maintenance window not set by the system.
:param maint_window_duration: Duration of maintenance time since
maintenance window start time in seconds. Required when updating
during maintenance window and default maintenance window not
set by the system.
:raises ValueError: When input apply time settings incorrect
:returns: Payload with adjusted apply time settings if valid
"""
if (not apply_time
and (maint_window_start_time or maint_window_duration)):
raise ValueError('"apply_time" missing when passing maintenance '
'window settings')
if apply_time:
prop = '@Redfish.SettingsApplyTime'
payload[prop] = {
'@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
'ApplyTime': res_cons.ApplyTime(apply_time).value,
}
if maint_window_start_time and not maint_window_duration:
raise ValueError('"maint_window_duration" missing')
if not maint_window_start_time and maint_window_duration:
raise ValueError('"maint_window_start_time" missing')
if maint_window_start_time and maint_window_duration:
payload[prop]['MaintenanceWindowStartTime'] =\
maint_window_start_time.isoformat()
payload[prop]['MaintenanceWindowDurationInSeconds'] =\
maint_window_duration
return payload