def run(self, args): init_args(args, self.args_lst) client = RestfulClient(args) try: ad_config_url = "/api/settings/active_directory_settings" resp = client.send_request("GET", ad_config_url) if isinstance(resp, dict) or Constant.SUCCESS_0 == resp.get( "cc", None): if 0 == resp.get("enable", None): self.err_list.append( "Failure: ad disable, can not add ad user") raise FailException(*self.err_list) else: self.err_list.append("Failure: failed to add ad user") raise FailException(*self.err_list) payload = self._construct_param(args) add_url = "/api/settings/active_directory_users" resp = client.send_request("POST", add_url, payload) if (isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get( "cc", None) or resp.get("role_group_name", None)): self.suc_list.append("Success: add ad user successfully") else: self.err_list.append("Failure: Failed to add ad user") raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) self._parse_args(args) client = RestfulClient(args) try: url = "/api/settings/ldap-settings" resp = client.send_request("GET", url) if not isinstance( resp, dict) or Constant.SUCCESS_0 != resp.get("cc", None): self.err_list.append("Failure: failed to set ldap") raise FailException(*self.err_list) self._construct_param(resp) resp = client.send_request("PUT", url, resp) if isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get( "cc", None): self.suc_list.append("Success: set ldap successfully") else: self.err_list.append("Failure: failed to set ldap") raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
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
def run(self, args): init_args(args, self.args_lst) if args.count is not None and args.count <= 0: err_info = ("Argument: invalid choice: %s (the value is a " "positive integer)") % args.count self.err_list.append(err_info) raise FailException(*self.err_list) client = RestfulClient(args) try: url = "/api/health/hdm_log" resp = client.send_request("get", url) if isinstance(resp, list): count = len(resp) if args.count and args.count < count: count = args.count self.hdm_log = get_log_resource(resp, count) else: err_info = "Failure: get hdm log failed" self.err_list.append(err_info) raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
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
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
def run(self, args): init_args(args, self.args_lst) if args.dev is None and args.effective is None and args.mode is None: self.err_list.append("Argument: need at least one parameter") raise FailException(*self.err_list) restful = RestfulClient(args) try: url = "/api/config/boot" resp = restful.send_request("GET", url) if isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get( "cc", None): payload = self._construct_param(args, resp) resp = restful.send_request("POST", url, payload) if isinstance(resp, dict) or Constant.SUCCESS_0 == resp.get( "cc", None): self.suc_list.append( "Success: set system startup item successfully") else: self.err_list.append( "Failure: failed to set system startup item") raise FailException(*self.err_list) else: self.err_list.append( "Failure: failed to get system startup item") raise FailException(*self.err_list) finally: if restful.cookie: restful.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) url = "/api/chassis-status" client = RestfulClient(args) try: resp = client.send_request("GET", url) if (isinstance(resp, dict) and resp.get("cc", None) == Constant.SUCCESS_0): payload = self.construct_request_parameters(resp, args) url = "/api/actions/power" sec_resp = client.send_request("POST", url, payload) if (isinstance(sec_resp, dict) and sec_resp.get("cc", None) == Constant.SUCCESS_0): operator_suc = ("Success: power control request " "succeeded: %s" % args.command_type) self.suc_list.append(operator_suc) else: err_info = "Failure: system power control failed" self.err_list.append(err_info) raise FailException(*self.err_list) else: err_info = "Failure: failed to get current system power status" self.err_list.append(err_info) raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) client = RestfulClient(args) try: url = "/api/settings/users" resp = client.send_request("GET", url) if isinstance(resp, list): for user in resp: if user.get("name", None) == args.name: user_id = user.get("id", None) url = "/api/settings/users/%s" % user_id resp = client.send_request("DELETE", url) if (isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get("cc", None)): suc = "Success: delete user successfully" self.suc_list.append(suc) else: err = "Failure: failed to delete user" self.err_list.append(err) raise FailException(*self.err_list) break else: err = "Failure: this user does not exist: %s" % args.name self.err_list.append(err) raise FailException(*self.err_list) else: self.err_list.append("Failure: failed to get user list") raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): client = RestfulClient(args) try: self._get_health_info(client) url = "/api/system/nic" resp = client.send_request("GET", url) finally: if client.cookie: client.delete_session() if isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get( "cc", None): nic_info = resp.get("nic_info", None) if not nic_info: suc_info = "Success: the NIC list is empty" self.suc_list.append(suc_info) else: self.maximum = len(self.suc_list) for info in nic_info: nic = Nic() nic.pack_nic_resource(info) self.nics.append(nic) else: self.err_list.append("Failure: failed to get nic information list") raise FailException(*self.err_list) return self.suc_list
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
def run(self, args): client = RestfulClient(args) try: restful_sensor = self.get_hardware_sensor(client) if restful_sensor: self.sensors = pack_sensor_resource(restful_sensor) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) client = RestfulClient(args) try: self._get_ctrl(client, args) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): client = RestfulClient(args) try: self.maximum = self.get_maximum(client) self.session_lst = self.get_session_list(client) if not self.session_lst: suc_info = "Success: vnc session is empty" self.suc_list.append(suc_info) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): client = RestfulClient(args) url = "/api/sensors" try: resp = client.send_request("GET", url) psu_sensor = (self.package_results( list(filter(is_power_sensor, resp)))) self.power = psu_sensor finally: if client.cookie: client.delete_session() return self.suc_list
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
def run(self, args): init_args(args, self.args_lst) config_type = args.config_type config_file = args.file_uri try: with open(config_file, "w"): pass except IOError as err: self.err_list.append(str(err)) raise FailException(*self.err_list) else: os.remove(config_file) client = RestfulClient(args) url = "/api/maintenance/%s" % URL_DICT[config_type] try: resp = client.send_request("GET", url) if resp and isinstance(resp, dict): if not (resp.get(Constant.COMPLETE_CODE) or resp.get(Constant.COMPLETE_ERROR)): with open(config_file, "w") as file_output: file_output.write( json.dumps(resp, indent=4, separators=(",", ": "))) suc_info = ("Success: export %s configuration " "is successful" % config_type) self.suc_list.append(suc_info) else: err_info = ( "Failure: export %s config file failed, " "reason: %s" % (config_type, resp.get(Constant.COMPLETE_ERROR))) self.err_list.append(err_info) else: err_info = ("Failure: export %s config file failed, reason: " "Response can not parse" % config_type) self.err_list.append(err_info) except (IOError, Exception) as err: self.err_list.append((str(err))) raise FailException(*self.err_list) else: if self.err_list: raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): client = RestfulClient(args) url = "/api/logs/event" try: resp = client.send_request("DELETE", url) finally: if client.cookie: client.delete_session() if isinstance(resp, dict) and not resp: self.suc_list.append( "Success: clear system event log successfully") else: self.err_list.append("Failure: failed to clear system event log") raise FailException(*self.err_list) return self.suc_list
def wrapper(*args, **kwargs): client = RestfulClient(args[1]) try: version = get_hdm_firmware(client) if version is not None and version < "1.11.00": err_list = [] err_info = ("Failure: this hdm version does not " "support this command") err_list.append(err_info) raise FailException(*err_list) else: return func(*args, **kwargs) finally: if client.cookie: client.delete_session()
def run(self, args): client = RestfulClient(args) try: url = "/api/maintenance/restore_defaults" resp = client.send_request("PUT", url) finally: if client.cookie: client.delete_session() if isinstance(resp, dict) or Constant.SUCCESS_0 == resp.get("cc"): self.suc_list.append( "Success: restore BMC default settings successfully") else: self.err_list.append( "Failure: restore BMC default settings failed") raise FailException(*self.err_list) return self.suc_list
def run(self, args): client = RestfulClient(args) url = "/api/settings/network_portmode" try: resp = client.send_request("get", url) if (isinstance(resp, dict) and resp.get( Constant.COMPLETE_CODE, None) == Constant.SUCCESS_0): self.net_mode = MODE_DICT.get(resp.get("port_mode")) else: err_info = ("Failure: failed to get network port mode " "information") self.err_list.append(err_info) raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): restful = RestfulClient(args) try: url = "/api/maintenance/restore_hdm" payload = {"reset": 1} resp = restful.send_request("POST", url, payload) finally: if restful.cookie: restful.delete_session() if isinstance(resp, dict) or Constant.SUCCESS_0 == resp.get( "cc", None): self.suc_list.append("Success: reset BMC successfully") else: self.err_list.append("Failure: failed to reset BMC") raise FailException(*self.err_list) return self.suc_list
def run(self, args): client = RestfulClient(args) try: url = "/api/health_info" resp = client.send_request("GET", url) if (isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get("cc", None)): self._pack_resource(resp) else: err_info = "Failure: failed to get system health status" self.err_list.append(err_info) raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
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): client = RestfulClient(args) ip_rules = list() try: url = "/api/settings/firewall-ip-mac-rule-forbid" ip_rules.extend(self.get_rule_ip(client, url, "block")) url = "/api/settings/firewall-ip-mac-rule-allow" ip_rules.extend(self.get_rule_ip(client, url)) if not ip_rules: suc_info = "Success: login rule is empty" self.suc_list.append(suc_info) else: self.rules_ip = _pack_ip_rules_resource(ip_rules) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) config_file = args.file_uri if not os.path.exists(config_file): err_info = ("Failure: upload config file failed, " "reason: File Not Exist") self.err_list.append(err_info) raise FailException(*self.err_list) config_type = args.config_type url = "/api/maintenance/%s" % URL_DICT[config_type] try: with open(config_file, "rb") as config_file_data: file_read = config_file_data.read() except (TypeError, ValueError, KeyError, IOError, Exception) as err: self.err_list.append(str(err)) raise FailException(*self.err_list) else: _, file_name = os.path.split(config_file) fields = { "config": (file_name, file_read, "application/octet-stream") } client = RestfulClient(args) try: resp = client.upload_request("POST", url, fields=fields) if (isinstance(resp, dict) and resp.get(Constant.COMPLETE_CODE) == Constant.SUCCESS_0): self.get_process(client, config_type) elif (isinstance(resp, dict) and resp.get(Constant.COMPLETE_CODE) != Constant.SUCCESS_0): err_info = ( "Failure: import %s config file failed, reason: %s" % (config_type, resp.get(Constant.COMPLETE_CODE))) self.err_list.append(err_info) else: err_info = ("Failure: import %s config file failed, " "reason: Response can not parse" % config_type) self.err_list.append(err_info) if self.err_list: raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) url, payload = self.construct_request_parameters(args) client = RestfulClient(args) try: resp = client.send_request("post", url, payload) if (isinstance(resp, dict) and resp.get(Constant.COMPLETE_CODE) == Constant.SUCCESS_0): suc_info = "Success: set ip login rule succeed" self.suc_list.append(suc_info) else: err_info = "Failure: set ip login rule failed" self.err_list.append(err_info) raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() return self.suc_list
def run(self, args): init_args(args, self.args_lst) client = RestfulClient(args) try: if self.check_conditions(client, args): url = "/api/settings/active_directory_users/%s" % args.role_id resp = client.send_request("DELETE", url) if isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get( "cc", None): err = "Success: delete ad user successfully" self.suc_list.append(err) else: self.err_list.append("Failure: failed to delete ad user") raise FailException(*self.err_list) finally: if client.cookie: client.delete_session() 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
def run(self, args): init_args(args, self.args_lst) client = RestfulClient(args) try: url = "/api/settings/ldap-users/%s" % str(args.role_id) resp = client.send_request("DELETE", url) finally: if client.cookie: client.delete_session() if (isinstance(resp, dict) and Constant.SUCCESS_0 == resp.get("cc", None)): suc = "Success: delete ldap user successfully" self.suc_list.append(suc) else: self.err_list.append("Failure: failed to delete ldap user") raise FailException(*self.err_list) return self.suc_list