1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

parallels: create VMs and containers with sdk

This patch replaces code, which creates domains by
running prlctl command.

prlsdkCreateVm/Ct will do prlsdkApplyConfig, because
we send request to the server only once in this case.

But prlsdkApplyConfig will be called also from
parallelsDomainDefineXML function. There is no problem with
it, parallelsDomainDefineXML will be refactored later.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
This commit is contained in:
Dmitry Guryanov 2014-12-01 18:38:53 +03:00 committed by Peter Krempa
parent 02954c0bd3
commit 66d89199b4
3 changed files with 88 additions and 44 deletions

View File

@ -657,47 +657,6 @@ parallelsDomainGetAutostart(virDomainPtr domain, int *autostart)
return ret;
}
static int
parallelsCreateVm(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainDefPtr def)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(def->uuid, uuidstr);
if (parallelsCmdRun(PRLCTL, "create", def->name, "--no-hdd",
"--uuid", uuidstr, NULL) < 0)
return -1;
return 0;
}
static int
parallelsCreateCt(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainDefPtr def)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(def->uuid, uuidstr);
if (def->nfss != 1 ||
def->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("There must be only 1 template FS for "
"container creation"));
goto error;
}
if (parallelsCmdRun(PRLCTL, "create", def->name, "--vmtype", "ct",
"--uuid", uuidstr,
"--ostemplate", def->fss[0]->src, NULL) < 0)
goto error;
return 0;
error:
return -1;
}
static virDomainPtr
parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
{
@ -720,10 +679,10 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
if (olddom == NULL) {
virResetLastError();
if (STREQ(def->os.type, "hvm")) {
if (parallelsCreateVm(conn, def))
if (prlsdkCreateVm(conn, def))
goto cleanup;
} else if (STREQ(def->os.type, "exe")) {
if (parallelsCreateCt(conn, def))
if (prlsdkCreateCt(conn, def))
goto cleanup;
} else {
virReportError(VIR_ERR_INVALID_ARG,

View File

@ -2538,7 +2538,6 @@ prlsdkDoApplyConfig(PRL_HANDLE sdkdom,
error:
return -1;
}
int
@ -2570,3 +2569,87 @@ prlsdkApplyConfig(virConnectPtr conn,
return ret;
}
int
prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def)
{
parallelsConnPtr privconn = conn->privateData;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
PRL_HANDLE job = PRL_INVALID_HANDLE;
PRL_HANDLE result = PRL_INVALID_HANDLE;
PRL_HANDLE srvconf = PRL_INVALID_HANDLE;
PRL_RESULT pret;
int ret = -1;
pret = PrlSrv_CreateVm(privconn->server, &sdkdom);
prlsdkCheckRetGoto(pret, cleanup);
job = PrlSrv_GetSrvConfig(privconn->server);
if (!(result = getJobResult(job, privconn->jobTimeout)))
goto cleanup;
pret = PrlResult_GetParamByIndex(result, 0, &srvconf);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmCfg_SetDefaultConfig(sdkdom, srvconf, PVS_GUEST_VER_LIN_REDHAT, 0);
prlsdkCheckRetGoto(pret, cleanup);
ret = prlsdkDoApplyConfig(sdkdom, def);
if (ret)
goto cleanup;
job = PrlVm_Reg(sdkdom, "", 1);
ret = waitJob(job, privconn->jobTimeout);
cleanup:
PrlHandle_Free(sdkdom);
return ret;
}
int
prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
{
parallelsConnPtr privconn = conn->privateData;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
PRL_GET_VM_CONFIG_PARAM_DATA confParam;
PRL_HANDLE job = PRL_INVALID_HANDLE;
PRL_HANDLE result = PRL_INVALID_HANDLE;
PRL_RESULT pret;
int ret = -1;
if (def->nfss && (def->nfss > 1 ||
def->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE)) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("There must be no more than 1 template FS for "
"container creation"));
return -1;
}
confParam.nVmType = PVT_CT;
confParam.sConfigSample = "vswap.1024MB";
confParam.nOsVersion = 0;
job = PrlSrv_GetDefaultVmConfig(privconn->server, &confParam, 0);
if (!(result = getJobResult(job, privconn->jobTimeout)))
goto cleanup;
pret = PrlResult_GetParamByIndex(result, 0, &sdkdom);
prlsdkCheckRetGoto(pret, cleanup);
if (def->nfss == 1) {
pret = PrlVmCfg_SetOsTemplate(sdkdom, def->fss[0]->src);
prlsdkCheckRetGoto(pret, cleanup);
}
ret = prlsdkDoApplyConfig(sdkdom, def);
if (ret)
goto cleanup;
job = PrlVm_RegEx(sdkdom, "", PACF_NON_INTERACTIVE_MODE);
ret = waitJob(job, privconn->jobTimeout);
cleanup:
PrlHandle_Free(sdkdom);
return ret;
}

View File

@ -48,3 +48,5 @@ int
prlsdkApplyConfig(virConnectPtr conn,
virDomainObjPtr dom,
virDomainDefPtr new);
int prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def);
int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def);