Exemplo n.º 1
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
Exemplo n.º 2
0
    def run(self, args):

        init_args(args, self.args_lst)
        url = "/redfish/v1/AccountService/Roles"
        client = RedfishClient(args)
        resp = client.send_request("GET", url)
        if (not isinstance(resp, dict)
                or Constant.SUCCESS_200 != resp.get("status_code", None)):
            self.err_list.append("Failure: get role information failed")
            raise FailException(*self.err_list)

        role_url_list = list()
        if args.role is None:
            members = resp["resource"].get("Members", None)
            if members and isinstance(members, list):
                for member in members:
                    role_url_list.append(member.get("@odata.id", None))
        else:
            url = "%s/%s" % (url, args.role)
            role_url_list.append(url)
        role_list = list()
        for role_url in role_url_list:
            role_resp = client.send_request("GET", role_url)
            if (isinstance(role_resp, dict)
                    and Constant.SUCCESS_200 == role_resp.get(
                        "status_code", None)):
                role = Role()
                role.pack_role_resource(role_resp["resource"])
                role_list.append(role)
            else:
                self.err_list.append("Failure: get role information failed")
                raise FailException(*self.err_list)
        self.roles = role_list

        return self.suc_list
Exemplo n.º 3
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
Exemplo n.º 4
0
    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
Exemplo n.º 5
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
Exemplo n.º 6
0
    def run(self, args):

        client = RedfishClient(args)
        url = "/redfish/v1/EventService/Subscriptions"
        resp = client.send_request("get", url)
        event_sub_list = []
        if (isinstance(resp, dict) and resp.get("status_code", None) in
                Constant.SUC_CODE):
            members = resp["resource"].get("Members", None)
            for member in members:
                url = member.get("@odata.id", None)
                resp = client.send_request("GET", url)
                if (isinstance(resp, dict) and
                        resp.get("status_code", None) in Constant.SUC_CODE):
                    event_sub = EventSub()
                    event_sub.pack_redfish_resource(resp["resource"])
                    event_sub_list.append(event_sub)
                else:
                    self.err_list.append("Failure: failed to get event "
                                         "subscription details")
                    raise FailException(*self.err_list)
            try:
                event_sub_list = sorted(
                    event_sub_list, key=lambda s: int(s.id))
            except (KeyError, ValueError, Exception) as err:
                self.err_list.append(str(err))
                raise FailException(*self.err_list)
        else:
            self.err_list.append("Failure: failed to get event subscription "
                                 "information collection")
            raise FailException(*self.err_list)
        self.subscriber = event_sub_list
        if not self.subscriber:
            suc_info = ("Success: "
                        "event subscription information collection is empty")
            self.suc_list.append(suc_info)
        return self.suc_list
    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
Exemplo n.º 8
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
Exemplo n.º 9
0
    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
Exemplo n.º 10
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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    def run(self, args):

        init_args(args, self.args_lst)
        if globalvar.HDM_VERSION < "2.08.00":
            err = "Failure: this hdm version does not support this command"
            self.err_list.append(err)
            raise FailException(*self.err_list)
        else:
            payload = self._parse_args(args)
            url = "/redfish/v1/AccountService/Roles/%s" % args.role_id
            client = RedfishClient(args)
            resp = client.send_request("PATCH", url, payload)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                suc = "Success: set user role information successfully"
                self.suc_list.append(suc)
            else:
                err = "Failure: failed to set user role information"
                self.err_list.append(err)
                raise FailException(*self.err_list)

        return self.suc_list
Exemplo n.º 13
0
    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