mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
Refactor original hosts, add related field
Also rename source_inventories to input_inventories
This commit is contained in:
parent
aa06940df5
commit
df6bb5a8b8
@ -1694,8 +1694,8 @@ class InventorySerializer(LabelsListMixin, BaseSerializerWithVariables):
|
||||
if obj.organization:
|
||||
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
|
||||
if obj.kind == 'constructed':
|
||||
res['source_inventories'] = self.reverse('api:inventory_source_inventories', kwargs={'pk': obj.pk})
|
||||
res['url'] = self.reverse('api:constructed_inventory_detail', kwargs={'pk': obj.pk})
|
||||
res['input_inventories'] = self.reverse('api:inventory_input_inventories', kwargs={'pk': obj.pk})
|
||||
res['constructed_url'] = self.reverse('api:constructed_inventory_detail', kwargs={'pk': obj.pk})
|
||||
return res
|
||||
|
||||
def to_representation(self, obj):
|
||||
@ -1875,6 +1875,8 @@ class HostSerializer(BaseSerializerWithVariables):
|
||||
ansible_facts=self.reverse('api:host_ansible_facts_detail', kwargs={'pk': obj.pk}),
|
||||
)
|
||||
)
|
||||
if obj.inventory.kind == 'constructed':
|
||||
res['original_host'] = self.reverse('api:host_detail', kwargs={'pk': obj.instance_id})
|
||||
if obj.inventory:
|
||||
res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk})
|
||||
if obj.last_job:
|
||||
|
||||
@ -9,7 +9,7 @@ from awx.api.views.inventory import (
|
||||
ConstructedInventoryDetail,
|
||||
ConstructedInventoryList,
|
||||
InventoryActivityStreamList,
|
||||
InventorySourceInventoriesList,
|
||||
InventoryInputInventoriesList,
|
||||
InventoryJobTemplateList,
|
||||
InventoryAccessList,
|
||||
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]+)/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]+)/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]+)/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'),
|
||||
|
||||
@ -109,11 +109,11 @@ class ConstructedInventoryList(InventoryList):
|
||||
return r.filter(kind='constructed')
|
||||
|
||||
|
||||
class InventorySourceInventoriesList(SubListAttachDetachAPIView):
|
||||
class InventoryInputInventoriesList(SubListAttachDetachAPIView):
|
||||
model = Inventory
|
||||
serializer_class = InventorySerializer
|
||||
parent_model = Inventory
|
||||
relationship = 'source_inventories'
|
||||
relationship = 'input_inventories'
|
||||
|
||||
|
||||
class InventoryActivityStreamList(SubListAPIView):
|
||||
|
||||
@ -11,7 +11,7 @@ class Migration(migrations.Migration):
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='inventory',
|
||||
name='source_inventories',
|
||||
name='input_inventories',
|
||||
field=models.ManyToManyField(
|
||||
blank=True,
|
||||
help_text='Only valid for constructed inventories, this links to the inventories that will be used.',
|
||||
|
||||
@ -140,7 +140,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
||||
default=None,
|
||||
help_text=_('Filter that will be applied to the hosts of this inventory.'),
|
||||
)
|
||||
source_inventories = models.ManyToManyField(
|
||||
input_inventories = models.ManyToManyField(
|
||||
'Inventory',
|
||||
blank=True,
|
||||
related_name='destination_inventories',
|
||||
|
||||
@ -1529,10 +1529,10 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask):
|
||||
# special case for constructed inventories, we pass source inventories from database
|
||||
# these must come in order, and in order _before_ the constructed inventory itself
|
||||
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')
|
||||
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))
|
||||
|
||||
# Add arguments for the source inventory file/script/thing
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user