mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 21:51:26 -03:30
Create /inventories/N/update_inventory_sources endpoint
This commit is contained in:
parent
44c1935590
commit
0e816a2d98
@ -1121,6 +1121,7 @@ class InventorySerializer(BaseSerializerWithVariables):
|
||||
script = self.reverse('api:inventory_script_view', kwargs={'pk': obj.pk}),
|
||||
tree = self.reverse('api:inventory_tree_view', kwargs={'pk': obj.pk}),
|
||||
inventory_sources = self.reverse('api:inventory_inventory_sources_list', kwargs={'pk': obj.pk}),
|
||||
update_inventory_sources = self.reverse('api:inventory_inventory_sources_update', kwargs={'pk': obj.pk}),
|
||||
activity_stream = self.reverse('api:inventory_activity_stream_list', kwargs={'pk': obj.pk}),
|
||||
job_templates = self.reverse('api:inventory_job_template_list', kwargs={'pk': obj.pk}),
|
||||
scan_job_templates = self.reverse('api:inventory_scan_job_template_list', kwargs={'pk': obj.pk}),
|
||||
|
||||
@ -93,6 +93,7 @@ inventory_urls = patterns('awx.api.views',
|
||||
url(r'^(?P<pk>[0-9]+)/script/$', 'inventory_script_view'),
|
||||
url(r'^(?P<pk>[0-9]+)/tree/$', 'inventory_tree_view'),
|
||||
url(r'^(?P<pk>[0-9]+)/inventory_sources/$', 'inventory_inventory_sources_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/update_inventory_sources/$', 'inventory_inventory_sources_update'),
|
||||
url(r'^(?P<pk>[0-9]+)/activity_stream/$', 'inventory_activity_stream_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/job_templates/$', 'inventory_job_template_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/scan_job_templates/$', 'inventory_scan_job_template_list'),
|
||||
|
||||
@ -2306,6 +2306,45 @@ class InventoryInventorySourcesList(SubListCreateAPIView):
|
||||
new_in_14 = True
|
||||
|
||||
|
||||
class InventoryInventorySourcesUpdate(RetrieveAPIView):
|
||||
view_name = _('Inventory Sources Update')
|
||||
|
||||
model = Inventory
|
||||
serializer_class = InventorySourceUpdateSerializer
|
||||
is_job_start = True
|
||||
new_in_320 = True
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
inventory = self.get_object()
|
||||
update_data = []
|
||||
for inventory_source in inventory.inventory_sources.all():
|
||||
details = {'inventory_source': inventory_source.pk,
|
||||
'can_update': inventory_source.can_update}
|
||||
update_data.append(details)
|
||||
return Response(update_data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
inventory = self.get_object()
|
||||
update_data = []
|
||||
for inventory_source in inventory.inventory_sources.all():
|
||||
details = {'inventory_source': inventory_source.pk, 'status': None, 'inventory_update': None}
|
||||
can_update = inventory_source.can_update
|
||||
|
||||
if inventory_source.source == 'scm' and inventory_source.update_on_project_update:
|
||||
if not self.request.user or self.request.user.can_access(self.model, 'update', inventory_source):
|
||||
details['status'] = 'You do not have permission to update project `{}`'.format(inventory_source.source_project.name)
|
||||
can_update = False
|
||||
|
||||
if can_update:
|
||||
details['status'] = 'started'
|
||||
details['inventory_update'] = inventory_source.update().id
|
||||
else:
|
||||
if not details.get('status'):
|
||||
details['status'] = 'Could not start because `can_update` returned False'
|
||||
update_data.append(details)
|
||||
return Response(update_data, status=status.HTTP_202_ACCEPTED)
|
||||
|
||||
|
||||
class InventorySourceList(ListCreateAPIView):
|
||||
|
||||
model = InventorySource
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user