NAME

Net::Async::WebService::lxd - REST client (asynchronous) for lxd Linux containers

SYNOPSIS

use IO::Async::Loop;
my $loop = IO::Async::Loop->new;

use Net::Async::WebService::lxd;
my $lxd = Net::Async::WebService::lxd->new( loop            => $loop,
                                            endpoint        => 'https://192.168.0.50:8443',
                                            SSL_cert_file   => "t/client.crt",
                                            SSL_key_file    => "t/client.key",
                                            SSL_fingerprint => 'sha1$92:DD:63:F8:99:C4:5F:82:59:52:82:A9:09:C8:57:F0:67:56:B0:1B',
                                            );
$lxd->create_instance(
         body => {
             architecture => 'x86_64',
             profiles     => [ 'default'  ],
             name         => 'test1',
             source       => { type        => 'image',
                               fingerprint => '6dc6aa7c8c00' },  # image already exists in image store
             config       => {},
         } )->get;                                               # wait for it
# container is still stopped
$lxd->instance_state( name => 'test1',
         body => {
             action   => "start",
             force    => JSON::false,
             stateful => JSON::false,
             timeout  => 30,
         } )->get;                                               # wait for it

INTERFACE

Constructor

The constructor returns a handle to one LXD server. It's address is specified via an endpoint parameter, be it of an HTTPS or of a UNIX socket kind.

If you are working with a non-default LXD project in mind, then you should also provide that project's name with the project parameter. Background operation polling will make use of that. Note, that when invoking any of the methods here, you will still have to specify that project, unless it is the default one, of course.

As we are operating under an IO::Async regime here, the handle also needs a loop parameter to the central event loop. The handle will also regularily poll autonomously the server which operations are still running or have completed. The optional parameter polling_time controls how often that will occur; it will default to 1 sec, if not provided.

As LXD can be accessed remotely only via HTTPS, TLS (SSL) parameters must be provided. These will be forwarded directly to IO::Socket::SSL. But, specifically, one should consider to provide:

Methods

All methods below are automatically generated from the LXD REST API Spec. They should work with API version 1.0.

Let's dissect method invocations with this example:

my $f = $lxd->instance_state( name => 'test1' );
my $r = $f->get;

Certificates

Cluster

Cluster Groups

Images

Instances

Metrics

Network ACLs

Network Forwards

Network Peers

Network Zones

Networks

Operations

Profiles

Projects

Server

Storage

Warnings

PSEUDO OBJECT ORIENTATION

Just for the sake of experimentation, I added a sub-package lxd::instance. To add OO-flavour, you simply bless the instance HASH with it:

my $r = $lxd->instance( name => "my-container" )->get;
my $i = bless $r, 'lxd::instance';

From then on, the following methods can operate on it:

Well, I'm not a big fan of objects.

EXAMPLES

I encourage you to look at the 02_instances.t test suite. It will show a complete life cycle for containers.

SEE ALSO

HINTS

ISSUES

Open issues are probably best put onto Github

AUTHOR

Robert Barta, <rho at devc.at>

CREDITS

IO::Async, Net::Async::HTTP, IO::Socket::SSL and friends are amazing.

LICENSE AND COPYRIGHT

Copyright 2022 Robert Barta.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.