本文整理汇总了Python中docker.errors.ImageNotFound方法的典型用法代码示例。如果您正苦于以下问题:Python errors.ImageNotFound方法的具体用法?Python errors.ImageNotFound怎么用?Python errors.ImageNotFound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker.errors
的用法示例。
在下文中一共展示了errors.ImageNotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pull_image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def _pull_image(self, repo, tag, registry):
auth_config = None
image_ref = docker_image.Reference.parse(repo)
registry_domain, remainder = image_ref.split_hostname()
if registry and registry.username:
auth_config = {'username': registry.username,
'password': registry.password}
elif (registry_domain and
registry_domain == CONF.docker.default_registry and
CONF.docker.default_registry_username):
auth_config = {'username': CONF.docker.default_registry_username,
'password': CONF.docker.default_registry_password}
with docker_utils.docker_client() as docker:
try:
docker.pull(repo, tag=tag, auth_config=auth_config)
except errors.NotFound as e:
raise exception.ImageNotFound(message=str(e))
except errors.APIError:
LOG.exception('Error on pulling image')
message = _('Error on pulling image: %(repo)s:%(tag)s') % {
'repo': repo, 'tag': tag}
raise exception.ZunException(message)
示例2: getImageByTag
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def getImageByTag(tag):
'''Check if an image with a given tag exists. No side-effects. Idempotent.
Handles ImageNotFound and APIError exceptions, but only reraises APIError.
'''
require_str("tag", tag)
image = None
try:
image = client.images.get(tag)
print("Found image", tag, "...")
except ImageNotFound:
print("Image", tag, "does not exist ...")
except APIError as exc:
eprint("Unhandled error while getting image", tag)
raise exc
return image
示例3: runContainer
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def runContainer(image, **kwargs):
'''Run a docker container using a given image; passing keyword arguments
documented to be accepted by docker's client.containers.run function
No extra side effects. Handles and reraises ContainerError, ImageNotFound,
and APIError exceptions.
'''
container = None
try:
container = client.containers.run(image, **kwargs)
if "name" in kwargs.keys():
print("Container", kwargs["name"], "is now running.")
except ContainerError as exc:
eprint("Failed to run container")
raise exc
except ImageNotFound as exc:
eprint("Failed to find image to run as a docker container")
raise exc
except APIError as exc:
eprint("Unhandled error")
raise exc
return container
示例4: delete_image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def delete_image(self, context, img_id):
LOG.debug('Delete an image %s in docker', img_id)
with docker_utils.docker_client() as docker:
try:
docker.remove_image(img_id)
except errors.ImageNotFound:
return
except errors.APIError as api_error:
raise exception.ZunException(str(api_error))
except Exception as e:
LOG.exception('Unknown exception occurred while deleting '
'image %s in glance:%s',
img_id,
str(e))
raise exception.ZunException(str(e))
示例5: pull_image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def pull_image(self, context, repo, tag, image_pull_policy, registry):
image_loaded = True
image = self._search_image_on_host(repo, tag)
if not utils.should_pull_image(image_pull_policy, bool(image)):
if image:
LOG.debug('Image %s present locally', repo)
return image, image_loaded
else:
message = _('Image %s not present with pull policy of Never'
) % repo
raise exception.ImageNotFound(message)
try:
LOG.debug('Pulling image from docker %(repo)s,'
' context %(context)s',
{'repo': repo, 'context': context})
self._pull_image(repo, tag, registry)
return {'image': repo, 'path': None}, image_loaded
except exception.ImageNotFound:
with excutils.save_and_reraise_exception():
LOG.error('Image %s was not found in docker repo', repo)
except exception.DockerError:
with excutils.save_and_reraise_exception():
LOG.error('Docker API error occurred during downloading '
'image %s', repo)
except Exception as e:
msg = _('Cannot download image from docker: {0}')
raise exception.ZunException(msg.format(e))
示例6: _pull_docker_images
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def _pull_docker_images(docker_client=None):
if docker_client is None:
docker_client = docker.from_env(version="auto")
for image in images.ALL:
try:
docker_client.images.get(image)
except ImageNotFound:
if armory.is_dev():
raise ValueError(
"For '-dev', please run 'docker/build-dev.sh' locally before running armory"
)
logger.info(f"Image {image} was not found. Downloading...")
docker_api.pull_verbose(docker_client, image)
示例7: image_exists
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def image_exists(self):
try:
self.client.inspect_image(self.image)
except ImageNotFound:
return False
return True
示例8: parallel_execute_watch
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def parallel_execute_watch(events, writer, errors, results, msg, get_name):
""" Watch events from a parallel execution, update status and fill errors and results.
Returns exception to re-raise.
"""
error_to_reraise = None
for obj, result, exception in events:
if exception is None:
writer.write(msg, get_name(obj), 'done', green)
results.append(result)
elif isinstance(exception, ImageNotFound):
# This is to bubble up ImageNotFound exceptions to the client so we
# can prompt the user if they want to rebuild.
errors[get_name(obj)] = exception.explanation
writer.write(msg, get_name(obj), 'error', red)
error_to_reraise = exception
elif isinstance(exception, APIError):
errors[get_name(obj)] = exception.explanation
writer.write(msg, get_name(obj), 'error', red)
elif isinstance(exception, (OperationFailedError, HealthCheckFailed, NoHealthCheckConfigured)):
errors[get_name(obj)] = exception.msg
writer.write(msg, get_name(obj), 'error', red)
elif isinstance(exception, UpstreamError):
writer.write(msg, get_name(obj), 'error', red)
else:
errors[get_name(obj)] = exception
error_to_reraise = exception
return error_to_reraise
示例9: image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def image(self):
try:
return self.client.inspect_image(self.image_name)
except ImageNotFound:
raise NoSuchImageError("Image '{}' not found".format(self.image_name))
示例10: image_present
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def image_present(client, image):
from docker import errors
try:
imginfo = client.inspect_image(image)
except errors.ImageNotFound:
return False
else:
return True
示例11: image_exists
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def image_exists(self, name) -> bool:
"""Method to check if a Docker image exists
Returns:
bool
"""
# Check if image exists
try:
self.docker_client.images.get(name)
return True
except ImageNotFound:
return False
示例12: checkDockerSchema
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def checkDockerSchema(appliance):
if not appliance:
raise ImageNotFound("No docker image specified.")
elif '://' in appliance:
raise ImageNotFound("Docker images cannot contain a schema (such as '://'): %s"
"" % appliance)
elif len(appliance) > 256:
raise ImageNotFound("Docker image must be less than 256 chars: %s"
"" % appliance)
示例13: testBroadDockerRepoBadTag
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def testBroadDockerRepoBadTag(self):
"""Bad tag. This should raise."""
broad_repo = 'broadinstitute/genomes-in-the-cloud:-----'
with self.assertRaises(ImageNotFound):
checkDockerImageExists(broad_repo)
示例14: testNonexistentRepo
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def testNonexistentRepo(self):
"""Bad image. This should raise."""
nonexistent_repo = '------:-----'
with self.assertRaises(ImageNotFound):
checkDockerImageExists(nonexistent_repo)
示例15: testBadQuayRepoNTag
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ImageNotFound [as 别名]
def testBadQuayRepoNTag(self):
"""Bad repo and tag. This should raise."""
nonexistent_quay_repo = 'quay.io/--------:---'
with self.assertRaises(ImageNotFound):
checkDockerImageExists(nonexistent_quay_repo)