Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 81fa84f

Browse files
committed
oh yeah.. inspection output and more
1 parent 6248384 commit 81fa84f

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

packer/interface.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import sh
44
import sys
5+
# import re
56

67
DEFAULT_PACKER_PATH = 'packer'
78

@@ -87,3 +88,29 @@ def build(self, parallel=True, debug=False, force=False):
8788
lgr.info('Running build: {0}'.format(self.packerfile))
8889
lgr.info('Executing: {0}'.format(self._join(builder().cmd)))
8990
return builder()
91+
92+
def inspect(self):
93+
inspector = self.packer.inspect
94+
inspector = inspector.bake('-machine-readable', self.packerfile)
95+
lgr.info('Inspecting packerfile: {0}'.format(self.packerfile))
96+
result = inspector()
97+
result.parsed_output = self._parse_inspection_output(result.stdout)
98+
return result
99+
100+
def _parse_inspection_output(self, output):
101+
parts = {'variables': [], 'builders': [], 'provisioners': []}
102+
for l in output.splitlines():
103+
l = l.split(',')
104+
if l[2].startswith('template'):
105+
del l[0:2]
106+
component = l[0]
107+
if component == 'template-variable':
108+
variable = {"name": l[1], "value": l[2]}
109+
parts['variables'].append(variable)
110+
elif component == 'template-builder':
111+
builder = {"name": l[1], "type": l[2]}
112+
parts['builders'].append(builder)
113+
elif component == 'template-provisioner':
114+
provisioner = {"type": l[1]}
115+
parts['provisioners'].append(provisioner)
116+
return parts

packer/tests/resources/packerfile.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@
7373
"only": ["virtualbox"],
7474
"output": "cloudify_{{.Provider}}.box"
7575
}
76+
],
77+
"post-processors": [
78+
{
79+
"type": "compress",
80+
"format": "tar.gz"
81+
}
7682
]
7783
}

tester.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import packer.interface as packer
22
import os
33

4-
packerfile = os.path.expanduser('~/repos/cloudify-packager/image-builder/quickstart-vagrantbox/packerfile.json') # NOQA
4+
packerfile = os.path.expanduser('packer/tests/resources/packerfile.json') # NOQA
55

66
# exc = ['z', 't']
77
exc = []
@@ -14,5 +14,7 @@
1414
p = packer.Packer(packerfile, exc=exc, only=only, vars=vars)
1515
# print(p.version())
1616

17-
print(p.validate(syntax_only=True))
17+
# print(p.validate(syntax_only=True))
1818
# print(p.build())
19+
result = p.inspect()
20+
print result.parsed_output

0 commit comments

Comments
 (0)