]> git.proxmox.com Git - pve-client.git/blob - pveclient
165505fe45f33b485c5029d955234890827ec93e
[pve-client.git] / pveclient
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use lib '/usr/share/pve-client';
6 use lib '.';
7 use Data::Dumper;
8
9 use PVE::JSONSchema;
10 use PVE::CLIHandler;
11
12 use PVE::APIClient::LWP;
13 use PVE::APIClient::Helpers;
14 use PVE::APIClient::Commands::remote;
15
16 use JSON;
17
18 sub print_usage {
19
20 my $text = "pveclient usage:\n\n";
21
22 $text .= "pveclient remote <help|add|remove> {options}\n\n";
23
24 $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
25
26 print STDERR $text;
27
28 }
29
30 sub call_method {
31 my ($path, $method, $args) = @_;
32
33 die "missing API path\n" if !defined($path);
34
35 my $info = PVE::APIClient::Helpers::lookup_api_method($path, $method);
36 my $param = PVE::JSONSchema::get_options($info->{parameters}, $args);
37 print Dumper($param);
38
39 die "implement me";
40 }
41
42 # NOTE: This binary is just a placeholer - nothing implemented so far!
43
44 #my $hostname = 'localhost';
45 #my $username = 'root@pam';
46 #
47 #my $conn = PVE::APIClient::LWP->new(
48 # username => $username,
49 # #password => 'yourpassword',
50 # #ticket => $ticket,
51 # #csrftoken => $csrftoken,
52 # host => $hostname,
53 # # allow manual fingerprint verification
54 # manual_verification => 1,
55 # );
56
57 #my $res = $conn->get("/", {});
58 #print to_json($res, { pretty => 1, canonical => 1});
59
60 my $cmd = shift || (print_usage() && exit(-1));
61
62 if ($cmd eq 'get') {
63 my $method = 'GET';
64 my $path;
65 if (scalar(@ARGV) && $ARGV[0] !~ m/^\-/) {
66 $path = shift @ARGV;
67 }
68 my $res = call_method($path, $method, \@ARGV);
69 die "implement me";
70 } elsif ($cmd eq 'set') {
71 die "implement me";
72 } elsif ($cmd eq 'create') {
73 die "implement me";
74 } elsif ($cmd eq 'delete') {
75 die "implement me";
76 } elsif ($cmd eq 'remote') {
77 PVE::APIClient::Commands::remote->run_cli_handler();
78 } else {
79 print_usage();
80 }
81
82 exit(0);