mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh-edit: Make force editing usable
When editing a domain with 'virsh edit' and failing validation, the usual message pops up: Failed. Try again? [y,n,f,?]: Turning off validation can be useful, mainly for testing (but other purposes too), so this patch adds support for relaxing definition in virsh-edit and makes 'virsh edit <domain>' more usable. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
675fa6b360
commit
1bb1de83b2
@ -11265,7 +11265,13 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
} while (0)
|
} while (0)
|
||||||
#define EDIT_DEFINE \
|
#define EDIT_DEFINE \
|
||||||
(dom_edited = vshDomainDefine(ctl->conn, doc_edited, define_flags))
|
(dom_edited = vshDomainDefine(ctl->conn, doc_edited, define_flags))
|
||||||
|
#define EDIT_RELAX \
|
||||||
|
do { \
|
||||||
|
define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
#include "virsh-edit.c"
|
#include "virsh-edit.c"
|
||||||
|
#undef EDIT_RELAX
|
||||||
|
|
||||||
vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
|
vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
|
||||||
virDomainGetName(dom_edited));
|
virDomainGetName(dom_edited));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virsh-edit.c: Implementation of generic virsh *-edit intelligence
|
* virsh-edit.c: Implementation of generic virsh *-edit intelligence
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Red Hat, Inc.
|
* Copyright (C) 2012, 2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -62,6 +62,7 @@ do {
|
|||||||
char *doc_reread = NULL;
|
char *doc_reread = NULL;
|
||||||
const char *msg = NULL;
|
const char *msg = NULL;
|
||||||
bool edit_success = false;
|
bool edit_success = false;
|
||||||
|
bool relax_avail = false;
|
||||||
|
|
||||||
/* Get the XML configuration of the object. */
|
/* Get the XML configuration of the object. */
|
||||||
doc = (EDIT_GET_XML);
|
doc = (EDIT_GET_XML);
|
||||||
@ -74,6 +75,11 @@ do {
|
|||||||
goto edit_cleanup;
|
goto edit_cleanup;
|
||||||
|
|
||||||
reedit:
|
reedit:
|
||||||
|
|
||||||
|
#ifdef EDIT_RELAX
|
||||||
|
relax_avail = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Start the editor. */
|
/* Start the editor. */
|
||||||
if (vshEditFile(ctl, tmp) == -1)
|
if (vshEditFile(ctl, tmp) == -1)
|
||||||
goto edit_cleanup;
|
goto edit_cleanup;
|
||||||
@ -112,7 +118,7 @@ do {
|
|||||||
msg = _("Failed.");
|
msg = _("Failed.");
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
int c = vshAskReedit(ctl, msg);
|
int c = vshAskReedit(ctl, msg, relax_avail);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'y':
|
case 'y':
|
||||||
goto reedit;
|
goto reedit;
|
||||||
@ -126,6 +132,17 @@ do {
|
|||||||
goto edit_cleanup;
|
goto edit_cleanup;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef EDIT_RELAX
|
||||||
|
case 'i':
|
||||||
|
if (relax_avail) {
|
||||||
|
EDIT_RELAX;
|
||||||
|
relax_avail = false;
|
||||||
|
goto redefine;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall-through */
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
vshError(ctl, "%s", msg);
|
vshError(ctl, "%s", msg);
|
||||||
break;
|
break;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virsh.c: a shell to exercise the libvirt API
|
* virsh.c: a shell to exercise the libvirt API
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005, 2007-2014 Red Hat, Inc.
|
* Copyright (C) 2005, 2007-2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -512,13 +512,14 @@ vshPrintRaw(vshControl *ctl, ...)
|
|||||||
* edited file.
|
* edited file.
|
||||||
*
|
*
|
||||||
* Returns 'y' if he wants to
|
* Returns 'y' if he wants to
|
||||||
* 'f' if he forcibly wants to
|
|
||||||
* 'n' if he doesn't want to
|
* 'n' if he doesn't want to
|
||||||
|
* 'i' if he wants to try defining it again while ignoring validation
|
||||||
|
* 'f' if he forcibly wants to
|
||||||
* -1 on error
|
* -1 on error
|
||||||
* 0 otherwise
|
* 0 otherwise
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vshAskReedit(vshControl *ctl, const char *msg)
|
vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail)
|
||||||
{
|
{
|
||||||
int c = -1;
|
int c = -1;
|
||||||
|
|
||||||
@ -531,9 +532,8 @@ vshAskReedit(vshControl *ctl, const char *msg)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
/* TRANSLATORS: For now, we aren't using LC_MESSAGES, and the user
|
vshPrint(ctl, "\r%s %s %s: ", msg, _("Try again?"),
|
||||||
* choices really are limited to just 'y', 'n', 'f' and '?' */
|
relax_avail ? "[y,n,i,f,?]" : "[y,n,f,?]");
|
||||||
vshPrint(ctl, "\r%s %s", msg, _("Try again? [y,n,f,?]:"));
|
|
||||||
c = c_tolower(getchar());
|
c = c_tolower(getchar());
|
||||||
|
|
||||||
if (c == '?') {
|
if (c == '?') {
|
||||||
@ -541,11 +541,21 @@ vshAskReedit(vshControl *ctl, const char *msg)
|
|||||||
"",
|
"",
|
||||||
_("y - yes, start editor again"),
|
_("y - yes, start editor again"),
|
||||||
_("n - no, throw away my changes"),
|
_("n - no, throw away my changes"),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (relax_avail) {
|
||||||
|
vshPrintRaw(ctl,
|
||||||
|
_("i - turn off validation and try to redefine again"),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
vshPrintRaw(ctl,
|
||||||
_("f - force, try to redefine again"),
|
_("f - force, try to redefine again"),
|
||||||
_("? - print this help"),
|
_("? - print this help"),
|
||||||
NULL);
|
NULL);
|
||||||
continue;
|
continue;
|
||||||
} else if (c == 'y' || c == 'n' || c == 'f') {
|
} else if (c == 'y' || c == 'n' || c == 'f' ||
|
||||||
|
(relax_avail && c == 'i')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,7 +567,9 @@ vshAskReedit(vshControl *ctl, const char *msg)
|
|||||||
}
|
}
|
||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
int
|
int
|
||||||
vshAskReedit(vshControl *ctl, const char *msg ATTRIBUTE_UNUSED)
|
vshAskReedit(vshControl *ctl,
|
||||||
|
const char *msg ATTRIBUTE_UNUSED,
|
||||||
|
bool relax_avail ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
vshDebug(ctl, VSH_ERR_WARNING, "%s", _("This function is not "
|
vshDebug(ctl, VSH_ERR_WARNING, "%s", _("This function is not "
|
||||||
"supported on WIN32 platform"));
|
"supported on WIN32 platform"));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virsh.h: a shell to exercise the libvirt API
|
* virsh.h: a shell to exercise the libvirt API
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005, 2007-2014 Red Hat, Inc.
|
* Copyright (C) 2005, 2007-2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -359,7 +359,7 @@ char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
|
|||||||
char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
|
char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
|
||||||
int vshEditFile(vshControl *ctl, const char *filename);
|
int vshEditFile(vshControl *ctl, const char *filename);
|
||||||
char *vshEditReadBackFile(vshControl *ctl, const char *filename);
|
char *vshEditReadBackFile(vshControl *ctl, const char *filename);
|
||||||
int vshAskReedit(vshControl *ctl, const char *msg);
|
int vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail);
|
||||||
int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
|
int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
double vshPrettyCapacity(unsigned long long val, const char **unit);
|
double vshPrettyCapacity(unsigned long long val, const char **unit);
|
||||||
|
Loading…
Reference in New Issue
Block a user