]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/CLI/qm.pm
bump version to 5.0-29
[qemu-server.git] / PVE / CLI / qm.pm
index 04beb48ef943525653dc177ad53df8c0b4efb38c..c017a597e1dd9413ffeb3cd1a28808dc8600c1eb 100755 (executable)
@@ -10,8 +10,10 @@ use Fcntl ':flock';
 use File::Path;
 use IO::Socket::UNIX;
 use IO::Select;
+use URI::Escape;
 
 use PVE::Tools qw(extract_param);
+use PVE::PTY;
 use PVE::Cluster;
 use PVE::SafeSyslog;
 use PVE::INotify;
@@ -20,6 +22,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;
@@ -662,6 +665,29 @@ 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 $cipassword_map = ['cipassword', sub {
+       my ($value) = @_;
+       return $value if $value;
+
+       my $pw = PVE::PTY::read_password('New cloud-init user password: ');
+       my $pw2 = PVE::PTY::read_password('Repeat password: ');
+       die "passwords do not match\n" if $pw ne $pw2;
+       return $pw;
+    }, '<password>', 1];
+    my $mapping = {
+       'update_vm' => [$ssh_key_map, $cipassword_map],
+       'create_vm' => [$ssh_key_map, $cipassword_map],
+    };
+
+    return $mapping->{$name};
+}
+
 our $cmddef = {
     list => [ "PVE::API2::Qemu", 'vmlist', [],
             { node => $nodename }, sub {
@@ -786,7 +812,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', []],