def instantiate_bigip(host, user, password): try: obj = BIGIP(host, user, password) except Exception as e: print(f"Failed to connect to {host} due to {type(e).__name__}:\n") print(f"{e}") sys.exit() return obj
def login_per(): try: BIGIP_ADDRESS = input('F5_Host: ') USERNAME = input('Username: '******'Password: '******'ACL Username: '******'ACL IP Address: ').lower() # user_acl(device, acl_username, acl_ip_list)
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: '******'請輸入資料 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
# REVISION: --- #=============================================================================== 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) partition_name = "/Common/" # ## Print virtual servers name virtuals = device.load("/mgmt/tm/ltm/virtual") print("List all virtual servers:") for virtual in virtuals: print(virtual.properties["name"]) print(virtual.properties["translatePort"]) #print(virtual)
Job_name = input('輸入單號或說明: ') #print("Node_ip : ", end="") #node_ip_address = input() print('請輸入資料_IP_Address,直接按下Enter 結束 : ') 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"] = Job_name node = device.create( f"/mgmt/tm/ltm/node/", data) if node.properties["fullPath"] != '/Common/' + 'node_' + node_ip_address:
requests.packages.urllib3.disable_warnings() import os import hashlib # 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 print('輸入帳號_Please enter credentials to login into Load Balancer -' + '\r') #F5_Host_IP = input('F5_mgmt_IP: ') F5_Host_IP = "192.168.101.167" f5_user = input('Username: '******'Password: '******',')) #print(pool_name) #for x in pool_member_list: # pool_member = '/Common/' + x # data = {} # #pool_name = "pool_8081_172.99.1.100" # #pool_member = "/Common/node_10.99.0.11:8081" # #Fource_Offline # state = "user-down" # session = "user-disabled" # # Static # data["state"] = state
import logging # ini option HTTPS F5 import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecurePlatformWarning) from bigrest.bigip import BIGIP ## # # F5 Host # try: BIGIP_ADDRESS = input('F5_GTM_Host: ') USERNAME = input('Username: '******'Password: '******'_VS_Wideip_' + tf + '.txt'
import os import hashlib # 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 from dateutil.parser import parse print('輸入帳號_Please enter credentials to login into Load Balancer -' + '\r') #F5_Host_IP = input('F5_mgmt_IP: ') F5_Host_IP = "172.19.4.166" f5_user = input('Username: '******'Password: '******'/mgmt/tm/sys/file/ssl-cert') for v in v2: #print(v.properties.get('name')) #print("\t{}".format(v.properties.get('subjectAlternativeName'))) tick = 0 crt = 0 # subnnn = v.properties.get('subjectAlternativeName') # exday = v.properties.get('expirationDate') expiration = parse(v.properties.get('expirationString')) #print(expiration) #print( '\t' + str((expiration.date() - datetime.date.today())) + '\t' + str(v.properties.get('name') + '\r' )) #if (((expiration.date() - datetime.date.today()).days <= 30 ) and ((expiration.date() - datetime.date.today()).days > 0 )): if ((expiration.date() - datetime.date.today()).days <= 30): tick = 1
requests.packages.urllib3.disable_warnings() import os import hashlib # 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 print('輸入帳號_Please enter credentials to login into Load Balancer -' + '\r') F5_Host_IP = input('F5_mgmt_IP: ') #F5_Host_IP = "172.19.37.248" f5_user = input('Username: '******'Password: ') device = BIGIP(F5_Host_IP, f5_user, f5_pw) # Print Pool name pools = device.load("/mgmt/tm/ltm/pool") print("List all Pool list:") for pool in pools: print(pool.properties["name"]) pool_n = pool.properties["name"] member = device.load(f"/mgmt/tm/ltm/pool/{rest_format(pool_n)}/members") for pool_member in member: print("\t {}".format(pool_member.properties["name"])) # Print node example #nodes = device.load(f"/mgmt/tm/ltm/node") #print("Print node example:") #for node in nodes: #` print(node.properties["name"])
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}.")
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("Node_ip : ", end="") #node_ip_address = input() VIP_address = input('VIP Address: ') print('請輸入資料 port list,如 \n80\n443\n8080\n...直接按下Enter 結束 : ') port_buffer = [] while True: line = sys.stdin.readline().rstrip('\n') if line == '': break else:
# 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 print("Username: "******"") username = input() password = getpass.getpass() print("Device IP or name: ", end="") #host = input() host = '192.168.88.166' print("Connect: {}".format(host)) # Create a device object with basic authentication device = BIGIP(host, username, password) print("select IP: ", end="") #s_n_ip = input() # Node to search for print('Node_清單使用換行分隔\n10.99.0.11\n10.99.0.12\n10.99.0.13\n.....\nIPaddress: ') try: member_list = [] while True: sn = input().strip() if sn == '': break member_list.append(sn) except: pass #action = input('[enabled, disabled, forced_offline, checked] : ')
username = parsed_args.username password = parsed_args.password pool_name = parsed_args.pool member = parsed_args.member action = str(parsed_args.action).lower() # # Get username, password, and ip print("Username: "******"") #username = input() #password = getpass.getpass() print("Device IP or name: ", end="") #host = input() #host = '192.168.88.166' print("Connect: {}".format(host)) # Create a device object with basic authentication device = BIGIP(host, username, password) if action == 'enabled': #enable actiont = {} actiont["state"] = "user-up" actiont["session"] = "user-enabled" pool_updated = device.modify( f"/mgmt/tm/ltm/pool/{pool_name}/members/~Common~{member}", actiont) pool_detail = device.load( f"/mgmt/tm/ltm/pool/{pool_name}/members/~Common~{member}") mem_status = pool_detail.properties['state'] pool_ststs = device.show( f"/mgmt/tm/ltm/pool/{pool_name}/members/~Common~{member}") mem_curr_conns = pool_ststs.properties["curSessions"]["value"] print("Member 目前狀態 : {} ".format(mem_status))
profile_name = "serverssl" # Get username, password, and ip print("Username: "******"") username = input() password = getpass.getpass() print("Device IP or name: ", end="") ip = input() print("Virtual Server Name: ", end="") domain_name = input() print(f"Domain Name is: {domain_name}") # Connect to BigIP b = BIGIP(ip, username, password) # Load the Profiles on a virtual server profiles = b.load(f"/mgmt/tm/ltm/virtual/{rest_format(domain_name)}/profiles") print(f"List of Profiles attached to {domain_name}") profile_context_list = [] for p in profiles: profile_context_list.append(p.properties["context"]) print(profile_context_list) if "serverside" in profile_context_list: print("Serverside SSL applied") print("Deleting Serverside SSL profile") path = ( f"/mgmt/tm/ltm/virtual/{rest_format(domain_name)}/profiles/{rest_format(profile_name)}"
import hashlib # 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 print('輸入帳號_Please enter credentials to login into Load Balancer -' + '\r') #F5_Host_IP = input('F5_mgmt_IP: ') F5_Host_IP = "172.19.4.166" f5_user = input('Username: '******'Password: '******'/mgmt/tm/ltm/pool') for p in p2: print(p.properties.get('name')) pirv = p.properties.get('name') pool = f5br.show(f"/mgmt/tm/ltm/pool/{rest_format(pirv)}") poolmem = f5br.load(f"/mgmt/tm/ltm/pool/{rest_format(pirv)}/members") for pm in poolmem: #print(pm.properties.get('name')) pmn = pm.properties.get('name') poolmemr = f5br.show(f"/mgmt/tm/ltm/pool/{rest_format(pirv)}/members/{rest_format(pmn)}") pmcurrent = poolmemr.properties["serverside.curConns"]["value"] print("\tpm-name : {} ,Current : {}".format(pmn, pmcurrent)) ###
#ip_input = '' #count = 0 #for line in iter(input,stopword): # count = count + 1 # ip_input+=line+',' # ip_lists = [] while True: s = input("輸入檢查 the IP address or press ENTER for Output: ") if s: ip_lists.append(s) else: break; # print(ip_lists) device = BIGIP(F5_Host_IP, f5_user, f5_pw) APM_ACL = device.load("/mgmt/tm/apm/acl") count = 0 aaacls = [] for acls in APM_ACL: #print(acls) #print(acls.properties['entries']) count = count + 1 n = acls.properties["name"] od = acls.properties["aclOrder"] #print("\n{}. ACL_Name : {}".format(count, n)) for k, v in acls.properties.items(): #print(k) #print("\n{}. ACL_Name : {}".format(count, n)) if k == 'entries': try:
from bigrest.bigip import BIGIP import logging, ipaddress import getpass import re import time import datetime #from datetime import datetime # f5_host = input('F5-IP: ') f5user = input('Username: '******'Password: '******'Find_Username ( ex: 10.101.139.21 ) : ') try: # Need to re-write this to store as an encrypted credential file #mgmt = ManagementRoot("192.168.1.11","admin","121278") device = BIGIP(f5_host, f5user, f5pw) except Exception as e: #logging.error("Error in connecting to bigip.",e) print("登入失敗 : {} ".format(e)) #print(e) exit() # t1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') print("開始時間 : {}".format(t1)) poolstats = device.show('/mgmt/tm/ltm/pool') for p in poolstats: for k, v in p.properties.items(): if v.get('description') != None: print(f'{k}: {v.get("description")}') elif v.get('value') != None: print(f'{k}: {v.get("value")}')
F5_Host = input() #print("Node_ip : ", end="") #node_ip_address = input() print('請輸入資料_IP_Address,直接按下Enter 結束 : ') 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:
import os import hashlib # 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 print('輸入帳號_Please enter credentials to login into Load Balancer -' + '\r') F5_Host_IP = input('F5_mgmt_IP: ') #F5_Host_IP = "172.19.37.248" f5_user = input('Username: '******'Password: ') device = BIGIP(F5_Host_IP, f5_user, f5_pw) # Print Pool name #pools = device.load("/mgmt/tm/ltm/pool") #print("List all Pool list:") #for pool in pools: # print(pool.properties["name"]) # pool_n = pool.properties["name"] # member = device.load(f"/mgmt/tm/ltm/pool/{rest_format(pool_n)}/members") # for pool_member in member: # print("\t {}".format(pool_member.properties["name"])) ## Print node example #nodes = device.load(f"/mgmt/tm/ltm/node") #print("Print node example:") #for node in nodes:
# print(data) member = pd.DataFrame(data, columns=["App_Name", "Create_Date", "Description", "type", "VIP", "VIP_port", "pool_member_ip", "pool_member_port"]) appv = member.values count = 0 print("\n") #導入excel數據 --------end----------- #dcreate auth token f5_ip = input("請輸入F5管理IP : ") username = input("請輸入F5管理帳戶 : ") password = getpass.getpass("請輸入F5管理密碼 : ") # # Create a device object with basic authentication device = BIGIP(f5_ip, username, password) # req_url = 'https://%s/mgmt/shared/authn/login' %(f5_ip) data = {'username':username, 'password':password, 'loginProviderName':'tmos' } r = requests.post(req_url,json.dumps(data),verify = False) # #get auth token f5_rep = json.loads(r.text) f5_token = f5_rep['token']['token'] # #header for connection f5 creat_header = { 'X-F5-Auth-Token':f5_token,
# 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 print("Username: "******"") username = input() password = getpass.getpass() print("Device IP or name: ", end="") #ip = input() ip = '192.168.84.167' print("Connect: {}".format(ip)) # Create a device object with basic authentication device = BIGIP(ip, username, password) # Print virtual servers name # 列出所有 Virtula server virtuals = device.load("/mgmt/tm/ltm/virtual") count = 0 print("List all virtual servers:") for virtual in virtuals: count = count + 1 vs_name = virtual.properties["name"] vsstats = device.show(f"/mgmt/tm/ltm/virtual/{rest_format(vs_name)}") #print(virtual.properties["name"]) print( f'Maximum number of connections client side: {count}. {vsstats.properties["clientside.curConns"]["value"]}' )