]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/CLI/qm.pm
cloud-init: sshkeys are now files on the CLI
[qemu-server.git] / PVE / CLI / qm.pm
index 7db65d36a737e71f832b34f6d422195a7014a298..3347612556bc3689abd783540bb9ea2d1cffeaba 100755 (executable)
@@ -10,6 +10,7 @@ use Fcntl ':flock';
 use File::Path;
 use IO::Socket::UNIX;
 use IO::Select;
+use URI::Escape;
 
 use PVE::Tools qw(extract_param);
 use PVE::Cluster;
@@ -20,6 +21,7 @@ use PVE::QemuServer;
 use PVE::QemuServer::ImportDisk;
 use PVE::QemuServer::OVF;
 use PVE::API2::Qemu;
+use PVE::API2::Qemu::Agent;
 use JSON;
 use PVE::JSONSchema qw(get_standard_option);
 use Term::ReadLine;
@@ -117,6 +119,12 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+           pretty => {
+               description => "Puts each option on a new line to enhance human readability",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
+           }
        },
     },
     returns => { type => 'null'},
@@ -124,7 +132,11 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $storecfg = PVE::Storage::config();
-       print PVE::QemuServer::vm_commandline($storecfg, $param->{vmid}) . "\n";
+       my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $param->{vmid});
+
+       $cmdline =~ s/ -/ \\\n  -/g if $param->{pretty};
+
+       print "$cmdline\n";
 
        return undef;
     }});
@@ -276,7 +288,7 @@ __PACKAGE__->register_method ({
        $tunnel_write->("tunnel online");
        $tunnel_write->("ver 1");
 
-       while (my $line = <>) {
+       while (my $line = <STDIN>) {
            chomp $line;
            if ($line =~ /^quit$/) {
                $tunnel_write->("OK");
@@ -652,6 +664,20 @@ my $print_agent_result = sub {
     print to_json($result, { pretty => 1, canonical => 1});
 };
 
+sub param_mapping {
+    my ($name) = @_;
+
+    my $ssh_key_map = ['sshkeys', sub {
+       return URI::Escape::uri_escape(PVE::Tools::file_get_contents($_[0]));
+    }];
+    my $mapping = {
+       'update_vm' => [$ssh_key_map],
+       'create_vm' => [$ssh_key_map],
+    };
+
+    return $mapping->{$name};
+}
+
 our $cmddef = {
     list => [ "PVE::API2::Qemu", 'vmlist', [],
             { node => $nodename }, sub {
@@ -776,7 +802,7 @@ our $cmddef = {
 
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
 
-    agent  => [ "PVE::API2::Qemu", 'agent', ['vmid', 'command'],
+    agent  => [ "PVE::API2::Qemu::Agent", 'agent', ['vmid', 'command'],
                { node => $nodename }, $print_agent_result ],
 
     mtunnel => [ __PACKAGE__, 'mtunnel', []],