]> git.proxmox.com Git - pve-apiclient.git/blob - examples/example1.pl
b0fedeedb4cdd405f24b583c484fe365e8f8c7c1
[pve-apiclient.git] / examples / example1.pl
1 #!/usr/bin/perl -w
2
3 # NOTE: you need to run this on a PVE host, or modify the source to
4 # provide username/password/hostname from somewhere else.
5
6 use strict;
7 use PVE::APIClient::LWP;
8
9 use PVE::AccessControl;
10 use PVE::INotify;
11 use JSON;
12
13 # normally you use username/password,
14 # but we can simply create a ticket and CRSF token if we are root
15 # running on a pve host
16
17 my $hostname = PVE::INotify::read_file("hostname");
18
19 my $ticket = PVE::AccessControl::assemble_ticket('root@pam');
20 my $csrftoken = PVE::AccessControl::assemble_csrf_prevention_token('root@pam');
21
22 my $conn = PVE::APIClient::LWP->new(
23 #username => 'root@pam',
24 #password => 'yourpassword',
25 ticket => $ticket,
26 csrftoken => $csrftoken,
27 host => $hostname,
28 # allow manual fingerprint verification
29 manual_verification => 1,
30 );
31
32 my $res = $conn->get("api2/json/", {});
33
34 print to_json($res, { pretty => 1, canonical => 1});