作业2:在haproxy文件中追加一段backend,内容如下

"""
2、新建
    输入:
        arg = {
            'bakend': 'www.oldboy.org',
            'record':{
                'server': '100.1.7.9',
                'weight': 20,
                'maxconn': 30
            }
        }
"""

def add(word):

    str1=""

    def value(key, word, temp):
        if isinstance(word,dict):
            for key in word:
                temp = temp + key + " " + str(word[key])+" "
        else:
            temp = temp + key + " " + str(word) + " "
        return temp
    if isinstance(word,dict):
        for key in word:
            if isinstance(word[key],dict):
                add(word[key])
            str1 = value(key, word[key], str1)
    else:
        print("输入格式不正确!")
    return str1

#search()
w='{"backend":"www.baidu.com","record":{"server":"100.512.4.32","weight":20,"maxcon":30}}'
file = open("haproxy.txt", "a")
x = eval(w)
temp=add(x).replace(" server","\n        server")
file.write("\n\n%s"%(temp))
file.close()
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页