Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
    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
Esempio n. 6
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/settings/pef/snmp"
                resp = client.send_request("GET", url)
                if isinstance(resp, dict):
                    self._pack_b01_snmp_resource(resp)
                else:
                    err = "Failure: failed to get snmp information"
                    self.err_list.append(err)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Managers/%s/SnmpService" % systems_id
            resp = client.send_request("get", url)
            if (isinstance(resp, dict)
                    and Constant.SUCCESS_200 == resp.get("status_code", None)):
                self._pack_snmp_resource(resp["resource"])
            else:
                err = "Failure: failed to get snmp information"
                self.err_list.append(err)
                raise FailException(*self.err_list)

        return self.suc_list
Esempio n. 7
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/power/capping"
                resp = client.send_request("GET", url)
                if (isinstance(resp, dict)) and resp.get("cc") ==\
                        Constant.SUCCESS_0:
                    self.limit_in_watts = resp.get("power_meter_set", None)
                    self.limit_exception = power_meter_shutdown_dict.get(
                        resp.get("power_meter_shutdown"), None)
                    self.power_limit_enable_str = power_meter_state_dict.get(
                        resp.get("power_meter_enable"), None)
                else:
                    err_info = "Failure: failed to get power limit"
                    self.err_list.append(err_info)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            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) in Constant.SUC_CODE):
                self._pack_resource(resp["resource"])
            else:
                err_info = "Failure: failed to get power capping information"
                self.err_list.append(err_info)
                raise FailException(*self.err_list)
        return self.suc_list
Esempio n. 8
0
    def run(self, args):

        init_args(args, self.args_lst)
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            physical_disk_list = self._get_b01_physical_disk_list(client)
            if not physical_disk_list:
                suc_info = "Success: raid card resource is empty"
                self.suc_list.append(suc_info)
                return self.suc_list
        else:
            client = RedfishClient(args)
            physical_disk_list = self._get_physical_disk_list(client)

            if args.physical_id is None and not physical_disk_list:
                suc_info = "Success: raid card resource is empty"
                self.suc_list.append(suc_info)
                return self.suc_list
            if not self._get_physical_disk_detail(client, physical_disk_list,
                                                  args):
                err_info = "Failure: resource was not found"
                self.err_list.append(err_info)
                raise FailException(*self.err_list)
        client = RestfulClient(args)
        try:

            self._get_health_info(client)
        finally:
            if client.cookie:
                client.delete_session()

        return self.suc_list
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
0
    def run(self, args):

        init_args(args, self.args_lst)
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:

            client = RestfulClient(args)
            try:
                url = "/api/settings/users"
                resp = client.send_request("GET", url)
                user_id = None
                if isinstance(resp, list):
                    for info in resp:

                        if info.get("name") == "":
                            user_id = info.get("id")
                            break
                if user_id is not None:
                    self._parse_b01_args(args)
                    payload = self._construct_b01_param()
                    payload["id"] = user_id
                    url = "/api/settings/users/" + str(user_id)
                    resp = client.send_request("PUT", url, payload)
                    if isinstance(resp, dict) and\
                            resp.get("cc") == Constant.SUCCESS_0:
                        suc = "Success: add user successfully"
                        self.suc_list.append(suc)
                    else:
                        err = "Failure: failed to add user"
                        self.err_list.append(err)
                        raise FailException(*self.err_list)
                else:
                    err = "Failure: the number of user is up to the limit!"
                    self.err_list.append(err)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            self._parse_args(args)
            payload = self._construct_param()
            url = "/redfish/v1/AccountService/Accounts"
            client = RedfishClient(args)
            resp = client.send_request("POST", url, payload)
            if (isinstance(resp, dict) and
                    resp.get("status_code", None) in Constant.SUC_CODE):
                suc = "Success: add user successfully"
                self.suc_list.append(suc)
            else:
                err = "Failure: failed to add user"
                self.err_list.append(err)
                raise FailException(*self.err_list)

        return self.suc_list
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
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
Esempio n. 16
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/sensors"
                resp = client.send_request("GET", url)
                if isinstance(resp, list):
                    data = sorted(resp, key=lambda s: s["sensor_number"])
                    for info in data:
                        if info.get("type") == "temperature":
                            temp = Temperature()
                            temp.pack_b01_temp_resource(info)
                            self.temperatures.append(temp)
                else:
                    err_info = "Failure: failed to get temperature information"
                    self.err_list.append(err_info)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Chassis/%s/Thermal" % systems_id
            resp = client.send_request("GET", url)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                temperatures = resp["resource"].get("Temperatures", None)
                if not temperatures:
                    self.err_list.append("Failure: no data available for the "
                                         "resource")
                    raise FailException(*self.err_list)
                try:
                    temperatures = sorted(temperatures,
                                          key=lambda s: s["SensorNumber"])
                except KeyError as err:
                    self.err_list.append(str(err))
                    raise FailException(*self.err_list)
                else:
                    for info in temperatures:
                        temp = Temperature()
                        temp.pack_temp_resource(info)
                        self.temperatures.append(temp)
            else:
                self.err_list.append("Failure: failed to get temperature "
                                     "information")
                raise FailException(*self.err_list)

        return self.suc_list
