Refactor: tried to refactor code
- move scripts to assets/scripts (and updated build) - put most logic into HaproxyConfigGenerator - created DockerLabelHandler for all label handling from previous code - added unit tests and fixtures to cover HaproxyConfigGenerator and DockerLabelHandler - added a Makefile with build (for docker build) and test targets
This commit is contained in:
parent
5f9eac4b8a
commit
08de132450
21 changed files with 387 additions and 131 deletions
16
assets/scripts/static.py
Normal file
16
assets/scripts/static.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import yaml
|
||||
import sys
|
||||
from easymapping import HaproxyConfigGenerator
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("You need to pass the easyconfig.yml path")
|
||||
exit(1)
|
||||
|
||||
|
||||
with open(sys.argv[1], 'r') as content_file:
|
||||
parsed = yaml.load(content_file.read(), Loader=yaml.FullLoader)
|
||||
|
||||
cfg = HaproxyConfigGenerator(parsed)
|
||||
print(cfg.generate())
|
||||
|
||||
exit(0)
|
||||
24
assets/scripts/swarm.py
Normal file
24
assets/scripts/swarm.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import os
|
||||
from easymapping import HaproxyConfigGenerator
|
||||
|
||||
# path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open("/tmp/.docker_data", 'r') as content_file:
|
||||
lineList = content_file.readlines()
|
||||
|
||||
result = {
|
||||
"customerrors": True if os.getenv("HAPROXY_CUSTOMERRORS") == "true" else False
|
||||
}
|
||||
|
||||
if os.getenv("HAPROXY_PASSWORD"):
|
||||
result["stats"] = {
|
||||
"username": os.getenv("HAPROXY_USERNAME") if os.getenv("HAPROXY_USERNAME") else "admin",
|
||||
"password": os.getenv("HAPROXY_PASSWORD"),
|
||||
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
|
||||
}
|
||||
|
||||
cfg = HaproxyConfigGenerator(result)
|
||||
print(cfg.generate(lineList))
|
||||
|
||||
# print(jsonStr)
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue