Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Created March 19, 2012 10:18
Show Gist options
  • Select an option

  • Save kenjiskywalker/2106545 to your computer and use it in GitHub Desktop.

Select an option

Save kenjiskywalker/2106545 to your computer and use it in GitHub Desktop.
KVMのXML作成テンプレート
<domain type='kvm'>
<name>[% NAME %]</name>
<uuid>[% UUID %]</uuid>
<memory>[% MEM %]</memory>
<currentMemory>[% MEM %]</currentMemory>
<vcpu>[% CPU %]</vcpu>
<os>
<type arch='x86_64' machine='rhel5.4.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'>
<timer name='pit' tickpolicy='delay'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='[% IMAGE %]'/>
<target dev='vda' bus='virtio'/>
</disk>
<interface type='bridge'>
<mac address='[% MAC %]'/>
<source bridge='[% VLAN %]'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target port='0'/>
</console>
</devices>
</domain>
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use 5.010;
use Text::Xslate;
our ($name, $cpu, $mem, $img, $vlan, $mac);
my $tx = Text::Xslate->new(syntax => 'TTerse');
$tx->load_file('./hoge.tt');
my $file = './hoge.csv';
open my $fh, '<', $file
or die "Can't open file \"$file\": $!";
for my $line (<$fh>){
my ( $name, $cpu, $mem, $img, $vlan, $mac ) = split(/,/, $line);
my @hoge = split(/,/, $line);
my $uuid = `/usr/bin/uuidgen`;
chomp($uuid);
$mem = $mem * 1024 * 1024;
my %data = (
NAME => $name,
UUID => $uuid,
MEM => $mem,
CPU => $cpu,
IMAGE => $img,
MAC => $mac,
VLAN => $vlan,
);
print $tx->render('./hoge.tt', \%data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment