]>
git.proxmox.com Git - qemu-server.git/blob - qmupdate
7 # script to upgrade V0.9.1 to V0.9.2 format
13 cpulimit
=> 'natural',
14 cpuunits
=> 'natural',
30 sub load_config_0_9_1
{
31 my ($vmid, $filename) = @_;
33 my $fh = new IO
::File
($filename, "r") ||
38 while (my $line = <$fh>) {
40 next if $line =~ m/^\#/;
42 next if $line =~ m/^\s*$/;
44 if ($line =~ m/^([a-z]+):\s*(\S+)\s*$/) {
47 if (my $type = $confvars_0_9_1->{$key}) {
48 $res->{$key} = $value;
50 return undef; # unknown setting
58 sub parse_network_0_9_1
{
64 foreach my $rec (split (/\s*,\s*/, $data)) {
65 if ($rec =~ m/^(tap|user)$/) {
67 } elsif ($rec =~ m/^model\s*=\s*(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)$/) {
69 } elsif ($rec =~ m/macaddr\s*=\s*([0-9a-f:]+)/i) {
79 sub random_ether_addr
{
81 my $rand = Digest
::SHA
::sha1_hex
(rand(), time());
84 for (my $i = 0; $i < 6; $i++) {
85 my $ss = hex (substr ($rand, $i*2, 2));
87 $ss &= 0xfe; # clear multicast
88 $ss |= 2; # set local id
90 $ss = sprintf ("%02X", $ss);
102 sub convert_0_9_1_to_0_9_2
{
103 my ($vmid, $cfile, $conf) = @_;
105 print "Upgrading VM $vmid to new format\n";
107 die "undefined vm id" if !$vmid || $vmid !~ m/^\d+$/;
116 my $tmpdir = "/var/lib/vz/images/$vmid.upgrade";
117 my $tmpconf = "$cfile.upgrade";
122 mkdir $tmpdir || die "unable to create dir '$tmpdir'\n";
124 my $fh = new IO
::File
($cfile, "r") ||
125 die "unable to read config for VM $vmid\n";
126 my $newfh = new IO
::File
($tmpconf, "w") ||
127 die "unable to create file '$tmpconf'\n";
129 while (my $line = <$fh>) {
131 next if $line =~ m/^\#/;
133 next if $line =~ m/^\s*$/;
135 if ($line =~ m/^([a-z]+):\s*(\S+)\s*$/) {
138 if (my $type = $confvars_0_9_1->{$key}) {
139 if ($key eq 'network') {
140 my $onw = parse_network_0_9_1
($value);
141 if ($onw && ($onw->{type
} eq 'tap')) {
142 if (!$onw->{macaddr
}) {
143 $onw->{macaddr
} = random_ether_addr
();
145 print $newfh "vlan0: $onw->{model}=$onw->{macaddr}\n";
146 } elsif ($onw && ($onw->{type
} eq 'user')) {
147 if (!$onw->{macaddr
}) {
148 $onw->{macaddr
} = random_ether_addr
();
150 print $newfh "vlanu: $onw->{model}=$onw->{macaddr}\n";
152 die "unable to convert network specification\n";
154 } elsif ($key eq 'cdrom') {
156 print $newfh "ide2: $value,media=cdrom\n";
157 } elsif (defined ($dmap->{$key})) {
158 if ($value =~ m
|^/var/lib
/vz/images
/([^/]+)$|) {
160 } elsif ($value !~ m
|/|) {
163 die "wrong image path";
166 link "/var/lib/vz/images/$value", "$tmpdir/$value";
168 (-f
"$tmpdir/$value") ||
169 die "unable to create image link\n";
171 push @$images, $value;
173 print $newfh "$dmap->{$key}: $value\n";
175 print $newfh "$key: $value\n";
178 die "unknown setting '$key'\n";
184 print $newfh "bootdisk: ide0\n";
185 } elsif ($conf->{hdb
}) {
186 print $newfh "bootdisk: ide1\n";
187 } elsif ($conf->{sda
}) {
188 print $newfh "bootdisk: scsi0\n";
189 } elsif ($conf->{sdb
}) {
190 print $newfh "bootdisk: scsi1\n";
197 system ("rm -rf $tmpdir $tmpconf");
200 if (!rename $tmpdir, "/var/lib/vz/images/$vmid") {
201 system ("rm -rf $tmpdir $tmpconf");
202 die "commiting '/var/lib/vz/images/$vmid' failed - $!\n";
204 if (!rename $tmpconf, $cfile) {
205 system ("rm -rf /var/lib/vz/images/$vmid $tmpconf");
206 die "commiting new configuration '$cfile' failed - $!\n";
209 foreach my $img (@$images) {
210 unlink "/var/lib/vz/images/$img";
216 foreach my $vmconf (</etc/qemu-server
/*.conf
>) {
217 next if $vmconf !~ m
|/etc/qemu-server
/(\d
+)\
.conf
|;
219 next if -d
"/var/lib/vz/images/$vmid"; # already new format
222 my $res = load_config_0_9_1
($vmid, $vmconf);
224 if ($res && ($res->{network
} || $res->{hda
} || $res->{hdb
} ||
225 $res->{sda
} || $res->{sda
} || $res->{cdrom
})) {
226 convert_0_9_1_to_0_9_2
($vmid, $vmconf, $res);