]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/Cluster.pm
fixup /cluster/resources schema
[pve-manager.git] / PVE / API2 / Cluster.pm
index a60f5231f6a5c2b717d1d9c86470e67d43bcee73..49e319a5c624b356e7d8b8fb8692b9e6bed3f3e6 100644 (file)
@@ -137,6 +137,7 @@ __PACKAGE__->register_method ({
            { name => 'config' },
            { name => 'firewall' },
            { name => 'ha' },
+           { name => 'jobs' },
            { name => 'log' },
            { name => 'metrics' },
            { name => 'nextid' },
@@ -253,18 +254,21 @@ __PACKAGE__->register_method({
                    description => "CPU utilization (when type in node,qemu,lxc).",
                    type => 'number',
                    optional => 1,
+                   minimum => 0,
                    renderer => 'fraction_as_percentage',
                },
                maxcpu => {
                    description => "Number of available CPUs (when type in node,qemu,lxc).",
                    type => 'number',
                    optional => 1,
+                   minimum => 0,
                },
                mem => {
                    description => "Used memory in bytes (when type in node,qemu,lxc).",
-                   type => 'string',
+                   type => 'integer',
                    optional => 1,
                    renderer => 'bytes',
+                   minimum => 0,
                },
                maxmem => {
                    description => "Number of available memory in bytes (when type in node,qemu,lxc).",
@@ -290,15 +294,17 @@ __PACKAGE__->register_method({
                },
                disk => {
                    description => "Used disk space in bytes (when type in storage), used root image spave for VMs (type in qemu,lxc).",
-                   type => 'string',
+                   type => 'integer',
                    optional => 1,
                    renderer => 'bytes',
+                   minimum => 0,
                },
                maxdisk => {
                    description => "Storage size in bytes (when type in storage), root image size for VMs (type in qemu,lxc).",
                    type => 'integer',
                    optional => 1,
                    renderer => 'bytes',
+                   minimum => 0,
                },
                content => {
                    description => "Allowed storage content types (when type == storage).",
@@ -311,6 +317,12 @@ __PACKAGE__->register_method({
                    type => 'string',
                    optional => 1,
                },
+               vmid => {
+                   description => "The numerical vmid (when type in qemu,lxc).",
+                   type => 'integer',
+                   optional => 1,
+                   minimum => 1,
+               },
            },
        },
     },
@@ -495,13 +507,11 @@ __PACKAGE__->register_method({
        my $authuser = $rpcenv->get_user();
 
        my $tlist = PVE::Cluster::get_tasklist();
-
-       my $res = [];
-
-       return $res if !$tlist;
+       return [] if !$tlist;
 
        my $all = $rpcenv->check($authuser, "/", [ 'Sys.Audit' ], 1);
 
+       my $res = [];
        foreach my $task (@$tlist) {
            if (PVE::AccessControl::pve_verify_tokenid($task->{user}, 1)) {
                ($task->{user}, $task->{tokenid}) = PVE::AccessControl::split_tokenid($task->{user});
@@ -551,26 +561,17 @@ __PACKAGE__->register_method({
     code => sub {
        my ($param) = @_;
 
-       my $filename = 'datacenter.cfg';
-
        my $delete = extract_param($param, 'delete');
 
-       my $code = sub {
+       cfs_lock_file('datacenter.cfg', undef, sub {
+           my $conf = cfs_read_file('datacenter.cfg');
 
-           my $conf = cfs_read_file($filename);
+           $conf->{$_} = $param->{$_} for keys $param->%*;
 
-           foreach my $opt (keys %$param) {
-               $conf->{$opt} = $param->{$opt};
-           }
+           delete $conf->{$_} for PVE::Tools::split_list($delete);
 
-           foreach my $opt (PVE::Tools::split_list($delete)) {
-               delete $conf->{$opt};
-           };
-
-           cfs_write_file($filename, $conf);
-       };
-
-       cfs_lock_file($filename, undef, $code);
+           cfs_write_file('datacenter.cfg', $conf);
+       });
        die $@ if $@;
 
        return undef;
@@ -700,7 +701,7 @@ __PACKAGE__->register_method({
            # fake entry for local node if no cluster defined
            my $pmxcfs = ($clinfo && $clinfo->{version}) ? 1 : 0; # pmxcfs online ?
 
-           my $subinfo = PVE::INotify::read_file('subscription');
+           my $subinfo = PVE::API2::Subscription::read_etc_subscription();
            my $sublevel = $subinfo->{level} || '';
 
            return [{
@@ -720,12 +721,14 @@ __PACKAGE__->register_method({
     name => 'nextid',
     path => 'nextid',
     method => 'GET',
-    description => "Get next free VMID. If you pass an VMID it will raise an error if the ID is already used.",
+    description => "Get next free VMID. Pass a VMID to assert that its free (at time of check).",
     permissions => { user => 'all' },
     parameters => {
        additionalProperties => 0,
        properties => {
-           vmid => get_standard_option('pve-vmid', {optional => 1}),
+           vmid => get_standard_option('pve-vmid', {
+                   optional => 1,
+           }),
        },
     },
     returns => {
@@ -743,11 +746,17 @@ __PACKAGE__->register_method({
            raise_param_exc({ vmid => "VM $vmid already exists" });
        }
 
-       for (my $i = 100; $i < 10000; $i++) {
+       my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
+       my $next_id = $dc_conf->{'next-id'} // {};
+
+       my $lower = $next_id->{lower} // 100;
+       my $upper = $next_id->{upper} // (1000 * 1000); # note, lower than the schema-maximum
+
+       for (my $i = $lower; $i < $upper; $i++) {
            return $i if !defined($idlist->{$i});
        }
 
-       die "unable to get any free VMID\n";
+       die "unable to get any free VMID in range [$lower, $upper]\n";
     }});
 
 1;