本文整理汇总了Python中docker.errors.NotFound方法的典型用法代码示例。如果您正苦于以下问题:Python errors.NotFound方法的具体用法?Python errors.NotFound怎么用?Python errors.NotFound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker.errors
的用法示例。
在下文中一共展示了errors.NotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: working_directory
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def working_directory():
docker_client = utils.get_docker_client()
volume_name = 'epicbox-' + str(uuid.uuid4())
log = logger.bind(volume=volume_name)
log.info("Creating new docker volume for working directory")
try:
volume = docker_client.volumes.create(volume_name)
except (RequestException, DockerException) as e:
log.exception("Failed to create a docker volume")
raise exceptions.DockerError(str(e))
log.info("New docker volume is created")
try:
yield _WorkingDirectory(volume=volume_name, node=None)
finally: # Ensure that volume cleanup takes place
log.info("Removing the docker volume")
try:
volume.remove()
except NotFound:
log.warning("Failed to remove the docker volume, it doesn't exist")
except (RequestException, DockerException):
log.exception("Failed to remove the docker volume")
else:
log.info("Docker volume removed")
示例2: _pull_image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [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)
示例3: _extract_container_info
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def _extract_container_info(project_name: str, ct_id: str):
"""Get a hash of info about a container : name, ports, image, ip ..."""
try:
ct_data = get_api_client().inspect_container(ct_id)
except NotFound:
return None
cts_info = {
'id': ct_id,
'name': ct_data['Name'].lstrip('/'),
'compose_name': ct_data['Config']['Labels']['com.docker.compose.service'],
'ports': _extract_host_ports(ct_data),
'image': ct_data['Config']['Image'],
'traefik_host': _get_traefik_host(ct_data['Config']['Labels']),
'ip': _get_ip_from_networks(project_name, ct_data['NetworkSettings']['Networks']),
'running': ct_data['State']['Running']
}
return cts_info
示例4: tag_image
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def tag_image(client, image, new_ref):
tag = encode_tag(new_ref)
old_image = image.name + ':' + image.ref
repository = image.name
evt = {
'event': 'tag',
'old_image': old_image,
'repository': repository,
'tag': tag,
}
try:
client.tag(
old_image,
repository,
tag=tag,
force=True,
)
except d_errors.NotFound:
message = 'Error tagging {}, not found'.format(old_image)
evt.update(error(message))
return evt
示例5: getContainer
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def getContainer(name_or_id):
'''Get the container with the given name or ID (str). No side effects.
Idempotent. Returns None if the container does not exist. Otherwise, the
continer is returned'''
require_str("name_or_id", name_or_id)
container = None
try:
container = client.containers.get(name_or_id)
except NotFound as exc:
# Return None when the container is not found
pass
except APIError as exc:
eprint("Unhandled error")
raise exc
return container
示例6: getContainerByTag
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def getContainerByTag(tag):
'''Check if a container with a given tag exists. No side-effects.
Idempotent. Handles NotFound and APIError exceptions, but only reraises
APIError. Returns None if the container is not found. Otherwise, returns the
container.'''
require_str("tag", tag)
container = None
try:
container = client.containers.get(tag)
print("Found container", tag, "...")
except NotFound:
#print("Container", tag, "does not exist ...")
pass
except APIError as exc:
eprint("Unhandled error while getting container", tag)
raise exc
return container
示例7: remove_recreate_database
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def remove_recreate_database(template):
"""
find existing database, remove it, then recreate
"""
backend = get_enabled_backend().Template
try:
db = backend(client, template, False)
if db.running():
db.stop()
db.do_backup()
db.remove()
except NonExistentTemplate:
pass # this means this database is being imported for the first time
try:
database = backend(client, template, True)
except ImageNotFound as e:
import sys
print("\n### ERROR ###", file=sys.stderr)
print(e.explanation.decode(), file=sys.stderr)
print("Pull the image and try again.", file=sys.stderr)
sys.exit(1)
return database
示例8: _run_pull
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def _run_pull(self):
from docker import errors
try:
self._disable_button('Pulling...')
self.status.value = self.LOADER
self.msg.value = 'Starting download.'
try:
response = self._client.pull(self.image, stream=True, decode=True)
self._watch_pull_logs(response)
except errors.NotFound as exc:
self._err = True
self.msg.value = 'ERROR: %s' % exc.explanation
except Exception as e:
self._err = True
self.msg = str(e)
raise
finally:
self._set_status_value()
self._reactivate_button()
if not self._err:
self.msg.value = 'Pull successful.'
示例9: is_repository_changed
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def is_repository_changed(user):
try:
setup = yield user.spawner.docker(
'exec_create',
container=user.spawner.container_id,
cmd="bash -c 'cd $JPY_WORKDIR && \
(git fetch --unshallow > /dev/null 2>&1; true) && \
git diff --name-only'",
)
out = yield user.spawner.docker(
'exec_start',
exec_id=setup['Id'],
)
except NotFound:
return False
if out:
return True
else:
return False
示例10: web1
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def web1(docker_compose):
"""
pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81.
"""
container = docker_compose.containers.run(
name="web1",
image="web",
detach=True,
environment={
"WEB_PORTS": "81",
"VIRTUAL_HOST": "web1.nginx-proxy"
},
ports={"81/tcp": None}
)
sleep(2) # give it some time to initialize and for docker-gen to detect it
yield container
try:
docker_compose.containers.get("web1").remove(force=True)
except NotFound:
pass
示例11: is_running
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def is_running(self):
"""
returns True if the container is running, this method should always ask the API and
should not use a cached value
:return: bool
"""
# # TODO: kick-off of https://github.com/fedora-modularity/conu/issues/24
# import pprint
# pprint.pprint(self._metadata)
# cmdline = ["docker", "container", "logs", self.tag]
# output = run_cmd(cmdline)
# print(output)
try:
return self.inspect(refresh=True)["State"]["Running"]
except NotFound:
return False
示例12: parse_inspect_output
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def parse_inspect_output(out, item_type):
"""
Parses the output of the Docker CLI 'docker inspect <container>' or 'docker network inspect <network>'. Essentially
just returns the parsed JSON string, like the Docker API does.
:param out: CLI output.
:type out: unicode | str
:param item_type: Type of the item that has been inspected (e.g. 'container').
:type item_type: unicode | str
:return: Parsed result.
:rtype: dict
"""
parsed = json.loads(out, encoding='utf-8')
if parsed:
return parsed[0]
raise NotFound("{0} not found.".format(item_type.title()), None)
示例13: _search_image_on_host
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def _search_image_on_host(self, repo, tag):
with docker_utils.docker_client() as docker:
image = repo + ":" + tag
LOG.debug('Inspecting image locally %s', image)
try:
image_dict = docker.inspect_image(image)
if image_dict:
return {'image': repo, 'path': None}
except errors.NotFound:
LOG.debug('Image %s not found locally', image)
return None
示例14: container_running
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def container_running(container: str):
"""Return True if the container is running else False."""
try:
return get_api_client().inspect_container(container)['State']['Running']
except (NotFound, NullResource):
return False
示例15: get_network_name
# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import NotFound [as 别名]
def get_network_name(project_name: str):
"""Find the full network name."""
try:
guessed_network_name = '{}_stakkr'.format(project_name).lower()
network = get_client().networks.get(guessed_network_name)
except NotFound:
raise RuntimeError("Couldn't identify network (check your project name)")
return network.name