This example describes how to determine the empty slots available for new memory cards. This information is useful to system administrators who want to upgrade the capacity of a managed server.
This example shows how to locate information about the installed memory and available slots by using only the objects in the Implementation namespace. Locating Physical Memory Slots shows the CIM objects involved.
You can locate used memory slots by enumerating physical memory instances. To locate unused slots, you also enumerate the OMC_MemorySlot instances and compare the results. The set of unused slots comprises all those OMC_MemorySlot instances whose ElementName property does not match any of the instances of OMC_PhysicalMemory.
Note:
This example assumes that the managed server is a single-node system.
Specify the Implementation namespace, supplied as a parameter, for the connection.
The actual namespace you will use depends on your implementation.
use wbemlib
use sys
use connection renamed cnx
connection = Null
params = cnx.get_params()
if params is Null
sys.exit(-1)
connection = cnx.connect_to_host( params )
if connection is Null
print 'Failed to connect to: ' + params['host'] + ' as user: ' + params['user']
sys.exit(-1)
Enumerate the OMC_PhysicalMemory instances.
chip_instances = connection.EnumerateInstances( ’OMC_PhysicalMemory’ )
if len( chip_instances ) is 0
print 'Error: No physical memory instances were found.'
sys.exit(-1)
Enumerate the OMC_MemorySlot instances.
slot_instances = connection.EnumerateInstances( ’OMC_MemorySlot’ )
if len( slot_instances ) is 0
print 'Error: No memory slot instances were found.'
sys.exit(-1)
For each OMC_MemorySlot instance, compare the ElementName property with the set of OMC_PhysicalMemory instances, and discard the instances that have matching ElementName properties.
For other instances, print the ElementName property.
function slot_filled( slot, chips )
for chip in chips
if slot['ElementName'] == chip['ElementName']
return True
return False
empty_slots = []
for slot_instance in slot_instances
if not slot_filled( slot_instance, chip_instances )
empty_slots.append( slot_instance )
print ' %s empty memory slots found.' % len( empty_slots )
for slot_instance in empty_slots
print slot_instance['ElementName']