oem: Add hpeoem lan commands #278
base: master
Are you sure you want to change the base?
Conversation
17c4d8c
to
1b31889
Compare
lib/ipmi_hpeoem.c
Outdated
|
||
input_length = 6; | ||
msg_data[0] = channel; | ||
msg_data[1] = IPMI_ILO_NETWORK_CONFIG_NIC_SELECTION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please think about reusing set_lan_param_nowait()
.
Thanks for thorough review from @AlexanderAmelkin. I will fix them ASAP. |
1b31889
to
9082c04
Compare
static int | ||
oem_hpe_parse_nic_selection_mode(char **argv) | ||
{ | ||
if (argv[current_arg] && !strcmp(argv[current_arg], "dedicated")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this the first time. Please avoid using global variables. That's an evil practice. :)
Pass the argument index among the function arguments instead if really needed, which is not the case here, I believe. It looks like this function is never called twice for a single invocation of ipmitool
. So you can safely pass a pointer to the required element in argv
instead of passing the pointer its head. Like this:
hpe_main(argv)
{
/*...*/
hpe_lan_main(argv + main_shift);
/*...*/
}
hpe_lan_main(argv)
{
/*...*/
hpe_parse_nic_selection_mode(argv + lan_shift);
/*...*/
}
hpe_parse_nic_selection_mode(argv)
{
/*...*/
/* just use argv and advance to next argument like this: */
++argv;
/*...*/
}
{ | ||
return OEM_HPE_LAN_NIC_SHARED_WITH_ALOM1; | ||
} | ||
else if (argv[current_arg] && !strcmp(argv[current_arg], "alom2")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a lot like all those if
/else if
could be reduced to a simple dictionary and a loop:
#define OEM_HPE_MAX_NIC_SIZE 10 /* the length of word 'dedicated' plus a null-byte */
struct elem {
char type[OEM_HPE_MAX_NIC_SIZE];
int rc;
bool advance;
} dictionary = {
{ "dedicated", OEM_HPE_LAN_NIC_DEDICATED, false },
{ "shared", OEM_HPE_LAN_NIC_INVALID, true },
{ "with", OEM_HPE_LAN_NIC_INVALID, true },
{ "lom1", OEM_HPE_LAN_NIC_SHARED_WITH_LOM1, false },
/*...*/
{ NULL, 0, false }
};
for (int i = 0; dictionary[i].name; ++i) {
if (argv[0] && !strcmp(argv[0], dicttionary[i].name)) {
return dictionary[i].rc;
}
argv += dictionary[i].advance ? 1 : 0;
}
}
or something like that. Separate the code from the data.
} | ||
} | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline is missing
Also to obey the 50/72 rule, please change the commit message to:
|
Please also fix the issues found by Codacy |
I got caught up in things recently, will continue to work on this later. |
Add supports for HPE iLO NIC selection. Example usage:
It uses the command documented in: https://support.hpe.com/hpesc/public/docDisplay?docId=c04530505&docLocale=en_US