sanpii / lxc-rs

Linux Containers API for rustaceans
MIT License
20 stars 5 forks source link

`create` doesn't provide a way to pass a null argument for the template #33

Open griwes opened 1 month ago

griwes commented 1 month ago

container.create in the C bindings for LXC allows a user to pass in a null pointer instead of a template name for that argument; this is used for example when you run lxc-create -t none, which allows creating a container, but without a rootfs (thus allowing for full customization of the container with config options).

The current API in this crate doesn't allow for that, as it always passes a string into the C bindings. There should be a way to create a container without a rootfs. (I'd be happy with just an additional function that invokes the bindings with a reasonable set of arguments to achieve this, but I'm not sure if that's the right design for such an interface in general.)

sanpii commented 1 month ago

The current API in this crate doesn't allow for that, as it always passes a string into the C bindings

Fixed 5bbe44a2fac251326a2816b84c6db5825e981d19

I'd be happy with just an additional function that invokes the bindings with a reasonable set of arguments to achieve this, but I'm not sure if that's the right design for such an interface in general.

It’s probably a good idea to redesign this function with a builder:

c.create()
    .template("download")
    .flag(lxc::CreateFlags::QUIET)
    .arg("-d")
    .arg("ubuntu")
    .arg("-r")
    .arg("trusty")
    .arg("-a")
    .arg("i386")
    // or .args(&["-d", "ubuntu", "-r", "trusty", "-a", "i386"])
    .build()

What do you think?