]> git.proxmox.com Git - pve-apiclient.git/commitdiff
add simple example code, bump version to 1.0-2
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 28 Dec 2016 09:47:23 +0000 (10:47 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 28 Dec 2016 09:47:23 +0000 (10:47 +0100)
Makefile
debian/changelog
debian/install
examples/example1.pl [new file with mode: 0755]

index 44f47ae4a75358990d5aa9cb30520b23d6caeda6..287dc46c5de3024d26d97cb0871626b0b30134a9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,13 @@
 PACKAGE=libpve-apiclient-perl
 PKGVER=1.0
-PKGREL=1
+PKGREL=2
 
 DEB=${PACKAGE}_${PKGVER}-${PKGREL}_all.deb
 
 DESTDIR=
 
-PERL5DIR=/usr/share/perl5
+PERL5DIR=${DESTDIR}/usr/share/perl5
+DOCDIR=${DESTDIR}/usr/share/doc/${PACKAGE}
 
 all: ${DEB}
 
@@ -19,7 +20,9 @@ deb ${DEB}:
        lintian ${DEB}
 
 install:
-       install -D -m 0644 PVE/APIClient/LWP.pm ${DESTDIR}${PERL5DIR}/PVE/APIClient/LWP.pm
+       install -D -m 0644 PVE/APIClient/LWP.pm ${PERL5DIR}/PVE/APIClient/LWP.pm
+       install -d -m 755 ${DOCDIR}/examples
+       install -m 0755 examples/example1.pl ${DOCDIR}/examples
 
 .PHONY: upload
 upload: ${DEB}
index 1067bea314c46e37d3735bb1e1577f9192399085..7ad1dee9e40245495165103c0ce8e62f7cd1bf34 100644 (file)
@@ -1,3 +1,9 @@
+libpve-apiclient-perl (1.0-2) unstable; urgency=medium
+
+  * add simple example code: example1.pl
+
+ -- Proxmox Support Team <support@proxmox.com>  Wed, 28 Dec 2016 10:46:52 +0100
+
 libpve-apiclient-perl (1.0-1) unstable; urgency=medium
 
   * first try
index 02830abdd6dae1f66d62c85f6cbb8cb7824fe874..aab4f0a3c2d400dc4dd06a037879f684a5eb7108 100644 (file)
@@ -1 +1,2 @@
 /usr/share/perl5
+/usr/share/doc/libpve-apiclient-perl
\ No newline at end of file
diff --git a/examples/example1.pl b/examples/example1.pl
new file mode 100755 (executable)
index 0000000..b0fedee
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+# NOTE: you need to run this on a PVE host, or modify the source to
+# provide username/password/hostname from somewhere else.
+
+use strict;
+use PVE::APIClient::LWP;
+
+use PVE::AccessControl;
+use PVE::INotify;
+use JSON;
+
+# normally you use username/password,
+# but we can simply create a ticket and CRSF token if we are root
+# running on a pve host
+
+my $hostname = PVE::INotify::read_file("hostname");
+
+my $ticket = PVE::AccessControl::assemble_ticket('root@pam');
+my $csrftoken = PVE::AccessControl::assemble_csrf_prevention_token('root@pam');
+
+my $conn = PVE::APIClient::LWP->new(
+    #username => 'root@pam',
+    #password => 'yourpassword',
+    ticket => $ticket,
+    csrftoken => $csrftoken,
+    host => $hostname,
+    # allow manual fingerprint verification
+    manual_verification => 1,
+    );
+
+my $res = $conn->get("api2/json/", {});
+
+print to_json($res, { pretty => 1, canonical => 1});