Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV FLASK_APP=/src/app
ENV ROLES_DIR=/roles

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt install -y python3-pip sshpass git openssh-client libhdf5-dev libssl-dev libffi-dev && \
apt install -y python3-pip sshpass git openssh-client libhdf5-dev libssl-dev libffi-dev imagemagick && \
rm -rf /var/lib/apt/lists/* && apt-get clean

WORKDIR /src
Expand Down
34 changes: 34 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from flask import Flask, request
import json
import os
from PIL import Image
import subprocess
import sys
import yaml

Expand All @@ -12,9 +14,23 @@
KEYS_DIR = "/keys"
WORK_DIR = "/var/tmp"
ROLES_DIR = os.environ.get("ROLES_DIR", "{}/roles".format(WORK_DIR))
IMG_MINT_DIR = "{}/images".format(WORK_DIR)

CONSTRUCTS = {}

def execute_command(command):
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

if process.returncode > 0:
print('Executing command \"%s\" returned a non-zero status code %d' % (command, process.returncode))
sys.exit(process.returncode)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't sys.exit on failure (error message should be created to return as API request response)


if error:
print(error.decode('utf-8'))

return output.decode('utf-8')

def generate_setup(spec):
with open("{dir}/{id}.yaml".format(dir=WORK_DIR, id=spec['id']), 'w') as f:
for role in spec['setup']:
Expand Down Expand Up @@ -50,6 +66,24 @@ def generate_inventory(spec):

return { 'message': "{id} inventory generation completed successfully.".format(id=spec['id']) }

def generate_file_images(dir):
l = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(dir)) for f in fn]
number_files = len(l)

new_im = Image.new('RGB', (800, 800))
for x in range(0, number_files):
target = "{}/{}_{}.png".format(IMG_MINT_DIR, os.path.dirname(l[x]).split('/')[-1], os.path.basename(l[x]))
execute_command("convert -size 720x720 xc:white -font FreeMono -pointsize 12 -fill black -annotate +15+15 @{} {}".format(l[x], target))
im = Image.open(target)
im.thumbnail((100, 100))

for i in range(0, 800, 100):
for j in range(0, 800, 100):

new_im.paste(im, (i, j))

new_im.save('{}/out.png'.format(IMG_MINT_DIR))

def load_construct_file(cid):
data = {}
with open("{dir}/{id}.yaml".format(dir=WORK_DIR, id=cid)) as file:
Expand Down
3 changes: 2 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Flask==2.0.2
ansible==4.8.0
ansible_runner==2.0.3
ansible_runner==2.0.3
pillow==8.4.0
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0
v0.1.1