https://github.com/j8r/crystalxd
Crystal client for the LXD REST API
https://github.com/j8r/crystalxd
api container crystal linux lxd rest
Last synced: 9 months ago
JSON representation
Crystal client for the LXD REST API
- Host: GitHub
- URL: https://github.com/j8r/crystalxd
- Owner: j8r
- License: isc
- Created: 2019-11-29T17:33:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T10:04:37.000Z (about 6 years ago)
- Last Synced: 2025-06-20T14:44:14.707Z (9 months ago)
- Topics: api, container, crystal, linux, lxd, rest
- Language: Crystal
- Homepage: https://j8r.github.io/crystalxd
- Size: 94.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CrystaLXD
Crystal client for the [LXD](https://linuxcontainers.org/lxd/) REST API.
[](https://cloud.drone.io/j8r/crystalxd)
[](https://en.wikipedia.org/wiki/ISC_license)
## Prerequisites
### Setup
[Install the LXD package](https://linuxcontainers.org/lxd/getting-started-cli/)
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](https://lxd.readthedocs.io/en/latest/storage/#storage-backends-and-supported-functions), depending of the needs.
### Certificates
The LXD daemon run as root, that's why its API uses [TLS certificates](https://lxd.readthedocs.io/en/latest/security/) 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 `
## Documentation
CrystaLXD documentation: https://j8r.github.io/con
This library is based on the [official LXD REST API document](https://github.com/lxc/lxd/blob/master/doc/rest-api.md).
## Installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
crystalxd:
github: j8r/crystalxd
```
## Documentation
https://j8r.github.io/crystalxd
## Usage
```cr
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