lester

A low-level API client for LXD

Lester

Lester is a low-level API client for LXD. It features an intuitive interface that maps directly to the LXD API.

Usage Examples

  1. Create client:

    lxd = Lester.new(socket: "/var/snap/lxd/common/lxd/unix.socket")
    
    # OR:
    #
    # lxd = Lester.new(
    #   base_uri: "https://1.2.3.4:8443",
    #   private_key: "priv.key",
    #   certificate: "cert.pem",
    #   # ca_certificates: "ca.pem",
    #   # verify_mode: "none"
    # )
    
  2. Add new trusted certificate:

    lxd.certificates.add(
      certificate: "X509 PEM certificate...",
      name: "castiana",
      password: "secret",
      # ...
    ) do |response|
      return puts response.message unless response.success?
    
      puts response.type
      puts response.code
    end
    
  3. List all images:

    lxd.images.list(project: "default") do |response|
      return puts response.message unless response.success?
    
      response.metadata.try &.each do |image|
        puts image.architecture
        puts image.auto_update?
        puts image.cached?
        # ...
      end
    end
    
  4. Download instance backup:

    lxd.instances.backups.export(
      instance_name: "instance-04",
      name: "backup0",
      destination: "/home/user/Downloads/backup.zip"
    ) do |response|
      puts response.message
    end
    
  5. Add new storage pool:

    lxd.pools.create(
      project: "default",
      target: "lxd0",
      config: {"volume.block.filesystem": "ext4", "volume.size": "50GiB"},
      description: "Local SSD pool",
      driver: "zfs",
      name: "local",
      # ...
    ) do |response|
      return puts response.message unless response.success?
    
      puts response.type
      puts response.code
    end
    

Documentation

Find the complete documentation in the docs/ directory of this repository.

Development

  1. Create a .env.sh file:

    #!/bin/bash
    #
    
    export LXD_SOCKET='/var/snap/lxd/common/lxd/unix.socket'
    
    # Set these if you need to test against a remote LXD server
    export LXD_BASE_URI='https://1.2.3.4:8443'
    export LXD_TLS_KEY_PATH='priv.key'
    export LXD_TLS_CERT_PATH='cert.pem'
    export LXD_TLS_CA_PATH=''
    export LXD_TLS_VERIFY_MODE='none'
    

    Update the file with your own details.

  2. Run tests with source .env.sh && crystal spec.

Contributing

  1. Fork it
  2. Switch to the master branch: git checkout master
  3. Create your feature branch: git checkout -b my-new-feature
  4. Make your changes, updating changelog and documentation as appropriate.
  5. Commit your changes: git commit
  6. Push to the branch: git push origin my-new-feature
  7. Submit a new Pull Request against the GrottoPress:master branch.
Repository

lester

Owner
Statistic
  • 3
  • 0
  • 0
  • 0
  • 2
  • 4 months ago
  • October 15, 2021
License

MIT License

Links
Synced at

Sat, 21 Dec 2024 09:50:56 GMT

Languages