Cloud Native应用交付

  • 首页
  • 关于本站
  • 个人介绍
  • Downloads
  • Repo
    • Github
    • Container
  • F5
    • F5 In AI Agent Arch
    • F5 AI Infrastructure Blueprint
    • F5 Python SDK
    • F5-container
    • F5-LBaaS
  • 社交
    • 联系我
    • 微信/微博
    • 公众号
    • 打赏赞助
行至水穷处 坐看云起时
Cloud Native Application Services: cnadn.net
  1. 首页
  2. F5-Tech tips
  3. 正文

基于业务模板自动化配置F5

2016年08月23日 9747点热度 0人点赞 0条评论

Warning: Array to string conversion in /home/wwwroot/myf5/wp-content/plugins/wpjam-basic/public/wpjam-utils.php on line 496

这是很早前写的一个样例,基于业务模板,系统自动化创建业务配置

业务输入模板(可以通过任何形式产生,例如一个自服务的portal website):

createvs.txt  createpool.txt createmonitor.txt

中间程序F5_Deploy.py, 中间输出 tmsh.txt (作为ssh.py的输入)

(如果系统支持iControlRest,可以直接利用Python执行REST)

自动执行ssh.py

 

图标

基于业务模板自动化配置F5业务

1 文件 3.91 KB
下载
###Tested on v11.6###
#only support tcp,http,icmp monitor now
## Created by WWW.MYF5.NET @2015
def createmonitor():
   try:
    f=file('createmonitor.txt')
    lines=f.readlines()
    print lines
    l=[]
    for line in lines:
        print line
        #get value of each line
        linedata=line.split(",")[1]
        #remove"\n"
        i=linedata.split("\n")[0]
        print i
        l.append(i)
    print l
    if l[6]=="enabled":
        if l[0]=="icmp" and l[7]!="" and l[7]!="*":
            #if it is icmp monitor, only need ip and it has an valid ip
            tr="transparent enabled destination %s"%l[7]
        else:
            #for other monitors, ip and port must be there
            if l[7]=="" or l[7]=="*" or l[8]=="" or l[8]=="*":
                print "Error: With transparent enabled, must have ip and port"
                return
            else:
                tr="transparent enabled destination %s:%s"%(l[7],l[8])            
    else:
        #not transparent, could set alias, f5 only support *:* or *:port or ip:port format
        if l[0]=="icmp":
            #icmp monitor,cant have port setting
            if l[7]=="" or l[7]=="*":
                #default setting
                tr=""
            else:
                tr="destination %s"%l[7]
        else:
            #not icmp,support  *:* or *:port or ip:port
            if (l[7]=="" or l[7]=="*") and (l[8]=="" or l[8]=="*"):
                #default setting
                tr=""
            elif l[7]!="" and l[7]!="*" and (l[8]=="" or l[8]=="*"):
                #it is ip:*, dont support
                print "Error: Dont support ip:* alias settting"
                return
            else:
                if l[7]=="":
                    l[7]="*"
                tr="destination %s:%s"%(l[7],l[8])
        
    if l[9]=="enabled":
        res="manual-resume enabled"
    else:
        res=""
    if l[4]!="" and l[5]!="" and l[0]!="icmp":
        sr="send \'%s\' recv \'%s\'"%(l[4],l[5])
    else:
        sr=""
    tmsh="tmsh create ltm monitor %s %s interval %s timeout %s %s %s %s\n"%(l[0],l[1],l[2],l[3],sr,tr,res)
    print tmsh
    f.close()
    out=file('tmsh.txt','a')
    out.write(tmsh)
    out.close
   except:
    print "Cant open the file,or something wrong in during creating pool. Please turn on debug for detail."


    
def createpool():
   try:
    tmsh=""
    monitor=""
    member=""
    mr=""
    noratio=1
    sda=""
    f=file('createpool.txt')
    lines=f.readlines()
    print lines
    l=[]
    for line in lines:
        print line
        #get value of each line
        linedata=line.split(",")[1]
        #remove "\n"
        i=linedata.split("\n")[0]
        print i
        #create string list for pool
        l.append(i)
    print l
    if l[1]=="":
        print "No monitor, will use tcp as default"
        monitor="monitor tcp"
        print l
    else:
        #handle monitor if it is more than 1
        if l[2]=="":
            #no min of monitor setting
            monitorstring=l[1].replace("|"," and ")
            monitor="monitor %s"%monitorstring
        else:
            #consider min of monitor
            monitorstring=l[1].replace("|"," ")
            monitor="monitor min %s of { %s }"%(l[2],monitorstring)
            print monitor
        print l
    if l[3]=="":
        sda=""
    else:
        sda="service-down-action %s"%l[3]
    if l[4]=="ratio-member" or l[4]=="ratio-least-connections-member":
        noratio=0
    if l[4]=="":
        l[4]="round-robin"
    if l[5]=="":
        #no priority group setting
        p=""
    else:
        #has priority, need set min-active-members in tmsh
        p="min-active-members %s"%l[5]
    if l[6]=="":
        print "No members!"
        return
    else:
        #handle members if it is more than 1
        member=l[6].split("|")
        for m in member:
            m1=m.split(":")
            if m1[2]=="" or noratio==1:
                m1[2]="1"
            if m1[3]=="":
                m1[3]="0"
            if p:
                mr=mr + " %s:%s { ratio %s priority-group %s} "%(m1[0],m1[1],m1[2],m1[3])
            else:
                mr=mr + " %s:%s { ratio %s } "%(m1[0],m1[1],m1[2])
        print mr
    tmsh="tmsh create ltm pool %s members add {%s} %s load-balancing-mode %s %s %s\n"%(l[0],mr,monitor,l[4],sda,p)
    f.close()
    out=file('tmsh.txt','a')
    out.write(tmsh)
    out.close
    print tmsh
   except:
    print "Cant open the file,or something wrong in during creating pool. Please turn on debug for detail."
   

