예제 #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_ebs_volume_parameters(params: dict):
    from spotty.providers.aws.deployment.project_resources.ebs_volume import EbsVolume

    schema = Schema({
        Optional('volumeName', default=''): And(str, Regex(r'^[\w-]{1,255}$')),
        Optional('mountDir', default=''): str,  # all the checks happened in the base configuration
        Optional('size', default=0): And(int, lambda x: x > 0),
        Optional('deletionPolicy', default=EbsVolume.DP_CREATE_SNAPSHOT): And(
            str,
            lambda x: x in [EbsVolume.DP_CREATE_SNAPSHOT,
                            EbsVolume.DP_UPDATE_SNAPSHOT,
                            EbsVolume.DP_RETAIN,
                            EbsVolume.DP_DELETE], error='Incorrect value for "deletionPolicy".'
        ),
    })

    return validate_config(schema, params)
예제 #4
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)
예제 #5
0
def validate_disk_volume_parameters(params: dict):
    from spotty.providers.gcp.config.disk_volume import DiskVolume

    schema = Schema({
        Optional('diskName', default=''): And(str, Regex(r'^[\w-]{1,255}$')),
        Optional('mountDir', default=''): And(
            str,
            And(os.path.isabs, error='Use absolute paths in the "mountDir" parameters'),
            Use(lambda x: x.rstrip('/'))
        ),
        Optional('size', default=0): And(int, lambda x: x > 0),
        Optional('deletionPolicy', default=DiskVolume.DP_RETAIN): And(
            str,
            lambda x: x in [DiskVolume.DP_CREATE_SNAPSHOT,
                            DiskVolume.DP_UPDATE_SNAPSHOT,
                            DiskVolume.DP_RETAIN,
                            DiskVolume.DP_DELETE], error='Incorrect value for "deletionPolicy".'
        ),
    })

    return validate_config(schema, params)
예제 #6
0
def validate_ebs_volume_parameters(params: dict):
    from spotty.providers.aws.config.ebs_volume import EbsVolume

    old_deletion_policies_map = {
        'create_snapshot': EbsVolume.DP_CREATE_SNAPSHOT,
        'update_snapshot': EbsVolume.DP_UPDATE_SNAPSHOT,
        'retain': EbsVolume.DP_RETAIN,
        'delete': EbsVolume.DP_DELETE,
    }

    schema = Schema({
        Optional('volumeName', default=''):
        And(str, Regex(r'^[\w-]{1,255}$')),
        Optional('mountDir', default=''):
        And(
            str,
            And(os.path.isabs,
                error='Use absolute paths in the "mountDir" parameters'),
            Use(lambda x: x.rstrip('/'))),
        Optional('size', default=0):
        And(int, lambda x: x > 0),
        # TODO: add the "iops" parameter to support the "io1" EBS volume type
        Optional('type', default='gp2'):
        lambda x: x in ['gp2', 'sc1', 'st1', 'standard'],
        Optional('deletionPolicy', default=EbsVolume.DP_RETAIN):
        And(
            str,
            lambda x: x in [
                EbsVolume.DP_CREATE_SNAPSHOT, EbsVolume.DP_UPDATE_SNAPSHOT,
                EbsVolume.DP_RETAIN, EbsVolume.DP_DELETE
            ] + list(old_deletion_policies_map.keys()),
            Use(lambda x: old_deletion_policies_map.get(x, x)),
            error='Incorrect value for "deletionPolicy".',
        ),
    })

    return validate_config(schema, params)
예제 #7
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)
예제 #8
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)
예제 #9
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)