storage_conf: Merge AuthChap and AuthCephx into AuthSecret

Merge virStoragePoolDefParseAuthChap and virStoragePoolDefParseAuthCephx
into a common virStoragePoolDefParseAuthSecret.  Change the output to be
common for both by putting 'type' first followed by 'username'.
This commit is contained in:
John Ferlan 2013-07-13 15:43:46 -04:00
parent 37029be4c0
commit 41ac818483

View File

@ -456,73 +456,35 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
} }
} }
static int static int
virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt, virStoragePoolDefParseAuthSecret(xmlXPathContextPtr ctxt,
virStoragePoolAuthChapPtr auth) virStoragePoolAuthSecretPtr secret)
{ {
char *uuid = NULL; char *uuid = NULL;
int ret = -1; int ret = -1;
uuid = virXPathString("string(./auth/secret/@uuid)", ctxt); uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
auth->secret.usage = virXPathString("string(./auth/secret/@usage)", ctxt); secret->usage = virXPathString("string(./auth/secret/@usage)", ctxt);
if (uuid == NULL && auth->secret.usage == NULL) { if (uuid == NULL && secret->usage == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing auth secret uuid or usage attribute")); _("missing auth secret uuid or usage attribute"));
return -1; return -1;
} }
if (uuid != NULL) { if (uuid != NULL) {
if (auth->secret.usage != NULL) { if (secret->usage != NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("either auth secret uuid or usage expected")); _("either auth secret uuid or usage expected"));
goto cleanup; goto cleanup;
} }
if (virUUIDParse(uuid, auth->secret.uuid) < 0) { if (virUUIDParse(uuid, secret->uuid) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid auth secret uuid")); _("invalid auth secret uuid"));
goto cleanup; goto cleanup;
} }
auth->secret.uuidUsable = true; secret->uuidUsable = true;
} else { } else {
auth->secret.uuidUsable = false; secret->uuidUsable = false;
}
ret = 0;
cleanup:
VIR_FREE(uuid);
return ret;
}
static int
virStoragePoolDefParseAuthCephx(xmlXPathContextPtr ctxt,
virStoragePoolAuthCephxPtr auth)
{
char *uuid = NULL;
int ret = -1;
uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
auth->secret.usage = virXPathString("string(./auth/secret/@usage)", ctxt);
if (uuid == NULL && auth->secret.usage == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing auth secret uuid or usage attribute"));
return -1;
}
if (uuid != NULL) {
if (auth->secret.usage != NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("either auth secret uuid or usage expected"));
goto cleanup;
}
if (virUUIDParse(uuid, auth->secret.uuid) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid auth secret uuid"));
goto cleanup;
}
auth->secret.uuidUsable = true;
} else {
auth->secret.uuidUsable = false;
} }
ret = 0; ret = 0;
@ -564,13 +526,15 @@ virStoragePoolDefParseAuth(xmlXPathContextPtr ctxt,
if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) { if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) {
source->auth.chap.username = username; source->auth.chap.username = username;
username = NULL; username = NULL;
if (virStoragePoolDefParseAuthChap(ctxt, &source->auth.chap) < 0) if (virStoragePoolDefParseAuthSecret(ctxt,
&source->auth.chap.secret) < 0)
goto cleanup; goto cleanup;
} }
else if (source->authType == VIR_STORAGE_POOL_AUTH_CEPHX) { else if (source->authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
source->auth.cephx.username = username; source->auth.cephx.username = username;
username = NULL; username = NULL;
if (virStoragePoolDefParseAuthCephx(ctxt, &source->auth.cephx) < 0) if (virStoragePoolDefParseAuthSecret(ctxt,
&source->auth.cephx.secret) < 0)
goto cleanup; goto cleanup;
} }