]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/JSONSchema.pm
register standard options for SPICE
[pve-common.git] / data / PVE / JSONSchema.pm
index 6b87302c6132951f78cfe571850530405e8fdca4..881120769778d944ef706357244ef0faaff1d8a2 100644 (file)
@@ -1,13 +1,14 @@
 package PVE::JSONSchema;
 
-use warnings;
 use strict;
+use warnings;
 use Storable; # for dclone
 use Getopt::Long;
 use Devel::Cycle -quiet; # todo: remove?
 use PVE::Tools qw(split_list);
 use PVE::Exception qw(raise);
 use HTTP::Status qw(:constants);
+use Net::IP qw(:PROC);
 
 use base 'Exporter';
 
@@ -75,7 +76,6 @@ PVE::JSONSchema::register_standard_option('pve-storage-id', {
     type => 'string', format => 'pve-storage-id',
 }); 
 
-
 my $format_list = {};
 
 sub register_format {
@@ -97,7 +97,7 @@ sub pve_verify_configid {
  
     if ($id !~ m/^[a-z][a-z0-9_]+$/i) {
        return undef if $noerr;
-       die "invalid cofiguration ID '$id'\n"; 
+       die "invalid configuration ID '$id'\n"; 
     }
     return $id;
 }
@@ -140,21 +140,51 @@ register_format('ipv4', \&pve_verify_ipv4);
 sub pve_verify_ipv4 {
     my ($ipv4, $noerr) = @_;
 
-   if ($ipv4 !~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ ||
-       !(($1 > 0) && ($1 < 255) &&
-        ($2 <= 255) && ($3 <= 255) && 
-        ($4 > 0) && ($4 < 255)))  {
-          return undef if $noerr;
+    if (!Net::IP::ip_is_ipv4($ipv4))  {
+       return undef if $noerr;
        die "value does not look like a valid IP address\n";
     }
     return $ipv4;
 }
+
+my $ipv4_mask_hash = {
+    '128.0.0.0' => 1,
+    '192.0.0.0' => 2,
+    '224.0.0.0' => 3,
+    '240.0.0.0' => 4,
+    '248.0.0.0' => 5,
+    '252.0.0.0' => 6,
+    '254.0.0.0' => 7,
+    '255.0.0.0' => 8,
+    '255.128.0.0' => 9,
+    '255.192.0.0' => 10,
+    '255.224.0.0' => 11,
+    '255.240.0.0' => 12,
+    '255.248.0.0' => 13,
+    '255.252.0.0' => 14,
+    '255.254.0.0' => 15,
+    '255.255.0.0' => 16,
+    '255.255.128.0' => 17,
+    '255.255.192.0' => 18,
+    '255.255.224.0' => 19,
+    '255.255.240.0' => 20,
+    '255.255.248.0' => 21,
+    '255.255.252.0' => 22,
+    '255.255.254.0' => 23,
+    '255.255.255.0' => 24,
+    '255.255.255.128' => 25,
+    '255.255.255.192' => 26,
+    '255.255.255.224' => 27,
+    '255.255.255.240' => 28,
+    '255.255.255.248' => 29,
+    '255.255.255.252' => 30
+};
+
 register_format('ipv4mask', \&pve_verify_ipv4mask);
 sub pve_verify_ipv4mask {
     my ($mask, $noerr) = @_;
 
-    if ($mask !~ m/^255\.255\.(\d{1,3})\.(\d{1,3})$/ ||
-       !(($1 <= 255) && ($2 <= 255)))  {
+    if (!defined($ipv4_mask_hash->{$mask})) {
        return undef if $noerr;
        die "value does not look like a valid IP netmask\n";
     }
@@ -198,6 +228,23 @@ sub pve_verify_iface {
     return $id;
 }
 
+register_standard_option('spice-proxy', {
+    description => "SPICE proxy server. This can be used by the client to specify the proxy server. All nodes in a cluster runs 'spiceproxy', so it is up to the client to choose one. By default, we return the node where the VM is currently running. As resonable setting is to use same node you use to connect to the API (This is window.location.hostname for the JS GUI).",
+    type => 'string', format => 'dns-name',
+}); 
+
+register_standard_option('remote-viewer-config', {
+    description => "Returned values can be directly passed to the 'remote-viewer' application.",
+    additionalProperties => 1,
+    properties => {
+       type => { type => 'string' },
+       password => { type => 'string' },
+       proxy => { type => 'string' },
+       host => { type => 'string' },
+       'tls-port' => { type => 'integer' },
+    },
+});
+
 sub check_format {
     my ($format, $value) = @_;
 
@@ -953,9 +1000,6 @@ sub get_options {
     }
 
     $opts = PVE::Tools::decode_utf8_parameters($opts);
-    if ($opts->{description}) {
-       print "TEST: " . PVE::Tools::encode_text($opts->{description}) . "\n";
-    }
 
     foreach my $p (keys %$opts) {
        if (my $pd = $schema->{properties}->{$p}) {