if ($volid eq 'cdrom') {
$rpcenv->check($authuser, "/", ['Sys.Console']);
} else {
- # we simply allow access
+ # we simply allow access
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
my $scfg = PVE::Storage::storage_config($storecfg, $sid);
$sharedvm = 0 if !$scfg->{shared};
} else {
my $path = $rpcenv->check_volume_access($authuser, $storecfg, $vmid, $volid);
-
+
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
my $foundvolid = undef;
}
});
}
-
+
die "image '$path' does not exists\n" if (!(-f $path || -b $path || $foundvolid));
my ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 1);
next if PVE::QemuServer::valid_drivename($opt);
if ($opt eq 'sockets' || $opt eq 'cores' ||
- $opt eq 'cpu' || $opt eq 'smp' ||
+ $opt eq 'cpu' || $opt eq 'smp' ||
$opt eq 'cpulimit' || $opt eq 'cpuunits') {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.CPU']);
} elsif ($opt eq 'boot' || $opt eq 'bootdisk') {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Memory']);
} elsif ($opt eq 'args' || $opt eq 'lock') {
die "only root can set '$opt' config\n";
- } elsif ($opt eq 'cpu' || $opt eq 'kvm' || $opt eq 'acpi' ||
+ } elsif ($opt eq 'cpu' || $opt eq 'kvm' || $opt eq 'acpi' ||
$opt eq 'vga' || $opt eq 'watchdog' || $opt eq 'tablet') {
$rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.HWType']);
} elsif ($opt =~ m/^net\d+$/) {
description => "Create or restore a virtual machine.",
permissions => {
description => "You need 'VM.Allocate' permissions on /vms/{vmid} or on the VM pool /pool/{pool}. If you create disks you need 'Datastore.AllocateSpace' on any used storage.",
- check => [ 'or',
+ check => [ 'or',
[ 'perm', '/vms/{vmid}', ['VM.Allocate']],
[ 'perm', '/pool/{pool}', ['VM.Allocate'], require_param => 'pool'],
],
description => "Assign a unique random ethernet address.",
requires => 'archive',
},
- pool => {
+ pool => {
optional => 1,
type => 'string', format => 'pve-poolid',
description => "Add the VM to the specified pool.",
my $force = extract_param($param, 'force');
my $unique = extract_param($param, 'unique');
-
+
my $pool = extract_param($param, 'pool');
my $filename = PVE::QemuServer::config_file($vmid);
if (defined($pool)) {
$rpcenv->check_pool_exist($pool);
- }
+ }
$rpcenv->check($authuser, "/storage/$storage", ['Datastore.AllocateSpace'])
if defined($storage);
}
}
- my $addVMtoPoolFn = sub {
+ my $addVMtoPoolFn = sub {
my $usercfg = cfs_read_file("user.cfg");
if (my $data = $usercfg->{pools}->{$pool}) {
$data->{vms}->{$vmid} = 1;
$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']);
my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
- if (my $sid = &$test_deallocate_drive($storecfg, $vmid, $opt, $drive, $force)) {
+ if (my $sid = &$test_deallocate_drive($storecfg, $vmid, $opt, $drive, $force)) {
$rpcenv->check($authuser, "/storage/$sid", ['Datastore.Allocate']);
}
}
my $safe_num_ne = sub {
my ($a, $b) = @_;
- return 0 if !defined($a) && !defined($b);
- return 1 if !defined($a);
- return 1 if !defined($b);
+ return 0 if !defined($a) && !defined($b);
+ return 1 if !defined($a);
+ return 1 if !defined($b);
return $a != $b;
};
&$safe_num_ne($drive->{iops}, $old_drive->{iops}) ||
&$safe_num_ne($drive->{iops_rd}, $old_drive->{iops_rd}) ||
&$safe_num_ne($drive->{iops_wr}, $old_drive->{iops_wr})) {
- PVE::QemuServer::qemu_block_set_io_throttle($vmid,"drive-$opt", $drive->{mbps}*1024*1024,
- $drive->{mbps_rd}*1024*1024, $drive->{mbps_wr}*1024*1024,
- $drive->{iops}, $drive->{iops_rd}, $drive->{iops_wr})
+ PVE::QemuServer::qemu_block_set_io_throttle($vmid,"drive-$opt", $drive->{mbps}*1024*1024,
+ $drive->{mbps_rd}*1024*1024, $drive->{mbps_wr}*1024*1024,
+ $drive->{iops}, $drive->{iops_rd}, $drive->{iops_wr})
if !PVE::QemuServer::drive_is_cdrom($drive);
}
}
#if model change, we try to hot-unplug
die "error hot-unplug $opt for update" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
}else{
-
+
if($newnet->{bridge} && $oldnet->{bridge}){
my $iface = "tap".$vmid."i".$1 if $opt =~ m/net(\d+)/;
die "error hot-unplug $opt for update" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
}
}
-
+
}
$conf->{$opt} = $value;
PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
};
my $vm_config_perm_list = [
- 'VM.Config.Disk',
- 'VM.Config.CDROM',
- 'VM.Config.CPU',
- 'VM.Config.Memory',
- 'VM.Config.Network',
+ 'VM.Config.Disk',
+ 'VM.Config.CDROM',
+ 'VM.Config.CPU',
+ 'VM.Config.Memory',
+ 'VM.Config.Network',
'VM.Config.HWType',
'VM.Config.Options',
];
my $drive = PVE::QemuServer::parse_drive($opt, $param->{$opt});
PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
$param->{$opt} = PVE::QemuServer::print_drive($vmid, $drive);
- } elsif ($opt =~ m/^net(\d+)$/) {
+ } elsif ($opt =~ m/^net(\d+)$/) {
# add macaddr
my $net = PVE::QemuServer::parse_net($param->{$opt});
$param->{$opt} = PVE::QemuServer::print_net($net);
if (PVE::QemuServer::valid_drivename($opt)) {
- &$vmconfig_update_disk($rpcenv, $authuser, $conf, $storecfg, $vmid,
+ &$vmconfig_update_disk($rpcenv, $authuser, $conf, $storecfg, $vmid,
$opt, $param->{$opt}, $force);
-
+
} elsif ($opt =~ m/^net(\d+)$/) { #nics
- &$vmconfig_update_net($rpcenv, $authuser, $conf, $storecfg, $vmid,
+ &$vmconfig_update_net($rpcenv, $authuser, $conf, $storecfg, $vmid,
$opt, $param->{$opt});
} else {
}
# allow manual ballooning if shares is set to zero
- if ($running && defined($param->{balloon}) &&
+ if ($running && defined($param->{balloon}) &&
defined($conf->{shares}) && ($conf->{shares} == 0)) {
my $balloon = $param->{'balloon'} || $conf->{memory} || $defaults->{memory};
PVE::QemuServer::vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024);
my $storecfg = PVE::Storage::config();
- my $delVMfromPoolFn = sub {
+ my $delVMfromPoolFn = sub {
my $usercfg = cfs_read_file("user.cfg");
if (my $pool = $usercfg->{vms}->{$vmid}) {
if (my $data = $usercfg->{pools}->{$pool}) {
my $cc = PVE::Cluster::cfs_read_file('cluster.conf');
if (PVE::Cluster::cluster_conf_lookup_pvevm($cc, 0, $vmid, 1)) {
return 1;
- }
+ }
return 0;
};
path => '{vmid}/feature',
method => 'GET',
proxyto => 'node',
- protected => 1,
+ protected => 1,
description => "Check if feature for virtual machine is available.",
permissions => {
check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
description => "You need 'VM.Copy' permissions on /vms/{vmid}, and 'VM.Allocate' permissions " .
"on /vms/{newid} (or on the VM pool /pool/{pool}). You also need " .
"'Datastore.AllocateSpace' on any used storage.",
- check =>
- [ 'and',
+ check =>
+ [ 'and',
['perm', '/vms/{vmid}', [ 'VM.Copy' ]],
- [ 'or',
+ [ 'or',
[ 'perm', '/vms/{newid}', ['VM.Allocate']],
[ 'perm', '/pool/{pool}', ['VM.Allocate'], require_param => 'pool'],
],
type => 'string',
description => "Description for the new VM.",
},
- pool => {
+ pool => {
optional => 1,
type => 'string', format => 'pve-poolid',
description => "Add the new VM to the specified pool.",
"you copy a normal VM. For VM templates, we try to create a linked copy by default.",
default => 0,
},
- target => get_standard_option('pve-node', {
+ target => get_standard_option('pve-node', {
description => "Target node. Only allowed if the original VM is on shared storage.",
optional => 1,
}),
# exclusive lock if VM is running - else shared lock is enough;
my $shared_lock = $running ? 0 : 1;
- # fixme: do early checks - re-check after lock
+ # fixme: do early checks - re-check after lock
# fixme: impl. target node parameter (mv VM config if all storages are shared)
die "unexpected state change\n" if $verify_running != $running;
- die "snapshot '$snapname' does not exist\n"
- if $snapname && !defined( $conf->{snapshots}->{$snapname});
+ die "snapshot '$snapname' does not exist\n"
+ if $snapname && !defined( $conf->{snapshots}->{$snapname});
- my $oldconf = $snapname ? $conf->{snapshots}->{$snapname} : $conf;
+ my $oldconf = $snapname ? $conf->{snapshots}->{$snapname} : $conf;
my $sharedvm = &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $oldconf, $storage);
die "can't copy VM to node '$target' (VM uses local storage)\n" if $target && !$sharedvm;
-
+
my $conffile = PVE::QemuServer::config_file($newid);
die "unable to create VM $newid: config file already exists\n"
}
} else {
# copy everything else
- $newconf->{$opt} = $value;
+ $newconf->{$opt} = $value;
}
}
if ($param->{description}) {
$newconf->{description} = $param->{description};
}
-
+
PVE::Storage::activate_volumes($storecfg, $vollist);
eval {
my ($size) = PVE::Storage::volume_size_info($storecfg, $newvolid, 3);
my $disk = { file => $newvolid, size => $size };
- $newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $disk);
+ $newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $disk);
push @$newvollist, $newvolid;
PVE::QemuServer::update_config_nolock($newid, $newconf, 1);
if !rename($conffile, $newconffile);
}
};
- if (my $err = $@) {
+ if (my $err = $@) {
unlink $conffile;
sleep 1; # some storage like rbd need to wait before release volume - really?
my $digest = extract_param($param, 'digest');
my $disk = extract_param($param, 'disk');
-
+
my $sizestr = extract_param($param, 'size');
my $skiplock = extract_param($param, 'skiplock');
die "you can't resize a cdrom\n" if PVE::QemuServer::drive_is_cdrom($drive);
- die "you can't online resize a virtio windows bootdisk\n"
+ die "you can't online resize a virtio windows bootdisk\n"
if PVE::QemuServer::check_running($vmid) && $conf->{bootdisk} eq $disk && $conf->{ostype} =~ m/^w/ && $disk =~ m/^virtio/;
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
PVE::Cluster::log_msg('info', $authuser, "update VM $vmid: resize --disk $disk --size $sizestr");
PVE::QemuServer::qemu_block_resize($vmid, "drive-$disk", $storecfg, $volid, $newsize);
-
+
$drive->{size} = $newsize;
$conf->{$disk} = PVE::QemuServer::print_drive($vmid, $drive);
foreach my $name (keys %$snaphash) {
my $d = $snaphash->{$name};
- my $item = {
- name => $name,
- snaptime => $d->{snaptime} || 0,
+ my $item = {
+ name => $name,
+ snaptime => $d->{snaptime} || 0,
vmstate => $d->{vmstate} ? 1 : 0,
description => $d->{description} || '',
};
my $realcmd = sub {
PVE::Cluster::log_msg('info', $authuser, "snapshot VM $vmid: $snapname");
- PVE::QemuServer::snapshot_create($vmid, $snapname, $param->{vmstate},
+ PVE::QemuServer::snapshot_create($vmid, $snapname, $param->{vmstate},
$param->{freezefs}, $param->{description});
};
my $snap = $conf->{snapshots}->{$snapname};
- die "snapshot '$snapname' does not exist\n" if !defined($snap);
-
+ die "snapshot '$snapname' does not exist\n" if !defined($snap);
+
$snap->{description} = $param->{description} if defined($param->{description});
PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
my $snap = $conf->{snapshots}->{$snapname};
- die "snapshot '$snapname' does not exist\n" if !defined($snap);
-
+ die "snapshot '$snapname' does not exist\n" if !defined($snap);
+
return $snap;
}});
description => "Create a Template.",
permissions => {
description => "You need 'VM.Allocate' permissions on /vms/{vmid} or on the VM pool /pool/{pool}.",
- check => [ 'or',
+ check => [ 'or',
[ 'perm', '/vms/{vmid}', ['VM.Allocate']],
[ 'perm', '/pool/{pool}', ['VM.Allocate'], require_param => 'pool'],
],
PVE::QemuServer::check_lock($conf);
- die "unable to create template, because VM contains snapshots\n"
+ die "unable to create template, because VM contains snapshots\n"
if $conf->{snapshots} && scalar(keys %{$conf->{snapshots}});
- die "you can't convert a template to a template\n"
+ die "you can't convert a template to a template\n"
if PVE::QemuServer::is_template($conf) && !$disk;
- die "you can't convert a VM to template if VM is running\n"
+ die "you can't convert a VM to template if VM is running\n"
if PVE::QemuServer::check_running($vmid);
my $realcmd = sub {