2012-09-18 11:41:26 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-09-18 11:41:26 +00:00
|
|
|
#include "domain_conf.h"
|
2016-04-12 22:29:52 +00:00
|
|
|
#include "virgettext.h"
|
2012-09-18 11:41:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
getArgs(int argc,
|
|
|
|
char **argv,
|
|
|
|
const char **uri,
|
|
|
|
const char **uuid,
|
|
|
|
virDomainLockFailureAction *action)
|
|
|
|
{
|
|
|
|
int act;
|
|
|
|
|
|
|
|
if (argc != 4) {
|
|
|
|
fprintf(stderr, _("%s uri uuid action\n"), argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*uri = argv[1];
|
|
|
|
*uuid = argv[2];
|
|
|
|
|
|
|
|
act = virDomainLockFailureTypeFromString(argv[3]);
|
|
|
|
if (act < 0) {
|
|
|
|
fprintf(stderr, _("invalid failure action: '%s'\n"), argv[3]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*action = act;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2019-10-14 12:45:33 +00:00
|
|
|
authCallback(virConnectCredentialPtr cred G_GNUC_UNUSED,
|
|
|
|
unsigned int ncred G_GNUC_UNUSED,
|
|
|
|
void *cbdata G_GNUC_UNUSED)
|
2012-09-18 11:41:26 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *uri;
|
|
|
|
const char *uuid;
|
|
|
|
virDomainLockFailureAction action;
|
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
int ret = EXIT_FAILURE;
|
|
|
|
|
|
|
|
int authTypes[] = {
|
|
|
|
VIR_CRED_AUTHNAME,
|
|
|
|
VIR_CRED_ECHOPROMPT,
|
|
|
|
VIR_CRED_PASSPHRASE,
|
|
|
|
VIR_CRED_NOECHOPROMPT,
|
|
|
|
};
|
|
|
|
virConnectAuth auth = {
|
|
|
|
.credtype = authTypes,
|
2019-10-15 11:55:26 +00:00
|
|
|
.ncredtype = G_N_ELEMENTS(authTypes),
|
2012-09-18 11:41:26 +00:00
|
|
|
.cb = authCallback,
|
|
|
|
};
|
|
|
|
|
2016-04-12 22:29:52 +00:00
|
|
|
if (virGettextInitialize() < 0)
|
2012-09-18 11:41:26 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
if (getArgs(argc, argv, &uri, &uuid, &action) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(conn = virConnectOpenAuth(uri, &auth, 0)) ||
|
|
|
|
!(dom = virDomainLookupByUUIDString(conn, uuid)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_POWEROFF:
|
|
|
|
if (virDomainDestroy(dom) == 0 ||
|
|
|
|
virDomainIsActive(dom) == 0)
|
|
|
|
ret = EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_PAUSE:
|
|
|
|
if (virDomainSuspend(dom) == 0)
|
|
|
|
ret = EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
2014-03-24 13:22:36 +00:00
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_DEFAULT:
|
2014-03-24 13:23:09 +00:00
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_RESTART:
|
2012-09-18 11:41:26 +00:00
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_IGNORE:
|
2014-03-24 13:22:36 +00:00
|
|
|
case VIR_DOMAIN_LOCK_FAILURE_LAST:
|
2012-09-18 11:41:26 +00:00
|
|
|
fprintf(stderr, _("unsupported failure action: '%s'\n"),
|
|
|
|
virDomainLockFailureTypeToString(action));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2014-11-30 14:57:02 +00:00
|
|
|
virObjectUnref(dom);
|
2012-09-18 11:41:26 +00:00
|
|
|
if (conn)
|
|
|
|
virConnectClose(conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|