Tags:
create new tag
view all tags

Using SysInfo Resources

This is a guide to how to query SysInfo information from LCFG components and scripts. For a general description of some of the resources which are provided to describe the current platform see SystemInformation.

The intention of the SysInfo component is to gather together all general information about a system which might be needed by other components. Traditionally much of that information, particularly paths, was hard-coded into the scripts - the problem being that this makes the code inflexible and platform-dependent. To improve platform-independence and reduce the effort required to port a component during platform upgrades we recommend never hard-coding paths in components. If you think there could be more useful general information provided by SysInfo please let us know.

The SysInfo component effectively has 2 types of resources: paths (a file or directory location on the system) and general information which describes the Operating System or the machine in a general way. The aim of the SysInfo component is to avoid having to duplicate the same general information in multiple components, this is different from the intention of the ngeneric resources where each component is expected to have similar features with different values.

Paths are managed via the sysinfo.paths tag list, for each tag there is an associated path_ resource. There are a number of standard paths specified, these are documented on the general System Information page.

Interfaces to the SysInfo resources are provided for shell and Perl.

1. Perl

To access the SysInfo resources from Perl you first need to get an instance of the LCFG::SysInfo class:

use LCFG::SysInfo;

my $sysinfo = LCFG::SysInfo->new();

This object has methods for querying paths, general information and also system features. For further information see the LCFG::SysInfo perldoc.

1.1 Querying Information

To query general information use the get_info method. The method should be passed the name of a SysInfo resource, it will return the value of the resource or an undef if it does not exist. For example:

my $platform = $sysinfo->get_info('platform');

1.2 Querying Paths

To query a path use the get_path method. The method should be passed the LCFG tag name for the path, it will return the value of the path_ resource (if it exists), if there is no resource an undef will be returned. For example:

my $lcfgdata = $sysinfo->get_path('lcfgdata');

1.3 Querying Features

To check if a system has a particular feature the has_feature method is used. This takes the name of a feature, this is a tag which might appear in the sysinfo.features resource value. The method will return a boolean value indicating the presence of the feature.

if ( $sysinfo->has_feature('logrotate_needs_su') ) {
   # handle the different logrotate config requirements...
}

2. Shell Components

The ngeneric framework for shell components provides convenience wrapper functions which make it fairly easy to query SysInfo information. It is possible to avoid these wrappers and query the information directly, see the shell scripts section below for details.

2.1 Querying Information

To query general information use the GetSysInfo function. The function should be passed the name of a SysInfo resource, if the resource exists a variable will be exported which is the upper-cased version of the name and the function will return 0 (zero) to note success. If the resource does not exist an error will be reported and the function will return a value of 1. For example:

GetSysInfo "PLATFORM"
echo "Platform is $PLATFORM"

2.2 Querying Paths

To query a path use the GetSysPath function. The function should be passed the LCFG tag name for the path, if the path_ resource exists a variable will be exported which is the upper-cased version of the name and the function will return 0 (zero) to note success. If the resource does not exist an error will be reported and the function will return a value of 1. For example:

GetSysPath "LCFGSTATUS"
_STATUSFILE="$LCFGSTATUS/$_COMP"

2.3 Querying Features

To check if a system has a particular feature the HasSysFeature method is used. This takes the name of a feature, which is a tag which might appear in the sysinfo.features resource value. The function will return zero or one to indicate the presence of the feature. For example:

local needs_su=0
if HasSysFeature "logrotate_needs_su"; then
    needs_su=1
fi

3. Shell Scripts

It is possible to query SysInfo information from any shell script (or the command line) using the lcfg-sysinfo tool. This has command line flags which are used to specify what particular type of information should be queried. For more information run the lcfg-sysinfo --help command.

3.1 Querying Information

To query general information use the --info option. The script should be passed the name of a SysInfo resource resource, if it exists the value will be printed on STDOUT and the script will exit with a status of 0 (zero) to note success. If the resource does not exist an error will be reported and the script will exit with a status of 1. For example:

lcfg-sysinfo --info platform

If you want to avoid any error message being printed (but still get the exit status) you can use the --quiet option.

3.2 Querying Paths

To query a path use the --path option. The script should be passed the LCFG tag name for the path, if the path_ resource exists the value will be printed on STDOUT and the script will exit with a status of 0 (zero) to note success. If the resource does not exist an error will be reported and the script will exit with a status of 1. For example:

lcfg-sysinfo --path lcfgdata

If you want to avoid any error message being printed (but still get the exit status) you can use the --quiet option.

3.3 Querying Features

To check if a system has a particular feature the --feature option should be used. This takes the name of a feature, which is a tag which might appear in the sysinfo.features resource value. The script will exit with a status of zero or one to indicate the presence of the feature. For example:

lcfg-sysinfo --feature logrotate_needs_su && echo "logrotate needs su"

-- Main.squinney - 2015-02-10

Topic revision: r2 - 2015-02-13 - squinney
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback