introduce base_handler_class
To make the framework more generic. The final plan is to move the generic server code to package pve-common. Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
6a123049cc
commit
d804d82f50
@ -6,7 +6,6 @@ use URI;
|
||||
use HTTP::Cookies;
|
||||
use LWP::UserAgent;
|
||||
use JSON;
|
||||
use PVE::API2;
|
||||
use Data::Dumper; # fixme: remove
|
||||
use HTTP::Request::Common;
|
||||
|
||||
|
@ -19,6 +19,9 @@ sub new {
|
||||
|
||||
die "no lockfile" if !$args{lockfile};
|
||||
|
||||
die "no base_handler_class" if !$args{base_handler_class};
|
||||
#require $args{base_handler_class};
|
||||
|
||||
my $lockfh = IO::File->new(">>$args{lockfile}") ||
|
||||
die "unable to open lock file '$args{lockfile}' - $!\n";
|
||||
|
||||
@ -37,6 +40,8 @@ sub new {
|
||||
my $cfg = { %args };
|
||||
my $self = bless { cfg => $cfg }, $class;
|
||||
|
||||
$cfg->{base_handler_class} = $args{base_handler_class};
|
||||
|
||||
$cfg->{socket} = $socket;
|
||||
$cfg->{lockfh} = $lockfh;
|
||||
$cfg->{max_workers} = 3 if !$cfg->{max_workers};
|
||||
|
@ -1292,12 +1292,14 @@ sub new {
|
||||
|
||||
my $class = ref($this) || $this;
|
||||
|
||||
foreach my $req (qw(socket lockfh lockfile)) {
|
||||
foreach my $req (qw(base_handler_class socket lockfh lockfile)) {
|
||||
die "misssing required argument '$req'" if !defined($args{$req});
|
||||
}
|
||||
|
||||
my $self = bless { %args }, $class;
|
||||
|
||||
PVE::REST::set_base_handler_class($self->{base_handler_class});
|
||||
|
||||
# init inotify
|
||||
PVE::INotify::inotify_init();
|
||||
|
||||
|
15
PVE/REST.pm
15
PVE/REST.pm
@ -6,7 +6,6 @@ use English;
|
||||
use PVE::Cluster;
|
||||
use PVE::SafeSyslog;
|
||||
use PVE::Tools;
|
||||
use PVE::API2;
|
||||
use JSON;
|
||||
use LWP::UserAgent;
|
||||
use HTTP::Request::Common;
|
||||
@ -22,6 +21,16 @@ use Data::Dumper; # fixme: remove
|
||||
|
||||
my $cookie_name = 'PVEAuthCookie';
|
||||
|
||||
my $base_handler_class;
|
||||
|
||||
sub set_base_handler_class {
|
||||
my ($class) = @_;
|
||||
|
||||
die "base_handler_class already defined" if $base_handler_class;
|
||||
|
||||
$base_handler_class = $class;
|
||||
}
|
||||
|
||||
sub extract_auth_cookie {
|
||||
my ($cookie) = @_;
|
||||
|
||||
@ -236,8 +245,10 @@ sub auth_handler {
|
||||
sub rest_handler {
|
||||
my ($rpcenv, $clientip, $method, $rel_uri, $auth, $params) = @_;
|
||||
|
||||
die "no base handler - internal error" if !$base_handler_class;
|
||||
|
||||
my $uri_param = {};
|
||||
my ($handler, $info) = PVE::API2->find_handler($method, $rel_uri, $uri_param);
|
||||
my ($handler, $info) = $base_handler_class->find_handler($method, $rel_uri, $uri_param);
|
||||
if (!$handler || !$info) {
|
||||
return {
|
||||
status => HTTP_NOT_IMPLEMENTED,
|
||||
|
@ -11,6 +11,7 @@ use POSIX ":sys_wait_h";
|
||||
use Socket;
|
||||
use PVE::SafeSyslog;
|
||||
use PVE::APIDaemon;
|
||||
use PVE::API2;
|
||||
|
||||
my $pidfile = "/var/run/pvedaemon.pid";
|
||||
my $lockfile = "/var/lock/pvedaemon.lck";
|
||||
@ -40,6 +41,7 @@ my $cpid;
|
||||
my $daemon;
|
||||
eval {
|
||||
$daemon = PVE::APIDaemon->new(
|
||||
base_handler_class => 'PVE::API2',
|
||||
host => "127.0.0.1",
|
||||
port => 85,
|
||||
trusted_env => 1, # partly trusted, because only local programs can connect
|
||||
|
@ -19,6 +19,7 @@ use URI;
|
||||
use URI::QueryParam;
|
||||
use File::Find;
|
||||
use Data::Dumper;
|
||||
use PVE::API2;
|
||||
|
||||
my $pidfile = "/var/run/pveproxy/pveproxy.pid";
|
||||
my $lockfile = "/var/lock/pveproxy.lck";
|
||||
@ -81,6 +82,7 @@ eval {
|
||||
add_dirs($dirs, '/vncterm/' => '/usr/share/vncterm/');
|
||||
|
||||
$daemon = PVE::APIDaemon->new(
|
||||
base_handler_class => 'PVE::API2',
|
||||
port => 8006,
|
||||
keep_alive => 100,
|
||||
max_conn => 500,
|
||||
|
@ -13,6 +13,7 @@ use English;
|
||||
use Getopt::Long;
|
||||
use PVE::SafeSyslog;
|
||||
use PVE::APIDaemon;
|
||||
use PVE::API2;
|
||||
|
||||
my $pidfile = "/var/run/pveproxy/spiceproxy.pid";
|
||||
my $lockfile = "/var/lock/spiceproxy.lck";
|
||||
@ -51,6 +52,7 @@ my $cpid;
|
||||
my $daemon;
|
||||
eval {
|
||||
$daemon = PVE::APIDaemon->new(
|
||||
base_handler_class => 'PVE::API2',
|
||||
port => 3128,
|
||||
keep_alive => 0,
|
||||
max_workers => 1, # do we need more?
|
||||
|
Loading…
x
Reference in New Issue
Block a user