Esempio n. 1
0
def print_http_dockyard_unavailability_warning(address,
                                               alias,
                                               header="Warning!"):
    docker_version = Version(get_docker_server_version())

    if docker_version >= Version('1.8.0'):
        if address.split(':')[0] not in ['127.0.0.1', 'localhost']:
            if urlparse(address).scheme:
                http_address = address
            else:
                http_address = 'http://' + address
            message = DISABLED_REMOTE_HTTP_REGISTRY.format(
                address=http_address, alias=alias, header=header)
            print_err(message)
            return True
        return False

    if docker_version > Version('1.3.0'):
        cmd = 'ps ax | grep $(which docker)'
        ps_output = subprocess.check_output(cmd, shell=True)
        if re.search(r'--insecure-registry[ =]' + re.escape(address) + r'\b',
                     ps_output) is None:
            message = INSECURE_REGISTRY_ERROR_MSG.format(address=address,
                                                         header=header)
            print_err(message)
            return True

    return False
Esempio n. 2
0
def command_dockyard_set(args):
    warning_header = " Warning!\n Your dockyard alias has been set BUT:"
    alias.set_alias(args.name, args.address, args.user, args.password)
    try:
        dockyard = dockyard_factory(args.address, args.user, args.password)
        if dockyard.is_http():
            print_http_dockyard_unavailability_warning(args.address, args.name, warning_header)
    except (DockyardFactoryException, DockyardDetectionException) as e:
        print_err('{}\n{}'.format(warning_header, e))
Esempio n. 3
0
def command_dockyard_set(args):
    warning_header = " Warning!\n Your dockyard alias has been set BUT:"
    alias.set_alias(args.name, args.address, args.user, args.password)
    try:
        dockyard = dockyard_factory(args.address, args.user, args.password)
        if dockyard.is_http():
            print_http_dockyard_unavailability_warning(args.address, args.name,
                                                       warning_header)
    except (DockyardFactoryException, DockyardDetectionException) as e:
        print_err('{}\n{}'.format(warning_header, e))
Esempio n. 4
0
def print_http_dockyard_unavailability_warning(address, alias, header="Warning!"):
    if address.split(':')[0] not in ['127.0.0.1', 'localhost']:
        if urlparse(address).scheme:
            http_address = address
        else:
            http_address = 'http://' + address
        message = DISABLED_REMOTE_HTTP_REGISTRY.format(address=http_address, alias=alias, header=header)
        print_err(message)
        return True
    return False
Esempio n. 5
0
def print_result_from_armada_api(result):
    if result['status'] == 'ok':
        result_value = dict(result)
        del result_value['status']
        if result_value:
            print(json.dumps(result_value))
    else:
        if result['status'] == 'error':
            print_err(result.get('error'))
        else:
            print_err(result)
        sys.exit(1)
Esempio n. 6
0
def print_http_dockyard_unavailability_warning(address, alias, header="Warning!"):
    docker_version = Version(get_docker_server_version())

    if docker_version >= Version('1.8.0'):
        if address.split(':')[0] not in ['127.0.0.1', 'localhost']:
            if urlparse(address).scheme:
                http_address = address
            else:
                http_address = 'http://' + address
            message = DISABLED_REMOTE_HTTP_REGISTRY.format(address=http_address, alias=alias, header=header)
            print_err(message)
            return True
        return False

    if docker_version > Version('1.3.0'):
        cmd = 'ps ax | grep $(which docker)'
        ps_output = subprocess.check_output(cmd, shell=True)
        if re.search(r'--insecure-registry[ =]' + re.escape(address) + r'\b', ps_output) is None:
            message = INSECURE_REGISTRY_ERROR_MSG.format(address=address, header=header)
            print_err(message)
            return True

    return False