Logo Search packages:      
Sourcecode: fence-agents version File versions  Download package

int main ( int  argc,
char **  argv 
)

.. but when a system receive the DIAG signal , it switches to a kdump kernel, but the machine is always "on" during the dump phase. It only become temporarily "off" at the end of the dump just before rebooting.

Definition at line 911 of file ipmilan.c.

References fail_exit(), get_options_stdin(), ipmi_destroy(), ipmi_init(), ipmi_op(), and print_xml_metadata().

{
      extern char *optarg;
      int opt, ret = -1;
      char authtype[64];
      char ip[64];
      char passwd[64];
      char user[64];
      char op[64];
      char method[64];
      char delay[64];
      char pwd_script[PATH_MAX] = { 0, };
      int lanplus=0;
      int verbose=0;
      char *pname = basename(argv[0]);
      struct ipmi *i;
      int timeout=DEFAULT_TIMEOUT;
      int down_sleep=DEFAULT_POWER_WAIT;
      int cipher=-1;
      int print_final_status=1;
      int translated_ret = -1;

      memset(ip, 0, sizeof(ip));
      memset(authtype, 0, sizeof(authtype));
      memset(passwd, 0, sizeof(passwd));
      memset(user, 0, sizeof(user));
      memset(op, 0, sizeof(op));
      memset(method, 0, sizeof(method));
      memset(delay, 0, sizeof(delay));

      if (argc > 1) {
            /*
               Parse command line options if any were specified
             */
            while ((opt = getopt(argc, argv, "A:a:i:l:p:S:Po:vV?hHt:T:C:M:f:")) != EOF) {
                  switch(opt) {
                  case 'A':
                        /* Auth type */
                        strncpy(authtype, optarg, sizeof(authtype));
                        break;
                  case 'a':
                  case 'i':
                        /* IP address */
                        strncpy(ip, optarg, sizeof(ip));
                        break;
                  case 'l':
                        /* user / login */
                        strncpy(user, optarg, sizeof(user));
                        break;
                  case 'p':
                        /* password */
                        strncpy(passwd, optarg, sizeof(passwd));
                        break;
                  case 'P':
                        lanplus = 1;
                        break;
                  case 'S':
                        strncpy(pwd_script, optarg, sizeof(pwd_script));
                        pwd_script[sizeof(pwd_script) - 1] = '\0';
                        break;
                  case 'o':
                        /* Operation */
                        strncpy(op, optarg, sizeof(op));
                        break;
                  case 'f':
                        /* Delay */
                        strncpy(delay, optarg, sizeof(delay));
                        break;
                  case 't':
                        /* Timeout */
                        if ((sscanf(optarg,"%d",&timeout)!=1) || timeout<1) {
                            fail_exit("Timeout option expects positive number parameter");
                        }
                        break;
                  case 'T':
                        /* Shutdown Sleep Time */
                        if ((sscanf(optarg,"%d",&down_sleep)!=1) || down_sleep<1) {
                            fail_exit("Shutdown time option expects positive number parameter");
                        }
                        break;
                  case 'C':
                        /* Ciphersuite */
                        if ((sscanf(optarg,"%d",&cipher)!=1) || cipher<0) {
                            fail_exit("Ciphersuite option expects positive number parameter");
                        }
                        break;
                  case 'M':
                        /* Reboot method */
                        strncpy(method, optarg, sizeof(method));
                        break;
                  case 'v':
                        verbose++;
                        break;
                  case 'V':
                        printf("%s %s (built %s %s)\n", pname,
                               VERSION,
                                    __DATE__, __TIME__);
                        printf("%s\n",
                               REDHAT_COPYRIGHT);
                        return 0;
                  default:
                        usage_exit(pname);
                  }
            }
      } else {
            /*
               No command line args?  Get stuff from stdin
             */
            if (get_options_stdin(ip, sizeof(ip),
                              authtype, sizeof(authtype),
                              passwd, sizeof(passwd),
                                pwd_script, sizeof(pwd_script),
                              user, sizeof(user),
                              op, sizeof(op), &lanplus, &verbose,&timeout,
                              &down_sleep,
                              &cipher, method, sizeof(method),
                              delay, sizeof(delay)) != 0)
                  return 1;
      }

      if (pwd_script[0] != '\0') {
            char pwd_buf[1024];
            FILE *fp;
            fp = popen(pwd_script, "r");
            if (fp != NULL) {
                  ssize_t len = fread(pwd_buf, 1, sizeof(pwd_buf), fp);
                  if (len > 0) {
                        char *p;
                        p = strchr(pwd_buf, '\n');
                        if (p != NULL)
                              *p = '\0';
                        p = strchr(pwd_buf, '\r');
                        if (p != NULL)
                              *p = '\0';
                        strncpy(passwd, pwd_buf, sizeof(passwd));
                        passwd[sizeof(passwd) - 1] = '\0';
                  }
                  pclose(fp);
            }
      }

      if (!strcasecmp(op, "metadata")) {
        print_xml_metadata(pname);
        translated_ret = ERR_OK;
        ret=0;
        print_final_status=0;
        goto metaout;
      }

      /*
         Validate the operating parameters
       */
      if (strlen(ip) == 0)
            fail_exit("no IP address specified");

      if (!strlen(op))
            snprintf(op,sizeof(op), "reboot");

      if (!strlen(method))
            snprintf(method, sizeof(method), "onoff");

      if (strcasecmp(op, "off") && strcasecmp(op, "on") &&
          strcasecmp(op, "status") && strcasecmp(op, "reboot") &&
          strcasecmp(op, "monitor") && strcasecmp(op, "list") &&
          strcasecmp(op, "metadata") && strcasecmp(op, "diag")) {
            fail_exit("operation must be 'on', 'off', 'status', "
                    "'reboot', 'diag', 'list', 'monitor' or 'metadata'");
      }

      if (strlen(authtype) &&
          strcasecmp(authtype, "md5") &&
          strcasecmp(authtype, "password") &&
          strcasecmp(authtype, "none")) {
            fail_exit("authtype, if included, must be 'md5', 'password',"
                    " 'none'.");
      }

      if (strcasecmp(method, "onoff") &&
          strcasecmp(method, "cycle")) {
            fail_exit("method, if included, muse be 'onoff', 'cycle'.");
      }

      if (!strcasecmp(method, "cycle") &&
          (!strcasecmp(op, "on") || !strcasecmp(op, "off"))) {
            fail_exit("cycle method supports only 'reboot' operation (not 'on' or 'off').");
      }

      /* Delay fencing if requested */
      if (delay) {
            if (!strcasecmp(op, "reboot") || !strcasecmp(op, "off")) {
                  sleep(atoi(delay));
            }
      }

      /* Ok, set up the IPMI struct */
      i = ipmi_init(NULL, ip, authtype, user, passwd, lanplus, verbose, timeout, down_sleep, cipher);
      if (!i)
            fail_exit("Failed to initialize\n");

      /*
         Perform the requested operation
       */
      if (!strcasecmp(op, "reboot")) {
            printf("Rebooting machine @ IPMI:%s...", ip);
            fflush(stdout);
            if (!strcasecmp(method, "cycle")) {
                  ret = ipmi_op(i, ST_STATUS, power_status);

                  if (ret == STATE_OFF) {
                        /* State is off -> use onoff method because cycle is not able to turn on*/
                        snprintf(method, sizeof(method), "onoff");
                  }
            }

            if (!strcasecmp(method, "cycle")) {
                  ret = ipmi_cycle(i);
            } else {
                  /* Original onoff method */
                  ret = ipmi_off(i);
                  translated_ret = (ret==0?ERR_OFF_SUCCESSFUL:ERR_OFF_FAIL);
                  if (ret != 0) {
                        goto out;
                  }
                  ret = ipmi_on(i);
            }
      } else if (!strcasecmp(op, "on")) {
            printf("Powering on machine @ IPMI:%s...", ip);
            fflush(stdout);
            ret = ipmi_on(i);
            translated_ret = (ret==0?ERR_ON_SUCCESSFUL:ERR_ON_FAIL);
      } else if (!strcasecmp(op, "off")) {
            printf("Powering off machine @ IPMI:%s...", ip);
            fflush(stdout);
            ret = ipmi_off(i);
            translated_ret = (ret==0?ERR_ON_SUCCESSFUL:ERR_ON_FAIL);
      } else if (!strcasecmp(op, "status") || !strcasecmp(op, "monitor")) {
            printf("Getting status of IPMI:%s...",ip);
            fflush(stdout);
            ret = ipmi_op(i, ST_STATUS, power_status);
            switch(ret) {
            case STATE_ON:
              if (!strcasecmp(op, "status"))
                      printf("Chassis power = On\n");
                  translated_ret = ERR_STATUS_ON;
                  ret = 0;
                  break;
            case STATE_OFF:
              if (!strcasecmp(op, "status"))
                      printf("Chassis power = Off\n");
                  translated_ret = ERR_STATUS_OFF;
                  ret = 0;
                  break;
            default:
              if (!strcasecmp(op, "status"))
                      printf("Chassis power = Unknown\n");
                  translated_ret = ERR_STATUS_FAIL;
                  ret = 1;
                  break;
            }
      } else if (!strcasecmp(op, "list")) {
        printf("%s\n","N/A");
        ret=0;
        translated_ret = ERR_OK;
        print_final_status=0;
      } else if (!strcasecmp(op, "diag")) {
        printf("Pulsing diagnostic interrupt to machine @ IPMI:%s...", ip);
        fflush(stdout);
        ret = ipmi_diag(i);
        translated_ret = (ret==0?ERR_ON_SUCCESSFUL:ERR_ON_FAIL);
        ret = 0;
      }


out:
      ipmi_destroy(i);
      free(i);

metaout:
      if (print_final_status) {
        if (ret == 0)
          printf("Done\n");
        else
          printf("Failed\n");
      }
      
      if (!strcasecmp(op, "monitor"))
          translated_ret = ret;
        
        if (!strcasecmp(op, "diag")) {
          /** .. but when a system receive the DIAG signal , it 
           ** switches to a kdump kernel, but the machine is always
           ** "on" during the dump phase. It only become temporarily
           ** "off" at the end of the dump just before rebooting.
           **/
          translated_ret = 0;
        }

      return translated_ret;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index