Commit fa239655 authored by Dietmar Maurer's avatar Dietmar Maurer

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: 's avatarDietmar Maurer <dietmar@proxmox.com>
parent 9819bdc4
...@@ -6,7 +6,6 @@ use URI; ...@@ -6,7 +6,6 @@ use URI;
use HTTP::Cookies; use HTTP::Cookies;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON;
use PVE::API2;
use Data::Dumper; # fixme: remove use Data::Dumper; # fixme: remove
use HTTP::Request::Common; use HTTP::Request::Common;
......
...@@ -19,6 +19,9 @@ sub new { ...@@ -19,6 +19,9 @@ sub new {
die "no lockfile" if !$args{lockfile}; 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}") || my $lockfh = IO::File->new(">>$args{lockfile}") ||
die "unable to open lock file '$args{lockfile}' - $!\n"; die "unable to open lock file '$args{lockfile}' - $!\n";
...@@ -37,6 +40,8 @@ sub new { ...@@ -37,6 +40,8 @@ sub new {
my $cfg = { %args }; my $cfg = { %args };
my $self = bless { cfg => $cfg }, $class; my $self = bless { cfg => $cfg }, $class;
$cfg->{base_handler_class} = $args{base_handler_class};
$cfg->{socket} = $socket; $cfg->{socket} = $socket;
$cfg->{lockfh} = $lockfh; $cfg->{lockfh} = $lockfh;
$cfg->{max_workers} = 3 if !$cfg->{max_workers}; $cfg->{max_workers} = 3 if !$cfg->{max_workers};
......
...@@ -1292,12 +1292,14 @@ sub new { ...@@ -1292,12 +1292,14 @@ sub new {
my $class = ref($this) || $this; 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}); die "misssing required argument '$req'" if !defined($args{$req});
} }
my $self = bless { %args }, $class; my $self = bless { %args }, $class;
PVE::REST::set_base_handler_class($self->{base_handler_class});
# init inotify # init inotify
PVE::INotify::inotify_init(); PVE::INotify::inotify_init();
......
...@@ -6,7 +6,6 @@ use English; ...@@ -6,7 +6,6 @@ use English;
use PVE::Cluster; use PVE::Cluster;
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::Tools; use PVE::Tools;
use PVE::API2;
use JSON; use JSON;
use LWP::UserAgent; use LWP::UserAgent;
use HTTP::Request::Common; use HTTP::Request::Common;
...@@ -22,6 +21,16 @@ use Data::Dumper; # fixme: remove ...@@ -22,6 +21,16 @@ use Data::Dumper; # fixme: remove
my $cookie_name = 'PVEAuthCookie'; 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 { sub extract_auth_cookie {
my ($cookie) = @_; my ($cookie) = @_;
...@@ -236,8 +245,10 @@ sub auth_handler { ...@@ -236,8 +245,10 @@ sub auth_handler {
sub rest_handler { sub rest_handler {
my ($rpcenv, $clientip, $method, $rel_uri, $auth, $params) = @_; my ($rpcenv, $clientip, $method, $rel_uri, $auth, $params) = @_;
die "no base handler - internal error" if !$base_handler_class;
my $uri_param = {}; 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) { if (!$handler || !$info) {
return { return {
status => HTTP_NOT_IMPLEMENTED, status => HTTP_NOT_IMPLEMENTED,
......
...@@ -11,6 +11,7 @@ use POSIX ":sys_wait_h"; ...@@ -11,6 +11,7 @@ use POSIX ":sys_wait_h";
use Socket; use Socket;
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::APIDaemon; use PVE::APIDaemon;
use PVE::API2;
my $pidfile = "/var/run/pvedaemon.pid"; my $pidfile = "/var/run/pvedaemon.pid";
my $lockfile = "/var/lock/pvedaemon.lck"; my $lockfile = "/var/lock/pvedaemon.lck";
...@@ -40,6 +41,7 @@ my $cpid; ...@@ -40,6 +41,7 @@ my $cpid;
my $daemon; my $daemon;
eval { eval {
$daemon = PVE::APIDaemon->new( $daemon = PVE::APIDaemon->new(
base_handler_class => 'PVE::API2',
host => "127.0.0.1", host => "127.0.0.1",
port => 85, port => 85,
trusted_env => 1, # partly trusted, because only local programs can connect trusted_env => 1, # partly trusted, because only local programs can connect
......
...@@ -19,6 +19,7 @@ use URI; ...@@ -19,6 +19,7 @@ use URI;
use URI::QueryParam; use URI::QueryParam;
use File::Find; use File::Find;
use Data::Dumper; use Data::Dumper;
use PVE::API2;
my $pidfile = "/var/run/pveproxy/pveproxy.pid"; my $pidfile = "/var/run/pveproxy/pveproxy.pid";
my $lockfile = "/var/lock/pveproxy.lck"; my $lockfile = "/var/lock/pveproxy.lck";
...@@ -81,6 +82,7 @@ eval { ...@@ -81,6 +82,7 @@ eval {
add_dirs($dirs, '/vncterm/' => '/usr/share/vncterm/'); add_dirs($dirs, '/vncterm/' => '/usr/share/vncterm/');
$daemon = PVE::APIDaemon->new( $daemon = PVE::APIDaemon->new(
base_handler_class => 'PVE::API2',
port => 8006, port => 8006,
keep_alive => 100, keep_alive => 100,
max_conn => 500, max_conn => 500,
......
...@@ -13,6 +13,7 @@ use English; ...@@ -13,6 +13,7 @@ use English;
use Getopt::Long; use Getopt::Long;
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::APIDaemon; use PVE::APIDaemon;
use PVE::API2;
my $pidfile = "/var/run/pveproxy/spiceproxy.pid"; my $pidfile = "/var/run/pveproxy/spiceproxy.pid";
my $lockfile = "/var/lock/spiceproxy.lck"; my $lockfile = "/var/lock/spiceproxy.lck";
...@@ -51,6 +52,7 @@ my $cpid; ...@@ -51,6 +52,7 @@ my $cpid;
my $daemon; my $daemon;
eval { eval {
$daemon = PVE::APIDaemon->new( $daemon = PVE::APIDaemon->new(
base_handler_class => 'PVE::API2',
port => 3128, port => 3128,
keep_alive => 0, keep_alive => 0,
max_workers => 1, # do we need more? max_workers => 1, # do we need more?
......
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