Last active
August 2, 2022 06:08
-
-
Save f5-rahm/eabc01b4cdedccda7cf088babbb4bc07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from typing import Dict | |
from bigrest.bigip import BIGIP | |
def get_credentials() -> Dict: | |
#return {'host': os.getenv('F5_HOST'), 'user': os.getenv('F5_USER'), 'pass': os.getenv('F5_PASS')} | |
return {'host': 'ltm3.test.local', 'user': 'admin', 'pass': 'admin'} | |
def prompt_user(msg: str) -> str: | |
return str(input(f'\t{msg}')) | |
def user_responses() -> str: | |
vip_name: str = prompt_user('Virtual name: ') | |
return vip_name | |
def instantiate_bigip(): | |
credentials = get_credentials() | |
br = BIGIP(credentials.get('host'), credentials.get('user'), credentials.get('pass'), request_token=True) | |
data = {'timeout': '300'} | |
br.modify(f"/mgmt/shared/authz/tokens/{br.session.headers._store.get('x-f5-auth-token')[1]}", data) | |
return br | |
def get_http_profile(bigip, vip_name): | |
vip_profiles = bigip.load(f'/mgmt/tm/ltm/virtual/{vip_name}/profiles') | |
http_profile = '' | |
for profile in vip_profiles: | |
if bigip.exist(f'/mgmt/tm/ltm/profile/http/{profile.properties.get("name")}'): | |
http_profile = profile.properties.get('name') | |
if http_profile != '': | |
print(f'\tVirtual {vip_name} has associated http profile {http_profile}...continuing.') | |
return http_profile | |
else: | |
sys.exit(f'\tVirtual {vip_name} has no associated http profile...exiting.') | |
if __name__ == '__main__': | |
vip_name = user_responses() | |
br = instantiate_bigip() | |
profile_name = get_http_profile(br, vip_name) | |
print(profile_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment