Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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)
Пример #5
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
Пример #6
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
Пример #7
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
Пример #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)
            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
Пример #9
0
    def run(self, args):

        cmd_type = self._parse_parameters(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):
                    payload = self.construct_b01_request_parameters(resp)

                    if payload["snmptrap_version"] == 2:
                        url = "/api/settings/users"
                        resp = client.send_request("GET", url)
                        if isinstance(resp, list):
                            user_id = None
                            for info in resp:
                                if str(payload["snmp_v3_user"]) == \
                                        str(info.get("id")) and \
                                        info.get("name") != "" \
                                        and info.get("snmp") == 1:
                                    user_id = info.get("id")
                                    break
                            if user_id is None:
                                err = ("Failure: failed to get %s, the v3 user"
                                       "id does not exist" % cmd_type)
                                self.err_list.append(err)
                                raise FailException(*self.err_list)
                    url = "/api/settings/pef/snmp"
                    resp = client.send_request("PUT", url, payload)
                    if isinstance(resp, dict) and\
                            Constant.SUCCESS_0 == resp.get("cc"):
                        suc = "Success: set %s successfully" % cmd_type
                        self.suc_list.append(suc)
                        return self.suc_list
                    else:
                        err = "Failure: failed to set %s failed" % cmd_type
                        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 (resp is None or Constant.SUCCESS_200 != resp.get("status_code",
                                                                 None)):
                err = ("Failure: failed to get %s! Check the connection please"
                       % cmd_type)
                self.err_list.append(err)
                raise FailException(*self.err_list)
            payload = self.construct_request_parameters(resp)
            url = "/redfish/v1/Managers/%s/SnmpService" % systems_id
            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)
                return self.suc_list
            elif ((isinstance(resp, dict) and
                   isinstance(resp.get("resource", None), dict) and
                   isinstance(resp["resource"].get("error", None), dict))):
                err = dumps(resp["resource"]["error"],
                            indent=4, separators=(",", ": "))
                self.err_list.append(err)
                raise FailException(*self.err_list)
            else:
                err = "Failure: failed to set %s failed" % cmd_type
                self.err_list.append(err)
                raise FailException(*self.err_list)