81 | 81 |
static gboolean opt_waitvm = FALSE;
|
82 | 82 |
static gboolean opt_reconnect = FALSE;
|
83 | 83 |
|
|
84 |
typedef enum {
|
|
85 |
DOMAIN_SELECTION_ID = (1 << 0),
|
|
86 |
DOMAIN_SELECTION_UUID = (1 << 1),
|
|
87 |
DOMAIN_SELECTION_NAME = (1 << 2),
|
|
88 |
DOMAIN_SELECTION_DEFAULT = DOMAIN_SELECTION_ID | DOMAIN_SELECTION_UUID | DOMAIN_SELECTION_NAME,
|
|
89 |
} DomainSelection;
|
|
90 |
|
|
91 |
static const gchar* domain_selection_to_opt[] = {
|
|
92 |
[DOMAIN_SELECTION_ID] = "--id",
|
|
93 |
[DOMAIN_SELECTION_UUID] = "--uuid",
|
|
94 |
[DOMAIN_SELECTION_NAME] = "--domain-name",
|
|
95 |
};
|
|
96 |
|
|
97 |
static DomainSelection domain_selection_type = DOMAIN_SELECTION_DEFAULT;
|
|
98 |
|
|
99 |
static gboolean
|
|
100 |
opt_domain_selection_cb(const gchar *option_name,
|
|
101 |
const gchar *value G_GNUC_UNUSED,
|
|
102 |
gpointer data G_GNUC_UNUSED,
|
|
103 |
GError **error)
|
|
104 |
{
|
|
105 |
guint i;
|
|
106 |
if (domain_selection_type != DOMAIN_SELECTION_DEFAULT) {
|
|
107 |
g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
|
|
108 |
"selection type has been already set");
|
|
109 |
return FALSE;
|
|
110 |
}
|
|
111 |
|
|
112 |
for (i = DOMAIN_SELECTION_ID; i <= G_N_ELEMENTS(domain_selection_to_opt); i++) {
|
|
113 |
if (g_strcmp0(option_name, domain_selection_to_opt[i]) == 0) {
|
|
114 |
domain_selection_type = i;
|
|
115 |
return TRUE;
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
g_assert_not_reached();
|
|
120 |
return FALSE;
|
|
121 |
}
|
|
122 |
|
84 | 123 |
static void
|
85 | 124 |
virt_viewer_add_option_entries(VirtViewerApp *self, GOptionContext *context, GOptionGroup *group)
|
86 | 125 |
{
|
|
95 | 134 |
N_("Wait for domain to start"), NULL },
|
96 | 135 |
{ "reconnect", 'r', 0, G_OPTION_ARG_NONE, &opt_reconnect,
|
97 | 136 |
N_("Reconnect to domain upon restart"), NULL },
|
|
137 |
{ "domain-name", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_domain_selection_cb,
|
|
138 |
N_("Select the virtual machine only by its name"), NULL },
|
|
139 |
{ "id", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_domain_selection_cb,
|
|
140 |
N_("Select the virtual machine only by its id"), NULL },
|
|
141 |
{ "uuid", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_domain_selection_cb,
|
|
142 |
N_("Select the virtual machine only by its uuid"), NULL },
|
98 | 143 |
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_args,
|
99 | 144 |
NULL, "-- DOMAIN-NAME|ID|UUID" },
|
100 | 145 |
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
|
|
130 | 175 |
}
|
131 | 176 |
|
132 | 177 |
|
133 | |
if (opt_waitvm) {
|
|
178 |
if (opt_waitvm || domain_selection_type != DOMAIN_SELECTION_DEFAULT) {
|
134 | 179 |
if (!self->priv->domkey) {
|
135 | |
g_printerr(_("\nNo DOMAIN-NAME|ID|UUID was specified for '--wait'\n\n"));
|
|
180 |
g_printerr(_("\nNo DOMAIN-NAME|ID|UUID was specified for '%s'\n\n"),
|
|
181 |
opt_waitvm ? "--wait" : domain_selection_to_opt[domain_selection_type]);
|
136 | 182 |
ret = TRUE;
|
137 | 183 |
*status = 1;
|
138 | 184 |
goto end;
|
139 | 185 |
}
|
140 | 186 |
|
141 | |
self->priv->waitvm = TRUE;
|
|
187 |
self->priv->waitvm = opt_waitvm;
|
142 | 188 |
}
|
143 | 189 |
|
144 | 190 |
virt_viewer_app_set_direct(app, opt_direct);
|
|
302 | 348 |
{
|
303 | 349 |
char *end;
|
304 | 350 |
VirtViewerPrivate *priv = self->priv;
|
305 | |
int id;
|
306 | 351 |
virDomainPtr dom = NULL;
|
307 | |
unsigned char uuid[16];
|
308 | 352 |
|
309 | 353 |
if (priv->domkey == NULL) {
|
310 | 354 |
return NULL;
|
311 | 355 |
}
|
312 | 356 |
|
313 | |
id = strtol(priv->domkey, &end, 10);
|
314 | |
if (id >= 0 && end && !*end) {
|
315 | |
dom = virDomainLookupByID(priv->conn, id);
|
316 | |
}
|
317 | |
if (!dom && virt_viewer_parse_uuid(priv->domkey, uuid) == 0) {
|
318 | |
dom = virDomainLookupByUUID(priv->conn, uuid);
|
319 | |
}
|
320 | |
if (!dom) {
|
321 | |
dom = virDomainLookupByName(priv->conn, priv->domkey);
|
322 | |
}
|
|
357 |
if (domain_selection_type & DOMAIN_SELECTION_ID) {
|
|
358 |
long int id = strtol(priv->domkey, &end, 10);
|
|
359 |
if (id >= 0 && end && !*end) {
|
|
360 |
dom = virDomainLookupByID(priv->conn, id);
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
if (domain_selection_type & DOMAIN_SELECTION_UUID) {
|
|
365 |
unsigned char uuid[16];
|
|
366 |
if (dom == NULL && virt_viewer_parse_uuid(priv->domkey, uuid) == 0) {
|
|
367 |
dom = virDomainLookupByUUID(priv->conn, uuid);
|
|
368 |
}
|
|
369 |
}
|
|
370 |
|
|
371 |
if (domain_selection_type & DOMAIN_SELECTION_NAME) {
|
|
372 |
if (dom == NULL) {
|
|
373 |
dom = virDomainLookupByName(priv->conn, priv->domkey);
|
|
374 |
}
|
|
375 |
}
|
|
376 |
|
323 | 377 |
return dom;
|
324 | 378 |
}
|
325 | 379 |
|