mirror of
https://github.com/ansible/awx.git
synced 2026-02-21 13:10:11 -03:30
Merge pull request #385 from AlanCoding/smart_validation
fuller validation for host_filter
This commit is contained in:
@@ -1171,15 +1171,30 @@ class InventorySerializer(BaseSerializerWithVariables):
|
|||||||
ret['organization'] = None
|
ret['organization'] = None
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def validate_host_filter(self, host_filter):
|
||||||
|
if host_filter:
|
||||||
|
try:
|
||||||
|
SmartFilter().query_from_string(host_filter)
|
||||||
|
except RuntimeError, e:
|
||||||
|
raise models.base.ValidationError(e)
|
||||||
|
return host_filter
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
kind = attrs.get('kind', 'standard')
|
kind = None
|
||||||
if kind == 'smart':
|
if 'kind' in attrs:
|
||||||
host_filter = attrs.get('host_filter')
|
kind = attrs['kind']
|
||||||
if host_filter is not None:
|
elif self.instance:
|
||||||
try:
|
kind = self.instance.kind
|
||||||
SmartFilter().query_from_string(host_filter)
|
|
||||||
except RuntimeError, e:
|
host_filter = None
|
||||||
raise models.base.ValidationError(e)
|
if 'host_filter' in attrs:
|
||||||
|
host_filter = attrs['host_filter']
|
||||||
|
elif self.instance:
|
||||||
|
host_filter = self.instance.host_filter
|
||||||
|
|
||||||
|
if kind == 'smart' and not host_filter:
|
||||||
|
raise serializers.ValidationError({'host_filter': _(
|
||||||
|
'Smart inventories must specify host_filter')})
|
||||||
return super(InventorySerializer, self).validate(attrs)
|
return super(InventorySerializer, self).validate(attrs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user