Пример #1
0
def validate_instance_parameters(params: dict):
    from spotty.providers.aws.config.instance_config import VOLUME_TYPE_EBS

    instance_parameters = {
        'region':
        And(str, Regex(r'^[a-z0-9-]+$')),
        Optional('availabilityZone', default=''):
        And(str, Regex(r'^[a-z0-9-]+$')),
        Optional('subnetId', default=''):
        And(str, Regex(r'^subnet-[a-z0-9]+$')),
        'instanceType':
        str,
        Optional('onDemandInstance', default=False):
        bool,
        Optional('amiName', default=None):
        And(str, len, Regex(r'^[\w\(\)\[\]\s\.\/\'@-]{3,128}$')),
        Optional('amiId', default=None):
        And(str, len, Regex(r'^ami-[a-z0-9]+$')),
        Optional('rootVolumeSize', default=0):
        And(
            Or(int, str),
            Use(str),
            Regex(r'^\d+$', error='Incorrect value for "rootVolumeSize".'),
            Use(int),
            And(lambda x: x > 0,
                error='"rootVolumeSize" should be greater than 0 or should '
                'not be specified.'),
        ),
        Optional('maxPrice', default=0):
        And(
            Or(float, int, str),
            Use(str),
            Regex(r'^\d+(\.\d{1,6})?$',
                  error='Incorrect value for "maxPrice".'),
            Use(float),
            And(lambda x: x > 0,
                error='"maxPrice" should be greater than 0 or '
                'should  not be specified.'),
        ),
        Optional('managedPolicyArns', default=[]): [str],
        Optional('ingressCidr', default=[]): [str],
    }

    volumes_checks = [
        And(lambda x: len(x) < 12,
            error='Maximum 11 volumes are supported at the moment.'),
    ]

    instance_checks = [
        And(lambda x: not (x['onDemandInstance'] and x['maxPrice']),
            error='"maxPrice" cannot be specified for on-demand instances.'),
        And(lambda x: not (x['amiName'] and x['amiId']),
            error='"amiName" and "amiId" parameters cannot be used together.'),
    ]

    schema = get_instance_parameters_schema(instance_parameters,
                                            VOLUME_TYPE_EBS, instance_checks,
                                            volumes_checks)

    return validate_config(schema, params)
Пример #2
0
def validate_instance_parameters(params: dict):
    from spotty.config.host_path_volume import HostPathVolume

    instance_parameters = {
        'user': str,
        'host': str,
        Optional('port', default=22): And(int, lambda x: 0 < x < 65536),
        'keyPath': str,
    }

    schema = get_instance_parameters_schema(instance_parameters, HostPathVolume.TYPE_NAME)

    return validate_config(schema, params)
Пример #3
0
def validate_instance_parameters(params: dict):
    from spotty.providers.gcp.config.instance_config import VOLUME_TYPE_DISK

    instance_parameters = {
        'zone':
        And(str, Regex(r'^[a-z0-9-]+$')),
        'machineType':
        And(str, And(is_valid_machine_type, error='Invalid instance type.')),
        Optional('gpu', default=None): {
            'type': str,
            Optional('count', default=1): int,
        },
        Optional('onDemandInstance', default=False):
        bool,
        Optional('imageName', default=None):
        And(str, len, Regex(r'^[\w-]+$')),
        Optional('imageUrl', default=None):
        And(str, len, Regex(IMAGE_URL_REGEX)),
        Optional('bootDiskSize', default=0):
        And(
            Or(int, str),
            Use(str),
            Regex(r'^\d+$', error='Incorrect value for "bootDiskSize".'),
            Use(int),
            And(lambda x: x > 0,
                error='"rootVolumeSize" should be greater than 0 or should '
                'not be specified.'),
        ),
    }

    instance_checks = [
        And(lambda x: not x['gpu'] or is_gpu_machine_type(x['machineType']),
            error=
            'GPU cannot be attached to shared-core or memory-optimized machine types.'
            ),
        And(lambda x: not (x['imageName'] and x['imageUrl']),
            error=
            '"imageName" and "imageUrl" parameters cannot be used together.'),
    ]

    schema = get_instance_parameters_schema(instance_parameters,
                                            VOLUME_TYPE_DISK, instance_checks,
                                            [])

    return validate_config(schema, params)
Пример #4
0
def validate_instance_parameters(params: dict):
    from spotty.providers.gcp.config.disk_volume import DiskVolume

    instance_parameters = {
        'zone': And(str, Regex(r'^[a-z0-9-]+$')),
        'machineType': str,
        Optional('gpu', default=None): {
            'type': str,
            Optional('count', default=1): int,
        },
        Optional('preemptibleInstance', default=False): bool,
        Optional('imageName', default=None): And(str, len, Regex(r'^[\w-]+$')),
        Optional('imageUri', default=None): And(str, len, Regex(IMAGE_URI_REGEX)),
        Optional('bootDiskSize', default=0): And(Or(int, str), Use(str),
                                                 Regex(r'^\d+$', error='Incorrect value for "bootDiskSize".'),
                                                 Use(int),
                                                 And(lambda x: x > 0,
                                                     error='"rootVolumeSize" should be greater than 0 or should '
                                                           'not be specified.'),
                                                 ),
        Optional('ports', default=[]): [And(int, lambda x: 0 < x < 65536)],
    }

    instance_checks = [
        And(lambda x: not (x['imageName'] and x['imageUri']),
            error='"imageName" and "imageUri" parameters cannot be used together.'),
    ]

    volume_checks = [
        And(lambda x: not has_prefix([(volume['parameters']['mountDir'] + '/') for volume in x
                                      if volume['parameters'].get('mountDir')]),
            error='Mount directories cannot be prefixes for each other.'),
    ]

    schema = get_instance_parameters_schema(instance_parameters, DiskVolume.TYPE_NAME, instance_checks, volume_checks)

    return validate_config(schema, params)
Пример #5
0
def validate_instance_parameters(params: dict):
    from spotty.providers.aws.config.ebs_volume import EbsVolume

    instance_parameters = {
        'region':
        And(str, Regex(r'^[a-z0-9-]+$')),
        Optional('availabilityZone', default=''):
        And(str, Regex(r'^[a-z0-9-]+$')),
        Optional('subnetId', default=''):
        And(str, Regex(r'^subnet-[a-z0-9]+$')),
        'instanceType':
        str,
        Optional('spotInstance', default=False):
        bool,
        Optional('amiName', default=None):
        And(str, len, Regex(r'^[\w\(\)\[\]\s\.\/\'@-]{3,128}$')),
        Optional('amiId', default=None):
        And(str, len, Regex(r'^ami-[a-z0-9]+$')),
        Optional('rootVolumeSize', default=0):
        And(
            Or(int, str),
            Use(str),
            Regex(r'^\d+$', error='Incorrect value for "rootVolumeSize".'),
            Use(int),
            And(lambda x: x > 0,
                error='"rootVolumeSize" should be greater than 0 or should '
                'not be specified.'),
        ),
        Optional('ports', default=[]): [And(int, lambda x: 0 < x < 65536)],
        Optional('maxPrice', default=0):
        And(
            Or(float, int, str),
            Use(str),
            Regex(r'^\d+(\.\d{1,6})?$',
                  error='Incorrect value for "maxPrice".'),
            Use(float),
            And(lambda x: x > 0,
                error='"maxPrice" should be greater than 0 or '
                'should  not be specified.'),
        ),
        Optional('managedPolicyArns', default=[]): [str],
        Optional('instanceProfileArn', default=None):
        str,
    }

    volumes_checks = [
        And(lambda x: len(x) < 12,
            error='Maximum 11 volumes are supported at the moment.'),
        And(lambda x: not has_prefix([(volume['parameters']['mountDir'] + '/')
                                      for volume in x if volume['parameters'].
                                      get('mountDir')]),
            error='Mount directories cannot be prefixes for each other.'),
    ]

    instance_checks = [
        And(lambda x: not (x['maxPrice'] and not x['spotInstance']),
            error='"maxPrice" can be specified only for spot instances.'),
        And(lambda x: not (x['amiName'] and x['amiId']),
            error='"amiName" and "amiId" parameters cannot be used together.'),
    ]

    schema = get_instance_parameters_schema(instance_parameters,
                                            EbsVolume.TYPE_NAME,
                                            instance_checks, volumes_checks)

    return validate_config(schema, params)
Пример #6
0
def validate_instance_parameters(params: dict):
    from spotty.config.host_path_volume import HostPathVolume

    schema = get_instance_parameters_schema({}, HostPathVolume.TYPE_NAME)

    return validate_config(schema, params)