diff --git a/README.md b/README.md index a2042ea..ae6097d 100644 --- a/README.md +++ b/README.md @@ -247,17 +247,19 @@ The tool will then perform an operation on the `Boot` object within the matching ``` usage: rf_manager_config.py [-h] --user USER --password PASSWORD --rhost RHOST [--manager MANAGER] - {info,reset,getnet,setnet} ... + {info,reset,getnet,setnet,resettodefaults,settime} + ... A tool to manage managers in a service positional arguments: - {info,reset,getnet,setnet,resettodefaults} + {info,reset,getnet,setnet,resettodefaults,settime} info Displays information about a manager reset Resets a manager getnet Displays information about an Ethernet interface setnet Configures an Ethernet interface - resettodefaults Resets a manager to default setting + resettodefaults Resets a manager to default settings + settime Sets the date-time on a manager required arguments: --user USER, -u USER The user name for authentication @@ -307,12 +309,34 @@ optional arguments: Example: `rf_manager_config.py -u root -p root -r https://192.168.1.100 reset -t GracefulRestart` The tool will log into the service specified by the *rhost* argument using the credentials provided by the *user* and *password* arguments. -It then traverses the manager collection for the service to find the matching system specified by the *manager* argument. +It then traverses the manager collection for the service to find the matching manager specified by the *manager* argument. It will perform the `Reset` action with the specified reset type from the *type* argument. * If *manager* is not specified, and if the service has exactly one manager, it will perform the operation on the one manager. * If *type* is not specified, it will attempt a `GracefulRestart`. +#### Set Time + +``` +usage: rf_manager_config.py settime [-h] [--datetime DATETIME] [--offset OFFSET] + +options: + -h, --help show this help message and exit + --datetime DATETIME, -dt DATETIME + The date-time value to set + --offset OFFSET, -o OFFSET + The date-time offset value to set +``` + +Example: `rf_manager_config.py -u root -p root -r https://192.168.1.100 settime -dt 2023-07-27T12:00:00-05:00` + +Example: `rf_manager_config.py -u root -p root -r https://192.168.1.100 settime -o=-05:00` + +The tool will log into the service specified by the *rhost* argument using the credentials provided by the *user* and *password* arguments. +It will then locate the manager specified by the *manager* argument, and applies the *datetime* and *offset* values to the manager instance. +* If *manager* is not specified, and if the service has exactly one manager, it will perform the operation on the one manager. + + #### Get Network Interface ``` diff --git a/redfish_utilities/__init__.py b/redfish_utilities/__init__.py index 281979f..9055fb4 100644 --- a/redfish_utilities/__init__.py +++ b/redfish_utilities/__init__.py @@ -30,6 +30,7 @@ from .logs import download_diagnostic_data from .managers import get_manager_ids from .managers import get_manager +from .managers import set_manager from .managers import print_manager from .managers import get_manager_reset_info from .managers import manager_reset diff --git a/redfish_utilities/managers.py b/redfish_utilities/managers.py index 29999c6..056de41 100644 --- a/redfish_utilities/managers.py +++ b/redfish_utilities/managers.py @@ -96,6 +96,39 @@ def get_manager( context, manager_id = None ): verify_response( manager ) return manager +def set_manager( context, manager_id = None, date_time = None, date_time_offset = None ): + """ + Finds a manager matching the given identifier and sets one or more properties + + Args: + context: The Redfish client object with an open session + manager_id: The manager to locate; if None, perform on the only manager + date_time: The date-time value to set + date_time_offset: The date-time offset value to set + + Returns: + The response of the PATCH + """ + + # Locate the manager + manager = get_manager( context, manager_id ) + + # Build the payload + payload = {} + if date_time is not None: + payload["DateTime"] = date_time + if date_time_offset is not None: + payload["DateTimeOffset"] = date_time_offset + + # Update the manager + headers = None + etag = manager.getheader( "ETag" ) + if etag is not None: + headers = { "If-Match": etag } + response = context.patch( manager.dict["@odata.id"], body = payload, headers = headers ) + verify_response( response ) + return response + def print_manager( manager ): """ Prints the manager info diff --git a/scripts/rf_manager_config.py b/scripts/rf_manager_config.py index 63afc88..7a05566 100644 --- a/scripts/rf_manager_config.py +++ b/scripts/rf_manager_config.py @@ -47,6 +47,9 @@ reset_to_defaults_argget = subparsers.add_parser( "resettodefaults", help = "Resets a manager to default settings" ) reset_to_defaults_argget.add_argument( "--type", "-t", type = str, help = "The type of reset-to-defaults operation to perform", choices = redfish_utilities.reset_to_defaults_types ) reset_to_defaults_argget.add_argument( "--info", "-info", action = "store_true", help = "Indicates if reset-to-defaults information should be reported" ) +set_time_argget = subparsers.add_parser( "settime", help = "Sets the date-time on a manager" ) +set_time_argget.add_argument( "--datetime", "-dt", type = str, help = "The date-time value to set" ) +set_time_argget.add_argument( "--offset", "-o", type = str, help = "The date-time offset value to set" ) args = argget.parse_args() if args.debug: @@ -91,6 +94,8 @@ response = redfish_utilities.manager_reset_to_defaults( redfish_obj, args.manager, args.type ) response = redfish_utilities.poll_task_monitor( redfish_obj, response ) redfish_utilities.verify_response( response ) + elif args.command == "settime": + redfish_utilities.set_manager( redfish_obj, args.manager, args.datetime, args.offset ) elif args.command == "getnet": interface = redfish_utilities.get_manager_ethernet_interface( redfish_obj, args.manager, args.id ) redfish_utilities.print_manager_ethernet_interface( interface )