sanpii / lxc-rs

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

lxc::Container::get_ips() design improvement #12

Open koutheir opened 2 years ago

koutheir commented 2 years ago

The lxc::Container::get_ips() API encapsulates the get_ips() of lxc_sys::lxc_container.

There are multiples issues with the design of lxc::Container::get_ips():

Given all these points, I suggest changing the prototype of lxc::Container::get_ips() to the following:

pub fn get_ips(
    &self,
    interface: Option<&str>,
    family: Option<&str>,
    scope: std::os::raw::c_int)
    -> Result<Vec<std::net::IpAddr>>
{
    /*... */
}
sanpii commented 2 years ago

I made the PR but I didn’t try it: https://github.com/sanpii/lxc-rs/pull/14

sanpii commented 2 years ago

It’s work fine:

Container state: RUNNING
Container PID: 32254
Interfaces: ["eth0", "lo"]
IPs: [10.0.3.206]
koutheir commented 2 years ago

The only issue remaining is the unwrap() calls that panic if liblxc generates an error. This is not reasonable for a library.

sanpii commented 2 years ago

The only issue remaining is the unwrap() calls that panic if liblxc generates an error. This is not reasonable for a library.

There is many unwrap in my code, I work on a redesign of errors handling.

koutheir commented 2 years ago

Until panics are reduced to a minimum, the only crate I can currently use is lxc-sys, basically reimplementing the ergonomic structures while reporting liblxc errors as normal Results.

sanpii commented 2 years ago

@koutheir The PR is here: https://github.com/sanpii/lxc-rs/pull/16