mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
add back in support of towervars lost in merge
This commit is contained in:
parent
bd91e8eb54
commit
1b0bca8229
@ -2443,7 +2443,8 @@ class InventoryScriptView(RetrieveAPIView):
|
||||
host = get_object_or_404(obj.hosts, **hosts_q)
|
||||
return Response(host.variables_dict)
|
||||
return Response(obj.get_script_data(
|
||||
hostvars=bool(request.query_params.get('hostvars', '')),
|
||||
hostvars=hostvars,
|
||||
towervars=towervars,
|
||||
show_all=show_all
|
||||
))
|
||||
|
||||
|
||||
@ -209,7 +209,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
||||
group_children.add(from_group_id)
|
||||
return group_children_map
|
||||
|
||||
def get_script_data(self, hostvars=False, show_all=False):
|
||||
def get_script_data(self, hostvars=False, towervars=False, show_all=False):
|
||||
if show_all:
|
||||
hosts_q = dict()
|
||||
else:
|
||||
@ -271,6 +271,10 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
||||
data['_meta'].setdefault('hostvars', dict())
|
||||
for host in self.hosts.filter(**hosts_q):
|
||||
data['_meta']['hostvars'][host.name] = host.variables_dict
|
||||
if towervars:
|
||||
tower_dict = dict(remote_tower_enabled=str(host.enabled).lower(),
|
||||
remote_tower_id=host.id)
|
||||
data['_meta']['hostvars'][host.name].update(tower_dict)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@ -13,6 +13,28 @@ from awx.main.models import (
|
||||
from awx.main.utils.filters import SmartFilter
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestInventoryScript:
|
||||
|
||||
def test_hostvars(self, inventory):
|
||||
inventory.hosts.create(name='ahost', variables={"foo": "bar"})
|
||||
assert inventory.get_script_data(
|
||||
hostvars=True
|
||||
)['_meta']['hostvars']['ahost'] == {
|
||||
'foo': 'bar'
|
||||
}
|
||||
|
||||
def test_towervars(self, inventory):
|
||||
host = inventory.hosts.create(name='ahost')
|
||||
assert inventory.get_script_data(
|
||||
hostvars=True,
|
||||
towervars=True
|
||||
)['_meta']['hostvars']['ahost'] == {
|
||||
'remote_tower_enabled': 'true',
|
||||
'remote_tower_id': host.id
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSCMUpdateFeatures:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user