Skip to content

Commit

Permalink
redfishpower: remove cycle support
Browse files Browse the repository at this point in the history
Problem: Due to the raciness of power status after a power cycle,
we now define power cycle as off, delay, on in all redfishpower
device files.  Now power "cycle" is no longer needed in redfishpower.

Remove all power cycle support in redfishpower.  Remove all documentation
in redfishpower(8) as well.
  • Loading branch information
chu11 committed Feb 25, 2024
1 parent 954308b commit 0c17ddc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 58 deletions.
12 changes: 0 additions & 12 deletions man/redfishpower.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ Set Redfish path for performing power on. Typically is redfish/v1/Systems/1/Act
.I "-F, --offpath string"
Set Redfish path for performing power off. Typically is redfish/v1/Systems/1/Actions/ComputerSystem.Reset.
.TP
.I "-C, --cyclepath string"
Set Redfish path for performing power cycle. Typically is redfish/v1/Systems/1/Actions/ComputerSystem.Reset.
.TP
.I "-P, --onpostdata string"
Set Redfish postdata for performing power on. Typically is {"ResetType":"On"}
.TP
.I "-G, --offpostdata string"
Set Redfish postdata for performing power off. Typically is {"ResetType":"ForceOff"}
.TP
.I "-D, --cyclepostdata string"
Set Redfish postdata for performing power cycle. Typically is {"ResetType":"ForceRestart"}
.TP
.I "-v, --verbose"
Increase output verbosity.
.SH INTERACTIVE COMMANDS
Expand All @@ -66,9 +60,6 @@ Set path and optional post data to turn on node.
.I "setoffpath <path> [postdata]"
Set path and optional post data to turn off node.
.TP
.I "setcyclepath <path> [postdata]"
Set path and optional post data to cycle node.
.TP
.I "settimeout <seconds>"
Set command timeout in seconds.
.TP
Expand All @@ -80,9 +71,6 @@ Turn on all nodes or specified subset of nodes. Will return "ok" after confirma
.TP
.I "off [nodes]"
Turn off all nodes or specified subset of nodes. Will return "ok" after confirmation "off" has completed.
.TP
.I "cycle [nodes]"
Power cycle all nodes or specified subset of nodes.

.SH "UPDATING REDFISHPOWER DEVICE FILES"
.LP
Expand Down
50 changes: 4 additions & 46 deletions src/redfishpower/redfishpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ static char *onpath = NULL;
static char *onpostdata = NULL;
static char *offpath = NULL;
static char *offpostdata = NULL;
static char *cyclepath = NULL;
static char *cyclepostdata = NULL;

static int test_mode = 0;
static hostlist_t test_fail_power_cmd_hosts;
Expand All @@ -68,7 +66,6 @@ static zhashx_t *test_power_status;
#define CMD_STAT "stat"
#define CMD_ON "on"
#define CMD_OFF "off"
#define CMD_CYCLE "cycle"

#define STATUS_ON "on"
#define STATUS_OFF "off"
Expand All @@ -83,10 +80,10 @@ struct powermsg {
CURLM *mh; /* curl multi handle pointer */

CURL *eh; /* curl easy handle */
char *cmd; /* "on", "off", "cycle", or "stat" */
char *cmd; /* "on", "off", or "stat" */
char *hostname; /* host we're working with */
char *url; /* on, off, cycle, stat */
char *postdata; /* on, off, cycle */
char *url; /* on, off, stat */
char *postdata; /* on, off */
char *output; /* on, off, stat */
size_t output_len;

Expand Down Expand Up @@ -114,17 +111,15 @@ struct powermsg {
err_exit(false, "curl_easy_setopt: %s", curl_easy_strerror(_ec)); \
} while(0)

#define OPTIONS "h:H:S:O:F:C:P:G:D:TEv"
#define OPTIONS "h:H:S:O:F:P:G:TEv"
static struct option longopts[] = {
{"hostname", required_argument, 0, 'h' },
{"header", required_argument, 0, 'H' },
{"statpath", required_argument, 0, 'S' },
{"onpath", required_argument, 0, 'O' },
{"offpath", required_argument, 0, 'F' },
{"cyclepath", required_argument, 0, 'C' },
{"onpostdata", required_argument, 0, 'P' },
{"offpostdata", required_argument, 0, 'G' },
{"cyclepostdata", required_argument, 0, 'D' },
{"test-mode", no_argument, 0, 'T' },
{"test-fail-power-cmd-hosts", required_argument, 0, 'E' },
{"verbose", no_argument, 0, 'v' },
Expand All @@ -141,12 +136,10 @@ void help(void)
printf(" setstatpath path\n");
printf(" setonpath path [postdata]\n");
printf(" setoffpath path [postdata]\n");
printf(" setcyclepath path [postdata]\n");
printf(" settimeout seconds\n");
printf(" stat [nodes]\n");
printf(" on [nodes]\n");
printf(" off [nodes]\n");
printf(" cycle [nodes]\n");
}

static size_t output_cb(void *contents, size_t size, size_t nmemb, void *userp)
Expand Down Expand Up @@ -518,11 +511,6 @@ static void off_cmd(zlistx_t *activecmds, CURLM *mh, char **av)
power_cmd(activecmds, mh, av, CMD_OFF, offpath, offpostdata);
}

