]> git.proxmox.com Git - pmg-api.git/commitdiff
add stub for proxdb binary
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 1 Feb 2017 10:39:57 +0000 (11:39 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 1 Feb 2017 10:39:57 +0000 (11:39 +0100)
Makefile
PMG/CLI/proxdb.pm [new file with mode: 0644]
bin/proxdb [new file with mode: 0644]

index 4de60c9dca9edc4134269b0ad2ef1b74638d7d66..271e982f6fd2bd8423df11b3e3b848d92ed37a9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,10 @@ BASHCOMPLDIR=${DESTDIR}/usr/share/bash-completion/completions/
 REPOID=`./repoid.pl .git`
 
 SERVICES = pmgdaemon pmgproxy
+CLITOOLS = proxdb
+
+CLI_CLASSES = $(addprefix, 'PMG/API2/', $(addsuffix '.pm', ${CLITOOLS}))
+CLI_BINARIES = $(addprefix, 'bin/', ${CLITOOLS})
 
 LIBSOURCES =                           \
        PMG/pmgcfg.pm                   \
@@ -21,17 +25,19 @@ LIBSOURCES =                                \
        PMG/HTTPServer.pm               \
        PMG/Ticket.pm                   \
        PMG/AccessControl.pm            \
-       PMG/API2/Network.pm             \
+       PMG/CLI/proxdb.pm               \
+       ${CLI_CLASSES}                  \
+       PMG/API2/Network.pm             \
        PMG/API2/Services.pm            \
        PMG/API2/Tasks.pm               \
        PMG/API2/Nodes.pm               \
        PMG/API2/AccessControl.pm       \
        PMG/API2.pm
 
-all: ${LIBSOURCES}
+all: ${LIBSOURCES} ${CLI_BINARIES}
 
 .PHONY: deb
-deb ${DEB}: ${LIBSOURCES}
+deb ${DEB}: ${LIBSOURCES} ${CLI_BINARIES}
        rm -rf build
        rsync -a * build
        cd build; dpkg-buildpackage -b -us -uc
@@ -42,12 +48,17 @@ PMG/pmgcfg.pm: PMG/pmgcfg.pm.in
        sed -e s/@VERSION@/${PKGVER}/ -e s/@PACKAGERELEASE@/${PKGREL}/ -e s/@PACKAGE@/${PACKAGE}/ -e s/@REPOID@/${REPOID}/ $< >$@.tmp
        mv $@.tmp $@
 
+%.bash-completion:
+       perl -I. -T -e "use PMG::CLI::$*; PMG::CLI::$*->generate_bash_completions();" >$@.tmp
+       mv $@.tmp $@
+
 %.service-bash-completion:
-       perl -I.. -T -e "use PMG::Service::$*; PMG::Service::$*->generate_bash_completions();" >$@.tmp
+       perl -I. -T -e "use PMG::Service::$*; PMG::Service::$*->generate_bash_completions();" >$@.tmp
        mv $@.tmp $@
 
-install: ${BTDATA} $(addsuffix .pm, $(addprefix PMG/Service/, ${SERVICES})) $(addsuffix .service-bash-completion, ${SERVICES}) ${LIBSOURCES}
+install: ${BTDATA} $(addsuffix .pm, $(addprefix PMG/Service/, ${SERVICES})) $(addsuffix .service-bash-completion, ${SERVICES}) ${LIBSOURCES} ${CLI_BINARIES} $(addsuffix .bash-completion, ${CLITOOLS})
        for i in ${SERVICES}; do perl -I. -T -e "use PMG::Service::$$i; PMG::Service::$$i->verify_api();"; done
+       for i in ${CLITOOLS}; do perl -I. -T -e "use PMG::CLI::$$i; PMG::CLI::$$i->verify_api();"; done
        install -d -m 0755 ${DESTDIR}/usr/bin
        install -d -m 0700 -o www-data -g www-data ${DESTDIR}/var/log/pmgproxy
        install -d -m 0755 ${DOCDIR}
@@ -57,7 +68,9 @@ install: ${BTDATA} $(addsuffix .pm, $(addprefix PMG/Service/, ${SERVICES})) $(ad
        for i in ${SERVICES}; do install -D -m 0644 PMG/Service/$$i.pm ${PERL5DIR}/PMG/Service/$$i.pm; done
        for i in ${SERVICES}; do install -m 0755 bin/$$i ${DESTDIR}/usr/bin; done
        for i in ${SERVICES}; do install -m 0644 -D $$i.service-bash-completion ${BASHCOMPLDIR}/$$i; done
-
+       for i in ${CLITOOLS}; do install -D -m 0644 PMG/CLI/$$i.pm ${PERL5DIR}/PMG/CLI/$$i.pm; done
+       for i in ${CLITOOLS}; do install -D -m 0755 bin/$$i ${DESTDIR}/usr/bin/$$i; done
+       for i in ${CLITOOLS}; do install -D -m 0644 $$i.bash-completion ${BASHCOMPLDIR}/$$i; done
 
 .PHONY: upload
 upload: ${DEB}
@@ -67,7 +80,7 @@ upload: ${DEB}
 distclean: clean
 
 clean:
-       rm -rf ./build *.deb *.changes *.buildinfo
+       rm -rf ./build *.deb *.changes *.buildinfo *.bash-completion *.service-bash-completion
        if test -d .git; then  rm -f PMG/pmgcfg.pm; fi
        find . -name '*~' -exec rm {} ';'
 
diff --git a/PMG/CLI/proxdb.pm b/PMG/CLI/proxdb.pm
new file mode 100644 (file)
index 0000000..476f012
--- /dev/null
@@ -0,0 +1,107 @@
+package PMG::CLI::proxdb;
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
+use PVE::INotify;
+
+use base qw(PVE::CLIHandler);
+
+my $nodename = PVE::INotify::nodename();
+
+my $upid_exit = sub {
+    my $upid = shift;
+    my $status = PVE::Tools::upid_read_status($upid);
+    exit($status eq 'OK' ? 0 : -1);
+};
+
+__PACKAGE__->register_method ({
+    name => 'dump',
+    path => 'dump',
+    method => 'GET',
+    description => "Print the PMG rule database.",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       print "DUMP\n";
+
+       return undef;
+    }});
+
+
+__PACKAGE__->register_method ({
+    name => 'delete',
+    path => 'delete',
+    method => 'DELETE',
+    description => "Delete PMG rule database.",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       syslog('info', "delete rule database");
+
+       print "DELETE\n";
+
+       return undef;
+    }});
+
+
+__PACKAGE__->register_method ({
+    name => 'update',
+    path => 'update',
+    method => 'POST',
+    description => "Update or initialize PMG rule database.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           init => {
+               type => 'boolean',
+               description => "Initialize the database.",
+               optional => 1,
+               default => 0,
+           },
+           fail => {
+               type => 'boolean',
+               description => "Fail if databse already exists. We normally try to update and reinitialize the existing database.",
+               requires => 'init',
+               optional => 1,
+               default => 0,
+           },
+           statistics => {
+               type => 'boolean',
+               description => "Update/initialize statistic database (this is done by default).",
+               optional => 1,
+               default => 1,
+           },
+       }
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       syslog('info', "init rule database");
+       
+       print "INIT\n";
+       print Dumper($param);
+
+       return undef;
+    }});
+
+
+our $cmddef = {
+    'dump' => [ __PACKAGE__, 'dump', []],
+    delete => [ __PACKAGE__, 'delete', []],
+    update => [ __PACKAGE__, 'update', []],
+};
+
+1;
diff --git a/bin/proxdb b/bin/proxdb
new file mode 100644 (file)
index 0000000..2d9462f
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -T
+
+use strict;
+use warnings;
+
+use PMG::CLI::proxdb;
+
+PMG::CLI::proxdb->run_cli_handler();