Skip to content

Commit

Permalink
Merge pull request #10 from navalkp/master
Browse files Browse the repository at this point in the history
Update for 2.5.0
  • Loading branch information
prabhosa authored Sep 5, 2019
2 parents 24c77ca + 2a182a1 commit de57e68
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 43 deletions.
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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
--------------------------------------------------
Expand All @@ -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.
>>>

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pylxca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Version of the pylxca package

__version__ = '2.4.0'
__version__ = '2.5.0'


# There are submodules, but clients shouldn't need to know about them.
Expand Down
16 changes: 13 additions & 3 deletions pylxca/pylxca_api/lxca_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -797,6 +802,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.")
Expand All @@ -806,6 +812,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']

Expand All @@ -819,6 +826,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)
Expand Down Expand Up @@ -1087,7 +1097,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)
Expand Down
22 changes: 20 additions & 2 deletions pylxca/pylxca_api/lxca_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
80 changes: 63 additions & 17 deletions pylxca/pylxca_cmd/lxca_cmd_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
"disconnect": {
"description": "Disconnect session from LXCA",
"cmd_args": [
[{
"args": "-c,--con",
"opt_dict": {
"help": "connection object"
}
}
]
]
},

Expand Down Expand Up @@ -425,6 +418,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",
Expand Down Expand Up @@ -495,7 +496,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": [
Expand Down Expand Up @@ -525,7 +527,7 @@
"args": "-a,--action",
"opt_dict": {
"help": "action to perform",
"choices": ["cancel", "update", "delete"]
"choices": ["cancel", "update", "delete","create"]
}
}
],
Expand All @@ -536,8 +538,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",
Expand Down Expand Up @@ -571,7 +581,13 @@
{
"args": "-f,--force",
"opt_dict": {
"help": "Force manage"
"help": "Force manage",
"choices": [
"True",
"true",
"False",
"false"
]
}
}
]
Expand Down Expand Up @@ -665,7 +681,13 @@
[{
"args": "-f,--force",
"opt_dict": {
"help": "Force manage"
"help": "Force manage",
"choices": [
"True",
"true",
"False",
"false"
]
}
}
]
Expand Down Expand Up @@ -1047,29 +1069,53 @@
{
"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"
]
}
}
],
[
{
"args": "-f,--force",
"opt_dict": {
"help": "Identifies whether to force profile deactivation"
"help": "Identifies whether to force profile deactivation",
"choices": [
"True",
"true",
"False",
"false"
]
}
}
]
Expand Down
27 changes: 27 additions & 0 deletions pylxca/pylxca_cmd/lxca_filters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,23 @@
<managementPatternPresent>managementPatternPresent</managementPatternPresent>
<rackID>rackID</rackID>
</Profile_List >
</configprofiles>
<configprofiles name="activate">
<Identifier>identifier</Identifier>
<Label>label</Label>
<Profile_List name="items" type="object">
<locationIds>locationIds</locationIds>
<endPointNames>endPointNames</endPointNames>
<uuidsFailed>uuidsFailed</uuidsFailed>
<jobRecordId>jobRecordId</jobRecordId>
<jobName>jobName</jobName>
<endPointIds>endPointIds</endPointIds>
<locationIdsFailed>locationIdsFailed</locationIdsFailed>
<message>message</message>
</Profile_List >
</configprofiles>
<configprofiles name="unassign">
<message>message</message>
</configprofiles>
<configprofiles name="id">
<ID>ID</ID>
Expand Down Expand Up @@ -589,6 +606,16 @@
<description>description</description>
<id>id</id>
</storedcredentials>
<storedcredentials name="create">
<id>id</id>
</storedcredentials>
<storedcredentials name="result">
<result>result</result>
<messages name="messages" type="object">
<explanation>explanation</explanation>
<text>text</text>
</messages >
</storedcredentials>
<osimages name="default">
<result>result</result>
<softwareFiles name="softwareFiles" type="object">
Expand Down
1 change: 0 additions & 1 deletion pylxca/pylxca_cmd/lxca_ishell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading

0 comments on commit de57e68

Please sign in to comment.