diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index a4aab1ee4a..ce0c4d332c 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -953,3 +953,44 @@ static int openvzAssignUUIDs(void) VIR_FREE(conf_dir); return 0; } + + +/* + * Return CTID from name + * + */ + +int openvzGetVEID(const char *name) { + char *cmd; + int veid; + FILE *fp; + + if (virAsprintf(&cmd, "%s %s -ovpsid -H", VZLIST, name) < 0) { + openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", + _("virAsprintf failed")); + return -1; + } + + fp = popen(cmd, "r"); + VIR_FREE(cmd); + + if (fp == NULL) { + openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("popen failed")); + return -1; + } + + if (fscanf(fp, "%d\n", &veid ) != 1) { + if (feof(fp)) + return -1; + + openvzError(NULL, VIR_ERR_INTERNAL_ERROR, + "%s", _("Failed to parse vzlist output")); + goto cleanup; + } + + return veid; + + cleanup: + fclose(fp); + return -1; +} diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index 00e18b4325..c863a2a3f6 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -66,5 +66,6 @@ void openvzFreeDriver(struct openvz_driver *driver); int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); unsigned int openvzGetNodeCPUs(void); +int openvzGetVEID(const char *name); #endif /* OPENVZ_CONF_H */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 68d03980db..5057b81943 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -667,7 +667,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { virBuffer buf = VIR_BUFFER_INITIALIZER; char *dev_name_ve; - int veid = strtoI(vpsid); + int veid = openvzGetVEID(vpsid); //--netif_add ifname[,mac,host_ifname,host_mac] ADD_ARG_LIT("--netif_add") ;