Esempio n. 17
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
Esempio n. 18
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
Esempio n. 19
0
    def run(self, args):

        client = RestfulClient(args)
        try:
            self.overall_health = self.get_overall_health(client)
            self.get_pcie_info(client)
            hdm_version = get_hdm_firmware(client)
        finally:
            if client.cookie:
                client.delete_session()

        if not hdm_version < "1.11":
            client = RedfishClient(args)
            pcie_detail = self._get_pcie_devices(client)
            if pcie_detail:
                package_pcie_info(self.pcie_device, pcie_detail)

        return self.suc_list
    def run(self, args):

        firmware_list = []
        client = RestfulClient(args)
        try:

            version = self.get_hdm_firmware(client)

            if version < "1.11.00":
                self.get_all_firmware(client, firmware_list)
            else:
                client1 = RedfishClient(args)
                self.get_redfish_firmware(client1, firmware_list)
                self.get_restful_firmware(client, firmware_list)
        finally:
            if client.cookie:
                client.delete_session()
        self.firmware = deal_firmware_info(firmware_list)
        return self.suc_list
Esempio n. 21
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/config/boot"
                resp = client.send_request("get", url)
                if isinstance(resp, dict) and Constant.SUCCESS_0 == \
                        resp.get("cc"):
                    self.boot_source_override_target = MODE_DICT.get(
                        resp.get("mode"), None)
                    self.boot_source_override_enabled = resp.get(
                        "alwaysflag", "Once")
                    self.boot_source_override_mode = DEV_DICT.get(
                        resp.get("dev"), None)
                else:
                    err_info = "Failure: failed to get boot startup information"
                    self.err_list.append(err_info)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Systems/%s" % systems_id
            resp = client.send_request("get", url)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                boot = resp["resource"].get("Boot", None)
                if isinstance(boot, dict):
                    self.boot_source_override_target = (boot.get(
                        "BootSourceOverrideTarget", None))
                    self.boot_source_override_enabled = (boot.get(
                        "BootSourceOverrideEnabled", None))
                    self.boot_source_override_mode = (boot.get(
                        "BootSourceOverrideMode", None))
            else:
                err_info = "Failure: failed to get boot startup information"
                self.err_list.append(err_info)
                raise FailException(*self.err_list)
Esempio n. 22
0
    def run(self, args):

        client = RestfulClient(args)
        try:

            self._get_fru(client)

            self._get_capping(client)
        finally:
            if client.cookie:
                client.delete_session()
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            try:
                client = RestfulClient(args)

                self._get_uuid(client)

                self._get_powerstate(client)

                self._get_healthinfo(client)

                self.slot_id = 1
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            self.slot_id = systems_id
            url = "/redfish/v1/Systems/%s" % systems_id
            resp = client.send_request("GET", url)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                self._pack_system_info(resp["resource"])
            else:
                self.err_list.append("Failure: failed to get product"
                                     "information")
                raise FailException(*self.err_list)
        return self.suc_list
Esempio n. 23
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/config/ntp"
                resp = client.send_request("GET", url)
                if isinstance(resp, dict):
                    if resp.get("timestamp") is not None:
                        date_array = datetime.datetime.utcfromtimestamp(
                            resp.get("timestamp"))
                        style_time = date_array.strftime("%Y-%m-%d %H:%M:%S")
                        self.time = style_time
                    self.timezone = resp.get("timezone")
                else:
                    err_info = "Failure: failed to get time information!"
                    self.err_list.append(err_info)
                    raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Managers/%s" % systems_id
            resp = client.send_request("GET", url)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                self.date_time = resp["resource"].get("DateTime", None)
                if self.date_time:
                    self.time = self.date_time[:19].replace("T", " ")
                self.timezone = resp["resource"].get("DateTimeLocalOffset",
                                                     None)
            else:
                self.err_list.append(
                    "Failure: failed to get time information!")
                raise FailException(*self.err_list)
        return self.suc_list
