Closed beckend closed 3 months ago
Is there a particular request or response that uses port_mapping that is failing?
I just tried to create a container and then view that container. Option<i32>
seems to be working for containers.
let name = "podman_rest_client_creation_with_ports_test";
let create = models::SpecGenerator {
name: Some(name.into()),
image: Some("docker.io/library/nginx:latest".into()),
portmappings: Some(vec![models::PortMapping {
container_port: Some(80),
host_port: Some(8000),
range: Some(10),
..models::PortMapping::default()
}]),
..models::SpecGenerator::default()
};
client
.containers_api()
.container_create_libpod(create)
.await
.expect("Failed to create container");
let list = client
.containers_api()
.container_list_libpod(
Some(true),
None,
None,
None,
None,
None,
Some(&format!(r#"{{"name": ["{}"]}}"#, name)),
)
.await
.expect("Failed to list containers");
let mappings = &list[0].ports.as_ref().unwrap();
assert_eq!(mappings[0].range, Some(10_i32));
What is range, is it one single IP? I am saying you can you supply a range of 3000-4000?
Looks like it's meant to just be a number. The range starts at container_port
and host_port
and counts up to range
from there. So in this example it would mean mapping port 8000 - 8010
on the host to port 80 - 90
on the container.
container_port: Some(80),
host_port: Some(8000),
range: Some(10),
Range is the number of ports that will be forwarded, starting at HostPort and ContainerPort and counting up. This is 1-indexed, so 1 is assumed to be a single port (only the Hostport:Containerport mapping will be added), 2 is two ports (both Hostport:Containerport and Hostport+1:Containerport+1), etc. If unset, assumed to be 1 (a single port). Both hostport + range and containerport + range must be less than 65536.
Got it, thank you.
https://github.com/blazzy/podman-rest-client/blob/db3ef593046820e5747bf877874d6662c5972f4d/podman-autogen-api/src/models/port_mapping.rs#L30
A range is of course "200-300", string.