Add gethostbyname filter to get ip address from host name

This is needed for ODL integration, where we need to set
a manager for OVS in OVS containers in the form of
tcp:<odl_ip_address>:<tcp_port>

Change-Id: I0a2919458770929b922148ce70100b0d71a16d14
This commit is contained in:
Oleg Bondarev 2016-12-01 11:41:04 +03:00
parent b218d3896b
commit f4afa36d90
3 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import os
import socket
import jinja2
@ -35,6 +36,7 @@ def jinja_render(path, context, functions=(), ignore_undefined=False):
env = jinja2.Environment(loader=jinja2.FileSystemLoader(
os.path.dirname(path)), **kwargs)
env.filters['host'] = get_host
env.filters['gethostbyname'] = socket.gethostbyname
for func in functions:
env.globals[func.__name__] = func
content = env.get_template(os.path.basename(path)).render(context)

View File

@ -4,3 +4,4 @@
{{ duck["egg"] }}
{{ duck.egg }}
{{ address('keystone') }}
{{ 'localhost' | gethostbyname }}

View File

@ -19,7 +19,7 @@ class TestJinjaUtils(base.TestCase):
functions=[utils.address])
self.assertEqual(
"debian\njessie\nsome maintainer\nneedle\nneedle\n"
"keystone.ccp.svc.cluster.local",
"keystone.ccp.svc.cluster.local\n127.0.0.1",
content)
context = {
@ -40,7 +40,7 @@ class TestJinjaUtils(base.TestCase):
ignore_undefined=True)
self.assertEqual(
"debian\njessie\nsome maintainer\nneedle\nneedle\n"
"keystone.ccp.svc.cluster.local",
"keystone.ccp.svc.cluster.local\n127.0.0.1",
content)
context = {
@ -50,4 +50,5 @@ class TestJinjaUtils(base.TestCase):
self.filename, context, functions=[utils.address],
ignore_undefined=True)
self.assertEqual(
"debian\n\n\n\n\nkeystone.ccp.svc.cluster.local", content)
"debian\n\n\n\n\nkeystone.ccp.svc.cluster.local\n127.0.0.1",
content)