summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-07-18 10:52:11 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-07-18 10:52:11 -0700
commitf9d18e2ed747a6d44e60547fbcc0bbff780f351f (patch)
tree66a2f42ac631081e848c7c849d1ceaf673a7f12d /cloudinit
parent960f7c637d07c81f9e8dab2c81f113ee6654f31d (diff)
downloadvyos-cloud-init-f9d18e2ed747a6d44e60547fbcc0bbff780f351f.tar.gz
vyos-cloud-init-f9d18e2ed747a6d44e60547fbcc0bbff780f351f.zip
Add non braces matching and a few more tests
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/templater.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index 95916dff..02f6261d 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -42,18 +42,25 @@ from cloudinit import util
LOG = logging.getLogger(__name__)
TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
-BASIC_MATCHER = re.compile(r'\$\{([A-Za-z0-9_.]+)\}')
+BASIC_MATCHER = re.compile(r'\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)')
def basic_render(content, params):
"""This does simple replacement of bash variable like templates.
- It identifies patterns like ${a} and can also identify patterns like
- ${a.b} which will look for a key 'b' in the dictionary rooted by key 'a'.
+ It identifies patterns like ${a} or $a and can also identify patterns like
+ ${a.b} or $a.b which will look for a key 'b' in the dictionary rooted
+ by key 'a'.
"""
def replacer(match):
- path = collections.deque(match.group(1).split("."))
+ # Only 1 of the 2 groups will actually have a valid entry.
+ name = match.group(1)
+ if name is None:
+ name = match.group(2)
+ if name is None:
+ raise RuntimeError("Match encountered but no valid group present")
+ path = collections.deque(name.split("."))
selected_params = params
while len(path) > 1:
key = path.popleft()