8个版本
0.1.1 | 2021年11月6日 |
---|---|
0.1.0 | 2021年11月4日 |
0.0.6 | 2021年10月31日 |
0.0.4 | 2021年9月25日 |
0.0.2 | 2021年6月24日 |
#1023 in 异步
39KB
837 行
xo-api-client
通过其API访问Xen Orchestra的非官方Rust crate
开发中
此库仍在早期开发阶段,请不要在生产环境中使用。API远未完成,仅覆盖了XO API的一小部分。许多事情可能会在任何时候以破坏性的方式更改或添加。
异步运行时
此库使用tokio v1运行时
示例
列出所有标记为 Test
的VM的示例
use std::collections::BTreeMap;
use xo_api_client::{credentials::EmailAndPassword, Client, Vm, VmId};
// We dont care about any of the data under the "other" attribute
// in this example
#[derive(serde::Deserialize)]
struct OtherInfo {}
impl xo_api_client::api::vm::OtherInfo for OtherInfo {}
#[tokio::main]
async fn main() {
let url = "ws://127.0.0.1:8080/api/";
let email = String::from("[email protected]");
let password = String::from("admin");
let con = Client::connect(url)
.await
.expect("Failed to connect to server");
con.session
.sign_in(EmailAndPassword { email, password })
.await
.expect("Failed to sign in");
let all_vms: BTreeMap<VmId, Vm<OtherInfo>> =
con.get_vms(None, None).await.expect("Failed to list VMs");
let test_vms = all_vms
.iter()
.filter(|(_id, vm)| vm.tags.iter().any(|tag| tag == "Test"));
println!("All VMs with the tag 'Test':");
for (id, vm) in test_vms {
println!("ID: {:?}, Name: {}", id, vm.name_label);
}
}
许可
xo-api-client
在MIT许可和Apache许可证(版本2.0)的条款下分发。
请参阅LICENSE-APACHE和LICENSE-MIT以获取详细信息。
贡献
除非您明确声明,否则根据Apache-2.0许可证定义,您提交的任何有意包含在xo-api-client中的贡献将按照上述方式双许可,不附加任何额外的条款或条件。
依赖项
~14–29MB
~483K SLoC