How to Implement a Profile Registration Provider
Introduction
The DMTF standard uses profiles to perform namespace
discovery. As an implementer of a
profile, you need to register a profile object that points to the
namespace of the implementing class. The profile object must be implemented under the root/interop namespace.
Profile Registration MOF Files
https://www.dmtf.org/sites/default/files/standards/documents/DSP1033_1.0.0.pdf
The above document fully describes the necessary profile
classes that the provider needs to implement.
For example, in order to implement the Ethernet switch
profile, you need to first
create the CIM_EthernetSwitchProfile class that derives from
CIM_RegisteredProfile as well as the CIM_EthernetSwitchConformsToProfile class
that derives from CIM_ElementConformsToProfile. The second class is an
association that provides the concrete implementation of the Ethernet switch
class (e.g. CIM_ComputerSystem).
Profile Registration Provider Implementation
Once the MOF files are created, you need to generate a provider skeleton. This can be done using
the following command:
Convert-MofToProvider –MofFile <Mof file location>
-ClassList CIM_EthernetSwitchProfile CIM_EthernetSwitchProfileConformsToProfile
After creating the provider skeleton, you need to implement
EnumerateInstances by returning a static instance of the
CIM_EthernetSwitchProfile class. Here
is a sample implementation of EnumerateInstances:
/*
**==============================================================================
**
** Open Management Infrastructure (OMI)
**
** Copyright (c) Microsoft Corporation
**
** Licensed under the Apache License, Version 2.0 (the "License"); you may not
** use this file except in compliance with the License. You may obtain a copy
** of the License at
**
** https://www.apache.org/licenses/LICENSE-2.0
**
** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
** MERCHANTABLITY OR NON-INFRINGEMENT.
**
** See the Apache 2 License for the specific language governing permissions
** and limitations under the License.
**
**==============================================================================
void MI_CALL MSFT_EthernetSwitchProfile_EnumerateInstances(
_In_opt_ MSFT_EthernetSwitchProfile_Self* self,
_In_ MI_Context* context,
_In_opt_z_ const MI_Char* nameSpace,
_In_opt_z_ const MI_Char* className,
_In_opt_ const MI_PropertySet* propertySet,
_In_ MI_Boolean keysOnly,
_In_opt_ const MI_Filter* filter)
{
CIM_RegisteredProfile staticEthernetSwitchProfile;
CIM_RegisteredProfile_Construct(&staticEthernetSwitchProfile,
context);
CIM_RegisteredProfile_Set_InstanceID(&staticEthernetSwitchProfile,
MI_T("EthernetSwitchProfile"));
CIM_RegisteredProfile_Set_RegisteredName(&staticEthernetSwitchProfile,
MI_T("Ethernet Switch Profile"));
CIM_RegisteredProfile_Set_RegisteredOrganization(&staticEthernetSwitchProfile,
1); // Other
organization
CIM_RegisteredProfile_Set_OtherRegisteredOrganization(&staticEthernetSwitchProfile,
MI_T("Microsoft"));
CIM_RegisteredProfile_Set_RegisteredVersion(&staticEthernetSwitchProfile,
MI_T("1.0"));
CIM_RegisteredProfile_Post(&staticEthernetSwitchProfile, context);
MI_Context_PostResult(context, MI_RESULT_OK);
}
You need to
implement the EnumerateInstances method of CIM_EthernetSwitchConformsToProfile
by returning the actual implementation of the Ethernet switch (e.g. CIM_ComputerSystem)
as a CIM_ManagedElement. Here is a
sample implementation of EnumerateInstances:
/*
**==============================================================================
**
** Open Management Infrastructure (OMI)
**
** Copyright (c) Microsoft Corporation
**
** Licensed under the Apache License, Version 2.0 (the "License"); you may not
** use this file except in compliance with the License. You may obtain a copy
** of the License at
**
** https://www.apache.org/licenses/LICENSE-2.0
**
** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
** MERCHANTABLITY OR NON-INFRINGEMENT.
**
** See the Apache 2 License for the specific language governing permissions
** and limitations under the License.
**
**==============================================================================
void MI_CALL MSFT_EthernetSwitchConformsToProfile_EnumerateInstances(
_In_opt_ MSFT_EthernetSwitchConformsToProfile_Self* self,
_In_ MI_Context* context,
_In_opt_z_ const MI_Char* nameSpace,
_In_opt_z_ const MI_Char* className,
_In_opt_ const MI_PropertySet* propertySet,
_In_ MI_Boolean keysOnly,
_In_opt_ const MI_Filter* filter)
{
MSFT_EthernetSwitchConformsToProfile element;
CIM_ManagedElement computerSystem;
CIM_ManagedElement_Construct(&computerSystem,
context);
CIM_ManagedElement_Set_InstanceID(&computerSystem,
MI_T("ComputerSystem"));
CIM_ManagedElement_Set_Caption(&computerSystem,
MI_T("TOR Switch Computer System"));
CIM_ManagedElement_Set_Description(&computerSystem,
MI_T("Replace with concrete implementation"));
MSFT_EthernetSwitchConformsToProfile_Construct(&element,
context);
MSFT_EthernetSwitchConformsToProfile_Set_ConformantStandard(&element,
&staticEthernetSwitchProfile);
MSFT_EthernetSwitchConformsToProfile_Set_ManagedElement(&element,
&computerSystem);
MSFT_EthernetSwitchConformsToProfile_Post(&element,
context);
MSFT_EthernetSwitchConformsToProfile_Destruct(&element);
CIM_ManagedElement_Destruct(&computerSystem);
MI_Context_PostResult(context, MI_RESULT_OK);
}
Provider Registration
Multiple profiles
should be combined into one single provider. The provider can be registered
using the following command:
Register-CimProvider ProfileProvider.dll
James Wei
[MSFT]