Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
packme
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PaNOSC
Data Analysis Services
packme
Commits
601b4817
Commit
601b4817
authored
5 years ago
by
eric pellegrini
Browse files
Options
Downloads
Patches
Plain Diff
better code for checking missing jinja 2 templates
parent
e3daea1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/packme/PackerTemplate.py
+13
-10
13 additions, 10 deletions
src/packme/PackerTemplate.py
templates/base-ill/manifest.yml
+2
-2
2 additions, 2 deletions
templates/base-ill/manifest.yml
with
15 additions
and
12 deletions
src/packme/PackerTemplate.py
+
13
−
10
View file @
601b4817
...
@@ -272,20 +272,23 @@ class PackerTemplate:
...
@@ -272,20 +272,23 @@ class PackerTemplate:
node
[
"
provisioners
"
]
=
self
.
_provisioners
node
[
"
provisioners
"
]
=
self
.
_provisioners
node
[
"
post-processors
"
]
=
self
.
_postprocessors
node
[
"
post-processors
"
]
=
self
.
_postprocessors
env
=
jinja2
.
Environment
(
undefined
=
jinja2
.
DebugUndefined
)
stringified_node
=
repr
(
node
)
template
=
env
.
from_string
(
repr
(
node
))
rendered
=
template
.
render
(
**
self
.
_environment
)
# Create a jinja evironment for parsing the manifest
env
=
jinja2
.
Environment
()
# Parse the string with jinja templates in unrendered state in order to get te set of all jinja templates
ast
=
env
.
parse
(
stringified_node
)
jinja_templates
=
jinja2
.
meta
.
find_undeclared_variables
(
ast
)
# Retrieve those templates which are not declared in the environment. These are the undefined templates.
undefined
=
jinja_templates
.
difference
(
self
.
_environment
.
keys
())
# Check if rendering was done correctly
# If there are some undefined templates, stop here.
ast
=
env
.
parse
(
rendered
)
undefined
=
jinja2
.
meta
.
find_undeclared_variables
(
ast
)
if
undefined
:
if
undefined
:
print
(
f
'
The following variables are undefined:
{
undefined
!r}
'
)
print
(
f
'
The following variables are undefined:
{
undefined
!r}
'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
# Replace back %< .* %> to {{ .* }}
template
=
env
.
from_string
(
stringified_node
)
rendered
=
rendered
.
replace
(
"
%<
"
,
"
{{
"
)
rendered
=
template
.
render
(
**
self
.
_environment
)
rendered
=
rendered
.
replace
(
"
>%
"
,
"
}}
"
)
# Dump to the output file
# Dump to the output file
with
open
(
output_file
,
"
w
"
)
as
fout
:
with
open
(
output_file
,
"
w
"
)
as
fout
:
...
...
This diff is collapsed.
Click to expand it.
templates/base-ill/manifest.yml
+
2
−
2
View file @
601b4817
...
@@ -24,7 +24,7 @@ packer:
...
@@ -24,7 +24,7 @@ packer:
boot_wait
:
5s
boot_wait
:
5s
boot_command
:
boot_command
:
-
"
<tab>
"
-
"
<tab>
"
-
"
preseed/url=http://
%<
.HTTPIP
>%:%<
.HTTPPort
>%
/{{
preseed_file_name
}}
"
-
"
preseed/url=http://
{%
raw
%}{{
.HTTPIP
}}:{{
.HTTPPort
}}{%
endraw
%}
/{{
preseed_file_name
}}
"
-
"
auto-install/enable=true
"
-
"
auto-install/enable=true
"
-
"
net.ifnames=0
"
-
"
net.ifnames=0
"
-
"
netcfg/get_hostname={{
vm_name
}}
"
-
"
netcfg/get_hostname={{
vm_name
}}
"
...
@@ -38,7 +38,7 @@ packer:
...
@@ -38,7 +38,7 @@ packer:
-
"
passwd/user-password-again=
{{
user_password
}}
"
-
"
passwd/user-password-again=
{{
user_password
}}
"
-
"
passwd/root-password={{
root_password
}}
"
-
"
passwd/root-password={{
root_password
}}
"
-
"
passwd/root-password-again={{
root_password
}}
"
-
"
passwd/root-password-again={{
root_password
}}
"
-
"
no_proxy=
%<
.HTTPIP
>%
,{{
no_proxy
}}
"
-
"
no_proxy=
{%
raw
%}{{
.HTTPIP
}}{%
endraw
%}
,{{
no_proxy
}}
"
-
"
<enter>"
-
"
<enter>"
disk_size
:
"
{{
disk_size
}}"
disk_size
:
"
{{
disk_size
}}"
http_directory
:
"
http"
http_directory
:
"
http"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment