[pve-devel] [PATCH qemu-server] implement 'edit' command for qm

Dominik Csapak d.csapak at proxmox.com
Mon Oct 16 15:55:20 CEST 2017


this opens the vm config file in the editor which is specified
via the "EDITOR" environment variable or set via
update-alternatives (which /usr/bin/editor is a symlink to)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/CLI/qm.pm | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 90a44ef..d1d22cc 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -606,6 +606,34 @@ __PACKAGE__->register_method ({
     }
 });
 
+__PACKAGE__->register_method ({
+    name => 'edit',
+    path => 'edit',
+    method => 'POST',
+    description => "Opens the VM config file in the editor set via the EDITOR variable or update-alternatives",
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	# test if vm exists
+	my $conf = PVE::QemuConfig->load_config ($param->{vmid});
+
+	my $vmid = $param->{vmid};
+	my $file = "/etc/pve/qemu-server/$vmid.conf";
+
+	my $editor = $ENV{EDITOR} // '/usr/bin/editor';
+	system("$editor $file");
+
+	return undef;
+    }});
+
+
 my $print_agent_result = sub {
     my ($data) = @_;
 
@@ -765,6 +793,8 @@ our $cmddef = {
 
     importovf => [ __PACKAGE__, 'importovf', ['vmid', 'manifest', 'storage']],
 
+    edit => [ __PACKAGE__, 'edit', ['vmid']],
+
 };
 
 1;
-- 
2.11.0





More information about the pve-devel mailing list