« Previous 1 2 3 Next »
Linux configuration with OpenLMI
Cosmopolitan
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 password: ========================================================== Host: ibm-x3455-2.example.com ========================================================== 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 Name=httpd Caption=The Apache HTTP Server Enabled=No Status=Running
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.
LMIShell
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("ibm-x3455-2.example.com", "pegasus", "redhat")
The following method can be used to verify the successful creation of the connection object:
> isinstance(c, LMIConnection) True
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:
#!/usr/bin/lmishell c = connect("ibm-x3455-2.example.com", "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 ibm-x3455-2.example.com
. 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("ibm-x3455-2.example.com", "pegasus", "redhat") realm = c.root.cimv2.LMI_RealmdService.first_instance() realm.JoinDomain( Domain="example.com", 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.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.