]> git.proxmox.com Git - pve-apiclient.git/blame - examples/example1.pl
example2.pl: add a second example
[pve-apiclient.git] / examples / example1.pl
CommitLineData
bc39c284 1#!/usr/bin/perl
d12f292e
DM
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
6use strict;
bc39c284
DM
7use warnings;
8
d12f292e
DM
9use PVE::APIClient::LWP;
10
11use PVE::AccessControl;
12use PVE::INotify;
13use JSON;
14
15# normally you use username/password,
16# but we can simply create a ticket and CRSF token if we are root
17# running on a pve host
18
19my $hostname = PVE::INotify::read_file("hostname");
20
21my $ticket = PVE::AccessControl::assemble_ticket('root@pam');
22my $csrftoken = PVE::AccessControl::assemble_csrf_prevention_token('root@pam');
23
24my $conn = PVE::APIClient::LWP->new(
25 #username => 'root@pam',
26 #password => 'yourpassword',
27 ticket => $ticket,
28 csrftoken => $csrftoken,
29 host => $hostname,
30 # allow manual fingerprint verification
31 manual_verification => 1,
32 );
33
ce70bf81 34my $res = $conn->get("/", {});
d12f292e
DM
35
36print to_json($res, { pretty => 1, canonical => 1});