Carry volume ID from build_image through ISO to manifest
This commit is contained in:
@@ -54,6 +54,11 @@ parser.add_argument(
|
||||
dest='source_iso',
|
||||
action='store',
|
||||
required=True)
|
||||
parser.add_argument(
|
||||
'--volume-id',
|
||||
dest='volume_id',
|
||||
action='store',
|
||||
required=True)
|
||||
FLAGS = parser.parse_args()
|
||||
|
||||
|
||||
@@ -92,7 +97,7 @@ class ImageBuilder(object):
|
||||
'loopback.cfg': 'boot/grub/loopback.cfg',
|
||||
}
|
||||
|
||||
def __init__(self, source_iso, image_dir, archive, arch, release, modules, kernel_args):
|
||||
def __init__(self, source_iso, image_dir, archive, arch, release, modules, kernel_args, volume_id=None):
|
||||
self._source_iso = source_iso
|
||||
self._image_dir = image_dir
|
||||
self._archive = archive
|
||||
@@ -100,6 +105,7 @@ class ImageBuilder(object):
|
||||
self._release = release
|
||||
self._modules = modules or []
|
||||
self._kernel_args = kernel_args or []
|
||||
self._volume_id = volume_id
|
||||
|
||||
self._ico_server_path = os.path.dirname(sys.argv[0])
|
||||
|
||||
@@ -275,10 +281,15 @@ class ImageBuilder(object):
|
||||
|
||||
def _CreateISO(self, union_path, timestamp):
|
||||
dest_iso = os.path.join(self._image_dir, '%d.iso' % timestamp)
|
||||
self._Exec(
|
||||
'grub-mkrescue',
|
||||
args = [
|
||||
'--output=%s' % dest_iso,
|
||||
union_path)
|
||||
'--',
|
||||
]
|
||||
if self._volume_id:
|
||||
args.extend(['-V', self._volume_id])
|
||||
args.append(union_path)
|
||||
|
||||
self._Exec('grub-mkrescue', *args)
|
||||
return dest_iso
|
||||
|
||||
def _BuildImage(self):
|
||||
@@ -333,7 +344,8 @@ def main():
|
||||
FLAGS.arch,
|
||||
FLAGS.release,
|
||||
FLAGS.modules,
|
||||
FLAGS.kernel_args)
|
||||
FLAGS.kernel_args,
|
||||
FLAGS.volume_id)
|
||||
builder.BuildImage()
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
@@ -37,6 +38,7 @@ FLAGS = parser.parse_args()
|
||||
class ManifestBuilder(object):
|
||||
|
||||
_FILE_REGEX = re.compile('^(?P<timestamp>\d+)\.iso$')
|
||||
_VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P<volume_id>.+)$', re.MULTILINE)
|
||||
_BUF_SIZE = 2 ** 16
|
||||
|
||||
def __init__(self, image_dir, old_manifest):
|
||||
@@ -55,6 +57,15 @@ class ManifestBuilder(object):
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
|
||||
def _GetVolumeID(self, path):
|
||||
isoinfo = subprocess.check_output([
|
||||
'isoinfo',
|
||||
'-d',
|
||||
'-i', path,
|
||||
])
|
||||
match = self._VOLUME_ID_REGEX.search(isoinfo)
|
||||
return match.group('volume_id').decode('ascii')
|
||||
|
||||
def BuildManifest(self):
|
||||
ret = {
|
||||
'timestamp': int(time.time()),
|
||||
@@ -77,7 +88,11 @@ class ManifestBuilder(object):
|
||||
image.update(old_image)
|
||||
continue
|
||||
|
||||
with open(os.path.join(self._image_dir, filename), 'rb') as fh:
|
||||
image_path = os.path.join(self._image_dir, filename)
|
||||
|
||||
image['volume_id'] = self._GetVolumeID(image_path)
|
||||
|
||||
with open(image_path, 'rb') as fh:
|
||||
hash_obj = hashlib.sha256()
|
||||
while True:
|
||||
data = fh.read(self._BUF_SIZE)
|
||||
|
||||
Reference in New Issue
Block a user