Created
December 14, 2017 01:42
-
-
Save kujiy/6c9fa234e985a5f57ffccc6c9dea5197 to your computer and use it in GitHub Desktop.
A tool creating comma-separated server list for docker phpmyadmin container #
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# A tool creating comma-separated server list for docker phpmyadmin container | |
# Make these lines from python dictionary | |
# | |
## PMA_VERBOSES=server1,server2,server3,... | |
## PMA_HOSTS=192.168.1.2,10.0.0.200,172.16.1.3,... | |
## PMA_PORTS=3306,13306,3307,... | |
# | |
# How to use | |
# 1. python phpmyadmin-dblist.py > dblist.env | |
# | |
# 2. Insert to docker-compose.yml | |
# | |
# env_file: | |
# - ./dblist.env | |
# | |
# 3. docker-compose up -d | |
# | |
# server difinition | |
from collections import OrderedDict | |
DBs = OrderedDict() | |
### WRITE YOUR SERVERS HERE | |
DBs['server1'] = { | |
'ip': '192.168.1.2', | |
'port': '' # empty=default=3306 | |
} | |
DBs['server2'] = { | |
'ip': '10.0.0.200', | |
'port': '13306' | |
} | |
DBs['server3'] = { | |
'ip': '172.16.1.3', | |
'port': '3307' | |
} | |
# Cups | |
OUT = OrderedDict() | |
OUT["PMA_VERBOSES"] = OrderedDict() | |
OUT["PMA_HOSTS"] = OrderedDict() | |
OUT["PMA_PORTS"] = OrderedDict() | |
# Loop for separating to each dictionary | |
for (db, items) in DBs.items(): | |
ip = items["ip"] | |
port = items["port"] | |
# Set default port | |
if port == '' : | |
port = 3306 | |
# make each line | |
OUT["PMA_VERBOSES"][db] = db | |
OUT["PMA_HOSTS"][db] = ip | |
OUT["PMA_PORTS"][db] = port | |
# print(db) | |
# print("ip="+items["ip"]) | |
# print("port="+items["port"]) | |
# print(OUT) | |
# Loop to make each strings | |
for (line, val) in OUT.items(): | |
# make key= part | |
line = line + "=" | |
for i in val.values(): | |
# push value with comma | |
line += str(i) + "," | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment