Struct lxd::Container [] [src]

pub struct Container(_);

An LXD container

Methods

impl Container
[src]

Create a new LXD container

Arguments

  • location - The location of the host
  • name - The name of the container
  • base - The base distribution to use, ubuntu:16.04 for example

Return

The newly created LXD container

Errors

Errors that are encountered while creating will be returned

Example

use lxd::{Container, Location};

let mut container = Container::new(Location::Local, "test-new", "ubuntu:16.04").unwrap();

Run a command in an LXD container

Arguments

  • command - An array of command arguments

Return

An empty tuple on success

Errors

Errors that are encountered while executing will be returned

Example

use lxd::{Container, Location};

let mut container = Container::new(Location::Local, "test-exec", "ubuntu:16.04").unwrap();
container.exec(&["echo", "hello"]).unwrap();

Mount a path in an LXD container

Arguments

  • name - The name of the mount
  • source - The source path to mount
  • dest - The destination of the mount

Return

An empty tuple on success

Errors

Errors that are encountered while mounting will be returned

Example

use lxd::{Container, Location};

let mut container = Container::new(Location::Local, "test-mount", "ubuntu:16.04").unwrap();
container.mount("source", ".", "/root/source").unwrap();

Push a file to the LXD container

Arguments

  • source - The source of the file in the host
  • dest - The destination of the file in the container
  • recursive - The source is a directory

Return

An empty tuple on success

Errors

Errors that are encountered while mounting will be returned

Example

extern crate lxd;
extern crate tempdir;

use lxd::{Container, Location};
use tempdir::TempDir;

fn main() {
    let mut container = Container::new(Location::Local, "test-push", "ubuntu:16.04").unwrap();
    let tmp = TempDir::new("").unwrap();
    container.push(tmp.path(), "/root", true).unwrap();
}

Pull a file from the LXD container

Arguments

  • source - The source of the file in the container
  • dest - The destination of the file in the host
  • recursive - The source is a directory

Return

An empty tuple on success

Errors

Errors that are encountered while mounting will be returned

Example

extern crate lxd;
extern crate tempdir;

use lxd::{Container, Location};
use tempdir::TempDir;

fn main() {
    let mut container = Container::new(Location::Local, "test-pull", "ubuntu:16.04").unwrap();
    container.exec(&["mkdir", "artifacts"]).unwrap();
    let tmp = TempDir::new("").unwrap();
    container.pull("/root/artifacts", tmp.path(), true).unwrap();
}

Trait Implementations

impl Drop for Container
[src]

A method called when the value goes out of scope. Read more