77from contextlib import suppress
88from typing import Any , Union
99from collections .abc import MutableMapping
10+ import requests
1011
1112from podman import api
1213from podman .domain .containers import Container
1314from podman .domain .images import Image
1415from podman .domain .pods import Pod
1516from podman .domain .secrets import Secret
16- from podman .errors import ImageNotFound
1717
1818logger = logging .getLogger ("podman.containers" )
1919
@@ -36,6 +36,12 @@ def create(
3636 command: Command to run in the container.
3737
3838 Keyword Args:
39+ all_tags (bool): Pull all tags from repository. Default: False.
40+ Only used if the method needs to pull the requested image.
41+ auth_config (Mapping[str, str]): Override the credentials that are found in the
42+ config for this request. auth_config should contain the username and password
43+ keys to be valid.
44+ Only used if the method needs to pull the requested image.
3945 auto_remove (bool): Enable auto-removal of the container on daemon side when the
4046 container's process exits.
4147 blkio_weight_device (dict[str, Any]): Block IO weight (relative device weight)
@@ -55,6 +61,9 @@ def create(
5561 cpuset_cpus (str): CPUs in which to allow execution (0-3, 0,1).
5662 cpuset_mems (str): Memory nodes (MEMs) in which to allow execution (0-3, 0,1).
5763 Only effective on NUMA systems.
64+ decode (bool): Decode the JSON data from the server into dicts.
65+ Only applies with ``stream=True``. Default: False.
66+ Only used if the method needs to pull the requested image.
5867 detach (bool): Run container in the background and return a Container object.
5968 device_cgroup_rules (list[str]): A list of cgroup rules to apply to the container.
6069 device_read_bps: Limit read rate (bytes per second) from a device in the form of:
@@ -210,6 +219,8 @@ def create(
210219 pids_limit (int): Tune a container's pids limit. Set -1 for unlimited.
211220 platform (str): Platform in the format os[/arch[/variant]]. Only used if the method
212221 needs to pull the requested image.
222+ policy (str): Pull policy. "missing" (default for create), "always", "never", "newer".
223+ Only used if the method needs to pull the requested image.
213224 ports (
214225 dict[
215226 Union[int, str],
@@ -271,7 +282,12 @@ def create(
271282
272283 }
273284 privileged (bool): Give extended privileges to this container.
285+ progress_bar (bool): Display a progress bar with the image pull progress (uses
286+ the compat endpoint). Default: False.
287+ Only used if the method needs to pull the requested image.
274288 publish_all_ports (bool): Publish all ports to the host.
289+ pull_stream (bool): When True, the pull progress will be published as received.
290+ Default: False. Only used if the method needs to pull the requested image.
275291 read_only (bool): Mount the container's root filesystem as read only.
276292 read_write_tmpfs (bool): Mount temporary file systems as read write,
277293 in case of read_only options set to True. Default: False
@@ -340,6 +356,8 @@ def create(
340356
341357 For example: {'/mnt/vol2': '', '/mnt/vol1': 'size=3G,uid=1000'}
342358
359+ tls_verify (bool): Require TLS verification. Default: True.
360+ Only used if the method needs to pull the requested image.
343361 tty (bool): Allocate a pseudo-TTY.
344362 ulimits (list[Ulimit]): Ulimits to set inside the container.
345363 use_config_proxy (bool): If True, and if the docker client configuration
@@ -391,7 +409,6 @@ def create(
391409 A Container object.
392410
393411 Raises:
394- ImageNotFound: when Image not found by Podman service
395412 APIError: when Podman service reports an error
396413 """
397414 if isinstance (image , Image ):
@@ -409,7 +426,24 @@ def create(
409426 headers = {"content-type" : "application/json" },
410427 data = payload ,
411428 )
412- response .raise_for_status (not_found = ImageNotFound )
429+ if response .status_code == requests .codes .not_found :
430+ self .podman_client .images .pull (
431+ image ,
432+ all_tags = kwargs .get ("all_tags" , False ),
433+ auth_config = kwargs .get ("auth_config" ),
434+ decode = kwargs .get ("decode" , False ),
435+ platform = kwargs .get ("platform" ),
436+ policy = kwargs .get ("policy" , "missing" ),
437+ progress_bar = kwargs .get ("progress_bar" , False ),
438+ stream = kwargs .get ("pull_stream" , False ),
439+ tls_verify = kwargs .get ("tls_verify" , True ),
440+ )
441+ response = self .client .post (
442+ "/containers/create" ,
443+ headers = {"content-type" : "application/json" },
444+ data = payload ,
445+ )
446+ response .raise_for_status ()
413447
414448 container_id = response .json ()["Id" ]
415449
@@ -479,6 +513,13 @@ def _render_payload(kwargs: MutableMapping[str, Any]) -> dict[str, Any]:
479513 "stdout" , # used by caller
480514 "stream" , # used by caller
481515 "detach" , # used by caller
516+ "all_tags" , # used by caller
517+ "auth_config" , # used by caller
518+ "decode" , # used by caller
519+ "policy" , # used by caller
520+ "progress_bar" , # used by caller
521+ "pull_stream" , # used by caller
522+ "tls_verify" , # used by caller
482523 "volume_driver" ,
483524 ):
484525 with suppress (KeyError ):
0 commit comments