OpenClovis Logo

API Usage Examples
Provisioning Library

Code Examples. More...

Code Examples.

The provision attributes for a hardware/software resource is specified during the modeling of the system. These resources are mere types and needs to be instantiated before using them. These resources needs to be associated with a component/application which creates the instances on coming up. The following example shows how to create/delete Prov MSO instances.

ClRcT rc = CL_OK;
ClUint32T attrData = 10;
ClNameT moIdName;
ClCorAttributeValueT attrValue[] = {
{ NULL, // Attribute path is NULL
0x10, // Specify attribute ID of WRITE-INITIALIZED
// attribute. Attribute ID can be found in
// $ASP_CONFIG/clCorMetaStruct.h file.
-1, // As this is a simple attribute give -1 for index
(ClPtrT)&attrData, // Value of WRITE-INITIALIZED attribute
sizeof(ClUint32T) } // Size of the given attribute
}
ClCorAttributeValueListT attrValueList = {
sizeof(attrValue)/sizeof(ClCorAttributeValueT),
&attrValue }
// SM_CFG_TBL_SIM1_TABLE_MO has one WRITE-INITALIZED attibute and
// one WRITE attribute. WRITE-INITALIZED attribute should be initialized
// at the time object creation.
#define SM_CFG_TBL_SIM1_TABLE_MO "\\Chassis:0\\smCfgTblSim1Table:0"
// Get MOID from MO Name
strcpy(moIdName.value, SM_CFG_TBL_SIM1_TABLE_MO);
moIdName.length = strlen(SM_CFG_TBL_SIM1_TABLE_MO);
rc = clCorMoIdNameToMoIdGet(&moIdName, &moId);
if(CL_OK != rc) {
return rc;
}
// Create Prov MSO
rc = clProvObjectCreate(&moId, &attrValue, &handle);
if(CL_OK != rc) {
return rc;
}
ClRcT rc = CL_OK;
// Delete Prov MSO at run time
rc = clProvObjectDelete(handle);
if(CL_OK != rc) {
//Error occurred. Take appropriate action.
return rc;
}

After the creation of Prov MSO, the Object Implementor (OI) can receive all change notifications like set, delete, create for the resource. Provisioning library on initialization registers its callbacks with Transaction Agent and also registers the OI with Clovis Object Repository(COR) on the creation of Prov objects. Subsequent requests like create, set, delete on this object will invoke the callbacks registered by Prov. Following code segment explains how to handle provisioning attribute change notifications.

// This function prints attribute information
ClRcT clProvTxnInfoPrint(ClProvTxnDataT* pProvTxnData)
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS,
"Attr ID[0x%x] AttrType[0x%x] AttrDataType [0x%x] Operation[0x%x]",\
pProvTxnData->attrId, pProvTxnData->attrType,
pProvTxnData->attrDataType, pProvTxnData->provCmd);
switch(pProvTxnData->attrType)
{
{
switch(pProvTxnData->attrDataType)
{
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data8[%c]",
*(ClCharT*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data16[%x]",
*(ClUint16T*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data32[%x]",
*(ClUint32T*)pProvTxnData->pProvData);
break;
}
{
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Data64[%llx]",
*(ClUint64T*)pProvTxnData->pProvData);
break;
}
}
}
}
// Callback function to validate attribute change
ClRcT cl<OIName><MSOName>ProvValidate(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// Perform some logic here to do validation of the attribute.
// For ex: range checking, checking for valid type etc
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Validate");
return rc;
}
// Callback function to update attribute change
ClRcT cl<OIName><MSOName>ProvUpdate(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// If any attribute of Prov MSO is changed
if(pProvTxnData->provCmd == CL_COR_OP_SET)
{
// Perform logic here to do set on the attribute
}
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Update");
clProvTxnInfoPrint(pProvTxnData);
return rc;
}
// Callback function to rollback in case cl<OIName><MSOName>Validate
// function returns error value
ClRcT cl<OIName><MSOName>ProvRollback(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
ClRcT rc = CL_OK;
// Perform logic here to rollback the changes done at validation phase
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Rollback");
return rc;
}

Provisioning library registers Read callback with Transaction Agent on initialization. This is being invoked when there is a request to read the attribute value of a resource. This is assuming the fact that the OI has done clCorPrimaryOISet() during its initialization. Following function will be called when get request comes to run-time attribute of given Prov MSO

ClRcT cl<OIName><MSOName>ProvRead(CL_OM_PROV_CLASS* pThis,
ClHandleT txnHandle,
ClProvTxnDataT* pProvTxnData)
{
// Need to have a logic to get the proper value for given attribute ID
ClUint32T tempData = 10;
// Find out proper size of given attribute
ClUint32T dataLen = sizeof(tempData);
memcpy((pProvTxnData->pProvData), &tempData, dataLen);
clLog(CL_LOG_INFO, CL_PROV, CL_PROV_CALL_BACKS, "Prov Read callback");
}

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen