예제 #1
0
def load_config(config_data):
    if 'knative' not in config_data or not config_data['knative']:
        config_data['knative'] = {}

    if 'git_url' not in config_data['knative']:
        config_data['knative']['git_url'] = BUILD_GIT_URL
    if 'git_rev' not in config_data['knative']:
        revision = 'master' if 'dev' in __version__ else __version__
        config_data['knative']['git_rev'] = revision
    if 'docker_repo' not in config_data['knative']:
        config_data['knative']['docker_repo'] = DOCKER_REPO

    if 'cpu' not in config_data['knative']:
        config_data['knative']['cpu'] = RUNTIME_CPU
    if 'concurrency' not in config_data['knative']:
        config_data['knative']['concurrency'] = RUNTIME_CONCURRENCY
    if 'min_instances' not in config_data['knative']:
        config_data['knative']['min_instances'] = RUNTIME_MIN_INSTANCES
    if 'max_instances' not in config_data['knative']:
        config_data['knative']['max_instances'] = RUNTIME_MAX_INSTANCES

    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT

    if 'runtime' not in config_data['serverless']:
        if 'docker_user' not in config_data['knative']:
            cmd = "{} info".format(DOCKER_PATH)
            docker_user_info = sp.check_output(cmd,
                                               shell=True,
                                               encoding='UTF-8',
                                               stderr=sp.STDOUT)
            for line in docker_user_info.splitlines():
                if 'Username' in line:
                    _, useranme = line.strip().split(':')
                    config_data['knative']['docker_user'] = useranme.strip()
                    break

        if 'docker_user' not in config_data['knative']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')

        docker_user = config_data['knative']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['serverless']['runtime'] = runtime_name

    if 'workers' not in config_data['lithops']:
        max_instances = config_data['knative']['max_instances']
        concurrency = config_data['knative']['concurrency']
        config_data['lithops']['workers'] = int(max_instances * concurrency)
예제 #2
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'kubectl_config' in config_data['code_engine']:
        print('"kubectl_config" variable in code_engine config is deprecated, use "kubecfg_path" instead')
        config_data['code_engine']['kubecfg_path'] = config_data['code_engine']['kubectl_config']

    if 'cpu' in config_data['code_engine']:
        print('"cpu" variable in code_engine config is deprecated, use "runtime_cpu" instead')
        config_data['code_engine']['runtime_cpu'] = config_data['code_engine']['cpu']

    if 'ibm' in config_data and config_data['ibm'] is not None:
        config_data['code_engine'].update(config_data['ibm'])

    if 'runtime_cpu' not in config_data['code_engine']:
        config_data['code_engine']['runtime_cpu'] = RUNTIME_CPU
    if 'runtime_memory' not in config_data['code_engine']:
        config_data['code_engine']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['code_engine']:
        config_data['code_engine']['runtime_timeout'] = RUNTIME_TIMEOUT
    if 'runtime' not in config_data['code_engine']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "code_engine" section')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['code_engine']['runtime'] = runtime_name

    runtime_cpu = config_data['code_engine']['runtime_cpu']
    if runtime_cpu not in VALID_CPU_VALUES:
        raise Exception('{} is an invalid runtime cpu value. Set one of: '
                        '{}'.format(runtime_cpu, VALID_CPU_VALUES))

    runtime_memory = config_data['code_engine']['runtime_memory']
    if runtime_memory not in VALID_MEMORY_VALUES:
        raise Exception('{} is an invalid runtime memory value in MB. Set one of: '
                        '{}'.format(runtime_memory, VALID_MEMORY_VALUES))

    region = config_data['code_engine'].get('region')
    if region and region not in VALID_REGIONS:
        raise Exception('{} is an invalid region name. Set one of: '
                        '{}'.format(region, VALID_REGIONS))

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS
예제 #3
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'cpu' not in config_data['code_engine']:
        config_data['code_engine']['cpu'] = RUNTIME_CPU

    if 'container_registry' not in config_data['code_engine']:
        config_data['code_engine']['container_registry'] = CONTAINER_REGISTRY

    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT

    if 'runtime' in config_data['code_engine']:
        config_data['serverless']['runtime'] = config_data['code_engine'][
            'runtime']
    if 'runtime' not in config_data['serverless']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['serverless']['runtime'] = runtime_name

    else:
        if config_data['serverless']['runtime'].count('/') > 1:
            # container registry is in the provided runtime name
            cr, rn = config_data['serverless']['runtime'].split('/', 1)
            config_data['code_engine']['container_registry'] = cr
            config_data['serverless']['runtime'] = rn

    config_data['serverless']['remote_invoker'] = True

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS

    if 'invoke_pool_threads' not in config_data['code_engine']:
        config_data['code_engine'][
            'invoke_pool_threads'] = INVOKE_POOL_THREADS_DEFAULT
    config_data['serverless']['invoke_pool_threads'] = config_data[
        'code_engine']['invoke_pool_threads']
예제 #4
0
파일: config.py 프로젝트: kpavel/lithops
def load_config(config_data):
    if 'knative' not in config_data or not config_data['knative']:
        config_data['knative'] = {}

    if 'git_url' not in config_data['knative']:
        config_data['knative']['git_url'] = BUILD_GIT_URL
    if 'git_rev' not in config_data['knative']:
        revision = 'master' if 'dev' in __version__ else __version__
        config_data['knative']['git_rev'] = revision

    if 'runtime_concurrency' not in config_data['knative']:
        config_data['knative']['runtime_concurrency'] = RUNTIME_CONCURRENCY
    if 'runtime_min_instances' not in config_data['knative']:
        config_data['knative']['runtime_min_instances'] = RUNTIME_MIN_INSTANCES
    if 'runtime_max_instances' not in config_data['knative']:
        config_data['knative']['runtime_max_instances'] = RUNTIME_MAX_INSTANCES

    if 'runtime_cpu' not in config_data['knative']:
        config_data['knative']['runtime_cpu'] = RUNTIME_CPU
    if 'runtime_memory' not in config_data['knative']:
        config_data['knative']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['knative']:
        config_data['knative']['runtime_timeout'] = RUNTIME_TIMEOUT
    if 'runtime' not in config_data['knative']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['knative']:
            config_data['knative']['docker_user'] = get_docker_username()
        if not config_data['knative']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['knative']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['knative']['runtime'] = runtime_name

    if 'workers' not in config_data['lithops']:
        max_instances = config_data['knative']['max_instances']
        concurrency = config_data['knative']['runtime_concurrency']
        config_data['lithops']['workers'] = int(max_instances * concurrency)

    if 'invoke_pool_threads' not in config_data['knative']:
        config_data['knative']['invoke_pool_threads'] = config_data['lithops'][
            'workers']
예제 #5
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'runtime_cpu' not in config_data['code_engine']:
        config_data['code_engine']['cpu'] = RUNTIME_CPU

    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT

    if 'runtime' not in config_data['serverless']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            cmd = "{} info".format(DOCKER_PATH)
            docker_user_info = sp.check_output(cmd,
                                               shell=True,
                                               encoding='UTF-8',
                                               stderr=sp.STDOUT)
            for line in docker_user_info.splitlines():
                if 'Username' in line:
                    _, useranme = line.strip().split(':')
                    config_data['code_engine']['docker_user'] = useranme.strip(
                    )
                    break

        if 'docker_user' not in config_data['code_engine']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')

        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['serverless']['runtime'] = runtime_name

    config_data['serverless']['remote_invoker'] = True

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS
예제 #6
0
def load_config(config_data):
    for key in DEFAULT_CONFIG_KEYS:
        if key not in config_data['k8s']:
            config_data['k8s'][key] = DEFAULT_CONFIG_KEYS[key]

    if 'runtime' not in config_data['k8s']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['k8s']:
            config_data['k8s']['docker_user'] = get_docker_username()
        if not config_data['k8s']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "k8s" section')
        docker_user = config_data['k8s']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['k8s']['runtime'] = runtime_name
예제 #7
0
def load_config(config_data):
    if 'knative' not in config_data:
        raise Exception("knative section is mandatory in configuration")

    required_keys = ('docker_user', )
    if not set(required_keys) <= set(config_data['knative']):
        raise Exception(
            'You must provide {} to access to Knative'.format(required_keys))

    if 'git_url' not in config_data['knative']:
        config_data['knative']['git_url'] = BUILD_GIT_URL_DEFAULT
    if 'git_rev' not in config_data['knative']:
        revision = 'master' if 'SNAPSHOT' in __version__ else __version__
        config_data['knative']['git_rev'] = revision

    if 'cpu' not in config_data['knative']:
        config_data['knative']['cpu'] = RUNTIME_CPU_DEFAULT

    if 'runtime_memory' not in config_data['lithops']:
        config_data['lithops']['runtime_memory'] = RUNTIME_MEMORY_DEFAULT
    if 'runtime_timeout' not in config_data['lithops']:
        config_data['lithops']['runtime_timeout'] = RUNTIME_TIMEOUT_DEFAULT

    if 'docker_repo' not in config_data['knative']:
        config_data['knative']['docker_repo'] = DOCKER_REPO_DEFAULT

    if 'runtime' not in config_data['lithops']:
        docker_user = config_data['knative']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'SNAPSHOT' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME_DEFAULT,
                                             python_version, revision)
        config_data['lithops']['runtime'] = runtime_name

    if 'workers' not in config_data['lithops']:
        config_data['lithops']['workers'] = CONCURRENT_WORKERS_DEFAULT

    if 'ibm_cos' in config_data and 'private_endpoint' in config_data[
            'ibm_cos']:
        del config_data['ibm_cos']['private_endpoint']
예제 #8
0
def load_config(config_data):

    if 'ibm' in config_data and config_data['ibm'] is not None:
        config_data['code_engine'].update(config_data['ibm'])

    for key in DEFAULT_CONFIG_KEYS:
        if key not in config_data['code_engine']:
            config_data['code_engine'][key] = DEFAULT_CONFIG_KEYS[key]

    if 'runtime' not in config_data['code_engine']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "code_engine" section')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['code_engine']['runtime'] = runtime_name

    runtime_cpu = config_data['code_engine']['runtime_cpu']
    if runtime_cpu not in VALID_CPU_VALUES:
        raise Exception('{} is an invalid runtime cpu value. Set one of: '
                        '{}'.format(runtime_cpu, VALID_CPU_VALUES))

    runtime_memory = config_data['code_engine']['runtime_memory']
    if runtime_memory not in VALID_MEMORY_VALUES:
        raise Exception('{} is an invalid runtime memory value in MB. Set one of: '
                        '{}'.format(runtime_memory, VALID_MEMORY_VALUES))

    region = config_data['code_engine'].get('region')
    if region and region not in VALID_REGIONS:
        raise Exception('{} is an invalid region name. Set one of: '
                        '{}'.format(region, VALID_REGIONS))
예제 #9
0
def load_config(config_data):
    if 'cloudrun' not in config_data:
        raise Exception("cloudrun section is mandatory in configuration")

    required_keys = ('project_id', 'region')
    if not set(required_keys) <= set(config_data['cloudrun']):
        raise Exception('You must provide {} to access to Cloud Run'.format(required_keys))

    if 'runtime_memory' not in config_data['lithops']:
        config_data['lithops']['runtime_memory'] = RUNTIME_MEMORY_DEFAULT
    if 'runtime_timeout' not in config_data['lithops']:
        config_data['lithops']['runtime_timeout'] = RUNTIME_TIMEOUT_DEFAULT

    if 'runtime' not in config_data['lithops']:
        project_id = config_data['cloudrun']['project_id']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'SNAPSHOT' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(project_id, RUNTIME_NAME_DEFAULT, python_version, revision)
        config_data['lithops']['runtime'] = runtime_name

    if 'workers' not in config_data['lithops']:
        config_data['cloudrun']['workers'] = CONCURRENT_WORKERS_DEFAULT
        config_data['lithops']['workers'] = CONCURRENT_WORKERS_DEFAULT
예제 #10
0
파일: cloudrun.py 프로젝트: cclauss/lithops
 def _get_default_runtime_image_name(self):
     project_id = self.cloudrun_config['project_id']
     python_version = version_str(sys.version_info).replace('.', '')
     revision = 'latest' if 'SNAPSHOT' in __version__ else __version__.replace('.', '')
     return '{}/{}-v{}:{}'.format(project_id, cr_config.RUNTIME_NAME_DEFAULT, python_version, revision)
