mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 23:17:32 -02:30
Add code that allows getting just the root groups for an inventory.
This commit is contained in:
@@ -216,6 +216,8 @@ class InventoryTest(BaseTest):
|
|||||||
##################################################
|
##################################################
|
||||||
# GROUPS->inventories POST via subcollection
|
# GROUPS->inventories POST via subcollection
|
||||||
|
|
||||||
|
root_groups = '/api/v1/inventories/1/root_groups/'
|
||||||
|
|
||||||
url = '/api/v1/inventories/1/groups/'
|
url = '/api/v1/inventories/1/groups/'
|
||||||
new_group_a = dict(name='web100')
|
new_group_a = dict(name='web100')
|
||||||
new_group_b = dict(name='web101')
|
new_group_b = dict(name='web101')
|
||||||
@@ -240,6 +242,10 @@ class InventoryTest(BaseTest):
|
|||||||
got = self.get(url5, expect=200, auth=self.get_other_credentials())
|
got = self.get(url5, expect=200, auth=self.get_other_credentials())
|
||||||
self.assertEquals(got['count'], 4)
|
self.assertEquals(got['count'], 4)
|
||||||
|
|
||||||
|
# side check: see if root groups URL is operational. These are groups without parents.
|
||||||
|
root_groups = self.get(root_groups, expect=200, auth=self.get_super_credentials())
|
||||||
|
self.assertEquals(root_groups['count'], 2)
|
||||||
|
|
||||||
remove_me = added_by_collection
|
remove_me = added_by_collection
|
||||||
remove_me['disassociate'] = 1
|
remove_me['disassociate'] = 1
|
||||||
self.post(url5, data=remove_me, expect=204, auth=self.get_other_credentials())
|
self.post(url5, data=remove_me, expect=204, auth=self.get_other_credentials())
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ inventory_urls = patterns('lib.main.views',
|
|||||||
url(r'^(?P<pk>[0-9]+)/$', 'inventory_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', 'inventory_detail'),
|
||||||
url(r'^(?P<pk>[0-9]+)/hosts/$', 'inventory_hosts_list'),
|
url(r'^(?P<pk>[0-9]+)/hosts/$', 'inventory_hosts_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/groups/$', 'inventory_groups_list'),
|
url(r'^(?P<pk>[0-9]+)/groups/$', 'inventory_groups_list'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/root_groups/$', 'inventory_root_groups_list'),
|
||||||
)
|
)
|
||||||
|
|
||||||
hosts_urls = patterns('lib.main.views',
|
hosts_urls = patterns('lib.main.views',
|
||||||
|
|||||||
@@ -876,6 +876,25 @@ class InventoryGroupsList(BaseSubList):
|
|||||||
# FIXME: verify that you can can_read permission on the inventory is required
|
# FIXME: verify that you can can_read permission on the inventory is required
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
class InventoryRootGroupsList(BaseSubList):
|
||||||
|
|
||||||
|
model = Group
|
||||||
|
serializer_class = GroupSerializer
|
||||||
|
permission_classes = (CustomRbac,)
|
||||||
|
parent_model = Inventory
|
||||||
|
relationship = 'groups'
|
||||||
|
postable = True
|
||||||
|
inject_primary_key_on_post_as = 'inventory'
|
||||||
|
severable = False
|
||||||
|
filter_fields = ('name',)
|
||||||
|
|
||||||
|
def _get_queryset(self):
|
||||||
|
inventory = Inventory.objects.get(pk=self.kwargs['pk'])
|
||||||
|
base = inventory.groups
|
||||||
|
all_ids = base.values_list('id', flat=True)
|
||||||
|
base.exclude(parents__id__in = all_ids)
|
||||||
|
return base
|
||||||
|
|
||||||
class GroupsVariableDetail(VariableBaseDetail):
|
class GroupsVariableDetail(VariableBaseDetail):
|
||||||
|
|
||||||
model = VariableData
|
model = VariableData
|
||||||
|
|||||||
Reference in New Issue
Block a user