Difference between revisions of "F5 sdk snippets"
Jump to navigation
Jump to search
Line 26: | Line 26: | ||
r = session.get(url, verify=False) | r = session.get(url, verify=False) | ||
r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries'] | r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries'] | ||
+ | ``` | ||
+ | |||
+ | ``` | ||
+ | import pprint as pp | ||
+ | pools_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" | ||
+ | pools_rsp = session.get(pools_url) | ||
+ | for pool in pools_rsp.json()['items']: | ||
+ | print(pool['name'], pool['partition']) | ||
+ | pool_stats_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" | ||
+ | pool_stats_url_local = f"https://localhost/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" | ||
+ | pool_stats_rsp = session.get(pool_stats_url) | ||
+ | pool_stats = pool_stats_rsp.json()['entries'][pool_stats_url_local]['nestedStats']['entries'] | ||
+ | pp.pprint(pool_stats) | ||
+ | break | ||
``` | ``` | ||
Revision as of 18:51, 10 September 2023
import requests import os requests.packages.urllib3.disable_warnings() F5_HOST = os.getenv('AD_HOST') AD_USER = os.getenv('AD_USER') AD_PASS = os.environ.get('AD_PASS') url = f"https://{F5_HOST}/mgmt/tm/ltm/virtual" session = requests.Session() session.auth = (AD_USER, AD_PASS)
Virtuals
r = session.get(url, verify=False) r.json()['entries']['https://localhost/mgmt/tm/ltm/virtual/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries']
Pools
url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" url = "https://{F5_HOST}/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats" r = session.get(url, verify=False) r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries']
import pprint as pp pools_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" pools_rsp = session.get(pools_url) for pool in pools_rsp.json()['items']: print(pool['name'], pool['partition']) pool_stats_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" pool_stats_url_local = f"https://localhost/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" pool_stats_rsp = session.get(pool_stats_url) pool_stats = pool_stats_rsp.json()['entries'][pool_stats_url_local]['nestedStats']['entries'] pp.pprint(pool_stats) break
Members (Pool)
url = "https://{F5_HOST}/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/members"
Nodes
url = "https://{F5_HOST}/mgmt/tm/ltm/node/~QA~foo-backend~/stats" url = https://{F5_HOST}/mgmt/tm/ltm/node