NAME

Conan::Configure::Xen - Used to parse and generate Xen compatible configuration files.

SYNOPSIS

 use Conan::Configure::Xen;
 
 my $config = Conan::Configure::Xen->new(
         basedir => '/tmp/',
         name => 'foo06',
         settings => {
                 ip => '1.2.3.5',
         },
 );
 
 $config->parse();
 
 print $config->generate();

DESCRIPTION

This class is used to pull in configuration templates (both class type, and image type) to generate Xen style configuration files.

All settings are pulled from the configuration files matching foo.cfg.tmpl and foo\d+.cfg in that order. Meaning, the settings data structure will source the base template file first, then complete the sourcing with the config file (if any) that matches the hostname provided.

USAGE

new

The new method uses /xen/prod/etc as its default basedir, and allows an override to be supplied to the constructor.

my $args = {
	basedir	=> '/xen/prod/etc/',
	@_,
};

This method also accepts generators to be supplied. A generator is a subroutine reference attached to a keyname that is called to provide special formatting for a given keyname. The most common case for this is to provide a hash before the line for certain variables to ensure that the values can be set within the template config file, but are not expressed in the final output.

The generators defined within the new method are the ip, netmask, gateway and extra fields.

An example of a generator being called during instance invocation is:

my $config = Conan::Configure::Xen->new(
  generators => {
    ip => sub {
      my $self = shift;
      my $output = '';
      $output .= "# I'm the IP generator\n";
      $output .= "ip = '" . $self->{settings}->{ip} . "'" . "\n"
        if( $self->{settings}->{ip} );
      return $output;
    }
  },
);
generate

This method generates a configuration file, outputing a line for each of the following keys:

name kernel memory vcpus vif ip netmask gateway on_poweroff on_reboot on_crash extra

note, if a generator exists with the keyname, it is called to express the output for that keyname rather than the values sourced by the config file and stored within the settings data structure.

parse

This method finds the appropriate configuration files, and executes the parse_template method on each matching config file.

parse_template

This method simply accepts a config filename, and executes the following regex against it:

%settings = map { ($1,$2) if /(\S+)\s*=\s*(?:\[\s*)?'(.*?)'/ } grep( ! /^\s*$/, @lines );

Example:

    # Comments are eliminated
    key = 'value'
    # To accomodate the vif stuff
    key = [ 'value' ]