2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 03:32:04 +00:00

Changes for review comments

This commit is contained in:
Mark Gurevich 2018-02-27 10:40:52 -05:00
parent 0e8fb75d3a
commit b56da57f77
5 changed files with 76 additions and 17 deletions

View File

@ -10,14 +10,31 @@ class EventlogInterface(object):
interface_type = 'eventlog'
version = '1.0'
def get_eventlog_info(self, task, eventlog_type=None):
def get_eventlog_info(self, task, number_of_records="all"):
"""Return the eventlog info of the task's nodes.
:param eventlog_type: type of eventlog info want to get.
:param number_of_records: number of records to display.
:param task: a Task instance containing the nodes to act on.
:return eventlog list
"""
return task.run('get_ev_info', eventlog_type)
return task.run('get_ev_info', number_of_records)
def clear_all_eventlog_records(self, task):
"""Clear all eventlog records.
:param task: a Task instance containing the nodes to act on.
:return
"""
return task.run('clear_all_ev_records')
def resolve_eventlog_records(self, task, resolve_list="LED"):
"""Return the eventlog info of the task's nodes.
:param resolve: list of eventlog ids to resolve or LED label.
:param task: a Task instance containing the nodes to act on.
:return eventlog list of resolved entries
"""
return task.run('resolve_ev_records', resolve_list)
class DefaultEventlogManager(EventlogInterface):
"""Interface for eventlog-related actions."""

View File

@ -20,13 +20,13 @@ logger = logging.getLogger('xcatagent')
class OpenBMCEventlogTask(ParallelNodesCommand):
"""Executor for eventlog-related actions."""
def get_ev_info(self, args, **kw):
def get_ev_info(self, num_to_display, **kw):
node = kw['node']
number_to_display = 0
try:
# Number of records to display from the end
number_to_display = 0-int(args[0])
number_to_display = 0-int(num_to_display[0])
except Exception:
# All records to display
number_to_display = 0
@ -52,3 +52,11 @@ class OpenBMCEventlogTask(ParallelNodesCommand):
self.callback.info('%s: %s' % (node, e.message))
return eventlog_info
def clear_all_ev_records(self, **kw):
node = kw['node']
def resolve_ev_records(self, resolve_list, **kw):
node = kw['node']

View File

@ -492,11 +492,16 @@ class OpenBMCRest(object):
return bool(func_list), fw_dict
# Extract all eventlog info and build a dictionary with eventid as a key
# Extract all eventlog info and parse it
def get_eventlog_info(self):
eventlog_data = self.request('GET', EVENTLOG_URL, cmd='get_eventlog_info')
return self.parse_eventlog_data(eventlog_data)
# Parse eventlog data and build a dictionary with eventid as a key
def parse_eventlog_data(self, eventlog_data):
# Check if policy table file is there
ras_event_mapping = {}
if os.path.isfile(RAS_POLICY_TABLE):
@ -512,7 +517,7 @@ class OpenBMCRest(object):
try:
eventlog_dict = {}
for key, value in sorted(eventlog_data.items()):
id, event_log_line = self.parse_event_data(value, ras_event_mapping)
id, event_log_line = self.parse_eventlog_data_record(value, ras_event_mapping)
if int(id) != 0:
eventlog_dict[str(id)] = event_log_line
return eventlog_dict
@ -521,7 +526,7 @@ class OpenBMCRest(object):
raise SelfServerException(error)
# Parse a single eventlog entry and return data in formatted string
def parse_event_data(self, event_log_entry, ras_event_mapping):
def parse_eventlog_data_record(self, event_log_entry, ras_event_mapping):
formatted_line = ""
callout_data = ""
LED_tag = " [LED]"

View File

@ -145,7 +145,7 @@ VITALS_OPTIONS = ('all', 'altitude', 'fanspeed', 'leds', 'power',
'temp', 'voltage', 'wattage')
# global variables of reventlog
EVENTLOG_OPTIONS = ('all', 'clear', 'resolved')
EVENTLOG_OPTIONS = ('list', 'clear', 'resolved')
class OpenBMC(base.BaseDriver):
@ -841,9 +841,9 @@ class OpenBMCManager(base.BaseManager):
reventlog_usage = """
Usage:
reventlog [-V|--verbose] [resolved=LED|resolved=<num>]
reventlog [-V|--verbose] [clear|all]
reventlog [-V|--verbose] [<number>]
reventlog [-V|--verbose] resolved <id_list>
reventlog [-V|--verbose] clear
reventlog [-V|--verbose] list <number_of_records>
Options:
-V --verbose eventlog verbose mode.
@ -859,13 +859,23 @@ class OpenBMCManager(base.BaseManager):
return
# 2, validate the args
#if action not in EVENTLOG_OPTIONS:
# self.messager.error("Not supported subcommand for reventlog: %s" % action)
# return
if action not in EVENTLOG_OPTIONS:
self.messager.error("Not supported subcommand for reventlog: %s" % action)
return
# 3, run the subcommands
runner = OpenBMCEventlogTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=self.verbose)
DefaultEventlogManager().get_eventlog_info(runner, args)
self.messager.info('revetlog.py processing action=%s args=%s' % (action, args))
if action == 'clear':
DefaultEventlogManager().clear_all_eventlog_records(runner)
elif action == 'resolved':
eventlog_id_list = opts.pop('<id_list>')
DefaultEventlogManager().resolve_eventlog_records(runner, eventlog_id_list)
elif action == 'list':
eventlog_number_of_records = opts.pop('<number_of_records>')
DefaultEventlogManager().get_eventlog_info(runner, eventlog_number_of_records)
else:
DefaultEventlogManager().get_eventlog_info(runner, "all")
def _get_full_path(self,file_path):
if type(self.cwd) == 'unicode':

View File

@ -364,8 +364,9 @@ sub refactor_args {
my $request = shift;
my $command = $request->{command}->[0];
my $extrargs = $request->{arg};
my $subcommand;
if ($command eq "rspconfig") {
my $subcommand = $extrargs->[0];
$subcommand = $extrargs->[0];
if ($subcommand !~ /^dump$|^sshcfg$|^ip=dhcp$/) {
if (grep /=/, @$extrargs) {
unshift @$extrargs, "set";
@ -374,6 +375,24 @@ sub refactor_args {
}
}
}
if ($command eq "reventlog") {
if (!defined($extrargs->[0])) {
# If no parameters are passed, default to list all records
$request->{arg} = ["list","all"];
}
else {
$subcommand = $extrargs->[0];
}
if ($subcommand =~ /^\d+$/) {
unshift @$extrargs, "list";
}
elsif ($subcommand =~/^resolved=(.*)/) {
unshift @$extrargs, "resolved";
}
elsif ($subcommand =~/^all$/) {
unshift @$extrargs, "list";
}
}
return 0;
}