Chapter 6. Rules and Classes

Table of Contents

1. Rule based auto-installation
1.1. Rules File explained
1.2. Rules file structure
1.3. Predefined System Attributes
1.4. Rule Matching
1.5. Using Operators
2. Classes
2.1. Creating Class files and Directories
2.2. Using Classes During Installation
3. Mixing Rules and Classes
4. The merging process of Rules and Classes

1. Rule based auto-installation

Rules offer the possibility to configure a system depending on system attributes by merging multiple control file during installation. The rules based installation is controlled by a rules file.

The rules file is an XML based file that contains rules for each group of systems (or single systems) that you want to automatically install. A set of rules distinguish a group of systems based on one or more system attributes, after passing all rules, it links each group of rules to a profile. Both the rules file and the profiles must be located in a pre-defined and accessible location.

The rules file is retrieved only if no specific control is supplied using the autoyast keyword. For example, if the following is used, the rules file wont be evaluated:

        autoyast=http://10.10.0.1/profile/test.xml
    

Figure 6.1. Rules

Rules

If more than one rule apply, the final profile for each group is generated on the fly using a merge script. The merging process is based on the order of the rules and later rules override configuration data in earlier rules.

The use of a rules file is optional. If the rules file is not found, system installation proceeds in the classic way by just using the supplied profile or by searching for the profile depending on the MAC or the IP address of the system.

1.1. Rules File explained

Example 6.1.  Simple rules file

The following simple example illustrates how the rules file is used to retrieve the configuration for a client with known hardware.


<?xml version="1.0"?>
<!DOCTYPE autoinstall SYSTEM "/usr/share/autoinstall/dtd/rules.dtd">
<autoinstall xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
  <rules config:type="list">
    <rule>
       <disksize>
            <match>/dev/hdc 1000</match>
            <match_type>greater</match_type>
       </disksize>
       <result>
            <profile>machine1.xml</profile>
            <continue config:type="boolean">false</continue>
        </result>
    </rule>
    <rule>
       <disksize>
            <match>/dev/hda 1000</match>
            <match_type>greater</match_type>
       </disksize>
       <result>
            <profile>machine2.xml</profile>
            <continue config:type="boolean">false</continue>
        </result>
    </rule>
  </rules>
</autoinstall>

	    

The last example defines 2 rules and provides a different profile for every rule. The rule used in this case is disksize. After parsing the rules file, YaST2 attempts to match the system being installed to the rules in the rules.xml file in the following order: first rule through the last rule. A rule match occurs when the system being installed matches all of the system attributes defined in the rule. As soon as a system matches a rule, the result resource is added to the stack of profiles AutoYaST will be using to create the final profile. The continue property tells AutoYaST if it should continue with other rules or not after a match has been found.

If the first rule does not match, next rule in the list is examined until a match is found.

Using the disksize attribute, you can provide different configurations for different hard drives with different size. First rule checks if the device /dev/hdc is available and if it is greater than 1 GB in size using the match property.

A rule must have at least one attribute to be matched. If you need to check more attributes, i.e. memory or architectures, you can add more attributes in the rule resource as shown in the next example.

Example 6.2.  Simple rules file

The following simple example illustrates how the rules file is used to retrieve the configuration for a client with known hardware.


<?xml version="1.0"?>
<!DOCTYPE autoinstall SYSTEM "/usr/share/autoinstall/dtd/rules.dtd"> 
<autoinstall xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
  <rules config:type="list">
    <rule>
       <disksize>
            <match>/dev/hdc 1000</match>
            <match_type>greater</match_type>
       </disksize>
       <memsize>	    
            <match>1000</match>
            <match_type>greater</match_type>
       </memsize>
       <result>
            <profile>machine1.xml</profile>
            <continue config:type="boolean">false</continue>
        </result>
    </rule>
    <rule>
       <disksize>
            <match>/dev/hda 1000</match>
            <match_type>greater</match_type>
       </disksize>
       <memsize>	    
            <match>256</match>
            <match_type>greater</match_type>
       </memsize>
       <result>
            <profile>machine2.xml</profile>
            <continue config:type="boolean">false</continue>
        </result>
    </rule>
  </rules>
</autoinstall>

	

The rules directory must be located in the same referenced directory used with the autoyast keyword on boot time, so if the client was booted using autoyast=http://10.10.0.1/profiles/, AutoYaST will search for the rules file in http://10.10.0.1/profiles/rules/rules.xml.

1.2. Rules file structure

The rules.xml file must have:

  • At least one rule

  • It must have the name rules.xml

  • It must be located in the directory rules in the profile repository

  • At least one attribute to match in the rule

1.3. Predefined System Attributes

The following table lists the predefined system attributes you can match in the rules file.

Table 6.1. System Attributes

AttributeValuesDescription
hostaddressIP address of hostThis attribute must always match exactly
domainDomain name of hostThis attribute must always match exactly
networknetwork address of hostThis attribute must always match exactly
macMAC address of hostThis attribute must always match exactly. (MAC addresses to be matched should be in the form 0080C8F6484C
linuxNumber of installed Linux partitions on the systemThis attribute can be 0 or more
othersNumber of installed non-Linux partitions on the systemThis attribute can be 0 or more
xserverX Server needed for graphic adapterThis attribute must always match exactly
memsizeMemory available on host in MByesAll match types are available
totaldiskTotal disk space available on host in MBytesAll match types are available
haspcmicaSystem has PCMCIA (i.e Laptops)Exact match required, 1 for available PCMCIA or 0 for none
hostidHex representation of IP addressExact match required
archArchitecture of hostExact match required
karchKernel Architecture of host (i.e. SMP kernel, Athlon Kernel)Exact match required
disksizeDrive device and sizeAll match types are available
productThe hardware product name as specified in SMBIOSExact match required
product_vendorThe hardware vendor as specified in SMBIOSExact match required
boardThe system board name as specified in SMBIOSExact match required
board_vendorThe system board vendor as specified in SMBIOSExact match required
custom1-5Custom rules using shell scriptsAll match types are available

1.4. Rule Matching

The tag match_type is used to define how the rules should be checked. There exist 4 types of matching:

  • exact

  • greater

  • lower

  • range (for IPs, memsize and totaldisk only)

exact should always be used with all string attributes

1.5. Using Operators

When using multiple rules, you might want to have either all rules match or just some. For example you might want either 2 or more rules to always match or just one of a list of rules in a rule set. The operator is defined with the operator tag which can either be "and" (default) or "or".