Hi Daniel,
I didn't realize that I even did not follow the manner of XML.
I have worked with this problem and got a small patch to handle "ID"
in OpenVZ functionality.
I found it is working well with the XML script included "ID" in domain
tag.
I am concerned that I had to edit the common file domain_conf.c.
I still believe I should keep it away from this problem for
compatibility with the others.
How do you think can I avoid this?
diff --git a/src/domain_conf.c b/src/domain_conf.c
index 5ae0775..f74961f 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -2492,7 +2492,7 @@ static virDomainDefPtr virDomainDefParseXML
(virConnectPtr conn,
return NULL;
}
- if (!(flags & VIR_DOMAIN_XML_INACTIVE))
+ // if (!(flags & VIR_DOMAIN_XML_INACTIVE))
if((virXPathLong(conn, "string(./@id)", ctxt, &id)) < 0)
id = -1;
def->id = (int)id;
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index be94b9e..d23f173 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -425,17 +425,18 @@ int openvzLoadDomains(struct openvz_driver
*driver) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObjPtr dom = NULL;
char temp[50];
+ char name[64];
if (openvzAssignUUIDs() < 0)
return -1;
- if ((fp = popen(VZLIST " -a -ovpsid,status -H 2>/dev/null",
"r"))
== NULL) {
+ if ((fp = popen(VZLIST " -a -ovpsid,name,status -H 2>/dev/null",
"r")) == NULL) {
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("popen
failed"));
return -1;
}
while(!feof(fp)) {
- if (fscanf(fp, "%d %s¥n", &veid, status) != 2) {
+ if (fscanf(fp, "%d %s¥n", &veid, name, status) != 3) {
if (feof(fp))
break;
@@ -465,7 +466,7 @@ int openvzLoadDomains(struct openvz_driver
*driver) {
dom->pid = veid;
dom->def->id = dom->state == VIR_DOMAIN_SHUTOFF ? -1 : veid;
- if (virAsprintf(&dom->def->name, "%i", veid) < 0)
+ if (virAsprintf(&dom->def->name, "%s", name) < 0)
goto no_memory;
openvzGetVPSUUID(veid, uuidstr, sizeof(uuidstr));
diff --git a/src/openvz_driver.c b/src/openvz_driver.c
index a8c24ba..c0c1e0f 100644
--- a/src/openvz_driver.c
+++ b/src/openvz_driver.c
@@ -101,6 +101,7 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
virDomainDefPtr vmdef)
{
int narg;
+ char str_id[10];
for (narg = 0; narg < maxarg; narg++)
args[narg] = NULL;
@@ -130,6 +131,11 @@ static int openvzDomainDefineCmd(virConnectPtr
conn,
ADD_ARG_LIT(VZCTL);
ADD_ARG_LIT("--quiet");
ADD_ARG_LIT("create");
+
+ sprintf( str_id, "%d", vmdef->id );
+ ADD_ARG_LIT(str_id);
+
+ ADD_ARG_LIT("--name");
ADD_ARG_LIT(vmdef->name);
if (vmdef->nfss == 1 &&
@@ -1229,7 +1235,11 @@ static int openvzListDefinedDomains
(virConnectPtr conn,
char vpsname[32];
char buf[32];
char *endptr;
- const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S",
NULL};
+ const char *cmd[] = {VZLIST, "-oname", "-H", "-S",
NULL};
+ int cnt = 0;
+ char name_buf[32];
+
+
/* the -S options lists only stopped domains */
ret = virExec(conn, cmd, NULL, NULL,
@@ -1241,14 +1251,14 @@ static int openvzListDefinedDomains
(virConnectPtr conn,
}
while(got < nnames){
- ret = openvz_readline(outfd, buf, 32);
+ ret = openvz_readline(outfd, buf, 64);
if(!ret) break;
- if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
- openvzError(conn, VIR_ERR_INTERNAL_ERROR,
- _("Could not parse VPS ID %s"), buf);
- continue;
+ cnt = 0;
+ while( buf[cnt] != ' ' ){
+ name_buf[cnt] = buf[cnt];
+ cnt++;
}
- snprintf(vpsname, sizeof(vpsname), "%d", veid);
+ snprintf(vpsname, sizeof(vpsname), "%d", name_buf);
if (!(names[got] = strdup(vpsname)))
goto no_memory;
got ++;
--
1.5.2.2
-----
Yuji Nishida
nishidy(a)nict.go.jp