Esempio n. 24
0
    def run(self, args):

        init_args(args, self.args_lst)
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            logic_disk_list = self._get_b01_logical_disk_list(client)
            if not logic_disk_list:
                suc_info = "Success: raid card resource is empty"
                self.suc_list.append(suc_info)
                return self.suc_list
        else:
            if ((args.controller_id is None and args.logical_id is not None) or
                (args.controller_id is not None and args.logical_id is None)):
                err = ("Argument: RAID card ID and logical disk "
                       "ID must be specified at the same time")
                self.err_list.append(err)
                raise FailException(*self.err_list)
            client = RedfishClient(args)
            logical_disk_list_url = self._get_logical_disk_list(client)

            if args.logical_id is None and not logical_disk_list_url:
                suc = "Success: raid card resource is empty"
                self.suc_list.append(suc)
                return self.suc_list
            if not self._get_logical_disk_detail(client, logical_disk_list_url,
                                                 args):
                err_info = "Failure: resource was not found"
                self.err_list.append(err_info)
                raise FailException(*self.err_list)
        client = RestfulClient(args)
        try:

            self._get_health_info(client)
        finally:
            if client.cookie:
                client.delete_session()

        return self.suc_list
Esempio n. 25
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                psu = self._get_b01_power_supply(client)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            psu = self._get_power_supply(client)
        try:
            client = RestfulClient(args)

            self._get_health_info(client)
        finally:
            if client.cookie:
                client.delete_session()
        self.psus = psu
        self.maximum = len(self.psus)
        return self.suc_list
Esempio n. 26
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                self._get_b01_raid(client)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            self._get_raid(client)
        if self.suc_list:
            return self.suc_list
        client = RestfulClient(args)
        try:

            self._get_health_info(client)
        finally:
            if client.cookie:
                client.delete_session()
        return self.suc_list
Esempio n. 27
0
    def run(self, args):

        init_args(args, self.args_lst)
        restful = RestfulClient(args)
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            self.cpus = self._get_b01_processor(restful, args)
        else:
            redfish = RedfishClient(args)
            redfish_cpu = self._get_processor(redfish, args)
        try:

            self._get_health_info(restful)
            restful_cpu = self._get_hardware_cpu(restful)
            if is_adapt_b01 is not True:

                if not restful_cpu:
                    return self.suc_list
                self.cpus = self._pack_cpu_resource(restful_cpu, redfish_cpu)
        finally:
            if restful.cookie:
                restful.delete_session()
        return self.suc_list
Esempio n. 28
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/config/ntp"
                payload = dict()
                resp = client.send_request("GET", url)
                if isinstance(resp, dict):
                    payload["auto_date"] = resp.get("auto_date")
                    payload["primary_ntp"] = resp.get("primary_ntp")
                    payload["secondary_ntp"] = resp.get("secondary_ntp")
                    payload["utc_minutes"] = resp.get("utc_minutes")

                    if payload["auto_date"] == 1:
                        err_info = ("Failure: automatically synchronize "
                                    "with NTP server, can not set timezone")
                        self.err_list.append(err_info)
                        raise FailException(*self.err_list)
                    else:

                        payload["timezone"] = \
                            args.datetime_local_offset.replace("UTC", "GMT")
                        resp = client.send_request("POST", url, payload)
                        if isinstance(resp, dict) and Constant.SUCCESS_0 == \
                                resp.get("cc"):
                            self.suc_list.append(
                                "Success: set system timezone "
                                "successfully: %s" %
                                args.datetime_local_offset)
                            return self.suc_list
                        else:
                            self.err_list.append("Failure: failed to set "
                                                 "system timezone")
                            raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            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):
                if resp["resource"].get("ServiceEnabled", None):
                    err_info = ("Failure: automatically synchronize "
                                "with NTP server, can not set timezone")
                    self.err_list.append(err_info)
                    raise FailException(*self.err_list)
            url = "/redfish/v1/Managers/%s/NtpService" % systems_id
            payload = {
                "Oem": {
                    "Public": {
                        "TimeZone": args.datetime_local_offset
                    }
                }
            }
            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 system timezone "
                                     "successfully: %s" %
                                     args.datetime_local_offset)
            else:
                self.err_list.append("Failure: failed to set system timezone")
                raise FailException(*self.err_list)
        return self.suc_list
