Skip to content

Commit

Permalink
Merge pull request #6 from navalkp/master
Browse files Browse the repository at this point in the history
Updated with changes for v 2.2.0
  • Loading branch information
prabhosa authored Nov 19, 2018
2 parents 354bda3 + 9d0870a commit e67f1e9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
2 changes: 0 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ command-line interface (CLI) to manage endpoints.
The sample scripts are location in the following directory:
lib/python2.7/site-packages/pylxca-1.0-py2.7.egg/pylxca\test


License
-------

Apache Software License (http://www.apache.org/licenses/LICENSE-2.0)
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.1.0'
__version__ = '2.2.0'


# There are submodules, but clients shouldn't need to know about them.
Expand Down
4 changes: 3 additions & 1 deletion pylxca/pylxca_api/lxca_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def disconnect( self, dict_handler=None):
def get_log_level(self, dict_handler=None):
lvl = None
if dict_handler:
lvl = dict_handler['l'] or dict_handler['lvl']
lvl = next((item for item in [dict_handler.get('l') , dict_handler.get('lvl')] if item is not None),None)
if lvl == None:
lvl = lxca_rest().get_log_level()
else:
Expand Down Expand Up @@ -581,6 +581,8 @@ def get_jobs( self, dict_handler = None ):
try:
if jobid:
py_obj = json.loads(resp.text)
py_obj = {'jobsList': [py_obj]}
return py_obj
if canceljobid or deletejobid:
return resp
else:
Expand Down
10 changes: 6 additions & 4 deletions pylxca/pylxca_api/lxca_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ def set_log_config(self):

def get_log_level(self):
logger.debug("Current Log Level is: " + str(logger.getEffectiveLevel()))
return logger.getEffectiveLevel()
return logging.getLevelName(logger.getEffectiveLevel())

def set_log_level(self,log_value):
logger.setLevel(log_value)
for handler in logger.handlers:
handler.setLevel(log_value)
logger.debug("Current Log Level is: " + str(logger.getEffectiveLevel()))
return

def do_discovery(self,url, session, ip_addr,jobid):
Expand Down Expand Up @@ -847,7 +850,7 @@ def do_updatecomp(self, url, session, query, mode, action, server, switch, stora

url= url + "?action=" + action

if not mode == None and mode == "immediate" or mode == "delayed" :
if not mode == None and mode == "immediate" or mode == "delayed" or mode == "prioritized":
url= url + "&activationMode=" + mode
else:
raise Exception("Invalid argument mode")
Expand Down Expand Up @@ -926,7 +929,7 @@ def do_updatecomp_all(self, url, session, action, mode,dev_list):
if action == "apply" or action == "cancelApply":
url = url + "?action=" + action

if not mode == None and mode == "immediate" or mode == "delayed":
if not mode == None and mode == "immediate" or mode == "delayed" or mode == "prioritized":
url = url + "&activationMode=" + mode
else:
raise Exception("Invalid argument mode")
Expand Down Expand Up @@ -1273,7 +1276,6 @@ def get_osimage(self, osimages_info, **kwargs):
url = ''
kwargs.pop("url", None)
kwargs.pop("session", None)

if not osimages_info and ('id' not in kwargs or 'fileName' not in kwargs):
url = baseurl + '/osImages'
if 'hostPlatforms' in osimages_info:
Expand Down
8 changes: 5 additions & 3 deletions pylxca/pylxca_cmd/lxca_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class log(InteractiveCommand):
"""
def handle_no_input(self,con_obj = None):
api = pylxca.pylxca_api.lxca_api()
self.sprint("Current Log Level is set to " + str(logging.getLevelName(api.get_log_level())))
self.sprint("Current Log Level is set to " + str(api.get_log_level()))
message = """
Possible Log Levels, Please use following values to set desired log level.
Expand All @@ -132,7 +132,7 @@ def handle_no_input(self,con_obj = None):
def handle_output(self, out_obj):
api = pylxca.pylxca_api.lxca_api()
if out_obj == True:
self.sprint("Current Log Level is set to " + logging.getLevelName(api.get_log_level()))
self.sprint("Current Log Level is set to " + api.get_log_level())
else:
self.sprint("Fail to set Log Level")
message = """
Expand Down Expand Up @@ -513,7 +513,7 @@ class ffdc(InteractiveCommand):
Retrieve and Manage information about ffdc
USAGE:
ffdc [-u <UUID of the target endpoint>]
ffdc -u <UUID of the target endpoint>
OPTIONS:
-u, --uuid <UUID of the target endpoint>
Expand Down Expand Up @@ -620,6 +620,8 @@ class updatecomp(InteractiveCommand):
-m, --mode Indicates when to activate the update. This can be one of the following values.
immediate - Uses Immediate Activation mode when applying firmware updates to the selected endpoints.
delayed - Uses Delayed Activation mode when applying firmware updates to the selected endpoints.
prioritized - Firmware updates on the baseboard management controller are activated immediately
-a, --action The action to take. This can be one of the following values.
apply - Applies the associated firmware to the submitted components.
power - Perform power action on selected endpoint.
Expand Down
42 changes: 33 additions & 9 deletions pylxca/pylxca_cmd/lxca_pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ def updatecomp(*args, **kwargs):
mode Indicates when to activate the update. This can be one of the following values.
immediate - Uses Immediate Activaton mode when applying firmware updates to the selected endpoints.
delayed - Uses Delayed Activaton mode when applying firmware updates to the selected endpoints.
prioritized. Firmware updates on the baseboard management controller are activated immediately
action The action to take. This can be one of the following values.
apply - Applies the associated firmware to the submitted components.
Expand Down Expand Up @@ -1033,9 +1034,10 @@ def ffdc(*args, **kwargs):
@param
The parameters for this command are as follows
uuid UUID of the target endpoint
uuid UUID of the target endpoint this is manadatory parameter
@example
@example
ffdc(con = lxca_con, uuid='UUID of endpoint")
'''
global shell_obj
Expand Down Expand Up @@ -1067,25 +1069,40 @@ def log(*args, **kwargs):
Where KeyList is as follows
keylist = ['con','filter']
keylist = ['con','lvl']
@param
The parameters for this command are as follows
filter filter for the event
lvl log level to be set
Possible Log Levels, Please use following values to set desired log level.
DEBUG: Detailed information, typically of interest only when diagnosing problems.
INFO: Confirmation that things are working as expected.
WARNING: An indication that something unexpected happened, or indicative of some problem in the near future.
ERROR: Due to a more serious problem, the software has not been able to perform some function.
CRITICAL: A serious error, indicating that the program itself may be unable to continue running.
@example
'''
global shell_obj
command_name = sys._getframe().f_code.co_name
keylist = ['lvl']

for i in range(len(args)):
kwargs[keylist[i]] = args[i]
param_dict = {}
con = None

long_short_key_map = {'lvl':'l'}
keylist = ['con','lvl']
optional_keylist = ['con', 'lvl']
mutually_exclusive_keys = []
mandatory_options_list = {}

ch = shell_obj.handle_input_args(command_name, args=args, kwargs=kwargs)
return ch
con = _validate_param(keylist, long_short_key_map, mandatory_options_list, optional_keylist, mutually_exclusive_keys,
param_dict, *args, **kwargs)

out_obj = shell_obj.handle_input_dict(command_name, con, param_dict)
return out_obj

def lxcalog(*args, **kwargs):
'''
Expand Down Expand Up @@ -1376,6 +1393,12 @@ def _validate_param(keylist, long_short_key_map, mandatory_options_list, optiona
me_key, str(mutually_exclusive_keys)))
raise AttributeError("Invalid command invocation")
me_key_found = True

if not set(keylist + long_short_key_map.values()).issuperset(set(kwargs.keys())):
logger.error(" Invalid Input args: %s unsupported argument passed"
% list(set(kwargs.keys()).difference(set(keylist + long_short_key_map.values()))))
raise ValueError("Invalid Input Arguments")

return con

def osimages(*args, **kwargs):
Expand Down Expand Up @@ -1444,6 +1467,7 @@ def osimages(*args, **kwargs):
con = None
param_dict = {}
param_dict = kwargs
kwargs = {} # this is required to avoid invalid argument error in _validate_param
command_name = sys._getframe().f_code.co_name

long_short_key_map = {'osimages_info':'i'}
Expand Down

0 comments on commit e67f1e9

Please sign in to comment.