当前位置: 首页>>代码示例>>Python>>正文


Python errors.NotFound方法代码示例

本文整理汇总了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") 
开发者ID:StepicOrg,项目名称:epicbox,代码行数:25,代码来源:sandboxes.py

示例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) 
开发者ID:openstack,项目名称:zun,代码行数:25,代码来源:driver.py

示例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 
开发者ID:stakkr-org,项目名称:stakkr,代码行数:21,代码来源:docker_actions.py

示例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 
开发者ID:6si,项目名称:shipwright,代码行数:24,代码来源:docker.py

示例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 
开发者ID:hyperledger,项目名称:indy-node,代码行数:19,代码来源:indypool.py

示例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 
开发者ID:hyperledger,项目名称:indy-node,代码行数:21,代码来源:indypool.py

示例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 
开发者ID:habitissimo,项目名称:myaas,代码行数:26,代码来源:update.py

示例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.' 
开发者ID:Autodesk,项目名称:notebook-molecular-visualization,代码行数:26,代码来源:images.py

示例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 
开发者ID:everware,项目名称:everware,代码行数:21,代码来源:home_handler.py

示例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 
开发者ID:nginx-proxy,项目名称:nginx-proxy,代码行数:22,代码来源:test_events.py

示例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 
开发者ID:user-cont,项目名称:conu,代码行数:19,代码来源:container.py

示例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) 
开发者ID:merll,项目名称:docker-map,代码行数:18,代码来源:cli.py

示例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 
开发者ID:openstack,项目名称:zun,代码行数:13,代码来源:driver.py

示例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 
开发者ID:stakkr-org,项目名称:stakkr,代码行数:8,代码来源:docker_actions.py

示例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 
开发者ID:stakkr-org,项目名称:stakkr,代码行数:11,代码来源:docker_actions.py


注:本文中的docker.errors.NotFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。