mirror of
https://github.com/ipxe/ipxe
synced 2026-05-16 15:00:48 +03:00
[cloud] Omit uploading empty blocks to EBS snapshots
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -12,6 +12,7 @@ import subprocess
|
|||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
BLOCKSIZE = 512 * 1024
|
BLOCKSIZE = 512 * 1024
|
||||||
|
EMPTY_CHECKSUM = b64encode(sha256(b'\0' * BLOCKSIZE).digest()).decode()
|
||||||
|
|
||||||
|
|
||||||
def detect_architecture(image):
|
def detect_architecture(image):
|
||||||
@@ -30,6 +31,7 @@ def create_snapshot(region, description, image, tags):
|
|||||||
Description=description,
|
Description=description,
|
||||||
Tags=tags)
|
Tags=tags)
|
||||||
snapshot_id = snapshot['SnapshotId']
|
snapshot_id = snapshot['SnapshotId']
|
||||||
|
changed = 0
|
||||||
with open(image, 'rb') as fh:
|
with open(image, 'rb') as fh:
|
||||||
for block in count():
|
for block in count():
|
||||||
data = fh.read(BLOCKSIZE)
|
data = fh.read(BLOCKSIZE)
|
||||||
@@ -37,14 +39,17 @@ def create_snapshot(region, description, image, tags):
|
|||||||
break
|
break
|
||||||
data = data.ljust(BLOCKSIZE, b'\0')
|
data = data.ljust(BLOCKSIZE, b'\0')
|
||||||
checksum = b64encode(sha256(data).digest()).decode()
|
checksum = b64encode(sha256(data).digest()).decode()
|
||||||
|
if checksum == EMPTY_CHECKSUM:
|
||||||
|
continue
|
||||||
client.put_snapshot_block(SnapshotId=snapshot_id,
|
client.put_snapshot_block(SnapshotId=snapshot_id,
|
||||||
BlockIndex=block,
|
BlockIndex=block,
|
||||||
BlockData=data,
|
BlockData=data,
|
||||||
DataLength=BLOCKSIZE,
|
DataLength=BLOCKSIZE,
|
||||||
Checksum=checksum,
|
Checksum=checksum,
|
||||||
ChecksumAlgorithm='SHA256')
|
ChecksumAlgorithm='SHA256')
|
||||||
|
changed += 1
|
||||||
client.complete_snapshot(SnapshotId=snapshot_id,
|
client.complete_snapshot(SnapshotId=snapshot_id,
|
||||||
ChangedBlocksCount=block)
|
ChangedBlocksCount=changed)
|
||||||
return snapshot_id
|
return snapshot_id
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user