]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
add /node/{NODE}/hosts API Call
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 12 Sep 2018 08:24:13 +0000 (10:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 14 Sep 2018 09:47:03 +0000 (11:47 +0200)
to get and set the content of /etc/hosts

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Nodes.pm

index 836dccaf33ce85d48e64a274a706f1165c373a26..495028309a5491b64c9b449fa3d42afb328b5c5f 100644 (file)
@@ -186,6 +186,7 @@ __PACKAGE__->register_method ({
            { name => 'firewall' },
            { name => 'certificates' },
            { name => 'config' },
+           { name => 'hosts' },
            ];
 
        return $result;
@@ -1815,6 +1816,78 @@ __PACKAGE__->register_method ({
 
     }});
 
+__PACKAGE__->register_method ({
+    name => 'get_etc_hosts',
+    path => 'hosts',
+    method => 'GET',
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+       check => ['perm', '/', [ 'Sys.Audit' ]],
+    },
+    description => "Get the content of /etc/hosts.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => {
+       type => 'object',
+       properties => {
+           digest => get_standard_option('pve-config-digest'),
+           data => {
+               type => 'string',
+               description => 'The content of /etc/hosts.'
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       return PVE::INotify::read_file('etchosts');
+
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'write_etc_hosts',
+    path => 'hosts',
+    method => 'POST',
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+       check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
+    },
+    description => "Write /etc/hosts.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           digest => get_standard_option('pve-config-digest'),
+           data => {
+               type => 'string',
+               description =>  'The target content of /etc/hosts.'
+           },
+       },
+    },
+    returns => {
+       type => 'null',
+    },
+    code => sub {
+       my ($param) = @_;
+
+       PVE::Tools::lock_file('/var/lock/pve-etchosts.lck', undef, sub{
+           if ($param->{digest}) {
+               my $hosts = PVE::INotify::read_file('etchosts');
+               PVE::Tools::assert_if_modified($hosts->{digest}, $param->{digest});
+           }
+           PVE::INotify::write_file('etchosts', $param->{data});
+       });
+       die $@ if $@;
+
+       return undef;
+    }});
+
 # bash completion helper
 
 sub complete_templet_repo {