예제 #11
0
 def _get_default_runtime_image_name(self):
     docker_user = self.code_engine_config.get('docker_user')
     python_version = version_str(sys.version_info).replace('.', '')
     revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
     return '{}/{}-v{}:{}'.format(docker_user, ce_config.RUNTIME_NAME, python_version, revision)
예제 #12
0
 def _get_default_runtime_image_name(self):
     py_version = version_str(sys.version_info).replace('.', '')
     revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
     runtime_name = '{}-{}-v{}-{}'.format(self.storage_account, az_config.RUNTIME_NAME,
                                          py_version, revision)
     return runtime_name
예제 #13
0
 def _get_default_runtime_image_name(self):
     docker_user = self.knative_config['docker_user']
     python_version = version_str(sys.version_info).replace('.', '')
     revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
     return '{}/{}-v{}:{}'.format(docker_user, kconfig.RUNTIME_NAME_DEFAULT, python_version, revision)
예제 #14
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'kubectl_config' in config_data['code_engine']:
        print(
            '"kubectl_config" variable in code_engine config is deprecated, use "kubecfg_path" instead'
        )
        config_data['code_engine']['kubecfg_path'] = config_data[
            'code_engine']['kubectl_config']

    if 'cpu' in config_data['code_engine']:
        print(
            '"cpu" variable in code_engine config is deprecated, use "runtime_cpu" instead'
        )
        config_data['code_engine']['runtime_cpu'] = config_data['code_engine'][
            'cpu']

    if 'runtime_cpu' not in config_data['code_engine']:
        config_data['code_engine']['runtime_cpu'] = RUNTIME_CPU

    if 'container_registry' not in config_data['code_engine']:
        config_data['code_engine']['container_registry'] = CONTAINER_REGISTRY

    if 'ibm' in config_data and config_data['ibm'] is not None:
        config_data['code_engine'].update(config_data['ibm'])

    # shared keys
    if 'runtime' in config_data['code_engine']:
        config_data['serverless']['runtime'] = config_data['code_engine'][
            'runtime']
    if 'runtime_memory' in config_data['code_engine']:
        config_data['serverless']['runtime_memory'] = config_data[
            'code_engine']['runtime_memory']
    if 'runtime_timeout' in config_data['code_engine']:
        config_data['serverless']['runtime_timeout'] = config_data[
            'code_engine']['runtime_timeout']

    if 'runtime_cpu' not in config_data['code_engine']:
        config_data['code_engine']['runtime_cpu'] = RUNTIME_CPU
    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT
    if 'runtime' not in config_data['serverless']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['serverless']['runtime'] = runtime_name

    else:
        if config_data['serverless']['runtime'].count('/') > 1:
            # container registry is in the provided runtime name
            cr, rn = config_data['serverless']['runtime'].split('/', 1)
            config_data['code_engine']['container_registry'] = cr
            config_data['serverless']['runtime'] = rn

    runtime_cpu = config_data['code_engine']['runtime_cpu']
    if runtime_cpu not in VALID_CPU_VALUES:
        raise Exception('{} is an invalid runtime cpu value. Set one of: '
                        '{}'.format(runtime_cpu, VALID_CPU_VALUES))

    runtime_memory = config_data['serverless']['runtime_memory']
    if runtime_memory not in VALID_MEMORY_VALUES:
        raise Exception(
            '{} is an invalid runtime memory value in MB. Set one of: '
            '{}'.format(runtime_memory, VALID_MEMORY_VALUES))

    region = config_data['code_engine'].get('region')
    if region and region not in VALID_REGIONS:
        raise Exception('{} is an invalid region name. Set one of: '
                        '{}'.format(region, VALID_REGIONS))

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS

    if 'invoke_pool_threads' not in config_data['code_engine']:
        config_data['code_engine'][
            'invoke_pool_threads'] = INVOKE_POOL_THREADS_DEFAULT
    config_data['serverless']['invoke_pool_threads'] = config_data[
        'code_engine']['invoke_pool_threads']