typetext => '[[order=]\d+] [,up=\d+] [,down=\d+] ',
description => "Startup and shutdown behavior. Order is a non-negative number defining the general startup order. Shutdown in done with reverse ordering. Additionally you can set the 'up' or 'down' delay in seconds, which specifies a delay to wait before the next VM is started or stopped.",
},
+ template => {
+ optional => 1,
+ type => 'boolean',
+ description => "Enable/disable Template.",
+ default => 0,
+ },
args => {
optional => 1,
type => 'string',
check_lock($conf);
- my $changes = update_disksize($vmid, $conf, $volid_hash);
+ my $vm_volids = {};
+ foreach my $volid (keys %$volid_hash) {
+ my $info = $volid_hash->{$volid};
+ $vm_volids->{$volid} = $info if $info->{vmid} && $info->{vmid} == $vmid;
+ }
+
+ my $changes = update_disksize($vmid, $conf, $vm_volids);
update_config_nolock($vmid, $conf, 1) if $changes;
};
die "you can't convert a vm to template if vm is running vm\n" if $running;
my $storecfg = PVE::Storage::config();
- my $i = 0;
foreach_drive($conf, sub {
my ($ds, $drive) = @_;
return if $disk && $ds ne $disk;
my $volid = $drive->{file};
- die "volume '$volid' does not support template/clone\n"
- if !PVE::Storage::volume_has_feature($storecfg, 'template', $volid);
- });
+ return if !PVE::Storage::volume_has_feature($storecfg, 'template', $volid);
- foreach_drive($conf, sub {
- my ($ds, $drive) = @_;
-
- return if drive_is_cdrom($drive);
- return if $disk && $ds ne $disk;
-
- my $volid = $drive->{file};
my $voliddst = PVE::Storage::vdisk_create_base($storecfg, $volid);
$drive->{file} = $voliddst;
$conf->{$ds} = PVE::QemuServer::print_drive($vmid, $drive);
PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
-
});
- if($conf->{snapshots}){
- delete $conf->{parent};
- delete $conf->{snapshots};
- PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
- #fixme : do we need to delete disks snapshots ?
- }
}
sub is_template {
my ($conf) = @_;
- my $baseimagecount = 0;
- my $totalvolumecount = 0;
- my $storecfg = PVE::Storage::config();
-
- foreach_drive($conf, sub {
- my ($ds, $drive) = @_;
- return if drive_is_cdrom($drive);
- $totalvolumecount++;
- my $volid = $drive->{file};
- if (PVE::Storage::volume_is_base($storecfg, $volid)){
- $baseimagecount++;
- }
-
- });
-
- return 0 if $baseimagecount == 0;
- return 1 if $baseimagecount == $totalvolumecount; #full template
- return 2 if $baseimagecount < $totalvolumecount; #semi-template
+ return 1 if defined $conf->{template} && $conf->{template} == 1;
}
1;