[pve-devel] r6487 - in pve-manager/pve2: . lib/PVE/API2
svn-commits at proxmox.com
svn-commits at proxmox.com
Wed Aug 17 13:57:44 CEST 2011
Author: dietmar
Date: 2011-08-17 13:57:44 +0200 (Wed, 17 Aug 2011)
New Revision: 6487
Modified:
pve-manager/pve2/ChangeLog
pve-manager/pve2/lib/PVE/API2/Cluster.pm
Log:
* lib/PVE/API2/Cluster.pm: impl. read/write datacenter.cfg
Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog 2011-08-17 11:50:35 UTC (rev 6486)
+++ pve-manager/pve2/ChangeLog 2011-08-17 11:57:44 UTC (rev 6487)
@@ -1,3 +1,7 @@
+2011-08-17 Proxmox Support Team <support at proxmox.com>
+
+ * lib/PVE/API2/Cluster.pm: impl. read/write datacenter.cfg
+
2011-08-05 Proxmox Support Team <support at proxmox.com>
* bin/pvestatd: always call cfs_update() to update versions
Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-08-17 11:50:35 UTC (rev 6486)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-08-17 11:57:44 UTC (rev 6487)
@@ -4,7 +4,8 @@
use warnings;
use PVE::SafeSyslog;
-use PVE::Cluster;
+use PVE::Tools qw(extract_param);
+use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
use PVE::Storage;
use JSON;
@@ -17,6 +18,18 @@
use base qw(PVE::RESTHandler);
+my $dc_schema = PVE::Cluster::get_datacenter_schema();
+my $dc_properties = {
+ delete => {
+ type => 'string', format => 'pve-configid-list',
+ description => "A list of settings you want to delete.",
+ optional => 1,
+ }
+};
+foreach my $opt (keys %{$dc_schema->{properties}}) {
+ $dc_properties->{$opt} = $dc_schema->{properties}->{$opt};
+}
+
__PACKAGE__->register_method ({
name => 'index',
path => '',
@@ -40,6 +53,7 @@
my $result = [
{ name => 'log' },
+ { name => 'options' },
{ name => 'resources' },
{ name => 'tasks' },
];
@@ -255,4 +269,68 @@
return $res;
}});
+__PACKAGE__->register_method({
+ name => 'get_options',
+ path => 'options',
+ method => 'GET',
+ description => "Get datacenter options.",
+ permissions => {
+ path => '/',
+ privs => [ 'Sys.Audit' ],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {},
+ },
+ returns => {
+ type => "object",
+ properties => {},
+ },
+ code => sub {
+ my ($param) = @_;
+ return PVE::Cluster::cfs_read_file('datacenter.cfg');
+ }});
+
+__PACKAGE__->register_method({
+ name => 'set_options',
+ path => 'options',
+ method => 'PUT',
+ description => "Set datacenter options.",
+ permissions => {
+ path => '/',
+ privs => [ 'Sys.Modify' ],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => $dc_properties,
+ },
+ returns => { type => "null" },
+ code => sub {
+ my ($param) = @_;
+
+ my $filename = 'datacenter.cfg';
+
+ my $delete = extract_param($param, 'delete');
+
+ my $code = sub {
+
+ my $conf = cfs_read_file($filename);
+
+ foreach my $opt (keys %$param) {
+ $conf->{$opt} = $param->{$opt};
+ }
+
+ foreach my $opt (PVE::Tools::split_list($delete)) {
+ delete $conf->{$opt};
+ };
+
+ cfs_write_file($filename, $conf);
+ };
+
+ cfs_lock_file($filename, undef, $code);
+ die $@ if $@;
+
+ return undef;
+ }});
+
1;
More information about the pve-devel
mailing list