mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
Implement passive copying as a new host to a group
requires that the variables isn't special on the new host implements AC-1265
This commit is contained in:
parent
24df1a88ee
commit
6773fd19d7
@ -821,6 +821,17 @@ class GroupHostsList(SubListCreateAPIView):
|
||||
parent_model = Group
|
||||
relationship = 'hosts'
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
parent_group = Group.objects.get(id=self.kwargs['pk'])
|
||||
existing_hosts = Host.objects.filter(inventory=parent_group.inventory, name=request.DATA['name'])
|
||||
if existing_hosts.count() > 0 and ('variables' not in request.DATA or \
|
||||
request.DATA['variables'] == '' or \
|
||||
request.DATA['variables'] == '{}' or \
|
||||
request.DATA['variables'] == '---'):
|
||||
request.DATA['id'] = existing_hosts[0].id
|
||||
return self.attach(request, *args, **kwargs)
|
||||
return super(GroupHostsList, self).create(request, *args, **kwargs)
|
||||
|
||||
class GroupAllHostsList(SubListAPIView):
|
||||
''' the list of all hosts below a group, even including subgroups '''
|
||||
|
||||
|
@ -572,6 +572,9 @@ class InventoryTest(BaseTest):
|
||||
|
||||
# access
|
||||
url1 = reverse('api:group_hosts_list', args=(groups[0].pk,))
|
||||
alt_group_hosts = reverse('api:group_hosts_list', args=(groups[1].pk,))
|
||||
other_alt_group_hosts = reverse('api:group_hosts_list', args(groups[2].pk,))
|
||||
|
||||
data = self.get(url1, expect=200, auth=self.get_normal_credentials())
|
||||
self.assertEquals(data['count'], 2)
|
||||
self.assertTrue(host1.pk in [x['id'] for x in data['results']])
|
||||
@ -593,6 +596,14 @@ class InventoryTest(BaseTest):
|
||||
data = self.get(url1, expect=200, auth=self.get_normal_credentials())
|
||||
self.assertEquals(data['count'], 4)
|
||||
|
||||
# You should be able to add an existing host to a group as a new host and have it be copied
|
||||
existing_host = new_host
|
||||
self.post(alt_group_hosts, data=existing_host, expect=204, auth=self.get_normal_credentials())
|
||||
|
||||
# Not if the variables are different though
|
||||
existing_host['variables'] = '{"booh": "bah"}'
|
||||
self.post(other_alt_group_hosts, data=existing_host, expect=400, auth=self.get_normal_credentials())
|
||||
|
||||
# removal
|
||||
got['disassociate'] = 1
|
||||
posted = self.post(url1, data=got, expect=204, auth=self.get_normal_credentials())
|
||||
|
Loading…
Reference in New Issue
Block a user