diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 29bef49bb9..f706da2cd4 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -736,6 +736,7 @@ class InventorySourceOptions(BaseModel): ('file', _('Local File, Directory or Script')), ('rax', _('Rackspace Cloud Servers')), ('ec2', _('Amazon EC2')), + ('gce', _('Google Compute Engine')), ] class Meta: @@ -826,13 +827,15 @@ class InventorySourceOptions(BaseModel): return None cred = self.credential if cred: - if self.source == 'ec2' and cred.kind != 'aws': - raise ValidationError('Credential kind must be "aws" for an ' - '"ec2" source') - if self.source == 'rax' and cred.kind != 'rax': - raise ValidationError('Credential kind must be "rax" for a ' - '"rax" source') - elif self.source in ('ec2', 'rax'): + # If a credential was provided, it's important that it matches + # the actual inventory source being used (Amazon requires Amazon + # credentials; Rackspace requires Rackspace credentials; etc...) + if self.source.replace('ec2', 'awx') != cred.kind: + raise ValidationError( + 'Cloud-based inventory sources (such as %s) require ' + 'credentials for the matching cloud service.' % self.source + ) + elif self.source in ('ec2', 'rax', 'gce'): raise ValidationError('Credential is required for a cloud source') return cred diff --git a/awx/ui/static/js/forms/Source.js b/awx/ui/static/js/forms/Source.js index 1d18b93566..add3e48feb 100644 --- a/awx/ui/static/js/forms/Source.js +++ b/awx/ui/static/js/forms/Source.js @@ -47,7 +47,7 @@ angular.module('SourceFormDefinition', []) source_regions: { label: 'Regions', type: 'text', - ngShow: "source && (source.value == 'rax' || source.value == 'ec2')", + ngShow: "source && (source.value == 'rax' || source.value == 'ec2' || source.value == 'gce')", addRequired: false, editRequired: false, awMultiselect: 'source_region_choices', @@ -155,4 +155,4 @@ angular.module('SourceFormDefinition', []) related: { } - }); \ No newline at end of file + }); diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index e7d9c04b47..3a911dc92a 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -1027,6 +1027,15 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched callback: 'choicesReadyGroup' }); + GetChoices({ + scope: sources_scope, + url: GetBasePath('inventory_sources'), + field: 'source_regions', + variable: 'gce_regions', + choice_name: 'gce_region_choices', + callback: 'choicesReadyGroup' + }); + Wait('start'); if (parent_scope.removeAddTreeRefreshed) { @@ -1864,4 +1873,4 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched }; } -]); \ No newline at end of file +]);