Initial Scan Job Template type implementation

This commit is contained in:
Matthew Jones
2015-03-03 14:48:22 -05:00
parent f6faff5b14
commit 4d271bef35
6 changed files with 41 additions and 17 deletions

View File

@@ -1304,11 +1304,19 @@ class JobOptionsSerializer(BaseSerializer):
ret['cloud_credential'] = None
return ret
def validate_project(self, attrs, source):
project = attrs.get('project', None)
if not project and attrs.get('job_type') != PERM_INVENTORY_SCAN:
raise serializers.ValidationError("This field is required")
return attrs
def validate_playbook(self, attrs, source):
project = attrs.get('project', None)
playbook = attrs.get('playbook', '')
if project and playbook and smart_str(playbook) not in project.playbooks:
raise serializers.ValidationError('Playbook not found for project')
if project and not playbook:
raise serializers.ValidationError('Must select playbook for project')
return attrs
@@ -1470,14 +1478,12 @@ class SystemJobSerializer(UnifiedJobSerializer):
args=(obj.system_job_template.pk,))
return res
class JobListSerializer(JobSerializer, UnifiedJobListSerializer):
pass
class SystemJobListSerializer(SystemJobSerializer, UnifiedJobListSerializer):
pass
class JobHostSummarySerializer(BaseSerializer):
class Meta:

View File

@@ -1451,7 +1451,7 @@ class JobTemplateLaunch(GenericAPIView):
status=status.HTTP_400_BAD_REQUEST)
if obj.credential is None and ('credential' not in request.DATA and 'credential_id' not in request.DATA):
return Response(dict(errors="Credential not provided"), status=status.HTTP_400_BAD_REQUEST)
if obj.project is None or not obj.project.active:
if obj.job_type != PERM_INVENTORY_SCAN and (obj.project is None or not obj.project.active):
return Response(dict(errors="Job Template Project is missing or undefined"), status=status.HTTP_400_BAD_REQUEST)
if obj.inventory is None or not obj.inventory.active:
return Response(dict(errors="Job Template Inventory is missing or undefined"), status=status.HTTP_400_BAD_REQUEST)