MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / new

Method new

crates/openshell-driver-podman/src/driver.rs:190–327  ·  view source on GitHub ↗

Create a new driver, verifying the Podman socket is reachable.

(mut config: PodmanComputeConfig)

Source from the content-addressed store, hash-verified

188impl PodmanComputeDriver {
189 /// Create a new driver, verifying the Podman socket is reachable.
190 pub async fn new(mut config: PodmanComputeConfig) -> Result<Self, PodmanApiError> {
191 const MAX_PING_RETRIES: u32 = 5;
192 const PING_RETRY_DELAY: Duration = Duration::from_secs(2);
193
194 if !config.socket_path.exists() {
195 if cfg!(target_os = "macos") {
196 warn!(
197 path = %config.socket_path.display(),
198 "Podman socket not found; is podman machine running? \
199 Try `podman machine start` or set OPENSHELL_PODMAN_SOCKET to override."
200 );
201 } else {
202 warn!(
203 path = %config.socket_path.display(),
204 "Podman socket not found; is the Podman service running? \
205 Set OPENSHELL_PODMAN_SOCKET or XDG_RUNTIME_DIR to override."
206 );
207 }
208 }
209
210 // Validate TLS configuration before connecting. Partial configs
211 // (e.g. CA set but cert/key missing) are rejected early so operators
212 // get a clear error instead of a silent fallback to plaintext HTTP.
213 config.validate_tls_config()?;
214 config.validate_runtime_limits()?;
215 config.validate_host_gateway_ip()?;
216
217 let client = PodmanClient::new(config.socket_path.clone());
218
219 // Verify connectivity, retrying briefly to tolerate transient socket
220 // unavailability (e.g. podman.socket restarting after a package
221 // upgrade). The systemd unit uses Wants=podman.socket (not Requires),
222 // so the gateway may start while the socket is briefly re-activating.
223 let mut attempts = 0;
224 loop {
225 match client.ping().await {
226 Ok(()) => break,
227 Err(e) if attempts < MAX_PING_RETRIES => {
228 attempts += 1;
229 warn!(
230 attempt = attempts,
231 max_retries = MAX_PING_RETRIES,
232 error = %e,
233 "Podman socket not ready, retrying"
234 );
235 tokio::time::sleep(PING_RETRY_DELAY).await;
236 }
237 Err(e) => return Err(e),
238 }
239 }
240
241 // Verify cgroups v2, detect rootless mode, and log system info.
242 match client.system_info().await {
243 Ok(info) => {
244 if info.host.cgroup_version != "v2" {
245 return Err(PodmanApiError::Connection(format!(
246 "cgroups v2 is required; detected cgroups '{}'. \
247 Ensure your host uses a unified cgroup hierarchy \

Callers

nothing calls this directly

Calls 12

check_subuid_rangeFunction · 0.85
existsMethod · 0.80
validate_tls_configMethod · 0.80
system_infoMethod · 0.80
ensure_networkMethod · 0.80
tls_enabledMethod · 0.80
pingMethod · 0.45
network_gateway_ipMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected