修改haproxy配置文件
需求:
1、查 输入:www.oldboy.org 获取当前backend下的所有记录 2、新建 输入: arg = { 'bakend': 'www.oldboy.org', 'record':{ 'server': '100.1.7.9', 'weight': 20, 'maxconn': 30 } } 3、删除 输入: arg = { 'bakend': 'www.oldboy.org', 'record':{ 'server': '100.1.7.9', 'weight': 20, 'maxconn': 30 } }
原配置文件
global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 info defaults log global mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms option dontlognull listen stats :8888 stats enable stats uri /admin stats auth admin:1234 frontend oldboy.org bind 0.0.0.0:80 option httplog option httpclose option forwardfor log global acl www hdr_reg(host) -i www.oldboy.org use_backend www.oldboy.org if www backend www.oldboy.org server 100.1.7.9 100.1.7.9 weight 20 maxconn 3000 原配置文件
我的作业
dic_function = {1:'search',2:'add',3:'delet',4:'update'} for i in dic_function.items(): print(i) user_chose = input('请选择您的需求 :') if user_chose == '1': with open('haproxy1', 'r', encoding='utf-8') as s: seach_f = input('请输入要查找的信息:') for line in s: if str(seach_f) in line: print(line) print(s.readline()) break # s_new.write(line) if user_chose == '2': dic = ''' { 'bakend': 'www.oldboy.org', 'record':{ 'server': '100.1.7.9', 'weight': 20, 'maxconn': 30 } } ''' dic = eval(dic) with open('haproxy', 'r', encoding='utf-8') as s: back = input('请输入backend:') for line in s: if back in line: print('发现重复数据') break elif back not in line: record_server = input('server:') record_weight = input('请输入weight:') record_maxconn = input('请输入maxconn:') dic['backend'] = back dic['record']['server'] = record_server dic['record']['weight'] = record_weight dic['record']['maxconn'] = record_maxconn with open('haproxy', 'a', encoding='utf-8') as s: s.write(' backend:%s ' % dic['backend']) s.write(' server%s' % dic['record']['server']) s.write(' weight%s' % dic['record']['weight']) s.write(' server%s' % dic['record']['maxconn']) s.close() # if user_chose == '3': # # backend_del = input('请输入要删除的backend:') # with open('haproxy', 'r', encoding='utf-8') as s: # for line in s: # if backend_del not in line: # print('您要删除的数据不存在') # break # elif backend_del in line: #
#############################还没做完,但是出bug了,我一开始编译的时候,添加功能正常,过了一会突然不好用了。。。明天再看看,先睡觉