Commit a28a67e2 authored by Dietmar Maurer's avatar Dietmar Maurer

add initlog API

parent faa429b9
......@@ -95,8 +95,6 @@ my $restore_openvz = sub {
my $root = $vzconf->{rootdir};
$root =~ s/\$VEID/$vmid/;
my $default_private = $vzconf->{privatedir};
$default_private =~ s/\$VEID/$vmid/;
print "you choose to force overwriting VPS config file, private and root directories.\n" if $force;
......@@ -115,7 +113,7 @@ my $restore_openvz = sub {
if ($force && -f $conffile) {
my $conf = PVE::OpenVZ::load_config($vmid);
my $oldprivate = $conf->{ve_private} ? $conf->{ve_private}->{value} : $default_private;
my $oldprivate = PVE::OpenVZ::get_privatedir($conf, $vmid);
rmtree $oldprivate if -d $oldprivate;
my $oldroot = $conf->{ve_root} ? $conf->{ve_root}->{value} : $root;
......@@ -416,6 +414,7 @@ __PACKAGE__->register_method({
{ subdir => 'status' },
{ subdir => 'vncproxy' },
{ subdir => 'migrate' },
{ subdir => 'initlog' },
{ subdir => 'rrd' },
{ subdir => 'rrddata' },
];
......@@ -512,6 +511,70 @@ __PACKAGE__->register_method({
"pve2-vm/$param->{vmid}", $param->{timeframe}, $param->{cf});
}});
__PACKAGE__->register_method({
name => 'initlog',
path => '{vmid}/initlog',
method => 'GET',
protected => 1,
permissions => {
path => '/vms/{vmid}',
privs => [ 'VM.Audit' ],
},
description => "Read init log.",
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid'),
start => {
type => 'integer',
minimum => 0,
optional => 1,
},
limit => {
type => 'integer',
minimum => 0,
optional => 1,
},
},
},
returns => {
type => 'array',
items => {
type => "object",
properties => {
n => {
description=> "Line number",
type=> 'integer',
},
t => {
description=> "Line text",
type => 'string',
}
}
}
},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $vmid = $param->{vmid};
my $conf = PVE::OpenVZ::load_config($vmid);
my $privatedir = PVE::OpenVZ::get_privatedir($conf, $vmid);
my $logfn = "$privatedir/var/log/init.log";
my ($count, $lines) = PVE::Tools::dump_logfile($logfn, $param->{start}, $param->{limit});
$rpcenv->set_result_count($count);
return $lines;
}});
__PACKAGE__->register_method({
name => 'vm_config',
path => '{vmid}/config',
......
......@@ -72,6 +72,18 @@ sub check_mounted {
return (-d "$root/etc" || -d "$root/proc");
}
sub get_privatedir {
my ($conf, $vmid) = @_;
my $private = $global_vzconf->{privatedir};
if ($conf->{ve_private} && $conf->{ve_private}->{value}) {
$private = $conf->{ve_private}->{value};
}
$private =~ s/\$VEID/$vmid/;
return $private;
}
sub read_user_beancounters {
my $ubc = {};
if (my $fh = IO::File->new ("/proc/user_beancounters", "r")) {
......@@ -1193,4 +1205,3 @@ sub set_rootpasswd {
replacepw ($pwfile, $opt_rootpasswd);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment