def patch_bmc_ethernet (slot_id, eth): pre_check_slot_id(slot_id) if (eth == "eth1"): raise HTTPError (status = 405) requested = view_helper.get_json_request_data () if ("IPv4Addresses" in requested): address = requested["IPv4Addresses"] if (len (address) > 1): raise HTTPError (status = 400, body = "No more than one IP address may be specified.") ip_args = {} actions = { "IPv4Addresses/[0]/Address" : (apply_ip_address, parameter_parser ("address", str, IPAddress), {"args" : ip_args}), "IPv4Addresses/[0]/SubnetMask" : (apply_ip_address, parameter_parser ("mask", str, parameter_parser.validate_subnet_mask), {"args" : ip_args}), "IPv4Addresses/[0]/Gateway" : (apply_ip_address, parameter_parser ("gateway", str, IPAddress), {"args" : ip_args}), "IPv4Addresses/[0]/AddressOrigin" : (apply_ip_address, parameter_parser ("addr_type", str, enums.AddressOrigin), {"args" : ip_args}) } result = validate_patch_request_and_execute (actions, "bmc_ethernet") if (not result): set_data = apply_ip_address (save_args = False, args = ip_args) view_helper.append_response_information (result, set_data) return get_handler.get_rack_manager_ethernet (eth, patch = result)
def patch_pmdu_power_meter(): view_helper.run_pre_check(pre_check.pre_check_function_call, command_name_enum.set_rm_state) throttle_args = {} actions = { "DatacenterThrottleEnabled": (apply_power_throttle, parameter_parser("dcpolicy", int, enums.Boolean), { "args": throttle_args }), "AlertEnabled": (apply_power_throttle, parameter_parser("policy", int, enums.Boolean), { "args": throttle_args }), "AlertLimitWatts": (controls.manage_powermeter.set_rack_power_limit_policy, parameter_parser("powerlimit", float), {}) } result = validate_patch_request_and_execute(actions, "pmdu_power_meter") throttle = apply_power_throttle(force_set=True, args=throttle_args) view_helper.append_response_information(result, throttle) return get_handler.get_pmdu_power_meter(patch=result)
def get_system_thermal (system): system = int (system) view_helper.run_pre_check (pre_check.pre_check_function_call, command_name_enum.get_blade_state, device_id = system) query_temp = [ (controls.server_health.show_temperature_health, {"serverid" : system}) ] query_fan = [ (controls.server_health.show_fan_health, {"serverid" : system}) ] result_temp = execute_get_request_queries (query_temp) result_fan = execute_get_request_queries (query_fan) temps = parse_sensor_list (sensors = result_temp, convert_reading = True, convert_number = True, sensor_type = "Sensor") fans = parse_sensor_list (sensors = result_fan, convert_reading = True, convert_number = False, sensor_type = "Fan") result = {} view_helper.append_response_information (result, result_temp) view_helper.append_response_information (result, result_fan) if (temps): result["temps"] = temps if (fans): result["fans"] = fans result["ID"] = system return view_helper.return_redfish_resource ("system_thermal", values = result)
def patch_system_power(system): system = int(system) view_helper.run_pre_check(pre_check.pre_check_function_call, command_name_enum.set_blade_config, device_id=system) limit_args = {} actions = { "PowerControl/[0]/PowerLimit/LimitInWatts": (controls.manage_ocspower.set_server_power_limit, parameter_parser("powerlimitvalue", int), { "serverid": system }), "PowerControl/[0]/Oem/Microsoft/DefaultLimitInWatts": (apply_default_power_limit, parameter_parser("power_limit", int), { "server_id": system, "args": limit_args }), "PowerControl/[0]/Oem/Microsoft/AutoRemoveDelayInSec": (apply_default_power_limit, parameter_parser("auto_remove", int), { "server_id": system, "args": limit_args }), "PowerControl/[0]/Oem/Microsoft/FastThrottleDurationInMs": (apply_default_power_limit, parameter_parser("ms_delay", int), { "server_id": system, "args": limit_args }), "PowerControl/[0]/Oem/Microsoft/AlertAction": (controls.manage_ocspower.set_server_activate_psu_alert, parameter_parser("alert_action", int, enums.AlertAction), { "serverid": system }) } result = validate_patch_request_and_execute(actions, "system_power") limit = apply_default_power_limit(server_id=system, force_set=True, args=limit_args) view_helper.append_response_information(result, limit) return get_handler.get_system_power(system, patch=result)
def execute_get_request_queries(query_list, init_values=dict()): """ Handler for all get requests to query the system for necessary information. :param query_list: A list of functions to be called that will provide the information required for the request. Each function is a pair that contains the function to call and dictionary of arguments. :param init_values: The initial set of response information. :return A dictionary containing the information for generating the response object. """ result = init_values.copy() for query in query_list: try: query_data = query[0](**query[1]) view_helper.append_response_information(result, query_data) except Exception as error: view_helper.append_response_information( result, set_failure_dict(str(error), completion_code.failure)) return view_helper.replace_key_spaces(result)
def patch_system(system): system = int(system) view_helper.run_pre_check(pre_check.pre_check_function_call, command_name_enum.set_blade_state, device_id=system) next_boot_args = {"serverid": system} actions = { "Boot/BootSourceOverrideTarget": (apply_blade_next_boot, parameter_parser("boottype", str, enums.BootSourceOverrideTarget, {"cmd_arg": True}), { "args": next_boot_args }), "Boot/BootSourceOverrideMode": (apply_blade_next_boot, parameter_parser("mode", int, enums.BootSourceOverrideMode), { "args": next_boot_args }), "Oem/Microsoft/TPMPhysicalPresence": (controls.bladetpmphypresence_lib.set_tpm_physical_presence, parameter_parser("presence", int, enums.Boolean), { "serverid": system }), "Oem/Microsoft/DefaultPowerState": (controls.bladepowerstate_lib.set_server_default_powerstate, parameter_parser("state", str, enums.PowerState), { "serverid": system }) } result = validate_patch_request_and_execute(actions, "system") next_boot = apply_blade_next_boot(force_set=True, args=next_boot_args) view_helper.append_response_information(result, next_boot) return get_handler.get_system(system, patch=result)
def get_all_power_control_status (port_type, count): """ Get the status for all power control ports of a single type. :param port_type: The port type to query. :param count: The number of ports. :return A dictionary with the operation result. """ status = [dict () for _ in range (0, count)] result = {} if (port_type == "relay"): for i in range (0, count): state = controls.manage_powerport.powerport_get_port_status (i + 1, port_type) if (state[completion_code.cc_key] == completion_code.success): status[i].update (state) if ("Relay" in status[i]): status[i]["Relay"] = enums.PowerState (status[i]["Relay"], convert = True) else: view_helper.append_response_information (result, state) else: start = 24 if (port_type == "rack") else 0 end = 24 + count if (port_type == "rack") else count present = controls.manage_powerport.powerport_get_all_port_presence (raw = True, ports = range (start, end)) if (present[completion_code.cc_key] == completion_code.success): for i in range (0, count): status[i]["Port Presence"] = enums.Boolean (present[i + 1], convert = True) else: view_helper.append_response_information (result, present) state = controls.manage_powerport.powerport_get_all_port_status (raw = True) if (state[completion_code.cc_key] == completion_code.success): for i in range (0, count): status[i]["Port State"] = enums.PowerState (state[i + 1], convert = True) if (port_type == "rack"): for i, j in enumerate (range (count + 1, (count * 2) + 1)): status[i]["Boot Strap"] = enums.BootStrapping (state[j], convert = True) else: view_helper.append_response_information (result, state) result[port_type + "_ports"] = status return result
def execute_patch_request_actions(requested, action_map, tree=[]): """ Handler for all patch requests to change system parameters based on received information. :param requested: A dictionary that contains the set of system parameters to change. :param action_map: A mapping of the function to call for each parameter that can be set. Each mapping contains a tuple that has a function pointer, parameter parser, and additional arguments that should be passed to the function. :param tree: The ancestry of the current set of request properties. :return A result dictionary to be used to generate the response. """ result = {} if requested is not None: for param, value in requested.items(): if ("@" not in param): try: if (hasattr(value, "keys")): parents = list(tree) parents.append(param) action_data = execute_patch_request_actions(value, action_map, tree=parents) view_helper.append_response_information(result, action_data) elif (isinstance(value, list)): for i, entry in enumerate(value): parents = list(tree) parents.append(param) parents.append("[{0}]".format(i)) action_data = execute_patch_request_actions(entry, action_map, tree=parents) view_helper.append_response_information(result, action_data) i = i + 1 else: action = "" if len(tree): action = "/".join(tree) + "/" action = action + param if (action in action_map): call = action_map[action] args = call[2].copy() try: call[1].parse_parameter(value, args) except TypeError as error: view_helper.append_invalid_property_type(result, action.split("/")) continue except Exception as error: view_helper.append_invalid_property_value(result, action.split("/"), str(error)) continue action_data = call[0](**args) view_helper.append_response_information(result, action_data) else: view_helper.append_read_only_property(result, action.split("/")) except Exception as error: view_helper.append_response_information( result, set_failure_dict(str(error), completion_code.failure)) return result
def patch_rack_manager_ethernet(eth): view_helper.run_pre_check(pre_check.pre_check_function_call, command_name_enum.set_rm_config) requested = view_helper.get_json_request_data() if ("IPv4Addresses" in requested): address = requested["IPv4Addresses"] if (len(address) > 1): raise HTTPError( status=400, body="No more than one IP address may be specified.") ip_args = {} mgmt_args = {} actions = { "IPv4Addresses/[0]/Address": (apply_ip_address, parameter_parser("address", str, IPAddress), { "args": ip_args }), "IPv4Addresses/[0]/SubnetMask": (apply_ip_address, parameter_parser("mask", str, parameter_parser.validate_subnet_mask), { "args": ip_args }), "IPv4Addresses/[0]/AddressOrigin": (apply_ip_address, parameter_parser("addr_type", str, enums.AddressOrigin), { "args": ip_args }) } if (eth == "eth0"): actions.update({ "IPv4Addresses/[0]/Gateway": (apply_ip_address, parameter_parser("gateway", str, IPAddress), { "args": ip_args }), }) else: actions.update({ "Oem/Microsoft/MgmtGateway": (apply_management_gateway, parameter_parser("gateway", str, IPAddress), { "args": mgmt_args }), "Oem/Microsoft/MgmtNetmask": (apply_management_gateway, parameter_parser("mask", str, parameter_parser.validate_subnet_mask), { "args": mgmt_args }) }) result = validate_patch_request_and_execute(actions, "rack_manager_ethernet", default_params={"Intf": eth}) if (not result): if (ip_args): ip_args["if_name"] = eth set_data = apply_ip_address(save_args=False, args=ip_args) view_helper.append_response_information(result, set_data) if (mgmt_args): set_data = apply_management_gateway(save_args=False, args=mgmt_args) view_helper.append_response_information(result, set_data) return get_handler.get_rack_manager_ethernet(eth, patch=result)