def run(func, args): c = openconfig_system_client.Configuration() c.verify_ssl = False aa = openconfig_system_client.OpenconfigSystemApi(api_client=openconfig_system_client.ApiClient(configuration=c)) # create a body block keypath, body = generate_body(func, args) try: if body is not None: api_response = getattr(aa,func.__name__)(*keypath, body=body) else : api_response = getattr(aa,func.__name__)(*keypath) #print(api_response) if api_response is None: print ("Success") else: response = api_response.to_dict() if 'openconfig_systemstate' in response.keys(): value = response['openconfig_systemstate'] if value is None: return show_cli_output(sys.argv[2], system_state_key_change(value)) elif 'openconfig_systemmemory' in response.keys(): value = response['openconfig_systemmemory'] if value is None: return show_cli_output(sys.argv[2], memory_key_change(value['state'])) elif 'openconfig_systemcpus' in response.keys(): value = response['openconfig_systemcpus'] if value is None: return show_cli_output(sys.argv[2], value['cpu']) elif 'openconfig_systemprocesses' in response.keys(): value = response['openconfig_systemprocesses'] if len(sys.argv) < 4: if value is None: return show_cli_output(sys.argv[2],value['process']) else: for proc in value['process']: if proc['pid'] == int(sys.argv[3]): show_cli_output(sys.argv[2],util_capitalize(proc['state'])) return print("command works") else: print("Failed") except ApiException as e: print("Exception when calling OpenconfigSystemApi->%s : %s\n" %(func.__name__, e))
def run(func, args): c = openconfig_system_client.Configuration() c.verify_ssl = False aa = openconfig_system_client.OpenconfigSystemApi(api_client=openconfig_system_client.ApiClient(configuration=c)) # create a body block keypath, body = generate_body(func, args) try: if body is not None: api_response = getattr(aa,func.__name__)(*keypath, body=body) else : api_response = getattr(aa,func.__name__)(*keypath) if api_response is None: print ("Success") else: response = api_response.to_dict() if 'openconfig_systemstate' in list(response.keys()): value = response['openconfig_systemstate'] if value is None: return show_cli_output(sys.argv[2], system_state_key_change(value)) elif 'openconfig_systemmemory' in list(response.keys()): value = response['openconfig_systemmemory'] if value is None: return show_cli_output(sys.argv[2], memory_key_change(value['state'])) elif 'openconfig_systemcpus' in list(response.keys()): value = response['openconfig_systemcpus'] if value is None: return show_cli_output(sys.argv[2], value['cpu']) elif 'openconfig_systemprocesses' in list(response.keys()): value = response['openconfig_systemprocesses'] if 'pid' not in sys.argv: if value is None: return show_cli_output(sys.argv[2],value['process']) else: for proc in value['process']: if proc['pid'] == int(sys.argv[3]): show_cli_output(sys.argv[2],util_capitalize(proc['state'])) return else: print("Failed") except ApiException as e: if e.body != "": body = json.loads(e.body) if "ietf-restconf:errors" in body: err = body["ietf-restconf:errors"] if "error" in err: errList = err["error"] errDict = {} for dict in errList: for k, v in dict.items(): errDict[k] = v if "error-message" in errDict: print("%Error: " + errDict["error-message"]) return print("%Error: Application Failure") return print("%Error: Application Failure") else: print("Failed")