def container_remove(name: str) -> None:
    ''' Remove container '''
    response = SESSION.delete(
        url=unixconn.url_format(SOCKET, '/containers/{0:s}'.format(name)),
        timeout=TIMEOUT,
    )

    if response.status_code not in (204, 404):
        raise RuntimeError('{0:s}'.format(
            json.dumps(dict(**unixconn.error(response), **{'name': name}))))
示例#2
0
def container_remove(name):
    ''' Remove container '''
    response = SESSION.delete(
        url=unixconn.url_format(SOCKET, '/containers/{0:s}'.format(name)),
        timeout=TIMEOUT,
    )

    if response.status_code not in (204, 404):
        raise RuntimeError('{0:s}'.format(json.dumps(
            dict(**unixconn.error(response), **{'name': name}))))
def image_exists(tag: str) -> bool:
    ''' Does image exist? '''
    response = SESSION.get(
        url=unixconn.url_format(SOCKET, '/images/{0:s}/json'.format(tag)),
        timeout=TIMEOUT,
    )

    if response.status_code == 200:
        return True
    if response.status_code == 404:
        return False
    raise RuntimeError('{0:s}'.format(
        json.dumps(dict(**unixconn.error(response), **{'tag': tag}))))
示例#4
0
def image_exists(tag):
    ''' Does image exist? '''
    response = SESSION.get(
        url=unixconn.url_format(SOCKET, '/images/{0:s}/json'.format(tag)),
        timeout=TIMEOUT,
    )

    if response.status_code == 200:
        return True
    elif response.status_code == 404:
        return False
    else:
        raise RuntimeError('{0:s}'.format(json.dumps(
            dict(**unixconn.error(response), **{'tag': tag}))))
示例#5
0
def container_create(name, config):
    ''' Create container '''
    response = SESSION.post(
        url=unixconn.url_format(SOCKET, '/containers/create'),
        headers={'Content-Type': 'application/json'},
        params={'name': name},
        data=json.dumps(config),
        timeout=TIMEOUT,
    )

    if response.status_code != 201:
        raise RuntimeError('{0:s}'.format(json.dumps(
            dict(**unixconn.error(response), **{'name': name, 'config': config}))))

    return json.loads(response.text)
def container_create(name: str, config: Dict[str, Any]) -> Any:
    ''' Create container '''
    response = SESSION.post(  # type: ignore
        url=unixconn.url_format(SOCKET, '/containers/create'),
        headers={'Content-Type': 'application/json'},
        params={'name': name},
        data=json.dumps(config),
        timeout=TIMEOUT,
    )

    if response.status_code != 201:
        raise RuntimeError('{0:s}'.format(
            json.dumps(
                dict(**unixconn.error(response), **{
                    'name': name,
                    'config': config
                }))))

    return response.json()