From: René Jochum <r.joc...@proxmox.com>

Signed-off-by: Dietmar Maurer <diet...@proxmox.com>
---
Changes in v2:
- use make instead of separate shell file
- do not copy Exception.pm
- install to correct path
- remove "use lib ..." 

 Makefile                              |  42 ++++++----
 PVE/{ => APIClient}/CLIHandler.pm     |  27 +++----
 PVE/APIClient/Commands/GuestStatus.pm |   8 +-
 PVE/APIClient/Commands/config.pm      |   4 +-
 PVE/APIClient/Commands/lxc.pm         |   1 -
 PVE/APIClient/Commands/remote.pm      |   4 +-
 PVE/APIClient/Config.pm               |   2 +-
 PVE/APIClient/Helpers.pm              |   2 +-
 PVE/{ => APIClient}/JSONSchema.pm     |  10 +--
 PVE/{ => APIClient}/PTY.pm            |   2 +-
 PVE/{ => APIClient}/RESTHandler.pm    |  49 ++++++------
 PVE/{ => APIClient}/SafeSyslog.pm     |   2 +-
 PVE/{ => APIClient}/SectionConfig.pm  |  10 +--
 PVE/{ => APIClient}/Tools.pm          |   2 +-
 PVE/Exception.pm                      | 142 ----------------------------------
 pveclient                             |   2 -
 16 files changed, 89 insertions(+), 220 deletions(-)
 rename PVE/{ => APIClient}/CLIHandler.pm (94%)
 rename PVE/{ => APIClient}/JSONSchema.pm (99%)
 rename PVE/{ => APIClient}/PTY.pm (99%)
 rename PVE/{ => APIClient}/RESTHandler.pm (93%)
 rename PVE/{ => APIClient}/SafeSyslog.pm (95%)
 rename PVE/{ => APIClient}/SectionConfig.pm (97%)
 rename PVE/{ => APIClient}/Tools.pm (99%)
 delete mode 100644 PVE/Exception.pm

diff --git a/Makefile b/Makefile
index b37b3fe..4c9572a 100644
--- a/Makefile
+++ b/Makefile
@@ -6,10 +6,19 @@ DEB=${PACKAGE}_${PKGVER}-${PKGREL}_all.deb
 
 DESTDIR=
 
+PERL5_DIR=${DESTDIR}/usr/share/perl5
 LIB_DIR=${DESTDIR}/usr/share/${PACKAGE}
 DOCDIR=${DESTDIR}/usr/share/doc/${PACKAGE}
 BASHCOMPLDIR=${DESTDIR}/usr/share/bash-completion/completions/
 
+PVE_COMMON_FILES=              \
+       CLIHandler.pm           \
+       JSONSchema.pm           \
+       PTY.pm                  \
+       RESTHandler.pm          \
+       SafeSyslog.pm           \
+       SectionConfig.pm        \
+
 all: ${DEB}
 
 .PHONY: deb
@@ -21,29 +30,30 @@ deb ${DEB}:
        lintian ${DEB}
 
 install:  pve-api-definition.dat
-       install -d -m 0755 ${LIB_DIR}/PVE
+       install -d -m 0755 ${PERL5_DIR}/PVE/APIClient
        # install library tools from pve-common
-       install -m 0644 PVE/Tools.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/SafeSyslog.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/Exception.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/JSONSchema.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/RESTHandler.pm  ${LIB_DIR}/PVE
-       install -m 0644 PVE/CLIHandler.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/PTY.pm ${LIB_DIR}/PVE
-       install -m 0644 PVE/SectionConfig.pm ${LIB_DIR}/PVE
+       for i in ${PVE_COMMON_FILES}; do install -m 0644 PVE/APIClient/$$i 
${PERL5_DIR}/PVE/APIClient; done
        # install pveclient
