[xen-tools-discuss] Fwd: cascading xen-tools templates
Henning Sprang
henning.sprang at gmail.com
Thu Feb 21 23:23:29 CET 2008
Resending, as I believe this mail didn't make it through to the list...
---------- Forwarded message ----------
From: Henning Sprang <henning.sprang at gmail.com>
Date: Wed, Jan 16, 2008 at 12:50 AM
Subject: cascading xen-tools templates
To: xen-tools-discuss at xen-tools.org
Hi,
I didn't work with my Xen systems a lot recently, and just these days
upgraded some systems to the newest (3.8 something) xen-tools version.
So, the disk part of the templates has grown enormously - admittedly
not very much to my pleasure - I'd have liked it a lot if there would
have been some backward compatible way, so people with simple setups
could have kept their simple disk config - it used to be about one
line in the template, now it's about 10 or something... sorry that I
didn't track development enough to complain about that sooner! :)
So the thing I want to do here is generally useful anyway, but even
more helpful with this new setup type:
I have a handful of different templates, but they all have the disk
part in common - and as it is so long now, I definitely don't want to
copy and paste it again and again - I just want to include it.
What I came up with was reading the docs for
Text::Template(http://search.cpan.org/~mjd/Text-Template-1.44/lib/Text/Template.pm#Including_files_into_templates)
and created a file base-disks.tmpl that contains:
{
$OUT .= "disk = [\n";
for ( my $i = 0; $i <= $#PARTITIONS; $i++ )
{
$OUT .= "
'$PARTITIONS[$i]{'imagetype'}$PARTITIONS[$i]{'image'},$device" . ( $i
+ 1 ) .",w',\n";
}
$OUT .= " ]\n";
}
And in all templates that need the standard disk setup, I do something like:
{
@Disk::PARTITIONS = @PARTITIONS;
$OUT.="# disks:\n";
$OUT.= Text::Template::fill_in_file('base-disks.tmpl', PACKAGE => 'Disk' );
}
like that I can include the somewhat long disk stuff.
Unfortunately, This is still some long code - but one line of it is a
comment - and if the partitions variable wouldn't be defined in a my
variable, but more in the ways described here, one wouldn't have to
care to hand over any variable needed in the included files manually:
http://search.cpan.org/~mjd/Text-Template-1.44/lib/Text/Template.pm#my_variables
But I didn't try to change xen-create-image in a way that this works out yet...
Henning
More information about the xen-tools-discuss
mailing list