diff --git a/src/openvz_conf.c b/src/openvz_conf.c index c5f4a14..f766d8e 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -781,6 +781,32 @@ static char return NULL; } +/* Return 0 if we can access and read file /etc/vz/conf/ve-$name.conf-sample + * Return -1 on error */ +int +openvzAccessDefaultProfile(const char *ostemplate) +{ + char *profile; + int ret = -1; + char *confdir = openvzLocateConfDir(); + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if (confdir == NULL) + return ret; + + virBufferVSprintf(&buf, "%s/ve-%s.conf-sample", confdir, ostemplate); + if (virBufferError(&buf)) + return ret; + + profile = virBufferContentAndReset(&buf); + if (profile != NULL) { + ret = access(profile, F_OK); + VIR_FREE(profile); + } + + return ret; +} + /* Richard Steven's classic readline() function */ int openvz_readline(int fd, char *ptr, int maxlen) diff --git a/src/openvz_conf.h b/src/openvz_conf.h index 00e18b4..b16409b 100644 --- a/src/openvz_conf.h +++ b/src/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 openvzAccessDefaultProfile(const char *ostemplate); #endif /* OPENVZ_CONF_H */ diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 755e449..5d12477 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -135,15 +135,16 @@ static int openvzDomainDefineCmd(virConnectPtr conn, if (vmdef->nfss == 1 && vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) { + char *ostemplate = vmdef->fss[0]->src; + ADD_ARG_LIT("--ostemplate"); - ADD_ARG_LIT(vmdef->fss[0]->src); - } -#if 0 - if ((vmdef->profile && *(vmdef->profile))) { - ADD_ARG_LIT("--config"); - ADD_ARG_LIT(vmdef->profile); + ADD_ARG_LIT(ostemplate); + + if (openvzAccessDefaultProfile(ostemplate) != -1) { + ADD_ARG_LIT("--config"); + ADD_ARG_LIT(ostemplate); + } } -#endif ADD_ARG(NULL); return 0;