]> git.proxmox.com Git - pve-manager.git/blob - PVE/API2/NodeConfig.pm
bump version to 5.4-15
[pve-manager.git] / PVE / API2 / NodeConfig.pm
1 package PVE::API2::NodeConfig;
2
3 use strict;
4 use warnings;
5
6 use PVE::JSONSchema qw(get_standard_option);
7 use PVE::NodeConfig;
8 use PVE::Tools qw(extract_param);
9
10 use base qw(PVE::RESTHandler);
11
12 my $node_config_schema = PVE::NodeConfig::get_nodeconfig_schema();
13 my $node_config_properties = {
14 delete => {
15 type => 'string', format => 'pve-configid-list',
16 description => "A list of settings you want to delete.",
17 optional => 1,
18 },
19 digest => {
20 type => 'string',
21 description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
22 maxLength => 40,
23 optional => 1,
24 },
25 node => get_standard_option('pve-node'),
26 };
27
28 foreach my $opt (keys %{$node_config_schema}) {
29 $node_config_properties->{$opt} = $node_config_schema->{$opt};
30 }
31
32 __PACKAGE__->register_method({
33 name => 'get_config',
34 path => '',
35 method => 'GET',
36 description => "Get node configuration options.",
37 permissions => {
38 check => ['perm', '/', [ 'Sys.Audit' ]],
39 },
40 proxyto => 'node',
41 parameters => {
42 additionalProperties => 0,
43 properties => {
44 node => get_standard_option('pve-node'),
45 },
46 },
47 returns => {
48 type => "object",
49 properties => {},
50 },
51 code => sub {
52 my ($param) = @_;
53
54 return PVE::NodeConfig::load_config($param->{node});
55 }});
56
57 __PACKAGE__->register_method({
58 name => 'set_options',
59 path => '',
60 method => 'PUT',
61 description => "Set node configuration options.",
62 permissions => {
63 check => ['perm', '/', [ 'Sys.Modify' ]],
64 },
65 protected => 1,
66 proxyto => 'node',
67 parameters => {
68 additionalProperties => 0,
69 properties => $node_config_properties,
70 },
71 returns => { type => "null" },
72 code => sub {
73 my ($param) = @_;
74
75 my $delete = extract_param($param, 'delete');
76 my $node = extract_param($param, 'node');
77 my $digest = extract_param($param, 'digest');
78
79 my $code = sub {
80 my $conf = PVE::NodeConfig::load_config($node);
81
82 PVE::Tools::assert_if_modified($digest, $conf->{digest});
83
84 foreach my $opt (keys %$param) {
85 $conf->{$opt} = $param->{$opt};
86 }
87
88 foreach my $opt (PVE::Tools::split_list($delete)) {
89 delete $conf->{$opt};
90 };
91
92 PVE::NodeConfig::write_config($node, $conf);
93 };
94
95 PVE::NodeConfig::lock_config($node, $code);
96 die $@ if $@;
97
98 return undef;
99 }});
100
101 1;