Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahamas10/rust-zonename
Rust bindings to getzoneid(3C), getzoneidbyname(3C), and getzonenamebyid(3C) for Illumos based systems
https://github.com/bahamas10/rust-zonename
Last synced: 2 months ago
JSON representation
Rust bindings to getzoneid(3C), getzoneidbyname(3C), and getzonenamebyid(3C) for Illumos based systems
- Host: GitHub
- URL: https://github.com/bahamas10/rust-zonename
- Owner: bahamas10
- Created: 2018-08-08T19:55:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-08T17:58:41.000Z (almost 6 years ago)
- Last Synced: 2024-08-09T04:38:38.486Z (5 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
rust-zonename
=============Rust bindings to [getzoneid(3C)](https://illumos.org/man/3C/getzoneid),
[getzoneidbyname(3C)](https://illumos.org/man/3C/getzoneidbyname), and
[getzonenamebyid(3C)](https://illumos.org/man/3C/getzonenamebyid) for illumos based
systems.Example
-------``` rust
extern crate zonename;fn main() {
// Max zonename length
let zonename_max = zonename::ZONENAME_MAX;
println!("zonename_max = {}", zonename_max);// Get the current zone id
let zoneid = zonename::getzoneid().expect("failed to get zoneid");
println!("getzoneid() = {}", zoneid);// Get the zonename for the current zone id (our zonename)
let zonename = zonename::getzonenamebyid(zoneid).expect("failed to get zonename");
println!("getzoneidbyname({}) = {}", zoneid, zonename);// Convenience wrapper for getting our current zonename
let zonename = zonename::getzonename().expect("failed to get zonename");
println!("getzonename() = {}", zonename);// Try to get a fake zoneid
let zoneid = -1;
match zonename::getzonenamebyid(zoneid) {
Ok(name) => println!("getzonenamebyid({}) = name: {}", zoneid, name),
Err(err) => println!("getzonenamebyid({}) = err: {}", zoneid, err)
};// Try to get a fake zonename
let zonename = "fake zone";
match zonename::getzoneidbyname(zonename) {
Ok(num) => println!("getzoneidbyname('{}') = num: {}", zonename, num),
Err(err) => println!("getzoneidbyname('{}') = err: {}", zonename, err)
};
}
```Yields
```
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/zonename`
zonename_max = 64
getzoneid() = 47
getzoneidbyname(47) = 5a88b137-93ba-4080-f5ca-d20fecad59e3
getzonename() = 5a88b137-93ba-4080-f5ca-d20fecad59e3
getzonenamebyid(-1) = err: Invalid argument
getzoneidbyname('fake zone') = err: Invalid argument
```Usage
-----``` rust
pub const ZONENAME_MAX: usize = 64;
pub fn getzoneid() -> Result;
pub fn getzoneidbyname(zonename: &str) -> Result;
pub fn getzonenamebyid(id: i32) -> Result;
pub fn getzonename() -> Result;
```License
-------MIT License