[pve-devel] [PATCH manager 1/2] add /node/{NODE}/hosts API Call

Dominik Csapak d.csapak at proxmox.com
Fri Aug 24 12:34:11 CEST 2018


to get and set the content of /etc/hosts

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Nodes.pm | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 836dccaf..b8a7c969 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -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 => {
+		type => 'string',
+		description => 'The SHA1 digest of the file.',
+	    },
+	    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 => {
+		type => 'string',
+		description => 'Prevent changes if current configuration file has different SHA1 digest. This is used to prevent concurrent modifications.',
+		maxLength => 40,
+	    },
+	    data => {
+		type => 'string',
+		description =>  'The target content of /etc/hosts.'
+	    },
+	},
+    },
+    returns => {
+	type => 'null',
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::INotify::write_file('etchosts', $param);
+
+	return undef;
+    }});
+
 # bash completion helper
 
 sub complete_templet_repo {
-- 
2.11.0





More information about the pve-devel mailing list