-       install -D -m 0644 PVE/APIClient/Helpers.pm 
${LIB_DIR}/PVE/APIClient/Helpers.pm
-       install -D -m 0644 PVE/APIClient/Config.pm 
${LIB_DIR}/PVE/APIClient/Config.pm
-       install -D -m 0644 PVE/APIClient/Commands/remote.pm 
${LIB_DIR}/PVE/APIClient/Commands/remote.pm
-       install -D -m 0644 PVE/APIClient/Commands/lxc.pm 
${LIB_DIR}/PVE/APIClient/Commands/lxc.pm
-       install -D -m 0644 PVE/APIClient/Commands/config.pm 
${LIB_DIR}/PVE/APIClient/Commands/config.pm
-       install -D -m 0644 PVE/APIClient/Commands/list.pm 
${LIB_DIR}/PVE/APIClient/Commands/list.pm
-       install -D -m 0644 PVE/APIClient/Commands/GuestStatus.pm 
${LIB_DIR}/PVE/APIClient/Commands/GuestStatus.pm
+       install -D -m 0644 PVE/APIClient/Tools.pm 
${PERL5_DIR}/PVE/APIClient/Tools.pm
+       install -D -m 0644 PVE/APIClient/Helpers.pm 
${PERL5_DIR}/PVE/APIClient/Helpers.pm
+       install -D -m 0644 PVE/APIClient/Config.pm 
${PERL5_DIR}/PVE/APIClient/Config.pm
+       install -D -m 0644 PVE/APIClient/Commands/remote.pm 
${PERL5_DIR}/PVE/APIClient/Commands/remote.pm
+       install -D -m 0644 PVE/APIClient/Commands/lxc.pm 
${PERL5_DIR}/PVE/APIClient/Commands/lxc.pm
+       install -D -m 0644 PVE/APIClient/Commands/config.pm 
${PERL5_DIR}/PVE/APIClient/Commands/config.pm
+       install -D -m 0644 PVE/APIClient/Commands/list.pm 
${PERL5_DIR}/PVE/APIClient/Commands/list.pm
+       install -D -m 0644 PVE/APIClient/Commands/GuestStatus.pm 
${PERL5_DIR}/PVE/APIClient/Commands/GuestStatus.pm
        install -D -m 0644 pve-api-definition.dat 
${LIB_DIR}/pve-api-definition.dat
        install -D -m 0755 pveclient ${DESTDIR}/usr/bin/pveclient
        install -D -m 0644 pveclient.bash-completion ${BASHCOMPLDIR}/pveclient
 
 
+update-pve-common:
+       for i in ${PVE_COMMON_FILES}; do cp ../pve-common/src/PVE/$$i 
PVE/APIClient/; done
+       for i in ${PVE_COMMON_FILES}; do sed -i 's/PVE::/PVE::APIClient::/g' 
PVE/APIClient/$$i; done
+       # Remove INotify from CLIHandler.pm
+       sed -i 's/use PVE::APIClient::INotify;//' PVE/APIClient/CLIHandler.pm
+
+
 pve-api-definition.dat:
        ./extractapi.pl > pve-api-definition.dat.tmp
        mv pve-api-definition.dat.tmp pve-api-definition.dat
diff --git a/PVE/CLIHandler.pm b/PVE/APIClient/CLIHandler.pm
similarity index 94%
rename from PVE/CLIHandler.pm
rename to PVE/APIClient/CLIHandler.pm
index 514906a..a1cd528 100644
--- a/PVE/CLIHandler.pm
+++ b/PVE/APIClient/CLIHandler.pm
@@ -1,13 +1,14 @@
-package PVE::CLIHandler;
+package PVE::APIClient::CLIHandler;
 
 use strict;
 use warnings;
 
-use PVE::SafeSyslog;
-use PVE::Exception qw(raise raise_param_exc);
-use PVE::RESTHandler;
+use PVE::APIClient::SafeSyslog;
+use PVE::APIClient::Exception qw(raise raise_param_exc);
+use PVE::APIClient::RESTHandler;
 
