[pve-devel] [PATCH container] implement 'edit' command for pct

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


this opens the container 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>
---
 src/PVE/CLI/pct.pm | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 3253906..f8a58d0 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -715,6 +715,34 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'edit',
+    path => 'edit',
+    method => 'POST',
+    description => "Opens the CT 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::LXC::complete_vmid_running }),
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	# test if ct exists
+	my $conf = PVE::LXC::Config->load_config ($param->{vmid});
+
+	my $vmid = $param->{vmid};
+	my $file = "/etc/pve/lxc/$vmid.conf";
+
+	my $editor = $ENV{EDITOR} // '/usr/bin/editor';
+	system("$editor $file");
+
+	return undef;
+    }});
+
+
 our $cmddef = {
     list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
 	my $res = shift;
@@ -799,6 +827,8 @@ our $cmddef = {
 
     cpusets => [ __PACKAGE__, 'cpusets', []],
 
+    edit => [ __PACKAGE__, 'edit', ['vmid']],
+
 };
 
 
-- 
2.11.0




More information about the pve-devel mailing list