]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
cleanup VNC websocket patch
[qemu-server.git] / PVE / API2 / Qemu.pm
index 696887f05be26f83cd33ba02f22cfe9b41e6dbdf..6fdf9da1a6fcb6009bc7093035c2e802091b299f 100644 (file)
@@ -18,6 +18,7 @@ use PVE::RPCEnvironment;
 use PVE::AccessControl;
 use PVE::INotify;
 use PVE::Network;
+use PVE::API2::Firewall::VM;
 
 use Data::Dumper; # fixme: remove
 
@@ -495,11 +496,17 @@ __PACKAGE__->register_method({
            { subdir => 'snapshot' },
            { subdir => 'spiceproxy' },
            { subdir => 'sendkey' },
+           { subdir => 'firewall' },
            ];
 
        return $res;
     }});
 
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Firewall::VM",  
+    path => '{vmid}/firewall',
+});
+
 __PACKAGE__->register_method({
     name => 'rrd',
     path => '{vmid}/rrd',
@@ -831,9 +838,9 @@ my $vmconfig_update_net = sub {
                    PVE::Network::tap_rate_limit($iface, $newnet->{rate});
                }
 
-               if(($newnet->{bridge} ne $oldnet->{bridge}) || ($newnet->{tag} ne $oldnet->{tag})){
-                   eval{PVE::Network::tap_unplug($iface, $oldnet->{bridge}, $oldnet->{tag});};
-                   PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag});
+               if(($newnet->{bridge} ne $oldnet->{bridge}) || ($newnet->{tag} ne $oldnet->{tag}) || ($newnet->{firewall} ne $oldnet->{firewall})){
+                   PVE::Network::tap_unplug($iface);
+                   PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall});
                }
 
            }else{
@@ -1263,6 +1270,11 @@ __PACKAGE__->register_method({
        properties => {
            node => get_standard_option('pve-node'),
            vmid => get_standard_option('pve-vmid'),
+           websocket => {
+               optional => 1,
+               type => 'boolean',
+               description => "starts websockify instead of vncproxy",
+           },
        },
     },
     returns => {
@@ -1284,6 +1296,7 @@ __PACKAGE__->register_method({
 
        my $vmid = $param->{vmid};
        my $node = $param->{node};
+       my $websocket = $param->{websocket};
 
        my $conf = PVE::QemuServer::load_config($vmid, $node); # check if VM exists
 
@@ -1301,7 +1314,7 @@ __PACKAGE__->register_method({
 
        if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
            $remip = PVE::Cluster::remote_node_ip($node);
-           # NOTE: kvm VNC traffic is already TLS encrypted
+           # NOTE: kvm VNC traffic is already TLS encrypted or is known unsecure
            $remcmd = ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes', $remip];
        }
 
@@ -1316,6 +1329,8 @@ __PACKAGE__->register_method({
 
            if ($conf->{vga} && ($conf->{vga} =~ m/^serial\d+$/)) {
 
+               die "Websocket mode is not supported in vga serial mode!" if $websocket;
+
                my $termcmd = [ '/usr/sbin/qm', 'terminal', $vmid, '-iface', $conf->{vga} ];
                #my $termcmd = "/usr/bin/qm terminal -iface $conf->{vga}";
                $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
@@ -1329,6 +1344,11 @@ __PACKAGE__->register_method({
 
                # also redirect stderr (else we get RFB protocol errors)
                $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null"];
+
+               if ($websocket) {
+                   $ENV{LC_PVE_TICKET} = $ticket;
+                   $cmd = ["/usr/share/novnc-pve/utils/wsproxy.py", '--run-once', "--timeout=$timeout", "--idle-timeout=$timeout", '--ssl-only', '--cert', '/etc/pve/local/pve-ssl.pem', '--key', '/etc/pve/local/pve-ssl.key', $port, '--', @$cmd];
+               }
            }
 
            PVE::Tools::run_command($cmd);
@@ -2409,7 +2429,7 @@ __PACKAGE__->register_method({
                     my $used_paths = PVE::QemuServer::get_used_paths($vmid, $storecfg, $conf, 1, 1);
                     my $path = PVE::Storage::path($storecfg, $old_volid);
                    if ($used_paths->{$path}){
-                       warn "volume $old_volid have snapshots. Can't delete it";
+                       warn "volume $old_volid have snapshots. Can't delete it\n";
                        PVE::QemuServer::add_unused_volume($conf, $old_volid);
                        PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
                    } else {