edit the vm config via PVE::Tools::edit_file minus the snapshot sections (we do not want to update those manually)
Signed-off-by: Dominik Csapak <d.csa...@proxmox.com> --- changes since v2: * use PVE::Tools::edit_file * do not remove pending section, as one might want to edit that directly * use correct completion helper (complete_vmid instead of _running) PVE/CLI/qm.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm index 90a44ef..e567091 100755 --- a/PVE/CLI/qm.pm +++ b/PVE/CLI/qm.pm @@ -606,6 +606,65 @@ __PACKAGE__->register_method ({ } }); +__PACKAGE__->register_method ({ + name => 'edit', + path => 'edit', + method => 'POST', + description => "Opens the VM config file in the editor set via update-alternatives.". + "This does not actually change the VM without turning it off and on.", + parameters => { + additionalProperties => 0, + properties => { + vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), + }, + }, + returns => { type => 'null'}, + code => sub { + my ($param) = @_; + + my $vmid = $param->{vmid}; + my $digest; + + my $readfn = sub { + # load config of vm + my $oldconf = PVE::QemuConfig->load_config($vmid); + + # for later check + $digest = $oldconf->{digest}; + + # we do not want to edit snapshots + delete $oldconf->{snapshots}; + + # write_vm_config returns the raw content + return PVE::QemuServer::write_vm_config("/qemu-server/$vmid.conf", $oldconf); + }; + + my $writefn = sub { + my ($content) = @_; + PVE::QemuConfig->lock_config($vmid, sub { + + # update cluster file system to avoid config cache + PVE::Cluster::cfs_update(); + my $conf = PVE::QemuConfig->load_config($vmid); + + PVE::Tools::assert_if_modified($digest, $conf->{digest}); + + my $newconf = PVE::QemuServer::parse_vm_config("/qemu-server/$vmid.conf", $content); + + # use the snapshots from the original config + $newconf->{snapshots} = $conf->{snapshots}; + + # write config back + PVE::QemuConfig->write_config($vmid, $newconf); + }); + }; + + PVE::Tools::edit_file($readfn, $writefn); + + return undef; + }}); + + my $print_agent_result = sub { my ($data) = @_; @@ -765,6 +824,8 @@ our $cmddef = { importovf => [ __PACKAGE__, 'importovf', ['vmid', 'manifest', 'storage']], + edit => [ __PACKAGE__, 'edit', ['vmid']], + }; 1; -- 2.11.0 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel