Skip to content

oem: Add hpeoem lan commands #278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jiegec
Copy link

@jiegec jiegec commented Mar 29, 2021

Add supports for HPE iLO NIC selection. Example usage:

> sudo ./src/ipmitool hpeoem lan get 1
NIC selection: shared
Reset needed: no
Shared NIC selection: ALOM
Shared NIC port: NIC port 1
Shared NIC support: ALOM
> sudo ./src/ipmitool hpeoem lan set 1 dedicated
Set NIC selection mode to dedicated
> sudo ./src/ipmitool hpeoem lan get 1
NIC selection: dedicated
Reset needed: yes

It uses the command documented in: https://support.hpe.com/hpesc/public/docDisplay?docId=c04530505&docLocale=en_US

@jiegec jiegec force-pushed the hpeoem-lan-command branch 5 times, most recently from 17c4d8c to 1b31889 Compare April 10, 2021 00:38
include/ipmitool/ipmi_hpeoem.h Show resolved Hide resolved
include/ipmitool/ipmi_hpeoem.h Outdated Show resolved Hide resolved
include/ipmitool/ipmi_hpeoem.h Outdated Show resolved Hide resolved
include/ipmitool/ipmi_hpeoem.h Outdated Show resolved Hide resolved
include/ipmitool/ipmi_hpeoem.h Outdated Show resolved Hide resolved
include/ipmitool/ipmi_hpeoem.h Outdated Show resolved Hide resolved
lib/ipmi_hpeoem.c Outdated Show resolved Hide resolved
lib/ipmi_hpeoem.c Outdated Show resolved Hide resolved
lib/ipmi_hpeoem.c Outdated Show resolved Hide resolved

input_length = 6;
msg_data[0] = channel;
msg_data[1] = IPMI_ILO_NETWORK_CONFIG_NIC_SELECTION;
Copy link
Contributor

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().

@jiegec
Copy link
Author

jiegec commented Nov 3, 2021

Thanks for thorough review from @AlexanderAmelkin. I will fix them ASAP.

static int
oem_hpe_parse_nic_selection_mode(char **argv)
{
if (argv[current_arg] && !strcmp(argv[current_arg], "dedicated"))
Copy link
Contributor

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"))
Copy link
Contributor

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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline is missing

@AlexanderAmelkin
Copy link
Contributor

Also to obey the 50/72 rule, please change the commit message to:

oem: Add hpeoem lan commands

Add commands to configure HPE iLO NIC selection

Signed-off-by: Jiajie Chen <your@email.address>

@AlexanderAmelkin
Copy link
Contributor

Please also fix the issues found by Codacy

@jiegec
Copy link
Author

jiegec commented Nov 11, 2021

I got caught up in things recently, will continue to work on this later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants