refactored original hosts and renamed source_inventories to input_inventories

This commit is contained in:
Gabe Muniz
2023-02-03 10:04:58 -05:00
parent c22d8f1d7e
commit 80c15e286f
6 changed files with 12 additions and 12 deletions

View File

@@ -1702,8 +1702,8 @@ class InventorySerializer(LabelsListMixin, BaseSerializerWithVariables):
if obj.organization: if obj.organization:
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk}) res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
if obj.kind == 'constructed': if obj.kind == 'constructed':
res['source_inventories'] = self.reverse('api:inventory_source_inventories', kwargs={'pk': obj.pk}) res['input_inventories'] = self.reverse('api:inventory_input_inventories', kwargs={'pk': obj.pk})
res['url'] = self.reverse('api:constructed_inventory_detail', kwargs={'pk': obj.pk}) res['constructed_url'] = self.reverse('api:constructed_inventory_detail', kwargs={'pk': obj.pk})
return res return res
def to_representation(self, obj): def to_representation(self, obj):
@@ -1883,8 +1883,8 @@ class HostSerializer(BaseSerializerWithVariables):
ansible_facts=self.reverse('api:host_ansible_facts_detail', kwargs={'pk': obj.pk}), ansible_facts=self.reverse('api:host_ansible_facts_detail', kwargs={'pk': obj.pk}),
) )
) )
if obj.instance_id and obj.pk != obj.instance_id: if obj.inventory.kind == 'constructed':
res['original_host'] = self.reverse('api:host_detail', kwargs={'pk': obj.instance_id }), res['original_host'] = self.reverse('api:host_detail', kwargs={'pk': obj.instance_id })
if obj.inventory: if obj.inventory:
res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk}) res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk})
if obj.last_job: if obj.last_job:

View File

@@ -9,7 +9,7 @@ from awx.api.views.inventory import (
ConstructedInventoryDetail, ConstructedInventoryDetail,
ConstructedInventoryList, ConstructedInventoryList,
InventoryActivityStreamList, InventoryActivityStreamList,
InventorySourceInventoriesList, InventoryInputInventoriesList,
InventoryJobTemplateList, InventoryJobTemplateList,
InventoryAccessList, InventoryAccessList,
InventoryObjectRolesList, InventoryObjectRolesList,
@@ -40,7 +40,7 @@ urls = [
re_path(r'^(?P<pk>[0-9]+)/script/$', InventoryScriptView.as_view(), name='inventory_script_view'), re_path(r'^(?P<pk>[0-9]+)/script/$', InventoryScriptView.as_view(), name='inventory_script_view'),
re_path(r'^(?P<pk>[0-9]+)/tree/$', InventoryTreeView.as_view(), name='inventory_tree_view'), re_path(r'^(?P<pk>[0-9]+)/tree/$', InventoryTreeView.as_view(), name='inventory_tree_view'),
re_path(r'^(?P<pk>[0-9]+)/inventory_sources/$', InventoryInventorySourcesList.as_view(), name='inventory_inventory_sources_list'), re_path(r'^(?P<pk>[0-9]+)/inventory_sources/$', InventoryInventorySourcesList.as_view(), name='inventory_inventory_sources_list'),
re_path(r'^(?P<pk>[0-9]+)/source_inventories/$', InventorySourceInventoriesList.as_view(), name='inventory_source_inventories'), re_path(r'^(?P<pk>[0-9]+)/input_inventories/$', InventoryInputInventoriesList.as_view(), name='inventory_input_inventories'),
re_path(r'^(?P<pk>[0-9]+)/update_inventory_sources/$', InventoryInventorySourcesUpdate.as_view(), name='inventory_inventory_sources_update'), re_path(r'^(?P<pk>[0-9]+)/update_inventory_sources/$', InventoryInventorySourcesUpdate.as_view(), name='inventory_inventory_sources_update'),
re_path(r'^(?P<pk>[0-9]+)/activity_stream/$', InventoryActivityStreamList.as_view(), name='inventory_activity_stream_list'), re_path(r'^(?P<pk>[0-9]+)/activity_stream/$', InventoryActivityStreamList.as_view(), name='inventory_activity_stream_list'),
re_path(r'^(?P<pk>[0-9]+)/job_templates/$', InventoryJobTemplateList.as_view(), name='inventory_job_template_list'), re_path(r'^(?P<pk>[0-9]+)/job_templates/$', InventoryJobTemplateList.as_view(), name='inventory_job_template_list'),

View File

@@ -109,11 +109,11 @@ class ConstructedInventoryList(InventoryList):
return r.filter(kind='constructed') return r.filter(kind='constructed')
class InventorySourceInventoriesList(SubListAttachDetachAPIView): class InventoryInputInventoriesList(SubListAttachDetachAPIView):
model = Inventory model = Inventory
serializer_class = InventorySerializer serializer_class = InventorySerializer
parent_model = Inventory parent_model = Inventory
relationship = 'source_inventories' relationship = 'input_inventories'
class InventoryActivityStreamList(SubListAPIView): class InventoryActivityStreamList(SubListAPIView):

View File

@@ -11,7 +11,7 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='inventory', model_name='inventory',
name='source_inventories', name='input_inventories',
field=models.ManyToManyField( field=models.ManyToManyField(
blank=True, blank=True,
help_text='Only valid for constructed inventories, this links to the inventories that will be used.', help_text='Only valid for constructed inventories, this links to the inventories that will be used.',

View File

@@ -140,7 +140,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
default=None, default=None,
help_text=_('Filter that will be applied to the hosts of this inventory.'), help_text=_('Filter that will be applied to the hosts of this inventory.'),
) )
source_inventories = models.ManyToManyField( input_inventories = models.ManyToManyField(
'Inventory', 'Inventory',
blank=True, blank=True,
related_name='destination_inventories', related_name='destination_inventories',

View File

@@ -1524,10 +1524,10 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask):
# special case for constructed inventories, we pass source inventories from database # special case for constructed inventories, we pass source inventories from database
# these must come in order, and in order _before_ the constructed inventory itself # these must come in order, and in order _before_ the constructed inventory itself
if inventory_update.inventory.kind == 'constructed': if inventory_update.inventory.kind == 'constructed':
for source_inventory in inventory_update.inventory.source_inventories.all(): for input_inventory in inventory_update.inventory.input_inventories.all():
args.append('-i') args.append('-i')
script_params = dict(hostvars=True, towervars=True) script_params = dict(hostvars=True, towervars=True)
source_inv_path = self.write_inventory_file(source_inventory, private_data_dir, f'hosts_{source_inventory.id}', script_params) source_inv_path = self.write_inventory_file(input_inventory, private_data_dir, f'hosts_{input_inventory.id}', script_params)
args.append(to_container_path(source_inv_path, private_data_dir)) args.append(to_container_path(source_inv_path, private_data_dir))
# Add arguments for the source inventory file/script/thing # Add arguments for the source inventory file/script/thing