You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

153 lines
3.6 KiB

  1. /*
  2. * virt-host-validate.c: Sanity check a hypervisor host
  3. *
  4. * Copyright (C) 2012 Red Hat, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include <config.h>
  22. #ifdef HAVE_LIBINTL_H
  23. # include <libintl.h>
  24. #endif /* HAVE_LIBINTL_H */
  25. #include <getopt.h>
  26. #include "internal.h"
  27. #include "virgettext.h"
  28. #include "virt-host-validate-common.h"
  29. #if WITH_QEMU
  30. # include "virt-host-validate-qemu.h"
  31. #endif
  32. #if WITH_LXC
  33. # include "virt-host-validate-lxc.h"
  34. #endif
  35. #if WITH_BHYVE
  36. # include "virt-host-validate-bhyve.h"
  37. #endif
  38. static void
  39. show_help(FILE *out, const char *argv0)
  40. {
  41. fprintf(out,
  42. _("\n"
  43. "syntax: %s [OPTIONS] [HVTYPE]\n"
  44. "\n"
  45. " Hypervisor types:\n"
  46. "\n"
  47. " - qemu\n"
  48. " - lxc\n"
  49. " - bhyve\n"
  50. "\n"
  51. " Options:\n"
  52. " -h, --help Display command line help\n"
  53. " -v, --version Display command version\n"
  54. " -q, --quiet Don't display progress information\n"
  55. "\n"),
  56. argv0);
  57. }
  58. static void
  59. show_version(FILE *out, const char *argv0)
  60. {
  61. fprintf(out, "version: %s %s\n", argv0, VERSION);
  62. }
  63. static const struct option argOptions[] = {
  64. { "help", 0, NULL, 'h', },
  65. { "version", 0, NULL, 'v', },
  66. { "quiet", 0, NULL, 'q', },
  67. { NULL, 0, NULL, '\0', }
  68. };
  69. int
  70. main(int argc, char **argv)
  71. {
  72. const char *hvname = NULL;
  73. int c;
  74. int ret = EXIT_SUCCESS;
  75. bool quiet = false;
  76. bool usedHvname = false;
  77. if (virGettextInitialize() < 0)
  78. return EXIT_FAILURE;
  79. while ((c = getopt_long(argc, argv, "hvq", argOptions, NULL)) != -1) {
  80. switch (c) {
  81. case 'v':
  82. show_version(stdout, argv[0]);
  83. return EXIT_SUCCESS;
  84. case 'h':
  85. show_help(stdout, argv[0]);
  86. return EXIT_SUCCESS;
  87. case 'q':
  88. quiet = true;
  89. break;
  90. case '?':
  91. default:
  92. show_help(stderr, argv[0]);
  93. return EXIT_FAILURE;
  94. }
  95. }
  96. if ((argc-optind) > 2) {
  97. fprintf(stderr, _("%s: too many command line arguments\n"), argv[0]);
  98. show_help(stderr, argv[0]);
  99. return EXIT_FAILURE;
  100. }
  101. if (argc > 1)
  102. hvname = argv[optind];
  103. virHostMsgSetQuiet(quiet);
  104. #if WITH_QEMU
  105. if (!hvname || STREQ(hvname, "qemu")) {
  106. usedHvname = true;
  107. if (virHostValidateQEMU() < 0)
  108. ret = EXIT_FAILURE;
  109. }
  110. #endif
  111. #if WITH_LXC
  112. if (!hvname || STREQ(hvname, "lxc")) {
  113. usedHvname = true;
  114. if (virHostValidateLXC() < 0)
  115. ret = EXIT_FAILURE;
  116. }
  117. #endif
  118. #if WITH_BHYVE
  119. if (!hvname || STREQ(hvname, "bhyve")) {
  120. usedHvname = true;
  121. if (virHostValidateBhyve() < 0)
  122. ret = EXIT_FAILURE;
  123. }
  124. #endif
  125. if (hvname && !usedHvname) {
  126. fprintf(stderr, _("%s: unsupported hypervisor name %s\n"),
  127. argv[0], hvname);
  128. return EXIT_FAILURE;
  129. }
  130. return ret;
  131. }