Skip to content

Commit

Permalink
python: wrap stop, kill, expose jid
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed Jul 7, 2018
1 parent 5c7b74e commit 7956a1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "BSD-3-Clause"
repository = "https://github.com/fubarnetes/libjail-rs"

[lib]
name = "jail"
name = "jail_python"
crate-type = ["cdylib"]

[dependencies]
Expand Down
37 changes: 31 additions & 6 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,35 @@ impl RunningJail {
})
}

/// Return a String representation of the Jail
fn __repr__(&self) -> PyResult<String> {
Ok(format!("{:?}", self.inner))
}

#[getter]
/// The Jail ID
fn get_jid(&self) -> PyResult<i32> {
Ok(self.inner.jid)
}

/// Stop the Jail, returning a StoppedJail instance with all properties,
/// resource limits, etc.
fn stop(&self) -> PyResult<Py<StoppedJail>> {
let inner = self.inner
.clone()
.stop()
.map_err(|_| exc::SystemError::new("Jail stop failed"))?;
self.py().init(|token| StoppedJail { inner, token })
}

/// Kill the Jail.
fn kill(&self) -> PyResult<()> {
self.inner
.clone()
.kill()
.map_err(|_| exc::SystemError::new("Jail stop failed"))?;
Ok(())
}
}

#[class]
Expand All @@ -62,12 +87,12 @@ impl StoppedJail {
Ok(format!("{:?}", self.inner))
}

fn start(&self) -> PyResult<i32> {
let running = self.inner
.clone()
.start()
.map_err(|_| exc::SystemError::new("Jail start failed"))?;
Ok(running.jid)
fn start(&self) -> PyResult<Py<RunningJail>> {
let inner = self.inner
.clone()
.start()
.map_err(|_| exc::SystemError::new("Jail start failed"))?;
self.py().init(|token| RunningJail { inner, token })
}
}

Expand Down

0 comments on commit 7956a1a

Please sign in to comment.