コード例 #1
0
ファイル: set_bios.py プロジェクト: H3C/hdm-redfish-script
    def run(self, args):

        init_args(args, self.args_lst)
        config_dict = self.check_args(args)

        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Systems/%s/Bios" % systems_id
        resp = client.send_request("GET", url)
        if (isinstance(resp, dict)
                and resp.get("status_code") in Constant.SUC_CODE):
            attrs = resp["resource"]["Attributes"]
            for key_, value_ in config_dict.items():
                if attrs.get(key_, None) is not None:
                    if isinstance(attrs.get(key_, None), int):
                        try:
                            config_dict[key_] = int(value_)
                        except (KeyError, ValueError) as err:
                            self.err_list.append(str(err))
                            raise FailException(*self.err_list)
                else:
                    err_message = ("Failure: the BIOS setting item does "
                                   "not exist: %s" % key_)
                    self.err_list.append(err_message)
                    raise FailException(*self.err_list)
            self.result_response(client, url, config_dict)
        else:
            err_message = ("Failure: failed to get current BIOS setup "
                           "information")
            self.err_list.append(err_message)
            raise FailException(*self.err_list)
        return self.suc_list
コード例 #2
0
    def run(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Chassis/%s/Drives/AlarmThreshold" % systems_id
        resp = client.send_request("GET", url)
        if (isinstance(resp, dict)
                and resp.get("status_code", None) in Constant.SUC_CODE):
            threshold_info = resp["resource"]
            if threshold_info.get("RevBlock") is not None:
                self.reserved_block = (
                    threshold_info["RevBlock"].get("AlarmLimit"))
            if threshold_info.get("Life") is not None:
                self.remain_life_percents = (
                    threshold_info["Life"].get("AlarmLimit"))
            if threshold_info.get("PredFail") is not None:
                self.pre_fail_count = (
                    threshold_info["PredFail"].get("PredFailCnt"))
            if threshold_info.get("MediaError") is not None:
                self.media_error = (
                    threshold_info["MediaError"].get("MediaErrorCnt"))
        else:
            self.err_list.append("Failure: failed to get predictive failure "
                                 "threshold")
            raise FailException(*self.err_list)
        return self.suc_list
コード例 #3
0
    def get_info_by_redfish(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()

        global MAX_NUM
        url = "/redfish/v1/Chassis/%s" % systems_id
        resp = client.send_request("get", url)
        if (isinstance(resp, dict) and
                Constant.SUCCESS_200 == resp.get("status_code", None)):
            try:
                self.maximum = (resp["resource"]["Oem"]["Public"]
                                ["DeviceMaxNum"].get("MemoryNum"))
                MAX_NUM = True
            except (KeyError, ValueError):
                self.maximum = None

        url = "/redfish/v1/Chassis/%s/Power" % systems_id
        resp = client.send_request("get", url)
        if (isinstance(resp, dict) and
                Constant.SUCCESS_200 == resp.get("status_code", None)):
            try:
                self.total_power_watts = (resp["resource"]["PowerControl"][0]
                                          ["Oem"]["Public"].
                                          get("CurrentMemoryPowerWatts"))
            except (KeyError, ValueError):
                self.total_power_watts = None
コード例 #4
0
    def run(self, args):

        init_args(args, self.args_lst)
        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Chassis/%s/Power" % systems_id
        resp = client.send_request("get", url)
        if (isinstance(resp, dict)
                and resp.get("status_code", None) == Constant.SUCCESS_200):
            if resp["resource"].get("PowerControl", None) is not None:
                try:
                    power_metrics = (resp["resource"]["PowerControl"][0].get(
                        "PowerMetrics", None))
                    power_limit = (resp["resource"]["PowerControl"][0].get(
                        "PowerLimit", None))
                except (TypeError, ValueError, KeyError, SyntaxError) as err:
                    self.err_list.append(str(err))
                    raise FailException(*self.err_list)
                else:
                    max_value = power_metrics.get("MaxConsumedWatts")
                    min_value = power_metrics.get("MinConsumedWatts")
                    exception = power_limit.get("LimitException")
                    limit_in_watts = power_limit.get('LimitInWatts')
                    payload = self.construct_request_parameters(
                        args, max_value, min_value, limit_in_watts, exception)
                    client = RestfulClient(args)
                    try:
                        url = "/api/power/capping"
                        resp = client.send_request("POST", url, payload)
                        if (isinstance(resp, dict) and resp.get(
                                Constant.COMPLETE_CODE) == Constant.SUCCESS_0):
                            suc_info = "Success: set power limit succeed"
                            self.suc_list.append(suc_info)
                        else:
                            err_info = "Failure: set power limit failed"
                            self.err_list.append(err_info)
                            raise FailException(*self.err_list)
                    finally:
                        if client.cookie:
                            client.delete_session()
            else:
                err_info = ("Failure: the machine does not "
                            "support setting power cap")
                self.err_list.append(err_info)
                raise FailException(*self.err_list)
        else:
            err_info = "Failure: failed to get the value range of the power cap"
            self.err_list.append(err_info)
            raise FailException(*self.err_list)
        return self.suc_list
コード例 #5
0
    def run(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Chassis/%s/Power" % systems_id
        payload = construct_request_parameters(args)
        resp = client.send_request("PATCH", url, payload)
        if (isinstance(resp, dict)
                and resp.get("status_code", None) in Constant.SUC_CODE):
            suc_info = "Success: set power redundancy succeed"
            self.suc_list.append(suc_info)
        else:
            err_info = "Failure: set power redundancy failed"
            self.err_list.append(err_info)
            raise FailException(*self.err_list)
        return self.suc_list
コード例 #6
0
    def run(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()

        url = ("/redfish/v1/Managers/%s/VirtualMedia/%s" %
               (systems_id, args.type))
        resp = client.send_request("get", url)
        if isinstance(resp, dict) and resp.get("status_code",
                                               None) in Constant.SUC_CODE:
            self._pack_resource(resp["resource"])
        else:
            self.err_list.append(
                "Failure: failed to get virtual media information")
            raise FailException(*self.err_list)

        return self.suc_list
コード例 #7
0
ファイル: get_gpu.py プロジェクト: H3C/hdm-redfish-script
    def run(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Systems/%s/GPU" % systems_id
        resp = client.send_request("GET", url)
        if (isinstance(resp, dict)
                and resp.get("status_code", None) in Constant.SUC_CODE):
            self._parse_gpu_resource(resp["resource"])
            if not self.gpu:
                suc_info = "Success: GPU resource is empty"
                self.suc_list.append(suc_info)
        else:
            self.err_list.append("Failure: failed to get GPU information")
            raise FailException(*self.err_list)

        return self.suc_list
コード例 #8
0
    def run(self, args):

        init_args(args, self.args_lst)
        payload = self.check_args(args)
        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Chassis/%s/Drives/AlarmThreshold" % systems_id
        resp = client.send_request("PATCH", url, payload)
        if (isinstance(resp, dict) and resp.get("status_code") in
                Constant.SUC_CODE):
            suc_info = ("Success: successfully set the "
                        "predictive failure threshold")
            self.suc_list.append(suc_info)
        else:
            err_message = ("Failure: failure to set predictive failure "
                           "threshold")
            self.err_list.append(err_message)
            raise FailException(*self.err_list)
        return self.suc_list
コード例 #9
0
ファイル: set_ntp.py プロジェクト: H3C/hdm-redfish-script
    def run(self, args):

        init_args(args, self.args_lst)
        self._parse_args(args)

        if self.command is not None:
            ret, output = getstatusoutput(self.command)
            output = output.strip()
            if Constant.SUCCESS_0 != ret:
                self.err_list.append(output)
                err = "Failure: failed to set ntp time synchronization interval"
                self.err_list.append(err)
                raise FailException(*self.err_list)
            else:
                if "a2 63 00" == output:
                    suc = ("Success: set ntp time "
                           "synchronization interval successful")
                    self.suc_list.append(suc)
                    return self.suc_list
                else:
                    err = ("Failure: failed to set "
                           "ntp time synchronization interval")
                    self.err_list.append(err)
                    raise FailException(*self.err_list)

        payload = self._construct_param()
        if payload:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Managers/%s/NtpService" % systems_id
            resp = client.send_request('PATCH', url, payload)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                self.suc_list.append("Success: set ntp server information "
                                     "successful")
            else:
                self.err_list.append("Failure: failed to set ntp server "
                                     "information")
                raise FailException(*self.err_list)

        return self.suc_list
コード例 #10
0
ファイル: get_ntp.py プロジェクト: H3C/hdm-redfish-script
    def run(self, args):

        client = RedfishClient(args)
        systems_id = client.get_systems_id()
        url = "/redfish/v1/Managers/%s/NtpService" % systems_id
        resp = client.send_request("get", url)
        if isinstance(resp, dict) and resp.get("status_code",
                                               None) in Constant.SUC_CODE:
            resp = resp["resource"]
            self.service_enabled = resp.get("ServiceEnabled", None)
            if (isinstance(resp.get("Oem", None), dict)
                    and isinstance(resp["Oem"].get("Public", None), dict)):
                self.time_zone = resp["Oem"]["Public"].get("TimeZone", None)
                self.tertiary_ntp_server = (resp["Oem"]["Public"].get(
                    "TertiaryNtpServer", None))
            self.preferred_ntp_server = resp.get("PreferredNtpServer", None)
            self.alternate_ntp_server = resp.get("AlternateNtpServer", None)
            self.ntp_address_origin = resp.get("NtpAddressOrigin", None)
        else:
            self.err_list.append("Failure: failed to get ntp")
            raise FailException(*self.err_list)

        return self.suc_list