mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-03 06:08:31 +00:00
implement file-write via guest-agent in the api
writes the given content to the file the size is at the moment limited by the max post size of the pveproxy/daemon, so we set the maxLength to 60k Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
bb14060a1c
commit
735821a4fe
@ -118,6 +118,7 @@ __PACKAGE__->register_method({
|
||||
exec
|
||||
exec-status
|
||||
file-read
|
||||
file-write
|
||||
set-user-password
|
||||
);
|
||||
|
||||
@ -438,4 +439,43 @@ __PACKAGE__->register_method({
|
||||
return $result;
|
||||
}});
|
||||
|
||||
__PACKAGE__->register_method({
|
||||
name => 'file-write',
|
||||
path => 'file-write',
|
||||
method => 'POST',
|
||||
protected => 1,
|
||||
proxyto => 'node',
|
||||
description => "Writes the given file via guest agent.",
|
||||
permissions => { check => [ 'perm', '/vms/{vmid}', [ 'VM.Monitor' ]]},
|
||||
parameters => {
|
||||
additionalProperties => 0,
|
||||
properties => {
|
||||
node => get_standard_option('pve-node'),
|
||||
vmid => get_standard_option('pve-vmid', {
|
||||
completion => \&PVE::QemuServer::complete_vmid_running }),
|
||||
file => {
|
||||
type => 'string',
|
||||
description => 'The path to the file.'
|
||||
},
|
||||
content => {
|
||||
type => 'string',
|
||||
maxLength => 60*1024, # 60k, smaller than our 64k POST limit
|
||||
description => "The content to write into the file."
|
||||
}
|
||||
},
|
||||
},
|
||||
returns => { type => 'null' },
|
||||
code => sub {
|
||||
my ($param) = @_;
|
||||
|
||||
my $vmid = $param->{vmid};
|
||||
my $buf = encode_base64($param->{content});
|
||||
|
||||
my $qgafh = agent_cmd($vmid, "file-open", { path => $param->{file}, mode => 'wb' }, "can't open file");
|
||||
my $write = agent_cmd($vmid, "file-write", { handle => $qgafh, 'buf-b64' => $buf }, "can't write to file");
|
||||
my $res = agent_cmd($vmid, "file-close", { handle => $qgafh }, "can't close file");
|
||||
|
||||
return undef;
|
||||
}});
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user