-use base qw(PVE::RESTHandler);
+
+use base qw(PVE::APIClient::RESTHandler);
 
 # $cmddef defines which (sub)commands are available in a specific CLI class.
 # A real command is always an array consisting of its class, name, array of
@@ -22,13 +23,13 @@ use base qw(PVE::RESTHandler);
 #
 # Examples:
 # $cmddef = {
-#     command => [ 'PVE::API2::Class', 'command', [ 'arg1', 'arg2' ], { node 
=> $nodename } ],
+#     command => [ 'PVE::APIClient::API2::Class', 'command', [ 'arg1', 'arg2' 
], { node => $nodename } ],
 #     do => {
-#         this => [ 'PVE::API2::OtherClass', 'method', [ 'arg1' ], undef, sub {
+#         this => [ 'PVE::APIClient::API2::OtherClass', 'method', [ 'arg1' ], 
undef, sub {
 #             my ($res) = @_;
 #             print "$res\n";
 #         }],
-#         that => [ 'PVE::API2::OtherClass', 'subroutine' [] ],
+#         that => [ 'PVE::APIClient::API2::OtherClass', 'subroutine' [] ],
 #     },
 #     dothat => { alias => 'do that' },
 # }
@@ -189,7 +190,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           'extra-args' => PVE::JSONSchema::get_standard_option('extra-args', {
+           'extra-args' => 
PVE::APIClient::JSONSchema::get_standard_option('extra-args', {
                description => 'Shows help for a specific command',
                completion => $complete_command_names,
            }),
@@ -309,7 +310,7 @@ my $print_bash_completion = sub {
     my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
     print STDERR "\nCMDLINE: $ENV{COMP_LINE}\n" if $debug;
 
-    my $args = PVE::Tools::split_args($cmdline);
+    my $args = PVE::APIClient::Tools::split_args($cmdline);
     shift @$args; # no need for program name
     my $print_result = sub {
        foreach my $p (@_) {
@@ -400,7 +401,7 @@ sub verify_api {
     my ($class) = @_;
 
     # simply verify all registered methods
-    PVE::RESTHandler::validate_method_schemas();
+    PVE::APIClient::RESTHandler::validate_method_schemas();
 }
 
 my $get_exe_name = sub {
@@ -476,7 +477,7 @@ my $handle_cmd  = sub {
     # call verifyapi before setup_environment(), don't execute any real code in
     # this case
     if ($cmd eq 'verifyapi') {
-       PVE::RESTHandler::validate_method_schemas();
+       PVE::APIClient::RESTHandler::validate_method_schemas();
        return;
     }
 
@@ -513,7 +514,7 @@ my $handle_simple_cmd = sub {
            print STDERR "$str\n\n";
            return;
        } elsif ($args->[0] eq 'verifyapi') {
-           PVE::RESTHandler::validate_method_schemas();
+           PVE::APIClient::RESTHandler::validate_method_schemas();
            return;
        }
     }
diff --git a/PVE/APIClient/Commands/GuestStatus.pm 
b/PVE/APIClient/Commands/GuestStatus.pm
index 50730db..4a50164 100644
--- a/PVE/APIClient/Commands/GuestStatus.pm
+++ b/PVE/APIClient/Commands/GuestStatus.pm
@@ -43,8 +43,8 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $remote = PVE::Tools::extract_param($param, 'remote');
-       my $vmid = PVE::Tools::extract_param($param, 'vmid');
+       my $remote = PVE::APIClient::Tools::extract_param($param, 'remote');
+       my $vmid = PVE::APIClient::Tools::extract_param($param, 'vmid');
 
        $guest_status_command->($remote, $vmid, 'start', $param);
 
@@ -67,8 +67,8 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $remote = PVE::Tools::extract_param($param, 'remote');
-       my $vmid = PVE::Tools::extract_param($param, 'vmid');
+       my $remote = PVE::APIClient::Tools::extract_param($param, 'remote');
+       my $vmid = PVE::APIClient::Tools::extract_param($param, 'vmid');
 
        $guest_status_command->($remote, $vmid, 'stop', $param);
 
diff --git a/PVE/APIClient/Commands/config.pm b/PVE/APIClient/Commands/config.pm
index 4015ad8..6f24e2c 100644
--- a/PVE/APIClient/Commands/config.pm
+++ b/PVE/APIClient/Commands/config.pm
@@ -5,7 +5,7 @@ use warnings;
 use Data::Dumper;
 
 use PVE::JSONSchema qw(get_standard_option);
-use PVE::Tools qw(extract_param);
+use PVE::APIClient::Tools qw(extract_param);
 use PVE::APIClient::Config;
 
 use PVE::CLIHandler;
@@ -60,7 +60,7 @@ __PACKAGE__->register_method ({
 
        if ($delete) {
            my $options = $plugin->private()->{options}->{'defaults'};
-           foreach my $k (PVE::Tools::split_list($delete)) {
+           foreach my $k (PVE::APIClient::Tools::split_list($delete)) {
                my $d = $options->{$k} ||
                    die "no such option '$k'\n";
                die "unable to delete required option '$k'\n"
diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index 4e76f70..d535188 100644
--- a/PVE/APIClient/Commands/lxc.pm
+++ b/PVE/APIClient/Commands/lxc.pm
@@ -11,7 +11,6 @@ use MIME::Base64;
 use Digest::SHA;
 use HTTP::Response;
 
-use PVE::Tools;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::CLIHandler;
 use PVE::PTY;
diff --git a/PVE/APIClient/Commands/remote.pm b/PVE/APIClient/Commands/remote.pm
index 0f465ea..0c3d17a 100644
--- a/PVE/APIClient/Commands/remote.pm
+++ b/PVE/APIClient/Commands/remote.pm
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use PVE::JSONSchema qw(get_standard_option);
-use PVE::Tools qw(extract_param);
+use PVE::APIClient::Tools qw(extract_param);
 use PVE::APIClient::Config;
 
 use PVE::CLIHandler;
@@ -127,7 +127,7 @@ __PACKAGE__->register_method ({
 
        if ($delete) {
            my $options = $plugin->private()->{options}->{'remote'};
-           foreach my $k (PVE::Tools::split_list($delete)) {
+           foreach my $k 
(PVE::APIClient::Tools::APIClient::split_list($delete)) {
                my $d = $options->{$k} ||
                    die "no such option '$k'\n";
                die "unable to delete required option '$k'\n"
diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm
index 166a629..7189d8e 100644
--- a/PVE/APIClient/Config.pm
+++ b/PVE/APIClient/Config.pm
@@ -6,7 +6,7 @@ use JSON;
 
 use PVE::JSONSchema;
 use PVE::SectionConfig;
-use PVE::Tools qw(file_get_contents file_set_contents);
+use PVE::APIClient::Tools qw(file_get_contents file_set_contents);
 
 use base qw(PVE::SectionConfig);
 
diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm
index 28fd1c4..1ea8a5e 100644
--- a/PVE/APIClient/Helpers.pm
+++ b/PVE/APIClient/Helpers.pm
@@ -175,7 +175,7 @@ sub extract_path_info {
            $test_path_properties->([$0, @ARGV]);
        } elsif ($cmd eq 'bashcomplete') {
            my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
-           my $args = PVE::Tools::split_args($cmdline);
+           my $args = PVE::APIClient::Tools::split_args($cmdline);
            $test_path_properties->($args);
        }
     }
diff --git a/PVE/JSONSchema.pm b/PVE/APIClient/JSONSchema.pm
similarity index 99%
rename from PVE/JSONSchema.pm
rename to PVE/APIClient/JSONSchema.pm
index f014dc3..0c88b63 100644
--- a/PVE/JSONSchema.pm
+++ b/PVE/APIClient/JSONSchema.pm
@@ -1,4 +1,4 @@
-package PVE::JSONSchema;
+package PVE::APIClient::JSONSchema;
 
 use strict;
 use warnings;
@@ -7,8 +7,8 @@ use Getopt::Long;
 use Encode::Locale;
 use Encode;
 use Devel::Cycle -quiet; # todo: remove?
-use PVE::Tools qw(split_list $IPV6RE $IPV4RE);
-use PVE::Exception qw(raise);
+use PVE::APIClient::Tools qw(split_list $IPV6RE $IPV4RE);
+use PVE::APIClient::Exception qw(raise);
 use HTTP::Status qw(:constants);
 use Net::IP qw(:PROC);
 use Data::Dumper;
@@ -146,7 +146,7 @@ sub pve_verify_configid {
     return $id;
 }
 
-PVE::JSONSchema::register_format('pve-storage-id', \&parse_storage_id);
+PVE::APIClient::JSONSchema::register_format('pve-storage-id', 
\&parse_storage_id);
 sub parse_storage_id {
     my ($storeid, $noerr) = @_;
 
@@ -466,7 +466,7 @@ sub pve_parse_startup_order {
     return $res;
 }
 
-PVE::JSONSchema::register_standard_option('pve-startup-order', {
+PVE::APIClient::JSONSchema::register_standard_option('pve-startup-order', {
     description => "Startup and shutdown behavior. Order is a non-negative 
number defining the general startup order. Shutdown in done with reverse 
ordering. Additionally you can set the 'up' or 'down' delay in seconds, which 
specifies a delay to wait before the next VM is started or stopped.",
     optional => 1,
     type => 'string', format => 'pve-startup-order',
diff --git a/PVE/PTY.pm b/PVE/APIClient/PTY.pm
similarity index 99%
rename from PVE/PTY.pm
rename to PVE/APIClient/PTY.pm
index 23d76c0..00010df 100644
--- a/PVE/PTY.pm
+++ b/PVE/APIClient/PTY.pm
@@ -1,4 +1,4 @@
-package PVE::PTY;
+package PVE::APIClient::PTY;
 
 use strict;
 use warnings;
diff --git a/PVE/RESTHandler.pm b/PVE/APIClient/RESTHandler.pm
similarity index 93%
rename from PVE/RESTHandler.pm
rename to PVE/APIClient/RESTHandler.pm
index 5e70503..ef30ba9 100644
--- a/PVE/RESTHandler.pm
+++ b/PVE/APIClient/RESTHandler.pm
@@ -1,12 +1,12 @@
-package PVE::RESTHandler;
+package PVE::APIClient::RESTHandler;
 
 use strict;
 no strict 'refs'; # our autoload requires this
 use warnings;
-use PVE::SafeSyslog;
-use PVE::Exception qw(raise raise_param_exc);
-use PVE::JSONSchema;
-use PVE::Tools;
+use PVE::APIClient::SafeSyslog;
+use PVE::APIClient::Exception qw(raise raise_param_exc);
+use PVE::APIClient::JSONSchema;
+use PVE::APIClient::Tools;
 use HTTP::Status qw(:constants :is status_message);
 use Text::Wrap;
 use Clone qw(clone);
@@ -45,7 +45,7 @@ sub api_clone_schema {
            # NOTE: add typetext property for more complex types, to
            # make the web api viewer code simpler
            if (!(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
-               my $typetext = PVE::JSONSchema::schema_get_type_text($tmp);
+               my $typetext = 
PVE::APIClient::JSONSchema::schema_get_type_text($tmp);
                if ($tmp->{type} && ($tmp->{type} ne $typetext)) {
                    $tmp->{typetext} = $typetext;
                }
@@ -58,7 +58,7 @@ sub api_clone_schema {
 }
 
 sub api_dump_full {
-    my ($tree, $index, $class, $prefix) = @_;
+    my ($tree, $index, $class, $prefix, $raw_dump) = @_;
 
     $prefix = '' if !$prefix;
 
@@ -70,7 +70,7 @@ sub api_dump_full {
        $path =~ s/\/+$//;
 
        if ($info->{subclass}) {
-           api_dump_full($tree, $index, $info->{subclass}, $path);
+           api_dump_full($tree, $index, $info->{subclass}, $path, $raw_dump);
        } else {
            next if !$path;
 
@@ -110,12 +110,15 @@ sub api_dump_full {
                        $k eq "path";
 
                    my $d = $info->{$k};
-                   
-                   if ($k eq 'parameters') {
-                       $data->{$k} = api_clone_schema($d);
-                   } else {
 
-                       $data->{$k} = ref($d) ? clone($d) : $d;
+                   if ($raw_dump) {
+                       $data->{$k} = $d;
+                   } else {
+                       if ($k eq 'parameters') {
+                           $data->{$k} = api_clone_schema($d);
+                       } else {
+                           $data->{$k} = ref($d) ? clone($d) : $d;
+                       }
                    }
                } 
                $res->{info}->{$info->{method}} = $data;
@@ -173,12 +176,12 @@ sub api_dump_remove_refs {
 }
 
 sub api_dump {
-    my ($class, $prefix) = @_;
+    my ($class, $prefix, $raw_dump) = @_;
 
     my $tree = [];
 
     my $index = {};
-    api_dump_full($tree, $index, $class);
+    api_dump_full($tree, $index, $class, $prefix, $raw_dump);
     api_dump_cleanup_tree($tree);
     return $tree;
 };
@@ -189,7 +192,7 @@ sub validate_method_schemas {
        my $ma = $method_registry->{$class};
 
        foreach my $info (@$ma) {
-           PVE::JSONSchema::validate_method_info($info);
+           PVE::APIClient::JSONSchema::validate_method_info($info);
        }
     }
 }
@@ -402,7 +405,7 @@ sub handle {
 
     if (my $schema = $info->{parameters}) {
        # warn "validate ". Dumper($param}) . "\n" . Dumper($schema);
-       PVE::JSONSchema::validate($param, $schema);
+       PVE::APIClient::JSONSchema::validate($param, $schema);
        # untaint data (already validated)
        my $extra = delete $param->{'extra-args'};
        while (my ($key, $val) = each %$param) {
@@ -415,7 +418,7 @@ sub handle {
 
     # todo: this is only to be safe - disable?
     if (my $schema = $info->{returns}) {
-       PVE::JSONSchema::validate($result, $schema, "Result verification 
failed\n");
+       PVE::APIClient::JSONSchema::validate($result, $schema, "Result 
verification failed\n");
     }
 
     return $result;
@@ -444,7 +447,7 @@ my $get_property_description = sub {
 
     chomp $descr;
 
-    my $type_text = PVE::JSONSchema::schema_get_type_text($phash, $style);
+    my $type_text = PVE::APIClient::JSONSchema::schema_get_type_text($phash, 
$style);
 
     if ($hidepw && $name eq 'password') {
        $type_text = '';
@@ -552,7 +555,7 @@ my $compute_param_mapping_hash = sub {
            ($name, $func, $desc, $interactive) = @$item;
        } else {
            $name = $item;
-           $func = sub { return PVE::Tools::file_get_contents($_[0]) };
+           $func = sub { return 
PVE::APIClient::Tools::file_get_contents($_[0]) };
        }
        $desc //= '<filepath>';
        $res->{$name} = { desc => $desc, func => $func, interactive => 
$interactive };
@@ -708,7 +711,7 @@ sub dump_properties {
        next if !$prop_fmt;
 
        if (ref($prop_fmt) ne 'HASH') {
-           $prop_fmt = PVE::JSONSchema::get_format($prop_fmt);
+           $prop_fmt = PVE::APIClient::JSONSchema::get_format($prop_fmt);
        }
 
        next if !(ref($prop_fmt) && (ref($prop_fmt) eq 'HASH'));
@@ -740,7 +743,7 @@ sub cli_handler {
     my $res;
     eval {
        my $param_mapping_hash = 
$compute_param_mapping_hash->($param_mapping_func->($name)) if 
$param_mapping_func;
-       my $param = PVE::JSONSchema::get_options($info->{parameters}, $args, 
$arg_param, $fixed_param, $read_password_func, $param_mapping_hash);
+       my $param = 
PVE::APIClient::JSONSchema::get_options($info->{parameters}, $args, $arg_param, 
$fixed_param, $read_password_func, $param_mapping_hash);
 
        if (defined($param_mapping_hash)) {
            &$replace_file_names_with_contents($param, $param_mapping_hash);
@@ -751,7 +754,7 @@ sub cli_handler {
     if (my $err = $@) {
        my $ec = ref($err);
 
-       die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc();
+       die $err if !$ec || $ec ne "PVE::APIClient::Exception" || 
!$err->is_param_exc();
        
        $err->{usage} = $self->usage_str($name, $prefix, $arg_param, 
$fixed_param, 'short', $read_password_func, $param_mapping_func);
 
diff --git a/PVE/SafeSyslog.pm b/PVE/APIClient/SafeSyslog.pm
similarity index 95%
rename from PVE/SafeSyslog.pm
rename to PVE/APIClient/SafeSyslog.pm
index 63b37f8..3b31c86 100644
--- a/PVE/SafeSyslog.pm
+++ b/PVE/APIClient/SafeSyslog.pm
@@ -1,4 +1,4 @@
-package PVE::SafeSyslog;
+package PVE::APIClient::SafeSyslog;
 
 use strict;
 use warnings;
diff --git a/PVE/SectionConfig.pm b/PVE/APIClient/SectionConfig.pm
similarity index 97%
rename from PVE/SectionConfig.pm
rename to PVE/APIClient/SectionConfig.pm
index cc03aea..28224e8 100644
--- a/PVE/SectionConfig.pm
+++ b/PVE/APIClient/SectionConfig.pm
@@ -1,10 +1,10 @@
-package PVE::SectionConfig;
+package PVE::APIClient::SectionConfig;
 
 use strict;
 use warnings;
 use Digest::SHA;
-use PVE::Exception qw(raise_param_exc);
-use PVE::JSONSchema qw(get_standard_option);
+use PVE::APIClient::Exception qw(raise_param_exc);
+use PVE::APIClient::JSONSchema qw(get_standard_option);
 
 use Data::Dumper;
 
@@ -251,7 +251,7 @@ sub check_value {
 
     if (!$skipSchemaCheck) {
        my $errors = {};
-       PVE::JSONSchema::check_prop($value, $schema, '', $errors);
+       PVE::APIClient::JSONSchema::check_prop($value, $schema, '', $errors);
        if (scalar(keys %$errors)) {
            die "$errors->{$key}\n" if $errors->{$key};
            die "$errors->{_root}\n" if $errors->{_root};
@@ -491,7 +491,7 @@ sub write_config {
 sub assert_if_modified {
     my ($cfg, $digest) = @_;
 
-    PVE::Tools::assert_if_modified($cfg->{digest}, $digest);
+    PVE::APIClient::Tools::assert_if_modified($cfg->{digest}, $digest);
 }
 
 1;
diff --git a/PVE/Tools.pm b/PVE/APIClient/Tools.pm
similarity index 99%
rename from PVE/Tools.pm
rename to PVE/APIClient/Tools.pm
index cd55932..754ecb5 100644
--- a/PVE/Tools.pm
+++ b/PVE/APIClient/Tools.pm
@@ -1,4 +1,4 @@
-package PVE::Tools;
+package PVE::APIClient::Tools;
 
 use strict;
 use warnings;
diff --git a/PVE/Exception.pm b/PVE/Exception.pm
deleted file mode 100644
index fa6b73a..0000000
--- a/PVE/Exception.pm
+++ /dev/null
@@ -1,142 +0,0 @@
-package PVE::Exception;
-
-# a way to add more information to exceptions (see man perlfunc (die))
-# use PVE::Exception qw(raise);
-# raise ("my error message", code => 400, errors => { param1 => "err1", ...} );
-
-use strict;
-use warnings;
-use vars qw(@ISA @EXPORT_OK);
-require Exporter;
-use Storable qw(dclone);       
-use HTTP::Status qw(:constants);
-
-@ISA = qw(Exporter);
-
-use overload '""' => sub {local $@; shift->stringify};
-use overload 'cmp' => sub {
-    my ($a, $b) = @_;
-    local $@;  
-    return "$a" cmp "$b"; # compare as string
-};
-
-@EXPORT_OK = qw(raise raise_param_exc raise_perm_exc);
-
-sub new {
-    my ($class, $msg, %param) = @_;
-
-    $class = ref($class) || $class;
-
-    my $self = {
-       msg => $msg,
-    };
-
-    foreach my $p (keys %param) {
-       next if defined($self->{$p}); 
-       my $v = $param{$p};
-       $self->{$p} = ref($v) ? dclone($v) : $v;
-    }
-
-    return bless $self;
-}
-
-sub raise {
-
-    my $exc = PVE::Exception->new(@_);
-    
-    my ($pkg, $filename, $line) = caller;
-
-    $exc->{filename} = $filename;
-    $exc->{line} = $line;
-
-    die $exc;
-}
-
-sub raise_perm_exc {
-    my ($what) = @_;
-
-    my $param = { code => HTTP_FORBIDDEN };
-
-    my $msg = "Permission check failed";
-    
-    $msg .= " ($what)" if $what;
-
-    my $exc = PVE::Exception->new("$msg\n", %$param);
-    
-    my ($pkg, $filename, $line) = caller;
-
-    $exc->{filename} = $filename;
-    $exc->{line} = $line;
-
-    die $exc;
-}
-
-sub is_param_exc {
-    my ($self) = @_;
-
-    return $self->{code} && $self->{code} eq HTTP_BAD_REQUEST;
-}
-
-sub raise_param_exc {
-    my ($errors, $usage) = @_;
-
-    my $param = {
-        code => HTTP_BAD_REQUEST,
-        errors => $errors,
-    };
-
-    $param->{usage} = $usage if $usage;
-
-    my $exc = PVE::Exception->new("Parameter verification failed.\n", %$param);
-    
-    my ($pkg, $filename, $line) = caller;
-
-    $exc->{filename} = $filename;
-    $exc->{line} = $line;
-
-    die $exc;
-}
-
-sub stringify {
-    my $self = shift;
-    
-    my $msg = $self->{code} ? "$self->{code} $self->{msg}" : $self->{msg};
-
-    if ($msg !~ m/\n$/) {
-
-       if ($self->{filename} && $self->{line}) {
-           $msg .= " at $self->{filename} line $self->{line}";
-       }
-
-       $msg .= "\n";
-    }
-
-    if ($self->{errors}) {
-       foreach my $e (keys %{$self->{errors}}) {
-           $msg .= "$e: $self->{errors}->{$e}\n";
-       }
-    }
-
-    if ($self->{propagate}) {
-       foreach my $pi (@{$self->{propagate}}) {
-           $msg .= "\t...propagated at $pi->[0] line $pi->[1]\n";
-       }
-    }
-
-    if ($self->{usage}) {
-       $msg .= $self->{usage};
-       $msg .= "\n" if $msg !~ m/\n$/;
-    }
-
-    return $msg;
-}
-
-sub PROPAGATE {
-    my ($self, $file, $line) = @_;
-
-    push @{$self->{propagate}}, [$file, $line]; 
-
-    return $self;
-}
-
-1;
diff --git a/pveclient b/pveclient
index 01cb74b..ded6736 100755
--- a/pveclient
+++ b/pveclient
@@ -5,8 +5,6 @@ package PVE::CLI::pveclient;
 use strict;
 use warnings;
 use Cwd 'abs_path';
-use lib '/usr/share/pve-client';
-use lib '.';
 use Data::Dumper;
 
 use PVE::JSONSchema qw(register_standard_option get_standard_option);
-- 
2.11.0

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to