From 71ff8ebaf24d8c3efbaa4037833495c0a5df3876 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Mon, 15 Apr 2019 12:25:43 +0530 Subject: [PATCH 1/9] Changed version to 2.5.0 --- pylxca/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylxca/__init__.py b/pylxca/__init__.py index 7687909..135b3ca 100644 --- a/pylxca/__init__.py +++ b/pylxca/__init__.py @@ -1,6 +1,6 @@ # Version of the pylxca package -__version__ = '2.99.99' +__version__ = '2.5.0' # There are submodules, but clients shouldn't need to know about them. From 076de986cc1b84acbf39d62beab0f1d1b042a138 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Thu, 6 Jun 2019 15:33:17 +0530 Subject: [PATCH 2/9] Create tasks support --- pylxca/pylxca_api/lxca_api.py | 5 +++++ pylxca/pylxca_api/lxca_rest.py | 22 ++++++++++++++++++++-- pylxca/pylxca_cmd/lxca_cmd_data.json | 17 +++++++++++++---- pylxca/pylxca_cmd/lxca_pyshell.py | 8 ++++---- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/pylxca/pylxca_api/lxca_api.py b/pylxca/pylxca_api/lxca_api.py index efb493b..844e34e 100644 --- a/pylxca/pylxca_api/lxca_api.py +++ b/pylxca/pylxca_api/lxca_api.py @@ -797,6 +797,7 @@ def get_set_tasks(self, dict_handler=None): action = None status = None cmd_updateList = None + template = None if not self.con: raise ConnectionError("Connection is not Initialized.") @@ -806,6 +807,7 @@ def get_set_tasks(self, dict_handler=None): includeChildren = next((item for item in [ dict_handler.get('children')] if item is not None), "true") action = next((item for item in [dict_handler.get('action')] if item is not None), None) updateList = next((item for item in [dict_handler.get('updateList')] if item is not None), None) + template = next((item for item in [dict_handler.get('template')] if item is not None), None) #if updateList: # updateList = updateList['taskList'] @@ -819,6 +821,9 @@ def get_set_tasks(self, dict_handler=None): elif action in ['update']: resp = lxca_rest().put_tasks_update(self.con.get_url(), self.con.get_session(), updateList) py_obj = resp.status_code + elif action in ['create']: + resp = lxca_rest().post_tasks(self.con.get_url(), self.con.get_session(), template) + py_obj = resp else: resp = lxca_rest().get_tasks(self.con.get_url(), self.con.get_session(), job_uuid, includeChildren) py_obj = json.loads(resp.text) diff --git a/pylxca/pylxca_api/lxca_rest.py b/pylxca/pylxca_api/lxca_rest.py index 4001acd..cf85df2 100644 --- a/pylxca/pylxca_api/lxca_rest.py +++ b/pylxca/pylxca_api/lxca_rest.py @@ -1172,6 +1172,24 @@ def get_tasks(self,url, session, job_uid, includeChildren): raise re return resp + def post_tasks(self, url, session, post_dict): + ''' + Handle action post + ''' + + + url = url + '/tasks' + + payload = post_dict + + try: + resp = session.post(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT) + resp.raise_for_status() + except HTTPError as re: + logger.error("REST API Exception: Exception = %s", re) + raise re + return resp + def put_tasks(self, url, session, job_uuid, action): ''' Handle action cancel @@ -1212,9 +1230,9 @@ def put_tasks_update(self, url, session, updated_dict): ''' - url = url + '/tasks' + url = url + '/tasks' + '/' + updated_dict[0]['jobUID'] - payload = updated_dict + payload = updated_dict[0] try: resp = resp = session.put(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT) diff --git a/pylxca/pylxca_cmd/lxca_cmd_data.json b/pylxca/pylxca_cmd/lxca_cmd_data.json index cf45819..2a26b71 100644 --- a/pylxca/pylxca_cmd/lxca_cmd_data.json +++ b/pylxca/pylxca_cmd/lxca_cmd_data.json @@ -495,7 +495,8 @@ "tasks -a update -u '[{\"jobUID\":\"9\",\"percentage\":50}]'"], "valid_combination": {"global":[[], ["children"], ["jobUID"], ["jobUID","children"], ["jobUID", "action"], - ["action", "updateList"] + ["action", "updateList"], + ["action", "template"] ] }, "cmd_args": [ @@ -525,7 +526,7 @@ "args": "-a,--action", "opt_dict": { "help": "action to perform", - "choices": ["cancel", "update", "delete"] + "choices": ["cancel", "update", "delete","create"] } } ], @@ -536,8 +537,16 @@ "type": "ast.literal_eval" } } - ] - ] + ], + [{ + "args": "-t,--template", + "opt_dict": { + "help": "Template for creating new task", + "type": "json.loads" + } + } + ] + ] }, "unmanage": { "description": "Unmanage device on LXCA", diff --git a/pylxca/pylxca_cmd/lxca_pyshell.py b/pylxca/pylxca_cmd/lxca_pyshell.py index 4dd34cc..f986d89 100644 --- a/pylxca/pylxca_cmd/lxca_pyshell.py +++ b/pylxca/pylxca_cmd/lxca_pyshell.py @@ -1381,7 +1381,7 @@ def tasks(*args, **kwargs): con Connection Object to Lenovo XClarity Administrator jobUID uuid of job children result will include children if True - action cancel/update + action cancel/update/create updateList required for update action , string containing list of update @example @@ -1399,9 +1399,9 @@ def tasks(*args, **kwargs): con = None long_short_key_map = {'jobUID': 'j', 'children': 'c', - 'action': 'a', 'updateList': 'u'} - keylist = ['con', 'jobUID', 'children', 'action', 'updateList'] - optional_keylist = ['con', 'jobUID', 'children', 'action', 'updateList'] + 'action': 'a', 'updateList': 'u', 'template': 't'} + keylist = ['con', 'jobUID', 'children', 'action', 'updateList','template'] + optional_keylist = ['con', 'jobUID', 'children', 'action', 'updateList','template'] mutually_exclusive_keys = [] mandatory_options_list = {} From 9fce576ca6e63507ab0466f286a12d63fc50aa6b Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Mon, 5 Aug 2019 11:12:06 +0530 Subject: [PATCH 3/9] Modified return of storedcredential post for create view --- pylxca/pylxca_api/lxca_api.py | 2 +- pylxca/pylxca_cmd/lxca_filters.xml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pylxca/pylxca_api/lxca_api.py b/pylxca/pylxca_api/lxca_api.py index 844e34e..a564f7c 100644 --- a/pylxca/pylxca_api/lxca_api.py +++ b/pylxca/pylxca_api/lxca_api.py @@ -1092,7 +1092,7 @@ def get_set_storedcredentials(self, dict_handler=None): elif user_name and password: resp = lxca_rest().post_storedcredentials(self.con.get_url(), self.con.get_session(), user_name, password, description) py_obj = json.loads(resp.text) - resp = {'storedcredentialsList': py_obj['response']} + resp = {'storedcredentialsList': [py_obj['response']]} else: resp = lxca_rest().get_storedcredentials(self.con.get_url(), self.con.get_session(), id) py_obj = json.loads(resp.text) diff --git a/pylxca/pylxca_cmd/lxca_filters.xml b/pylxca/pylxca_cmd/lxca_filters.xml index 0057221..8775fa8 100644 --- a/pylxca/pylxca_cmd/lxca_filters.xml +++ b/pylxca/pylxca_cmd/lxca_filters.xml @@ -589,6 +589,10 @@ description id + + id + + result From 6fd4f76679a47810b6f9bf96abf5502461d9fac9 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Tue, 6 Aug 2019 12:35:58 +0530 Subject: [PATCH 4/9] BUG 180137 Added choices for boolean parameters --- pylxca/pylxca_cmd/lxca_cmd_data.json | 48 ++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/pylxca/pylxca_cmd/lxca_cmd_data.json b/pylxca/pylxca_cmd/lxca_cmd_data.json index 2a26b71..13d378a 100644 --- a/pylxca/pylxca_cmd/lxca_cmd_data.json +++ b/pylxca/pylxca_cmd/lxca_cmd_data.json @@ -580,7 +580,13 @@ { "args": "-f,--force", "opt_dict": { - "help": "Force manage" + "help": "Force manage", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ] @@ -674,7 +680,13 @@ [{ "args": "-f,--force", "opt_dict": { - "help": "Force manage" + "help": "Force manage", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ] @@ -1056,21 +1068,39 @@ { "args": "-p,--powerdown", "opt_dict": { - "help": "Identifies whether to power off the server" + "help": "Identifies whether to power off the server", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ], [{ "args": "--resetimm", "opt_dict": { - "help": "Identifies whether to reset the baseboard management controller." + "help": "Identifies whether to reset the baseboard management controller.", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ], [{ "args": "--resetswitch", "opt_dict": { - "help": "Identifies whether to reset the switch internal port settings to default values" + "help": "Identifies whether to reset the switch internal port settings to default values", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ], @@ -1078,7 +1108,13 @@ { "args": "-f,--force", "opt_dict": { - "help": "Identifies whether to force profile deactivation" + "help": "Identifies whether to force profile deactivation", + "choices": [ + "True", + "true", + "False", + "false" + ] } } ] From 2357fde696c3df4ba48a8f4006d626f4982ba0e7 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Tue, 6 Aug 2019 15:50:51 +0530 Subject: [PATCH 5/9] BUG 180340 create result filter for and used it for Storedcredentials --- pylxca/pylxca_cmd/lxca_cmd_data.json | 8 ++++++++ pylxca/pylxca_cmd/lxca_filters.xml | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pylxca/pylxca_cmd/lxca_cmd_data.json b/pylxca/pylxca_cmd/lxca_cmd_data.json index 13d378a..40e4ec1 100644 --- a/pylxca/pylxca_cmd/lxca_cmd_data.json +++ b/pylxca/pylxca_cmd/lxca_cmd_data.json @@ -425,6 +425,14 @@ "storedcredentials": { "description": "Retrieve and update stored credentials on lxca.", + "additional_detail": ["Example List all storedcredentials", + "storedcredentials", + "Example Create storedcredentials", + "storedcredentials -u admin -p Passw0rd -d \"Test User\" -v create", + "Example modify storedcredentials", + "storedcredentials -i 2056 -u admin -p Passw0rd -d \"Test User\" -v result", + "Example delete storedcredentials", + "storedcredentials --delete_id 2056 -v result"], "cmd_args": [ [{ "args": "-i,--id", diff --git a/pylxca/pylxca_cmd/lxca_filters.xml b/pylxca/pylxca_cmd/lxca_filters.xml index 8775fa8..fd3c7f1 100644 --- a/pylxca/pylxca_cmd/lxca_filters.xml +++ b/pylxca/pylxca_cmd/lxca_filters.xml @@ -592,7 +592,13 @@ id - + + result + + explanation + text + + result From 58d8bcf1f9d80c6b5a39f47f7765fa27bb20ed84 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Wed, 7 Aug 2019 14:18:14 +0530 Subject: [PATCH 6/9] Added 2 new views for configprofiles --- pylxca/pylxca_api/lxca_api.py | 9 +++++++-- pylxca/pylxca_cmd/lxca_filters.xml | 17 +++++++++++++++++ pylxca/pylxca_cmd/lxca_pyshell.py | 7 +++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pylxca/pylxca_api/lxca_api.py b/pylxca/pylxca_api/lxca_api.py index a564f7c..2e7ed0d 100644 --- a/pylxca/pylxca_api/lxca_api.py +++ b/pylxca/pylxca_api/lxca_api.py @@ -551,9 +551,14 @@ def get_configprofiles( self, dict_handler = None ): elif subcmd == 'activate' and endpoint and restart: resp = lxca_rest().post_configprofiles(self.con.get_url(), self.con.get_session(), profileid, endpoint, restart) elif subcmd == 'delete' and profileid: - resp = lxca_rest().delete_configprofiles(self.con.get_url(), self.con.get_session(), profileid) + resp = lxca_rest().delete_configprofiles(self.con.get_url(), self.con.get_session(), profileid) elif subcmd == 'unassign' and profileid: - resp = lxca_rest().unassign_configprofiles(self.con.get_url(), self.con.get_session(), profileid, powerdown, resetimm, resetswitch, force) + resp = lxca_rest().unassign_configprofiles(self.con.get_url(), self.con.get_session(), profileid, powerdown, resetimm, resetswitch, force) + if len(resp.text): + py_obj = json.loads(resp.text) + py_obj['dummy'] = {'status': []} + return py_obj + elif subcmd == 'list': resp = lxca_rest().get_configprofiles(self.con.get_url(),self.con.get_session(),profileid) diff --git a/pylxca/pylxca_cmd/lxca_filters.xml b/pylxca/pylxca_cmd/lxca_filters.xml index fd3c7f1..6f2fdf7 100644 --- a/pylxca/pylxca_cmd/lxca_filters.xml +++ b/pylxca/pylxca_cmd/lxca_filters.xml @@ -533,6 +533,23 @@ managementPatternPresent rackID + + + identifier + + + locationIds + endPointNames + uuidsFailed + jobRecordId + jobName + endPointIds + locationIdsFailed + message + + + + message ID diff --git a/pylxca/pylxca_cmd/lxca_pyshell.py b/pylxca/pylxca_cmd/lxca_pyshell.py index f986d89..f9a6721 100644 --- a/pylxca/pylxca_cmd/lxca_pyshell.py +++ b/pylxca/pylxca_cmd/lxca_pyshell.py @@ -821,6 +821,13 @@ def configprofiles(*args, **kwargs): param_dict, *args, **kwargs) out_obj = SHELL_OBJ.handle_input_dict(command_name, con, param_dict) + + #remove dummy field added for view + if 'dummy' in out_obj: + out_obj.pop('dummy') + return out_obj + + return out_obj From 932b5963c7c87780572b1feb9eb39060cc91ace1 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Wed, 7 Aug 2019 14:39:04 +0530 Subject: [PATCH 7/9] bug 180302 change LXCA_shell help for disconnect --- pylxca/pylxca_cmd/lxca_cmd_data.json | 7 ------- pylxca/pylxca_cmd/lxca_pyshell.py | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pylxca/pylxca_cmd/lxca_cmd_data.json b/pylxca/pylxca_cmd/lxca_cmd_data.json index 40e4ec1..8d58a46 100644 --- a/pylxca/pylxca_cmd/lxca_cmd_data.json +++ b/pylxca/pylxca_cmd/lxca_cmd_data.json @@ -43,13 +43,6 @@ "disconnect": { "description": "Disconnect session from LXCA", "cmd_args": [ - [{ - "args": "-c,--con", - "opt_dict": { - "help": "connection object" - } - } - ] ] }, diff --git a/pylxca/pylxca_cmd/lxca_pyshell.py b/pylxca/pylxca_cmd/lxca_pyshell.py index f9a6721..cdef9e8 100644 --- a/pylxca/pylxca_cmd/lxca_pyshell.py +++ b/pylxca/pylxca_cmd/lxca_pyshell.py @@ -152,7 +152,7 @@ def disconnect(*args, **kwargs): mutually_exclusive_keys, param_dict, *args, **kwargs) - out_obj = SHELL_OBJ.handle_input_dict(command_name, con, param_dict) + out_obj = SHELL_OBJ.handle_input_dict(command_name, con, param_dict, False) return out_obj From 37fc5f5013f460f3e2abb6543c9c6e53c5ac99c5 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Fri, 9 Aug 2019 14:11:57 +0530 Subject: [PATCH 8/9] Removing jobs commands --- pylxca/pylxca_cmd/lxca_ishell.py | 3 +-- pylxca/pylxca_cmd/lxca_pyshell.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pylxca/pylxca_cmd/lxca_ishell.py b/pylxca/pylxca_cmd/lxca_ishell.py index b691383..11510a5 100644 --- a/pylxca/pylxca_cmd/lxca_ishell.py +++ b/pylxca/pylxca_cmd/lxca_ishell.py @@ -142,7 +142,6 @@ def __init__(self, self.add_command(lxca_cmd.cmms(self)) self.add_command(lxca_cmd.scalablesystem(self)) self.add_command(lxca_cmd.ostream(self)) - self.add_command(lxca_cmd.jobs(self)) self.add_command(lxca_cmd.discover(self)) self.add_command(lxca_cmd.manage(self)) self.add_command(lxca_cmd.unmanage(self)) @@ -335,4 +334,4 @@ def auto_complete(self, text, state): return [cmd + ' '][state] results = [c + ' ' for c in command_list if c.startswith(cmd)] + [None] return results[state] - """ \ No newline at end of file + """ diff --git a/pylxca/pylxca_cmd/lxca_pyshell.py b/pylxca/pylxca_cmd/lxca_pyshell.py index cdef9e8..e76daf6 100644 --- a/pylxca/pylxca_cmd/lxca_pyshell.py +++ b/pylxca/pylxca_cmd/lxca_pyshell.py @@ -46,7 +46,6 @@ def set_interactive(): "discover": discover, "manage": manage, "unmanage": unmanage, - "jobs": jobs, "users": users, "lxcalog": lxcalog, "ffdc": ffdc, From 2a182a1044527ba004b3f80ad666cc08b2e36fe9 Mon Sep 17 00:00:00 2001 From: Naval Patel Date: Fri, 30 Aug 2019 14:25:05 +0530 Subject: [PATCH 9/9] Updated Readme for 2.5.0 --- README.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cd9aca9..4dca06a 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,9 @@ Lenovo XClarity Administrator REST APIs to automate functions such as: * Configuring servers through the use of Configuration Patterns * Applying firmware updates to endpoints -Whats New in 2.4.0 +Whats New in 2.5.0 ------------------ -* Argument Parsing library replaced from optparse to argparse. -* Support for subcmd under various commands. -* New commands supported under shell - osimages - managementserver - resourcegroups -* Better Error handling. +* Few bug fixes for views and jobs command Installation ------------ @@ -49,7 +43,7 @@ Complete the following steps to install the PYLXCA CLI. $lxca_shell -------------------------------------------------- - Welcome to PyLXCA Shell v2.4.0 + Welcome to PyLXCA Shell v2.5.0 Type "help" at any time for a list of commands. Type "pyshell" at any time to get interactive python shell -------------------------------------------------- @@ -60,7 +54,7 @@ Complete the following steps to install the PYLXCA CLI. $lxca_shell --api - Interactive Python Shell for Lenovo XClarity Administrator v2.4.0 + Interactive Python Shell for Lenovo XClarity Administrator v2.5.0 Type "dir()" or "help(lxca command object)" for more information. >>> @@ -77,12 +71,11 @@ API Reference ------------- PyLXCA command reference is available at - http://ralfss30.labs.lenovo.com:8120/help/topic/com.lenovo.lxca.doc/pycli_overview.html - + https://sysmgt.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.lxca_restapis.doc%2Fpycli_overview.html&cp=1_23_1 PyLXCA API Help can be seen from Interactive Python Shell as follows. $lxca_shell --api - Interactive Python Shell for Lenovo XClarity Administrator v2.4.0 + Interactive Python Shell for Lenovo XClarity Administrator v2.5.0 Type "dir()" or "help(lxca command object)" for more information. >>> >>> help(connect)