def get_pmdu_chassis (): view_helper.run_pre_check (pre_check.pre_check_function_call, command_name_enum.get_rm_state) if ((pre_check.get_mode () == rm_mode_enum.rowmanager) or (pre_check.get_mode () == rm_mode_enum.standalone_rackmanager)): board = "row_pib" else: board = "rm_pib" query = [ (controls.manage_rack_manager.read_fru, {"boardtype" : board}) ] result = execute_get_request_queries (query) return view_helper.return_redfish_resource ("pmdu_chassis", values = result)
def append_rack_manager_configuration(result): """ Append the current rack manager configuration to the set of response information. :param result: The dictionary that contains the information to provide in the response. This will be updated to include the current configuration. """ result[manager_config_key] = get_mode()
def get_pmdu_power_control (): view_helper.run_pre_check (pre_check.pre_check_function_call, command_name_enum.get_rm_state) if (pre_check.get_mode () == rm_mode_enum.rowmanager): query = [ (get_all_power_control_status, {"port_type" : "rack", "count" : 24}) ] elif (pre_check.get_mode () == rm_mode_enum.standalone_rackmanager): query = [ (get_all_power_control_status, {"port_type" : "pdu", "count" : 24}) ] else: query = [ (get_all_power_control_status, {"port_type" : "pdu", "count" : 48}), (get_all_power_control_status, {"port_type" : "relay", "count" : 4}) ] result = execute_get_request_queries (query) return view_helper.return_redfish_resource ("pmdu_power_control", values = result)
def process_command(command): """ Extract the command parameters and execute the command. :param command: The command being executed. """ try: handler = COMMANDS.get(command.lower(), None) if (not handler): raise HTTPError(status=404) parameters = {} for name, value in request.query.iteritems(): parameters[name.lower()] = value.lower() execute = handler(parameters) execute.pre_check() if (pre_check.get_mode() != rm_mode_enum.rowmanager): result = execute.get_response() else: result = execute.get_row_manager() result = result.format()[0] response.content_type = "application/xml" response.status = 200 response.body = [ElementTree.tostring(result)] return response except (HTTPResponse, HTTPError): raise except: ocslog.log_exception() raise HTTPError(status=500)
def get_rack_manager (patch = dict ()): if (not patch): view_helper.run_pre_check (pre_check.pre_check_function_call, command_name_enum.get_rm_state) query = [ (controls.manage_rack_manager.show_rack_manager_hostname, {}), (controls.manage_fwversion.get_ocsfwversion, {}), (controls.manage_rack_manager.manager_tftp_server_status, {}), (controls.manage_rack_manager.manager_nfs_server_status, {}), (controls.manage_rack_manager.get_rack_manager_ntp_status, {}), (controls.manage_rack_manager.get_rack_manager_itp_status, {}), (controls.manage_rack_manager.get_rack_manager_ntp_server, {}), (controls.manage_rack_manager.get_manager_throttle_local_bypass, {}), (controls.manage_rack_manager.get_manager_throttle_output_enable, {}), (controls.manage_rack_manager.show_rack_manager_time, {"edm" : True}), (controls.manage_rack_manager.get_rm_uptime, {}) ] if (pre_check.get_mode () == rm_mode_enum.rowmanager): query.append ((controls.manage_rack_manager.get_row_throttle_bypass, {})) query.append ((controls.manage_rack_manager.get_row_throttle_output_enable, {})) result = execute_get_request_queries (query) for key in ["TFTPStatus", "NFSStatus", "NTPState", "ITPState"]: if (key in result): result[key] = enums.ServiceStatus (result[key], convert = True) for key in ["TFTPService", "NFSService", "NTPService", "ITPService", "Local_Bypass", "Row_Bypass", "Local_Enable", "Row_Enable"]: if (key in result): result[key] = enums.Boolean (result[key], convert = True) view_helper.update_and_replace_status_information (result, patch) return view_helper.return_redfish_resource ("rack_manager", values = result)
# Copyright (C) Microsoft Corporation. All rights reserved. # This program is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. import sys sys.path.append ("/usr/lib/commonapi") import ocslog import commands from ocsrest import pre_check from bottle import Bottle, request from pre_settings import rm_mode_enum try: ocslog.initialize_log (ocslog.loglevel_t_enum.INFO_LEVEL) except Exception as error: print "Failed to initialize the ocslog", error pre_check.set_op_mode () ocslog.log_info ("Running Legacy REST in configuration", pre_check.get_mode ()) app = Bottle (__name__) app.route (path = "/<command>", method = "GET", callback = commands.process_command)
sys.path.append("/usr/lib/commonapi") import ocslog import bottle import resources import view_helper from ocsrest import pre_check try: ocslog.initialize_log(ocslog.loglevel_t_enum.INFO_LEVEL) except Exception as error: print "Failed to initialize the ocslog", error pre_check.set_op_mode() ocslog.log_info("Running REST in configuration", pre_check.get_mode()) class msocs_bottle(bottle.Bottle): def default_error_handler(self, res): bottle.response.content_type = "application/json" return view_helper.get_error_body(res.status_code, msg=res.body) app = msocs_bottle(__name__) resources.add_bottle_filters(app) for name, resource in resources.REDFISH_RESOURCES.iteritems(): resource.register_resource(app, pre_check.get_mode(), name) systems_app = msocs_bottle(__name__) resources.add_bottle_filters(systems_app)
def patch_rack_manager(): view_helper.run_pre_check(pre_check.pre_check_function_call, command_name_enum.set_rm_config) actions = { "DateTime": (controls.manage_rack_manager.set_rack_manager_time, parameter_parser("datetime", str, validate_datetime), {}), "Oem/Microsoft/HostName": (controls.manage_rack_manager.set_hostname, parameter_parser("hostname", str), {}), "Oem/Microsoft/TFTP/ServiceStatus": (controls.manage_rack_manager.set_manager_tftp_service_state, parameter_parser("state", str, enums.ServiceStatus), {}), "Oem/Microsoft/TFTP/ServiceEnabled": (controls.manage_rack_manager.set_manager_tftp_service_config, parameter_parser("enable", bool, parameter_parser.validate_bool), {}), "Oem/Microsoft/NFS/ServiceStatus": (controls.manage_rack_manager.set_manager_nfs_service_state, parameter_parser("state", str, enums.ServiceStatus), {}), "Oem/Microsoft/NFS/ServiceEnabled": (controls.manage_rack_manager.set_manager_nfs_service_config, parameter_parser("enable", bool, parameter_parser.validate_bool), {}), "Oem/Microsoft/NTP/ServiceStatus": (controls.manage_rack_manager.set_manager_ntp_service_state, parameter_parser("state", str, enums.ServiceStatus), {}), "Oem/Microsoft/NTP/ServiceEnabled": (controls.manage_rack_manager.set_manager_ntp_service_config, parameter_parser("enable", bool, parameter_parser.validate_bool), {}), "Oem/Microsoft/NTP/TimeServer": (controls.manage_rack_manager.set_rack_manager_ntp_server, parameter_parser("server_ip", str, IPAddress), {}), "Oem/Microsoft/ThrottleControl/LocalBypass": (controls.manage_rack_manager.set_manager_throttle_local_bypass, parameter_parser("enable", bool, parameter_parser.validate_bool), {}), "Oem/Microsoft/ThrottleControl/LocalEnable": (controls.manage_rack_manager.set_manager_throttle_output_enable, parameter_parser("enable", bool, parameter_parser.validate_bool), {}) } if (not pre_check.get_mode() == rm_mode_enum.rowmanager): actions.update({ "Oem/Microsoft/RemoteITP/ServiceStatus": (controls.manage_rack_manager.set_manager_itp_service_state, parameter_parser("state", str, enums.ServiceStatus), {}), "Oem/Microsoft/RemoteITP/ServiceEnabled": (controls.manage_rack_manager.set_manager_itp_service_config, parameter_parser("enable", bool, parameter_parser.validate_bool), {}) }) else: actions.update({ "Oem/Microsoft/ThrottleControl/RowBypass": (controls.manage_rack_manager.set_row_throttle_bypass, parameter_parser("enable", bool, parameter_parser.validate_bool), {}), "Oem/Microsoft/ThrottleControl/RowEnable": (controls.manage_rack_manager.set_row_throttle_output_enable, parameter_parser("enable", bool, parameter_parser.validate_bool), {}) }) result = validate_patch_request_and_execute(actions, "rack_manager") return get_handler.get_rack_manager(patch=result)