Linux configuration with OpenLMI


First Steps

The lmi tool is useful for testing whether communication between the broker and a client system is working. Listing 2 shows how to access the client information via the broker system.

Listing 2

Access Client Information

# lmi --user pegasus -h ibm-x3455-2.example.comm
lmi> system
Hardware:       IBM IBM eServer x3455-[xxxxxxx]
Serial Number:  -[UUID:C8040008000011037D001276EE0201AB]-
Asset Tag:      -[UUID:C8040008000011037D001276EE0201AB]-
CPU:            AMD, x86_64 arch
CPU Topology:   4 cpu(s), 8 core(s), 8 thread(s)
Memory:         2.0 GB
Disk Space:     N/A GB total, N/A GB free
OS:             Fedora release 23 (Twenty Three)
Kernel:         4.3.5-300.fc23.x86_64
Firewall:       off
Logging:        on (journald)

Within the lmi tool, you can use the built-in help to discover the features provided by the previously installed OpenLMI scripts. help script name calls the help for an installed script. For example, calling help service shows that this provider gives you an easy approach to managing the remote services.

A simple httpd service show indicates the status of the web server on the remote system. The statement for starting service httpd start would then be:

lmi> service show httpd
Caption=The Apache HTTP Server

It is worthwhile experimenting a little with the scripts. For many standard tasks, they are capable of simply and easily managing a wide variety of systems. See the scripts tutorial [5] for help developing your own scripts for the lmi tool.


Things become really interesting when you start using the LMIShell. It is fully programmable and can even be used interactively, like the Python interpreter itself. Each CIM object is converted by the LMIShell to a Python object so that you can develop very comprehensive scripts given some basic knowledge of Python. The following section introduces some basic functions that should make it easier to get started with writing your own scripts.

To access a broker system, you first need to define a connection object. It contains the name of the system you want to communicate with and defines how to handle authentication against this system:

# lmishell
> c = connect("", "pegasus", "redhat")

The following method can be used to verify the successful creation of the connection object:

> isinstance(c, LMIConnection)

The broker breaks down the available classes into namespaces that you can view by typing c.root.print_namespaces(). If you want to access a particular namespace, this is achieved as follows:

> ns = c.root.cimv2

You can display the classes contained within this namespace by typing ns.print_classes(). To access a particular class, simply create a new instance of the class (e.g., srv=ns.LMI_Service for the service class). By the way, the shell also supports tab completion. After creating a namespace object, you can type ns. and press Tab to show all the classes. srv.doc() tells more about the existing methods of the services object you just created.

The following simple script should now return all of a system's services. Save it in the services.lmi file:

c = connect("", "pegasus", "redhat")
ns = c.root.cimv2
srv = c.root.cimv2.LMI_Service
for service in srv.instances():
    print "Name:\t %s" % (service.Name)

Of course, you can choose a shorter notation instead:

for service in c.root.cimv2.LMI_Service.instances():
       print "Name:\t %s" % (service.Name)

After calling the script with lmishell services.lmi, you see an overview of the existing services on the system If you are interested in the enabled services instead, simply change the statement:

for service in srv.instances():
  if service.EnabledDefault == srv.EnabledDefaultValues.Enabled:
    print "Name:\t %s" % (service.Name)

For similar examples and additional information, see the excellent and detailed OpenLMI documentation [6].

Joining a Domain

Finally, let's just point out the Realmd CIM provider; this subject is discussed in detail in the article on the FreeIPA identity management framework in this issue. The Realmd provider is a practical example of how you can easily add a variety of Linux systems to an existing FreeIPA domain with the help of OpenLMI. This is usually done by calling ipa-client install. With just three lines of OpenLMI code, the Realmd provider handles this task:

c = connect("", "pegasus", "redhat")
realm = c.root.cimv2.LMI_RealmdService.first_instance()
realm.JoinDomain( Domain="", User="admin", Password="password")

The charm of this approach is that you can include this snippet of code in a larger script, with the help of which you could define, for example, the complete provisioning action for the system, ranging from the installation to the configuration of individual services.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus