]> git.proxmox.com Git - pve-client.git/blob - pveclient
d8d4d15da682bc772558e0099d75761dd46b6d12
[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 use PVE::APIClient::Commands::lxc;
16
17 use JSON;
18
19 sub print_usage {
20
21 my $text = "pveclient usage:\n\n";
22
23 $text .= "pveclient remote <help|add|remove> {options}\n\n";
24
25 $text .= "pveclient lxc <help|create|destroy|...> {options}\n\n";
26
27 $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
28
29 print STDERR $text;
30
31 }
32
33 sub call_method {
34 my ($path, $method, $args) = @_;
35
36 die "missing API path\n" if !defined($path);
37
38 my $info = PVE::APIClient::Helpers::lookup_api_method($path, $method);
39 my $param = PVE::JSONSchema::get_options($info->{parameters}, $args);
40 print Dumper($param);
41
42 die "implement me";
43 }
44
45 # NOTE: This binary is just a placeholer - nothing implemented so far!
46
47 #my $hostname = 'localhost';
48 #my $username = 'root@pam';
49 #
50 #my $conn = PVE::APIClient::LWP->new(
51 # username => $username,
52 # #password => 'yourpassword',
53 # #ticket => $ticket,
54 # #csrftoken => $csrftoken,
55 # host => $hostname,
56 # # allow manual fingerprint verification
57 # manual_verification => 1,
58 # );
59
60 #my $res = $conn->get("/", {});
61 #print to_json($res, { pretty => 1, canonical => 1});
62
63 my $cmd = shift || (print_usage() && exit(-1));
64
65 if ($cmd eq 'get') {
66 my $method = 'GET';
67 my $path;
68 if (scalar(@ARGV) && $ARGV[0] !~ m/^\-/) {
69 $path = shift @ARGV;
70 }
71 my $res = call_method($path, $method, \@ARGV);
72 die "implement me";
73 } elsif ($cmd eq 'set') {
74 die "implement me";
75 } elsif ($cmd eq 'create') {
76 die "implement me";
77 } elsif ($cmd eq 'delete') {
78 die "implement me";
79 } elsif ($cmd eq 'lxc') {
80 PVE::APIClient::Commands::lxc->run_cli_handler();
81 } elsif ($cmd eq 'remote') {
82 PVE::APIClient::Commands::remote->run_cli_handler();
83 } elsif ($cmd eq 'bashcomplete') {
84
85 my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
86 $cmdline =~ s/$cur$//;
87
88 my ($bash_command, $cur, $prev) = @ARGV;
89
90 my $args = [split(/\s+/, $cmdline)];
91
92 if (scalar(@$args) == 1) {
93 foreach my $p (qw(get set create delete lxc remote)) {
94 print "$p\n" if $p =~ m/^$cur/;
95 }
96 }
97
98 } else {
99 print_usage();
100 }
101
102 exit(0);