Conan::Configure::Xen - Used to parse and generate Xen compatible configuration files.
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();
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.
foo.cfg.tmpl
foo\d+.cfg
The new method uses /xen/prod/etc as its default basedir, and allows an override to be supplied to the constructor.
/xen/prod/etc
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.
ip
netmask
gateway
extra
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; } }, );
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
name
kernel
memory
vcpus
vif
on_poweroff
on_reboot
on_crash
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.
settings
This method finds the appropriate configuration files, and executes the parse_template method on each matching config file.
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' ]
To install Conan, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Conan
CPAN shell
perl -MCPAN -e shell install Conan
For more information on module installation, please visit the detailed CPAN module installation guide.