virsh.h 5.3 KB
Newer Older
E
Eric Blake 已提交
1 2 3
/*
 * virsh.h: a shell to exercise the libvirt API
 *
4
 * Copyright (C) 2005, 2007-2016 Red Hat, Inc.
E
Eric Blake 已提交
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
E
Eric Blake 已提交
18 19 20
 * <http://www.gnu.org/licenses/>.
 */

21
#pragma once
E
Eric Blake 已提交
22

23 24 25 26
#include <stdarg.h>
#include <unistd.h>
#include <sys/stat.h>
#include <termios.h>
E
Eric Blake 已提交
27

28 29 30 31 32 33
#include "internal.h"
#include "virerror.h"
#include "virthread.h"
#include "virpolkit.h"
#include "vsh.h"
#include "virsh-completer.h"
E
Eric Blake 已提交
34

35 36
#define VIRSH_PROMPT_RW    "virsh # "
#define VIRSH_PROMPT_RO    "virsh > "
E
Eric Blake 已提交
37

38
#define VIR_FROM_THIS VIR_FROM_NONE
E
Eric Blake 已提交
39 40 41 42

/*
 * Command group types
 */
43
#define VIRSH_CMD_GRP_CHECKPOINT       "Checkpoint"
44 45 46 47 48 49 50 51 52 53
#define VIRSH_CMD_GRP_DOM_MANAGEMENT   "Domain Management"
#define VIRSH_CMD_GRP_DOM_MONITORING   "Domain Monitoring"
#define VIRSH_CMD_GRP_STORAGE_POOL     "Storage Pool"
#define VIRSH_CMD_GRP_STORAGE_VOL      "Storage Volume"
#define VIRSH_CMD_GRP_NETWORK          "Networking"
#define VIRSH_CMD_GRP_NODEDEV          "Node Device"
#define VIRSH_CMD_GRP_IFACE            "Interface"
#define VIRSH_CMD_GRP_NWFILTER         "Network Filter"
#define VIRSH_CMD_GRP_SECRET           "Secret"
#define VIRSH_CMD_GRP_SNAPSHOT         "Snapshot"
54
#define VIRSH_CMD_GRP_BACKUP           "Backup"
55 56
#define VIRSH_CMD_GRP_HOST_AND_HV      "Host and Hypervisor"
#define VIRSH_CMD_GRP_VIRSH            "Virsh itself"
E
Eric Blake 已提交
57

58 59 60
/*
 * Common command options
 */
61
#define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \
62 63 64
    {.name = "pool", \
     .type = VSH_OT_DATA, \
     .flags = VSH_OFLAG_REQ, \
65 66 67
     .help = _helpstr, \
     .completer = virshStoragePoolNameCompleter, \
     .completer_flags = cflags, \
68
    }
69

70
#define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \
71 72 73
    {.name = "domain", \
     .type = VSH_OT_DATA, \
     .flags = VSH_OFLAG_REQ, \
74 75 76
     .help = _helpstr, \
     .completer = virshDomainNameCompleter, \
     .completer_flags = cflags, \
77
    }
78

79
#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \
80 81
    VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags)

82
#define VIRSH_COMMON_OPT_CONFIG(_helpstr) \
83 84 85
    {.name = "config", \
     .type = VSH_OT_BOOL, \
     .help = _helpstr \
86
    }
87

88
#define VIRSH_COMMON_OPT_LIVE(_helpstr) \
89 90 91
    {.name = "live", \
     .type = VSH_OT_BOOL, \
     .help = _helpstr \
92
    }
93

94
#define VIRSH_COMMON_OPT_CURRENT(_helpstr) \
95 96 97
    {.name = "current", \
     .type = VSH_OT_BOOL, \
     .help = _helpstr \
98
    }
99

100
#define VIRSH_COMMON_OPT_FILE(_helpstr) \
101 102 103 104
    {.name = "file", \
     .type = VSH_OT_DATA, \
     .flags = VSH_OFLAG_REQ, \
     .help = _helpstr \
105
    }
106

107
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING(_helpstr, oflags, cflags) \
108 109
    {.name = "domain", \
     .type = VSH_OT_STRING, \
110
     .flags = oflags, \
111 112 113 114 115
     .help = _helpstr, \
     .completer = virshDomainNameCompleter, \
     .completer_flags = cflags, \
    }

116
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(oflags, cflags) \
117 118
    VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), \
                                      oflags, cflags)
119

120
#define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(_helpstr, cflags) \
121 122 123 124 125 126 127 128
    {.name = "domain", \
     .type = VSH_OT_ARGV, \
     .flags = VSH_OFLAG_NONE, \
     .help = _helpstr, \
     .completer = virshDomainNameCompleter, \
     .completer_flags = cflags, \
    }

129
#define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV_FULL(cflags) \
130 131
    VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("domain name, id or uuid"), cflags)

132 133
typedef struct _virshControl virshControl;
typedef virshControl *virshControlPtr;
E
Eric Blake 已提交
134

135
typedef struct _virshCtrlData virshCtrlData;
E
Eric Blake 已提交
136 137 138 139

/*
 * vshControl
 */
140
struct _virshControl {
E
Eric Blake 已提交
141 142 143 144 145 146 147 148
    virConnectPtr conn;         /* connection to hypervisor (MAY BE NULL) */
    bool readonly;              /* connect readonly (first time only, not
                                 * during explicit connect command)
                                 */
    bool useGetInfo;            /* must use virDomainGetInfo, since
                                   virDomainGetState is not supported */
    bool useSnapshotOld;        /* cannot use virDomainSnapshotGetParent or
                                   virDomainSnapshotNumChildren */
149 150
    bool blockJobNoBytes;       /* true if _BANDWIDTH_BYTE blockjob flags
                                   are missing */
E
Eric Blake 已提交
151 152
    const char *escapeChar;     /* String representation of
                                   console escape character */
E
Eric Blake 已提交
153
};
E
Eric Blake 已提交
154 155 156 157 158

/* Typedefs, function prototypes for job progress reporting.
 * There are used by some long lingering commands like
 * migrate, dump, save, managedsave.
 */
159
struct _virshCtrlData {
E
Eric Blake 已提交
160 161 162
    vshControl *ctl;
    const vshCmd *cmd;
    int writefd;
163
    virConnectPtr dconn;
E
Eric Blake 已提交
164
};
E
Eric Blake 已提交
165

166 167 168 169 170 171 172
/* Filter flags for various vshCommandOpt*By() functions */
typedef enum {
    VIRSH_BYID   = (1 << 1),
    VIRSH_BYUUID = (1 << 2),
    VIRSH_BYNAME = (1 << 3),
    VIRSH_BYMAC  = (1 << 4),
} virshLookupByFlags;
173

174
virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);