Crates.io | podtender |
lib.rs | podtender |
version | 0.5.0 |
source | src |
created_at | 2022-03-18 14:39:05.035939 |
updated_at | 2023-04-17 13:54:56.747175 |
description | A rust client for the podman API. |
homepage | |
repository | https://github.com/PEASEC/podtender |
max_upload_size | |
id | 552728 |
size | 412,559 |
An async rust client library for the Podman REST API.
use tokio;
use podtender::podman_service::PodmanService;
#[tokio::main]
async fn main() {
let podman_service = PodmanService::new("path/to/podman/socket");
let podtender_result = podman_service.system().get_info().await.unwrap();
println!("{podtender_result:?}");
}
The integration tests also act as examples for how to use the crate.
The Podman service needs to be set up before the crate can be used.
# Set up podman service
podman system service unix:///home/`whoami`/podman.sock --log-level=debug --time=50
# Test if the socket is up and running
curl --unix-socket /home/`whoami`/podman.sock http://d/v4.0.0/libpod/info
We aim to support the latest Podman version only. Currently, this is 4.5.x.
The builder
feature enables the builder pattern for request types. This is implemented with the builder derive macro.
IDE support for code created by macros may be limited.
// with builder feature
let create_volume_parameter = CreateVolumeParameterBuilder::default()
.driver("local".to_owned())
.volume_name("some_volume_name".to_owned())
.options(some_previously_created_hashmap)
.build()
.expect("Error building CreateVolumeParameter");
// without builder feature
let create_volume_parameter = CreateVolumeParameter {
driver: Some("local".to_owned()),
labels: None,
volume_name: Some("some_volume_name".to_owned())
options: Some(some_previously_created_hashmap),
}
The examples
feature enables initialized parameters via the ExampleValues
trait. This is mostly intended for tests and
to showcase a usable example parameter per API operation.
tracing
enables logs/tracing powered by Tokio's tracing crate.
Podtender uses hyper and requires tokio. An active Podman socket is needed to communicate with Podman.
To run the integration tests, the tracing
and examples
features are required. To allow easy testing, the tests are
defined as target in the Cargo.toml file and can be run with cargo test --test {target-name} --features="examples tracing"
where {target-name}
is one of the specified targets (e.g. containers-test
).
The Podman socket and network operations are internally managed by the PodmanService
struct.
The Podman API categorizes endpoints into multiple sections. This crate is based on that structure. The pods module contains all api call functions, parameter types and response types for the implemented pods API endpoints.
Every endpoint category module contains:
To start a pod, you would configure podtender::pods::parameter_types::PodStatsParameter
use it with podman_service.pods().start(parameter).await
and expect podtender::pods::response_types::StartPodResponse
.
CreateContainerParameter {
netns: Some(Namespace {
nsmode: Some("bridge".to_owned()),
value: None,
}),
..Default::default()
};
HyperError(
hyper::Error(
Connect,
Os {
code: 2,
kind: NotFound,
message: "No such file or directory",
},
),
)
connect_container_to_network_from_example
test require the 192.168.123.0/24
subnet to be unused on the machine executing the tests.2021-05-26T10:42:00+02:00
timestamps are supported by Podman, this crate currently only supports dates as strings.containers=container1&containers=container2
unix:///home/{user}/{socket_name}.sock
, the socket_name
can be changed in tests/utils.Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in podtender
by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
String
)