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.
 
 
 
 
 
 

176 lines
5.4 KiB

  1. /*
  2. * virsh.h: a shell to exercise the libvirt API
  3. *
  4. * Copyright (C) 2005, 2007-2016 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. #pragma once
  21. #include <stdarg.h>
  22. #include <unistd.h>
  23. #include <sys/stat.h>
  24. #include "internal.h"
  25. #include "virerror.h"
  26. #include "virthread.h"
  27. #include "virpolkit.h"
  28. #include "vsh.h"
  29. #include "virsh-completer.h"
  30. #include "virenum.h"
  31. #define VIRSH_PROMPT_RW "virsh # "
  32. #define VIRSH_PROMPT_RO "virsh > "
  33. #define VIR_FROM_THIS VIR_FROM_NONE
  34. /*
  35. * Command group types
  36. */
  37. #define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint"
  38. #define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
  39. #define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
  40. #define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool"
  41. #define VIRSH_CMD_GRP_STORAGE_VOL "Storage Volume"
  42. #define VIRSH_CMD_GRP_NETWORK "Networking"
  43. #define VIRSH_CMD_GRP_NODEDEV "Node Device"
  44. #define VIRSH_CMD_GRP_IFACE "Interface"
  45. #define VIRSH_CMD_GRP_NWFILTER "Network Filter"
  46. #define VIRSH_CMD_GRP_SECRET "Secret"
  47. #define VIRSH_CMD_GRP_SNAPSHOT "Snapshot"
  48. #define VIRSH_CMD_GRP_BACKUP "Backup"
  49. #define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor"
  50. #define VIRSH_CMD_GRP_VIRSH "Virsh itself"
  51. /*
  52. * Common command options
  53. */
  54. #define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \
  55. {.name = "pool", \
  56. .type = VSH_OT_DATA, \
  57. .flags = VSH_OFLAG_REQ, \
  58. .help = _helpstr, \
  59. .completer = virshStoragePoolNameCompleter, \
  60. .completer_flags = cflags, \
  61. }
  62. #define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \
  63. {.name = "domain", \
  64. .type = VSH_OT_DATA, \
  65. .flags = VSH_OFLAG_REQ, \
  66. .help = _helpstr, \
  67. .completer = virshDomainNameCompleter, \
  68. .completer_flags = cflags, \
  69. }
  70. #define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \
  71. VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags)
  72. #define VIRSH_COMMON_OPT_CONFIG(_helpstr) \
  73. {.name = "config", \
  74. .type = VSH_OT_BOOL, \
  75. .help = _helpstr \
  76. }
  77. #define VIRSH_COMMON_OPT_LIVE(_helpstr) \
  78. {.name = "live", \
  79. .type = VSH_OT_BOOL, \
  80. .help = _helpstr \
  81. }
  82. #define VIRSH_COMMON_OPT_CURRENT(_helpstr) \
  83. {.name = "current", \
  84. .type = VSH_OT_BOOL, \
  85. .help = _helpstr \
  86. }
  87. #define VIRSH_COMMON_OPT_FILE(_helpstr) \
  88. {.name = "file", \
  89. .type = VSH_OT_DATA, \
  90. .flags = VSH_OFLAG_REQ, \
  91. .help = _helpstr \
  92. }
  93. #define VIRSH_COMMON_OPT_DOMAIN_OT_STRING(_helpstr, oflags, cflags) \
  94. {.name = "domain", \
  95. .type = VSH_OT_STRING, \
  96. .flags = oflags, \
  97. .help = _helpstr, \
  98. .completer = virshDomainNameCompleter, \
  99. .completer_flags = cflags, \
  100. }
  101. #define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(oflags, cflags) \
  102. VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), \
  103. oflags, cflags)
  104. #define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(_helpstr, cflags) \
  105. {.name = "domain", \
  106. .type = VSH_OT_ARGV, \
  107. .flags = VSH_OFLAG_NONE, \
  108. .help = _helpstr, \
  109. .completer = virshDomainNameCompleter, \
  110. .completer_flags = cflags, \
  111. }
  112. #define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV_FULL(cflags) \
  113. VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("domain name, id or uuid"), cflags)
  114. typedef struct _virshControl virshControl;
  115. typedef virshControl *virshControlPtr;
  116. typedef struct _virshCtrlData virshCtrlData;
  117. /*
  118. * vshControl
  119. */
  120. struct _virshControl {
  121. virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */
  122. bool readonly; /* connect readonly (first time only, not
  123. * during explicit connect command)
  124. */
  125. bool useGetInfo; /* must use virDomainGetInfo, since
  126. virDomainGetState is not supported */
  127. bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or
  128. virDomainSnapshotNumChildren */
  129. bool blockJobNoBytes; /* true if _BANDWIDTH_BYTE blockjob flags
  130. are missing */
  131. const char *escapeChar; /* String representation of
  132. console escape character */
  133. };
  134. /* Typedefs, function prototypes for job progress reporting.
  135. * There are used by some long lingering commands like
  136. * migrate, dump, save, managedsave.
  137. */
  138. struct _virshCtrlData {
  139. vshControl *ctl;
  140. const vshCmd *cmd;
  141. GMainLoop *eventLoop;
  142. int ret;
  143. virConnectPtr dconn;
  144. };
  145. /* Filter flags for various vshCommandOpt*By() functions */
  146. typedef enum {
  147. VIRSH_BYID = (1 << 1),
  148. VIRSH_BYUUID = (1 << 2),
  149. VIRSH_BYNAME = (1 << 3),
  150. VIRSH_BYMAC = (1 << 4),
  151. } virshLookupByFlags;
  152. virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);