-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable export_compose module to return changed state
using the digest function specified by module_utils, we can do a hash comparison if the dest file already exists and return a little extra signal (the written dest) from get_compose_image to determine if we changed or not
- Loading branch information
1 parent
7fe8e3a
commit 26060a5
Showing
2 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# | ||
# (c) 2022, Adam Miller ([email protected]) | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
import hashlib | ||
import json | ||
import os | ||
import shutil | ||
import socket # noqa E402 | ||
from pathlib import Path | ||
|
||
from ansible.module_utils._text import to_bytes | ||
from ansible.module_utils.six.moves.urllib.parse import quote | ||
|
@@ -368,7 +370,7 @@ def get_compose_failed(self): | |
results = json.load(self.weldr.request.open("GET", "http://localhost/api/v1/compose/failed")) | ||
return results | ||
|
||
def get_compose_image(self, compose_uuid, dest): | ||
def get_compose_image(self, compose_uuid, dest, digest_function): | ||
""" | ||
# api.router.GET("/api/v:version/compose/image/:uuid", api.composeImageHandler) | ||
""" | ||
|
@@ -378,11 +380,20 @@ def get_compose_image(self, compose_uuid, dest): | |
method="GET", | ||
unix_socket=self.weldr.unix_socket, | ||
) | ||
|
||
if Path(dest).exists(): | ||
# Check if we need to overwrite | ||
tmpdigest = digest_function(tmpfile) | ||
destdigest = digest_function(dest) | ||
if tmpdigest == destdigest: | ||
os.remove(tmpfile) | ||
return None | ||
|
||
shutil.copy(tmpfile, dest) | ||
with open(dest) as fd: | ||
os.fsync(fd) | ||
os.remove(tmpfile) | ||
return None | ||
return dest | ||
|
||
def get_compose_metadata(self, compose_uuid): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters