]> git.proxmox.com Git - pmg-api.git/blob - PMG/CLI/pmgdb.pm
rename proxdb to pmgdb
[pmg-api.git] / PMG / CLI / pmgdb.pm
1 package PMG::CLI::pmgdb;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 use PVE::SafeSyslog;
8 use PVE::Tools qw(extract_param);
9 use PVE::INotify;
10
11 use PMG::DBTools;
12
13 use base qw(PVE::CLIHandler);
14
15 my $nodename = PVE::INotify::nodename();
16
17 __PACKAGE__->register_method ({
18 name => 'dump',
19 path => 'dump',
20 method => 'GET',
21 description => "Print the PMG rule database.",
22 parameters => {
23 additionalProperties => 0,
24 },
25 returns => { type => 'null'},
26 code => sub {
27 my ($param) = @_;
28
29 print "DUMP\n";
30
31 return undef;
32 }});
33
34
35 __PACKAGE__->register_method ({
36 name => 'delete',
37 path => 'delete',
38 method => 'DELETE',
39 description => "Delete PMG rule database.",
40 parameters => {
41 additionalProperties => 0,
42 },
43 returns => { type => 'null'},
44 code => sub {
45 my ($param) = @_;
46
47 my $list = PMG::DBTools::database_list();
48
49 my $dbname = "Proxmox_ruledb";
50
51 die "Database '$dbname' does not exist\n" if !$list->{$dbname};
52
53 syslog('info', "delete rule database");
54
55 PMG::DBTools::delete_ruledb($dbname);
56
57 return undef;
58 }});
59
60
61 __PACKAGE__->register_method ({
62 name => 'update',
63 path => 'update',
64 method => 'POST',
65 description => "Update or initialize PMG rule database.",
66 parameters => {
67 additionalProperties => 0,
68 properties => {
69 force => {
70 type => 'boolean',
71 description => "Delete existing database.",
72 optional => 1,
73 default => 0,
74 },
75 statistics => {
76 type => 'boolean',
77 description => "Update/initialize statistic database (this is done by default).",
78 optional => 1,
79 default => 1,
80 },
81 }
82 },
83 returns => { type => 'null'},
84 code => sub {
85 my ($param) = @_;
86
87 my $list = PMG::DBTools::database_list();
88
89 my $dbname = "Proxmox_ruledb";
90
91 if (!$list->{$dbname} || $param->{force}) {
92
93 if ($list->{$dbname}) {
94 print "Destroy existing rule database\n";
95 PMG::DBTools::delete_ruledb($dbname);
96 }
97
98 print "Initialize rule database\n";
99
100 my $dbh = PMG::DBTools::create_ruledb ($dbname);
101 #$ruledb = Proxmox::RuleDB->new ($dbh);
102 #Proxmox::Utils::init_ruledb ($ruledb);
103
104 $dbh->disconnect();
105
106 } else {
107
108 my $dbh = PMG::DBTools::open_ruledb("Proxmox_ruledb");
109 #$ruledb = Proxmox::RuleDB->new ($dbh);
110
111 #print "Analyzing/Upgrading existing Databases...";
112 #Proxmox::Utils::upgradedb ($ruledb);
113 #print "done\n";
114
115 # reset and update statistic databases
116 if ($param->{statistics}) {
117 print "Generating Proxmox Statistic Databases... ";
118 #Proxmox::Statistic::clear_stats($dbh);
119 #Proxmox::Statistic::update_stats($dbh, $cinfo);
120 print "done\n";
121 }
122
123 $dbh->disconnect();
124 }
125
126 return undef;
127 }});
128
129
130 our $cmddef = {
131 'dump' => [ __PACKAGE__, 'dump', []],
132 delete => [ __PACKAGE__, 'delete', []],
133 update => [ __PACKAGE__, 'update', []],
134 };
135
136 1;