static void cycle_cmd(zlistx_t *activecmds, CURLM *mh, char **av)
{
power_cmd(activecmds, mh, av, CMD_CYCLE, cyclepath, cyclepostdata);
}

static void send_status_poll(zlistx_t *delayedcmds, struct powermsg *pm)
{
struct powermsg *nextpm;
Expand Down Expand Up @@ -596,13 +584,6 @@ static void off_process(zlistx_t *delayedcmds, struct powermsg *pm)
on_off_process(delayedcmds, pm);
}

static void cycle_process(struct powermsg *pm)
{
if (test_mode)
zhashx_update(test_power_status, pm->hostname, STATUS_ON);
printf("%s: %s\n", pm->hostname, "ok");
}

static void power_cmd_process(zlistx_t *delayedcmds, struct powermsg *pm)
{
if (strcmp(pm->cmd, CMD_STAT) == 0)
Expand All @@ -611,8 +592,6 @@ static void power_cmd_process(zlistx_t *delayedcmds, struct powermsg *pm)
on_process(delayedcmds, pm);
else if (strcmp(pm->cmd, CMD_OFF) == 0)
off_process(delayedcmds, pm);
else if (strcmp(pm->cmd, CMD_CYCLE) == 0)
cycle_process(pm);
}

static void power_cleanup(struct powermsg *pm)
Expand All @@ -634,11 +613,6 @@ static void off_cleanup(struct powermsg *pm)
power_cleanup(pm);
}

static void cycle_cleanup(struct powermsg *pm)
{
power_cleanup(pm);
}

static void auth(char **av)
{
if (av[0] == NULL) {
Expand Down Expand Up @@ -726,8 +700,6 @@ static void process_cmd(zlistx_t *activecmds, CURLM *mh, char **av, int *exitfla
setpowerpath(av + 1, &onpath, &onpostdata);
else if (strcmp(av[0], "setoffpath") == 0)
setpowerpath(av + 1, &offpath, &offpostdata);
else if (strcmp(av[0], "setcyclepath") == 0)
setpowerpath(av + 1, &cyclepath, &cyclepostdata);
else if (strcmp(av[0], "settimeout") == 0)
settimeout(av + 1);
else if (strcmp(av[0], CMD_STAT) == 0)
Expand All @@ -736,8 +708,6 @@ static void process_cmd(zlistx_t *activecmds, CURLM *mh, char **av, int *exitfla
on_cmd(activecmds, mh, av + 1);
else if (strcmp(av[0], CMD_OFF) == 0)
off_cmd(activecmds, mh, av + 1);
else if (strcmp(av[0], CMD_CYCLE) == 0)
cycle_cmd(activecmds, mh, av + 1);
else
printf("type \"help\" for a list of commands\n");
}
Expand All @@ -753,8 +723,6 @@ static void cleanup_powermsg(void **x)
on_cleanup(pm);
else if (strcmp(pm->cmd, CMD_OFF) == 0)
off_cleanup(pm);
else if (strcmp(pm->cmd, CMD_CYCLE) == 0)
cycle_cleanup(pm);
}
}

Expand Down Expand Up @@ -993,10 +961,8 @@ static void usage(void)
" -S, --statpath Set stat path\n"
" -O, --onpath Set on path\n"
" -F, --offpath Set off path\n"
" -C, --cyclepath Set cycle path\n"
" -P, --onpostdata Set on post data\n"
" -G, --offpostdata Set off post data\n"
" -D, --cyclepostdata Set cycle post data\n"
" -v, --verbose Increase output verbosity\n"
);
exit(1);
Expand Down Expand Up @@ -1024,8 +990,6 @@ static void cleanup_redfishpower(void)
xfree(onpostdata);
xfree(offpath);
xfree(offpostdata);
xfree(cyclepath);
xfree(cyclepostdata);

hostlist_destroy(hosts);

Expand Down Expand Up @@ -1059,18 +1023,12 @@ int main(int argc, char *argv[])
case 'F': /* --offpath */
offpath = xstrdup(optarg);
break;
case 'C': /* --cyclepath */
cyclepath = xstrdup(optarg);
break;
case 'P': /* --onpostdata */
onpostdata = xstrdup(optarg);
break;
case 'G': /* --offpostdata */
offpostdata = xstrdup(optarg);
break;
case 'D': /* --cyclepostdata */
cyclepostdata = xstrdup(optarg);
break;
case 'T': /* --test-mode */
test_mode = 1;
break;
Expand Down

0 comments on commit 0c17ddc

Please sign in to comment.