This post just walk through the usage of CIMPLE and OpenPegasus in CentOS 5.x. For background knowledge, please refer to wikipedia.
In CentOS 5.x, just install OpenPegasus(2.9.1) from yum:
1 |
# yum install tog-pegasus tog-pegasus-devel |
We install the devel package since CIMPLE needs to build against it. I used CIMPLE 1.2.4. Before build it, we should fix broken symbolic links of OpenPegasus package, otherwise link error occurs:
1 2 3 4 |
# ln -s /usr/lib/libpegconfig.so.1 /usr/lib/libpegconfig.so # ln -s /usr/lib/libpeglistener.so.1 /usr/lib/libpeglistener.so # ln -s /usr/lib/libpegprm.so.1 /usr/lib/libpegprm.so # ln -s /usr/lib/libpegprovidermanager.so.1 /usr/lib/libpegprovidermanager.so |
There’s also a trivial bug which prevent CIMPLE from generating CMPI version of makefiles. Edit ${CIMPLE}/src/tools/genmak/main.cpp, find line “case ‘c'”, and change to “case ‘C'”. Now configure and make:
1 2 3 |
# ./configure --prefix=/usr --with-pegasus=/usr --with-cmpi=/usr/include/Pegasus/Provider/CMPI # make # make install |
Aha!! Another annoying bug: wrong permissions in *.tar.gz source package. Fix with:
1 2 |
# chmod 644 /usr/share/cimple/mak/*.mak # chmod 755 /usr/share/cimple/mak/*.sh |
Demo code refers to CIMPLE official tutorial. It can be found in source package. A repository.mof file is created first:
1 2 3 4 5 6 7 8 9 10 11 12 |
class President { [Key] uint32 Number; string First; string Last; }; class VicePresident { [Key] uint32 Number; string First; string Last; }; |
Run genproj to generate class files, provider files, and module files:
1 |
# genproj President President VicePresident |
Generate makefiles using genmak. First line is for OpenPegasus adapter, while second line for CMPI adapter:
1 2 |
# genmak President *.cpp # genmak -C President *.cpp |
We implemented President::get_instance()
and President::enum_instance()
in our code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
Get_Instance_Status President_Provider::get_instance( const President* model, President*& instance) { /* return GET_INSTANCE_UNSUPPORTED; */ if (model->Number.value == 1) { instance = President::create(true); instance->Number.set(1); instance->First.set("George"); instance->Last.set("Washington"); return GET_INSTANCE_OK; } else if (model->Number.value == 2) { instance = President::create(true); instance->Number.set(2); instance->First.set("John"); instance->Last.set("Adams"); return GET_INSTANCE_OK; } else if (model->Number.value == 3) { instance = President::create(true); instance->Number.set(3); instance->First.set("Thomas"); instance->Last.set("Jefferson"); return GET_INSTANCE_OK; } return GET_INSTANCE_NOT_FOUND; } Enum_Instances_Status President_Provider::enum_instances( const President* model, Enum_Instances_Handler<President>* handler) { President* instance; instance = President::create(true); instance->Number.set(1); instance->First.set("George"); instance->Last.set("Washington"); handler->handle(instance); instance = President::create(true); instance->Number.set(2); instance->First.set("John"); instance->Last.set("Adams"); handler->handle(instance); instance = President::create(true); instance->Number.set(3); instance->First.set("Thomas"); instance->Last.set("Jefferson"); handler->handle(instance); return ENUM_INSTANCES_OK; } |
If get_instance()
returns GET_INSTANCE_UNSUPPORTED
, the adapter satisfies the request by calling enum_instances()
and searching for a matching instances. It is recommend to leave get_instance()
unsupported when the total number of instances is small.
After making your module, a registration is required for OpenPegasus CIM server. Start your server and register. The shared library should also be copied to OpenPegasus’s providers folder manually:
1 2 3 4 5 6 7 8 |
# cp libPresident.so /usr/lib/Pegasus/providers # /etc/init.d/tog-pegasus start # regmod -c ./libPresident.so Using Pegasus C++ provider interface Creating class VicePresident (root/cimv2) Creating class President (root/cimv2) Registering VicePresident_Provider (class VicePresident) Registering President_Provider (class President) |
To unregister this provider, run:
1 2 3 4 5 6 |
# regmod -u -c ./libPresident.so Using Pegasus C++ provider interface Unregistering VicePresident_Provider (class VicePresident) Deleted class VicePresident Unregistering President_Provider (class President) Deleted class President |
You may want to dump MOF registration instance for your provide:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# regmod -d ./libPresident.so instance of PG_ProviderModule { Name = "President_Module"; Vendor = "Pegasus"; Version = "2.5.0"; InterfaceType = "C++Default"; InterfaceVersion = "2.5.0"; Location = "President"; }; instance of PG_Provider { Name = "VicePresident_Provider"; ProviderModuleName = "President_Module"; }; instance of PG_ProviderCapabilities { CapabilityID = "VicePresident"; ProviderModuleName = "President_Module"; ProviderName = "VicePresident_Provider"; ClassName = "VicePresident"; Namespaces = {"root/cimv2"}; ProviderType = {2}; supportedProperties = NULL; supportedMethods = NULL; }; instance of PG_Provider { Name = "President_Provider"; ProviderModuleName = "President_Module"; }; instance of PG_ProviderCapabilities { CapabilityID = "President"; ProviderModuleName = "President_Module"; ProviderName = "President_Provider"; ClassName = "President"; Namespaces = {"root/cimv2"}; ProviderType = {2}; supportedProperties = NULL; supportedMethods = NULL; }; |
Install command line utilities and test OpenPegasus server:
1 2 3 4 |
# yum install sblim-wbemcli # yum install sblim-cmpi-base # wbemcli ecn https://<user>:<pass>@localhost:5989/root/cimv2 # wbemcli -nl ei https://<user>:<pass>@localhost:5989/root/cimv2:Linux_Processor |
Test our President provider:
1 2 3 4 5 6 |
# wbemcli ei https://<user>:<pass>@localhost:5989/root/cimv2:President localhost:5989/root/cimv2:President.Number=1 Number=1,First="George",Last="Washington" localhost:5989/root/cimv2:President.Number=2 Number=2,First="John",Last="Adams" localhost:5989/root/cimv2:President.Number=3 Number=3,First="Thomas",Last="Jefferson" # wbemcli gi https://<user>:<pass>@localhost:5989/root/cimv2:President.Number=1 localhost:5989/root/cimv2:President.Number="1" Number=1,First="George",Last="Washington" |
All code can be found in my skydrive here: