CrystaLXD

Crystal client for the LXD REST API.

Build Status ISC

Prerequisites

Setup

Install the LXD package

Add yourself to the lxd group, so you can run lxc without being root:

sudo usermod -aG lxd $USER

Then logout and login again.

Before running containers, LXD must be configured:

lxd init --auto --storage-backend btrfs --network-address '[::1]'

The default port is 8443 HTTPS.

Other backends are also available, depending of the needs.

Certificates

The LXD daemon run as root, that's why its API uses TLS certificates for encryption and authentication.

In this directory, create self-signed certificates:

mkdir -p certs && cd certs

openssl ecparam -name secp521r1 -genkey -noout -out lxd.key
openssl req -new -sha256 -newkey rsa:4096 -key lxd.key -out lxd.csr -subj "/CN=CrystaLXD specs"
openssl x509 -days 365 -signkey lxd.key -in lxd.csr -req -out lxd.crt

Then add the certificate to the trust store: lxc config trust add lxd.crt

If you want to remove one: lxc config trust remove <FINGERPRINT>

Documentation

CrystaLXD documentation: https://j8r.github.io/con

This library is based on the official LXD REST API document.

Installation

Add the dependency to your shard.yml:

dependencies:
  crystalxd:
    github: j8r/crystalxd

Documentation

https://j8r.github.io/crystalxd

Usage

require "crystalxd"

CLIENT = CrystaLXD::Client.new(
  tls: OpenSSL::SSL::Context::Client.from_hash({
    "key"         => "certs/lxd.key",
    "cert"        => "certs/lxd.crt",
    "verify_mode" => "none",
  })
)

Running test specs

crystal spec

Warning: The specs will try as much as possible to restore the initial LXD state, but there is no guarantees of any kind.

License

Copyright (c) 2019-2020 Julien Reichardt - ISC License