Esempio n. 29
0
    def run(self, args):

        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                cmd_type = self._parse_b01_args(args)
                url = "/api/settings/users"
                user_id = None
                user_info = None
                resp = client.send_request("GET", url)
                if isinstance(resp, list):
                    for info in resp:
                        if self.user_name == info.get("name"):
                            user_id = info.get("id")
                            user_info = info
                            break
                if user_id is None:
                    err = "Failure: the user does not exist: %s" \
                          % self.user_name
                    self.err_list.append(err)
                    raise FailException(*self.err_list)
                else:
                    url = "/api/settings/users/" + str(user_id)
                    payload = self._construct_b01_request_param(user_info)
                    payload["id"] = user_id
                    resp = client.send_request("PUT", url, payload)
                    if isinstance(resp, dict) and resp.get("cc") ==\
                            Constant.SUCCESS_0:
                        suc = "Success: set %s successfully" % cmd_type
                        self.suc_list.append(suc)
                    else:
                        err = "Failure: failed to set %s" % cmd_type
                        self.err_list.append(err)
                        raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            cmd_type = self._parse_args(args)
            url = "/redfish/v1/AccountService/Accounts"
            client = RedfishClient(args)
            resp = client.send_request("GET", url)
            if ((not isinstance(resp, dict))
                    or resp.get("status_code", None) not in Constant.SUC_CODE):
                self.err_list.append("Failure: failed to get user collection")
                raise FailException(*self.err_list)
            user_list = resp["resource"].get("Members", [])
            for user in user_list:
                user_url = user.get("@odata.id", None)
                user_resp = client.send_request("GET", user_url)
                if (isinstance(user_resp, dict) and user_resp.get(
                        "status_code", None) in Constant.SUC_CODE):
                    if (user_resp["resource"].get("UserName",
                                                  None) == self.user_name):
                        user_cache = user_resp
                        break
                else:
                    err = "Failure: failed to get user details"
                    self.err_list.append(err)
                    raise FailException(*self.err_list)
            else:
                err = "Failure: the user does not exist: %s" % self.user_name
                self.err_list.append(err)
                raise FailException(*self.err_list)
            url, payload = self._construct_request_param(user_cache, url)
            resp = client.send_request("PATCH", url, payload)
            if (isinstance(resp, dict)
                    and resp.get("status_code", None) in Constant.SUC_CODE):
                suc = "Success: set %s successfully" % cmd_type
                self.suc_list.append(suc)
            else:
                err = "Failure: failed to set %s" % cmd_type
                self.err_list.append(err)
                raise FailException(*self.err_list)

        return self.suc_list
Esempio n. 30
0
    def run(self, args):

        init_args(args, self.args_lst)
        is_adapt_b01 = globalvar.IS_ADAPT_B01
        if is_adapt_b01:
            client = RestfulClient(args)
            try:
                url = "/api/settings/network"
                resp = client.send_request("GET", url)
                if args.network_port_id is not None:
                    if isinstance(resp, list):
                        data = self._choose_port_resp(args, resp)
                        if data is not None:
                            self._pack_b01_ip_resource(data)
                            return self.suc_list
                    else:
                        err_info = "Failure: failed to get the ip info"
                        self.err_list.append(err_info)
                        raise FailException(*self.err_list)
                else:
                    if isinstance(resp, list):
                        data = self._check_b01_resp(args, resp)
                        if data is not None:
                            self._pack_b01_ip_resource(data)
                            return self.suc_list
                    else:
                        err_info = "Failure: failed to get the ip info"
                        self.err_list.append(err_info)
                        raise FailException(*self.err_list)
            finally:
                if client.cookie:
                    client.delete_session()
        else:
            client = RedfishClient(args)
            systems_id = client.get_systems_id()
            url = "/redfish/v1/Managers/%s/EthernetInterfaces" % systems_id
            if args.network_port_id is not None:
                url = ("/redfish/v1/Managers/%s/EthernetInterfaces/%s" %
                       (systems_id, args.network_port_id))
                resp = client.send_request("GET", url)
                if (isinstance(resp, dict) and resp.get("status_code", None)
                        in Constant.SUC_CODE):
                    self._pack_ip_resource(resp["resource"])
                else:
                    self.err_list.append("Failure: failed to get ip "
                                         "information")
                    raise FailException(*self.err_list)
            else:
                resp = client.send_request("GET", url)
                if (isinstance(resp, dict) and resp.get("status_code", None)
                        in Constant.SUC_CODE):
                    eth_list = resp["resource"]["Members"]
                    for eth in eth_list:
                        url = eth.get("@odata.id", None)
                        resp = client.send_request("GET", url)
                        if self._check_resp(args, resp):
                            self._pack_ip_resource(resp["resource"])
                            return self.suc_list
                    else:
                        self.err_list.append("Failure: failed to "
                                             "get ip information")
                        raise FailException(*self.err_list)
                else:
                    self.err_list.append("Failure: failed to get network port "
                                         "collection information!")
                    raise FailException(*self.err_list)

        return self.suc_list