def createvs():
    try:
     f=file('createvs.txt')
     lines = f.readlines()
     print lines
     vlan=""
     snat=""
     l=[]
     tmsh=''
     for line in lines:
         print line
         #get value of each line
         linedata=line.split(",")[1]
         #remove "\n"
         i= linedata.split("\n")[0]
         print i
         #create string list for vs
         l.append(i)
     print l
     if l[3]=="":
         #vs_type is blank, so it will be performance l4 or standard vs
         if l[13]!="":
             #vlan enabled_on has setting
             vlan="vlans add { %s } vlans-enabled"%l[13]
         if l[14]!="":
             #vlan disabled_on has setting
             vlan="vlans add { %s } vlans-disabled"%l[14]
         if l[15]!="":
             #it is snat automap
             snat="source-address-translation { type automap } "
         if l[16]!="":
             #it is snat pool
             snat="source-address-translation { type snat pool %s }"%l[16]
         tmsh="tmsh create ltm virtual %s destination %s:%s ip-protocol %s profiles add { %s %s %s %s %s %s %s %s} %s %s mirror %s persist replace-all-with { %s %s } pool %s rules { %s %s} %s\n"\
         %(l[0],l[1],l[2],l[4],l[5],l[6],l[7],l[8],l[9],l[10],l[11],l[12],vlan,snat,l[17],l[18],l[19],l[20],l[21],l[22],l[23])
     elif l[3]=="ipforwarding":
         print "it is ip forwarding vs"
         return
     else:
         print "Not support vs type"
         return
     print tmsh
     f.close()
     out=file('tmsh.txt','a')
     out.write(tmsh)
     out.close()
    except:
     print "Cant open the file,or something wrong in during creating vs. Please turn on debug for detail."
     
createmonitor()
createpool()
createvs()

 

Array
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2016年08月29日

纳米

linjing.io

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

页面AI聊天助手

纳米

linjing.io

☁️迈向Cloud Native ADC ☁️

认证获得:
TOGAF: ID 152743
Kubernetes: CKA #664
Microsoft: MCSE MCDBA
Cisco: CCNP
Juniper: JNCIS
F5:
F5 Certified Solution Expert, Security
F5 Certified Technology Specialist, LTM/GTM/APM/ASM
F5 Certified BIG-IP Administrator
  • 点击查看本博技术要素列表
  • 归档
    分类
    • AI
    • Automation
    • Avi Networks
    • Cisco ACI
    • CISCO资源
    • F5 with ELK
    • F5-Tech tips
    • F5技术
    • Juniper
    • Linux
    • NGINX
    • SDN
    • ServiceMesh
    • WEB编程
    • WINDOWS相关
    • 业界文章
    • 交换机技术
    • 化云为雨/Openstack
    • 协议原理
    • 容器/k8s
    • 我的工作
    • 我的生活
    • 网站技术
    • 路由器技术
    • 项目案例
    标签聚合
    irule F5 DNS gtm nginx api docker flannel network k8s envoy bigip neutron openstack istio
    最近评论
    Abeny 发布于 8 个月前(02月20日) Very good!
    lz 发布于 2 年前(02月26日) 66666666666666
    汤姆 发布于 2 年前(09月10日) 嗨,楼主,里面的json怎么下载啊,怎么收费啊?
    汤姆 发布于 2 年前(09月09日) 大佬,kib的页面可以分享下吗?谢谢
    zhangsha 发布于 3 年前(05月12日) 资料发给我下,谢谢纳米同志!!!!lyx895@qq.com
    浏览次数
    • Downloads - 196,808 views
    • 联系我 - 137,994 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 127,817 views
    • Github - 115,689 views
    • Sniffer Pro 4 70 530抓包软件 中文版+视频教程 - 91,997 views
    • F5常见log日志解释 - 90,978 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 89,441 views
    • 从传统ADC迈向CLOUD NATIVE ADC - 下载 - 88,219 views
    • 关于本站 - 77,129 views
    • F5利用Elastic stack(ELK)进行应用数据挖掘系列(2)-DNS - 65,226 views
    链接表
    • F5SE创新
    • Jimmy Song‘s Blog
    • SDNlab
    • Service Mesh社区
    • 三斗室
    • 个人profile
    • 云原生社区

    COPYRIGHT © 2023 Cloud Native 应用交付. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    京ICP备14048088号-1

    京公网安备 11010502041506号