#header for connection f5 creat_header = { 'X-F5-Auth-Token':f5_token, 'Content-Type':'application/json' } # for l in appv: count = count + 1 poolname = l[0] Descrip = l[2] t = l[4] vip_addr = l[4] vip_port = l[5] if poolname != '': monic_name = 'TCP_' + str(vip_port) if device.exist(f"/mgmt/tm/ltm/monitor/tcp/{rest_format(monic_name)}"): print(f"monitor {monic_name} exists.") else: #raise Exception(f"monitor {member_name} in {pool_name}.") data = {} data["name"] = monic_name data["destination"] = '*.' + str(vip_port) monitor = device.create( f"/mgmt/tm/ltm/monitor/tcp", data) if monitor.properties["fullPath"] != '/Common/' + monic_name: raise Exception(monitor.properties["fullPath"]) else: print(f"Health Monitor {monic_name} created.") # # if vip_port == '80' or vip_port == '443': # moni_name = 'http'
buffer = [] while True: line = sys.stdin.readline().rstrip('\n') if line == '': break else: buffer.append(line) #print (buffer) node_list = buffer # Create a device object with basic authentication device = BIGIP(F5_Host, F5_username, F5_password) # Create node for node_ip_address in node_list: node_name = 'node_' + node_ip_address if device.exist(f"/mgmt/tm/ltm/node/{rest_format(node_name)}"): print(f"Node {node_name} exists.") else: raise Exception(f"Create {node_name} and Check not exists.") data = {} data["name"] = node_name data["address"] = node_ip_address data["description"] = 'webserver_NS2020-1026-001' node = device.create(f"/mgmt/tm/ltm/node/", data) if node.properties[ "fullPath"] != '/Common/' + 'node_' + node_ip_address: raise Exception(node.properties["fullPath"]) else: print(f"Node {node_ip_address} created.")
partition_name = "/Common/" # print('請輸入資料 port list,如 80\n443\n8080\n...直接按下Enter 結束 : ') port_buffer = [] while True: line = sys.stdin.readline().rstrip('\n') if line == '': break else: port_buffer.append(line) #print (buffer) port_list = port_buffer for port in port_list: moni_name = 'TCP-' + port if device.exist(f"/mgmt/tm/ltm/monitor/tcp/{rest_format(moni_name)}"): print(f"monitor {moni_name} exists.") else: #raise Exception(f"monitor {member_name} in {pool_name}.") data = {} data["name"] = moni_name data["destination"] = '*.' + port monitor = device.create( f"/mgmt/tm/ltm/monitor/tcp", data) if monitor.properties["fullPath"] != '/Common/' + moni_name: raise Exception(monitor.properties["fullPath"]) else: print(f"Pool {moni_name} created.") #Job_name = input('輸入單號或說明: ') #print("Node_ip : ", end="") #node_ip_address = input()
#header for connection f5 creat_header = { 'X-F5-Auth-Token': f5_token, 'Content-Type': 'application/json' } # for l in appv: count = count + 1 poolname = l[0] Descrip = l[2] t = l[4] vip_addr = l[4] vip_port = l[5] if poolname != '': monic_name = 'TCP_' + str(vip_port) if device.exist(f"/mgmt/tm/ltm/monitor/tcp/{rest_format(monic_name)}"): print(f"monitor {monic_name} exists.") else: #raise Exception(f"monitor {member_name} in {pool_name}.") data = {} data["name"] = monic_name data["destination"] = '*.' + str(vip_port) monitor = device.create(f"/mgmt/tm/ltm/monitor/tcp", data) if monitor.properties["fullPath"] != '/Common/' + monic_name: raise Exception(monitor.properties["fullPath"]) else: print(f"Health Monitor {monic_name} created.") # # if vip_port == '80' or vip_port == '443': # moni_name = 'http' # else:
import getpass import os import hashlib import sys # Internal imports # Import only with "from x import y", to simplify the code. from bigrest.bigip import BIGIP from bigrest.utils.utils import rest_format from bigrest.utils.utils import token # Get username, password, and ip F5_Host = input('Device IP or name: ') print("Username: "******"") F5_username = input() F5_password = getpass.getpass('Password: ') #print("Device IP or name: ", end="") # Create a device object with basic authentication device = BIGIP(F5_Host, F5_username, F5_password) # Add pool member pool_name = "pool_80_172.97.1.99" member_name = "/Common/node_10.99.0.20:80" path = (f"/mgmt/tm/ltm/pool/{rest_format(pool_name)}" f"/members/{rest_format(member_name)}") # Test if poolmember not exists if device.exist(path): print(f"poolmember {member_name} in {pool_name} exists.") else: raise Exception(f"Creat poolmemeber {member_name} in {pool_name}.")
print('請輸入資料 port list,如 \n80\n443\n8080\n...直接按下Enter 結束 : ') port_buffer = [] while True: line = sys.stdin.readline().rstrip('\n') if line == '': break else: port_buffer.append(line) #print (buffer) port_list = port_buffer # Create pool for pools in port_list: pool_names = 'pool_' + pools + '_' + VIP_address if device.exist(f"/mgmt/tm/ltm/pool/{rest_format(pool_names)}"): print(f"Pool {pool_names} exists.") else: #raise Exception(f"Create {pool_names} and Check not exists.") data = {} data["name"] = pool_names print(pool_names) data["description"] = Job_name pool = device.create("/mgmt/tm/ltm/pool", data) if pool.properties["fullPath"] != '/Common/' + pool_names: raise Exception(pool.properties["fullPath"]) else: print(f"Pool {pool_names} created.") ## Add pool member #for port in port_list: