class AWSFilterSerializer(FilterSerializer): """Serializer for handling tag query parameter filter.""" account = StringOrListField(child=serializers.CharField(), required=False) def __init__(self, *args, **kwargs): """Initialize the AWSFilterSerializer.""" super().__init__(*args, **kwargs) add_operator_specified_fields(self.fields, AWS_FILTER_OP_FIELDS)
class AzureFilterSerializer(FilterSerializer): """Serializer for handling tag query parameter filter.""" subscription_guid = StringOrListField(child=serializers.CharField(), required=False) enabled = serializers.BooleanField(default=True, required=False) def __init__(self, *args, **kwargs): """Initialize the AzureFilterSerializer.""" super().__init__(*args, **kwargs) add_operator_specified_fields(self.fields, AZURE_FILTER_OP_FIELDS)
class OCPFilterSerializer(FilterSerializer): """Serializer for handling tag query parameter filter.""" TYPE_CHOICES = (("pod", "pod"), ("storage", "storage"), ("*", "*")) type = serializers.ChoiceField(choices=TYPE_CHOICES, required=False) project = StringOrListField(child=serializers.CharField(), required=False) enabled = serializers.BooleanField(default=True, required=False) def __init__(self, *args, **kwargs): """Initialize the OCPFilterSerializer.""" super().__init__(*args, **kwargs) add_operator_specified_fields(self.fields, OCP_FILTER_OP_FIELDS)
class OCPFilterSerializer(FilterSerializer): """Serializer for handling tag query parameter filter.""" TYPE_CHOICES = (('pod', 'pod'), ('storage', 'storage')) type = serializers.ChoiceField(choices=TYPE_CHOICES, required=False) project = StringOrListField(child=serializers.CharField(), required=False) def __init__(self, *args, **kwargs): """Initialize the OCPFilterSerializer.""" super().__init__(*args, **kwargs) add_operator_specified_fields(self.fields, OCP_FILTER_OP_FIELDS)
def __init__(self, *args, **kwargs): """Initialize the FilterSerializer.""" tag_keys = kwargs.pop('tag_keys', None) super().__init__(*args, **kwargs) if tag_keys is not None: tag_keys = { key: StringOrListField(child=serializers.CharField(), required=False) for key in tag_keys } # Add AWS tag keys to allowable fields self.fields.update(tag_keys)
class GroupBySerializer(serializers.Serializer): """Serializer for handling query parameter group_by.""" account = StringOrListField(child=serializers.CharField(), required=False) avail_zone = StringOrListField(child=serializers.CharField(), required=False) instance_type = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) storage_type = StringOrListField(child=serializers.CharField(), required=False) def validate(self, data): """Validate incoming data. Args: data (Dict): data to be validated Returns: (Dict): Validated data Raises: (ValidationError): if field inputs are invalid """ handle_invalid_fields(self, data) return data
class FilterSerializer(BaseFilterSerializer): """Serializer for handling query parameter filter.""" INFRASTRUCTURE_CHOICES = ( ('aws', 'aws'), ('azure', 'azure'), ) _opfields = ('project', 'cluster', 'node', 'pod', 'infrastructures') project = StringOrListField(child=serializers.CharField(), required=False) cluster = StringOrListField(child=serializers.CharField(), required=False) pod = StringOrListField(child=serializers.CharField(), required=False) node = StringOrListField(child=serializers.CharField(), required=False) infrastructures = serializers.ChoiceField(choices=INFRASTRUCTURE_CHOICES, required=False) def validate(self, data): """Validate incoming data. Args: data (Dict): data to be validated Returns: (Dict): Validated data Raises: (ValidationError): if filter inputs are invalid """ super().validate(data) if data.get('infrastructures'): infra_value = data['infrastructures'] data['infrastructures'] = [infra_value.upper()] return data
class GroupBySerializer(GroupSerializer): """Serializer for handling query parameter group_by.""" _opfields = ("account", "az", "instance_type", "region", "service", "storage_type", "product_family") # account field will accept both account number and account alias. account = StringOrListField(child=serializers.CharField(), required=False) az = StringOrListField(child=serializers.CharField(), required=False) instance_type = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) storage_type = StringOrListField(child=serializers.CharField(), required=False) product_family = StringOrListField(child=serializers.CharField(), required=False)
class FilterSerializer(BaseFilterSerializer): """Serializer for handling query parameter filter.""" _opfields = ("account", "service", "region", "az", "product_family", "org_unit_id") account = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) az = StringOrListField(child=serializers.CharField(), required=False) product_family = StringOrListField(child=serializers.CharField(), required=False) org_unit_id = StringOrListField(child=serializers.CharField(), required=False)
class GroupBySerializer(serializers.Serializer): """Serializer for handling query parameter group_by.""" account = StringOrListField(child=serializers.CharField(), required=False) az = StringOrListField(child=serializers.CharField(), required=False) instance_type = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) storage_type = StringOrListField(child=serializers.CharField(), required=False) product_family = StringOrListField(child=serializers.CharField(), required=False) def __init__(self, *args, **kwargs): """Initialize the GroupBySerializer.""" tag_keys = kwargs.pop('tag_keys', None) super().__init__(*args, **kwargs) if tag_keys is not None: tag_keys = { key: StringOrListField(child=serializers.CharField(), required=False) for key in tag_keys } # Add AWS tag keys to allowable fields self.fields.update(tag_keys) def validate(self, data): """Validate incoming data. Args: data (Dict): data to be validated Returns: (Dict): Validated data Raises: (ValidationError): if field inputs are invalid """ handle_invalid_fields(self, data) return data
class FilterSerializer(serializers.Serializer): """Serializer for handling query parameter filter.""" RESOLUTION_CHOICES = ( ('daily', 'daily'), ('monthly', 'monthly'), ) TIME_CHOICES = ( ('-10', '-10'), ('-30', '-30'), ('-1', '1'), ('-2', '-2'), ) TIME_UNIT_CHOICES = ( ('day', 'day'), ('month', 'month'), ) resolution = serializers.ChoiceField(choices=RESOLUTION_CHOICES, required=False) time_scope_value = serializers.ChoiceField(choices=TIME_CHOICES, required=False) time_scope_units = serializers.ChoiceField(choices=TIME_UNIT_CHOICES, required=False) resource_scope = StringOrListField(child=serializers.CharField(), required=False) limit = serializers.IntegerField(required=False, min_value=1) account = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) avail_zone = StringOrListField(child=serializers.CharField(), required=False) def validate(self, data): """Validate incoming data. Args: data (Dict): data to be validated Returns: (Dict): Validated data Raises: (ValidationError): if filter inputs are invalid """ handle_invalid_fields(self, data) resolution = data.get('resolution') time_scope_value = data.get('time_scope_value') time_scope_units = data.get('time_scope_units') if time_scope_units and time_scope_value: msg = 'Valid values are {} when time_scope_units is {}' if (time_scope_units == 'day' and # noqa: W504 (time_scope_value == '-1' or time_scope_value == '-2')): valid_values = ['-10', '-30'] valid_vals = ', '.join(valid_values) error = {'time_scope_value': msg.format(valid_vals, 'day')} raise serializers.ValidationError(error) if (time_scope_units == 'day' and resolution == 'monthly'): valid_values = ['daily'] valid_vals = ', '.join(valid_values) error = {'resolution': msg.format(valid_vals, 'day')} raise serializers.ValidationError(error) if (time_scope_units == 'month' and # noqa: W504 (time_scope_value == '-10' or time_scope_value == '-30')): valid_values = ['-1', '-2'] valid_vals = ', '.join(valid_values) error = {'time_scope_value': msg.format(valid_vals, 'month')} raise serializers.ValidationError(error) return data
class FilterSerializer(serializers.Serializer): """Serializer for handling query parameter filter.""" # IMPORTANT: Changing these serializer choices impacts the aggregate tables. # Don't change these without coordinating the change across to Masu. RESOLUTION_CHOICES = ( ('daily', 'daily'), ('monthly', 'monthly'), ) TIME_CHOICES = ( ('-10', '-10'), ('-30', '-30'), ('-1', '1'), ('-2', '-2'), ) TIME_UNIT_CHOICES = ( ('day', 'day'), ('month', 'month'), ) resolution = serializers.ChoiceField(choices=RESOLUTION_CHOICES, required=False) time_scope_value = serializers.ChoiceField(choices=TIME_CHOICES, required=False) time_scope_units = serializers.ChoiceField(choices=TIME_UNIT_CHOICES, required=False) resource_scope = StringOrListField(child=serializers.CharField(), required=False) limit = serializers.IntegerField(required=False, min_value=1) offset = serializers.IntegerField(required=False, min_value=0) account = StringOrListField(child=serializers.CharField(), required=False) service = StringOrListField(child=serializers.CharField(), required=False) region = StringOrListField(child=serializers.CharField(), required=False) az = StringOrListField(child=serializers.CharField(), required=False) product_family = StringOrListField(child=serializers.CharField(), required=False) def __init__(self, *args, **kwargs): """Initialize the FilterSerializer.""" tag_keys = kwargs.pop('tag_keys', None) super().__init__(*args, **kwargs) if tag_keys is not None: tag_keys = { key: StringOrListField(child=serializers.CharField(), required=False) for key in tag_keys } # Add AWS tag keys to allowable fields self.fields.update(tag_keys) def validate(self, data): """Validate incoming data. Args: data (Dict): data to be validated Returns: (Dict): Validated data Raises: (ValidationError): if filter inputs are invalid """ handle_invalid_fields(self, data) resolution = data.get('resolution') time_scope_value = data.get('time_scope_value') time_scope_units = data.get('time_scope_units') if time_scope_units and time_scope_value: msg = 'Valid values are {} when time_scope_units is {}' if (time_scope_units == 'day' and # noqa: W504 (time_scope_value == '-1' or time_scope_value == '-2')): valid_values = ['-10', '-30'] valid_vals = ', '.join(valid_values) error = {'time_scope_value': msg.format(valid_vals, 'day')} raise serializers.ValidationError(error) if (time_scope_units == 'day' and resolution == 'monthly'): valid_values = ['daily'] valid_vals = ', '.join(valid_values) error = {'resolution': msg.format(valid_vals, 'day')} raise serializers.ValidationError(error) if (time_scope_units == 'month' and # noqa: W504 (time_scope_value == '-10' or time_scope_value == '-30')): valid_values = ['-1', '-2'] valid_vals = ', '.join(valid_values) error = {'time_scope_value': msg.format(valid_vals, 'month')} raise serializers.ValidationError(error) return data
class OCPAWSFilterSerializer(FilterSerializer): """Serializer for handling query parameter filter.""" project = StringOrListField(child=serializers.CharField(), required=False) cluster = StringOrListField(child=serializers.CharField(), required=False) node = StringOrListField(child=serializers.CharField(), required=False)
class OCPAWSOrderBySerializer(OrderBySerializer): """Serializer for handling query parameter order_by.""" project = StringOrListField(child=serializers.CharField(), required=False) cluster = StringOrListField(child=serializers.CharField(), required=False) node = StringOrListField(child=serializers.CharField(), required=False)