Python applet-Modify the Haproxy configuration file

Source: Internet
Author: User

Program 2: Modify the Haproxy configuration file

Demand:

11, check2 Input: www.oldboy.org3 get all records under the current backend4 52, New6 Input:7arg = {8             'Bakend':'www.oldboy.org',9             'Record':{Ten                 'Server':'100.1.7.9', One                 'Weight': 20, A                 'Maxconn': 30 -             } -         } the  -3, delete - Input: -arg = { +             'Bakend':'www.oldboy.org', -             'Record':{ +                 'Server':'100.1.7.9', A                 'Weight': 20, at                 'Maxconn': 30 -             } -}
View Code
1 Global       2Log 127.0.0.1Local23 Daemon4Maxconn 2565Log 127.0.0.1Local2 Info6 Defaults7LogGlobal8 Mode HTTP9 Timeout Connect 5000msTen Timeout Client 50000ms One Timeout Server 50000ms A option Dontlognull -  -Listen stats:8888 the Stats Enable -Stats URI/Admin -Stats Auth admin:1234 -  + frontend oldboy.org -Bind 0.0.0.0:80 + option Httplog A option Httpclose at option Forwardfor -LogGlobal -ACL www hdr_reg (host)-I www.oldboy.org -Use_backend www.oldboy.orgifwww -  - Backend www.oldboy.org inServer 100.1.7.9 100.1.7.9 Weight maxconn 3000
View Code

Temporarily only the code to check and add functionality:

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #Author linux ku4 #{' backend ': ' www.oldboy.org ', ' record ': {' server ': ' 100.1.7.9 ', ' weight ': ', ' Maxconn ':-}}5 #{' backend ': ' www.cool2.org ', ' record ': {' server ': ' 100.2.8.9 ', ' weight ': +, ' maxconn ': +}}6 defRecd_add ():7     " "used to add data, temporarily not adding content to determine the type of input data" "8Add_inf_tmp = input ('Please enter the content you want to add')9Add_inf =eval (add_inf_tmp)TenWith open ('G:\ Learning \python\learnning\homework3\record.txt','r+') as File:#open in a form that can be read and written One          forLineinchFile#to determine if the data already exists A             if 'Backend' inchLine : -Line_ful ="Backend {website}\n". Format (website=add_inf['Backend']) -                 ifline = =line_ful: the                     return Print('The record already exits.') -File.write ('\nbackend {backend}\n'. Format (backend = add_inf['Backend'])) -File.write ('\tserver {red1} weight {num1} maxconn {num2}\n'. Format (red1=add_inf['Record']['Server'],#Remember reading is to use this form, can not use the number Oh, the number that is the list -num1=add_inf['Record']['Weight'], +num2=add_inf['Record']['Maxconn'])) -     return Print('Adding record successfully.') +  A  at defrecd_read (): -     " "used to read data" " -Read_inf = (Input ('Please enter the contents of the address to be read')) -With open ('G:\ Learning \python\learnning\homework3\record.txt','R') as File:#open in a form that can be read and written -          forLineinchFile#to determine if the data already exists -             if 'Backend' inchLine : inLine_ful ="Backend {website}\n". Format (website=Read_inf) -                 ifline = =line_ful: toRD =File.readline () +                     return Print(RD)#print here, or you can't output it. -     return 'The record does not exit.' the  * """ $ def recd_delete ():Panax Notoginseng " to delete data" - Del_inf = eval (input (' Please enter the contents of the address to be read ') the with open (' G:\ learning \python\learnning\homework3\record.txt ', ' r+ ') as file: #用可以读写的形式打开 + For line in file: #用来判断是否数据已存在 A if ' backend ' in line: the if Del_inf in line: + rd = File.readline () - Return Rd $ return ' The record does not exit. ' $ """ -CHOICE_RECD = ['Add','Delete','Read','quit']#to determine what is being entered, right ? -  whileTrue: theChoice = input ("Please input ' add ', ' delete ', ' read ', ' Quit '") -     ifChoiceinchCHOICE_RECD:#Judging what you've entered, right ?Wuyi         ifChoice = ='Add': the Recd_add () -         elifChoice = ='Read': Wu Recd_read () -         elifChoice = ='quit': About              Break
View Code

Python applet-Modify the Haproxy configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.