Skip to content

Instantly share code, notes, and snippets.

@f5-rahm
f5-rahm / dgmgmt.py
Created January 9, 2021 04:16
This script was created for managing individual or multiple data-group records on BIG-IP without having to update the entire record set. It uses a combination of a tmsh script on BIG-IP with a python script executed remotely.
###################################################################################
# dgmgmt.py
#
# author: jason rahm
# tmsh script author: john alam
#
# usage: dgmgmt.py [-h] host user {add,modify,delete} datagroup dgvalues
#
# positional arguments:
# host BIG-IP IP/FQDN
###################################################################################
# dgmgmt.py
#
# author: jason rahm
#
# usage: dgmgmt.py [-h] host user {add,modify,delete} datagroup dgvalues
#
# positional arguments:
# host BIG-IP IP/FQDN
# user BIG-IP Username
#####################################################
### Required net resolver - example configuration ###
#####################################################
#net dns-resolver r1 {
# forward-zones {
# . {
# nameservers {
# 8.8.8.8:domain { }
# 9.9.9.9:domain { }
@f5-rahm
f5-rahm / toolchain_prep.py
Created May 5, 2021 16:07
Upload the F5 Automation Toolchain packages
import argparse
import sys
from time import sleep
from bigrest.bigip import BIGIP
from bigrest.common.exceptions import RESTAPIError
from pathlib import Path
DO = "/Users/rahm/Downloads/f5-declarative-onboarding-1.20.0-2.noarch.rpm"
@f5-rahm
f5-rahm / file_upload.py
Created May 21, 2021 15:41
Upload files to BIG-IP with python
def _upload(host, creds, fp):
chunk_size = 512 * 1024
headers = {
'Content-Type': 'application/octet-stream'
}
fileobj = open(fp, 'rb')
filename = os.path.basename(fp)
if os.path.splitext(filename)[-1] == '.iso':
uri = 'https://%s/mgmt/cm/autodeploy/software-image-uploads/%s' % (host, filename)
@f5-rahm
f5-rahm / tmos_install.py
Created September 8, 2021 01:21
INCOMPLETE - Install tmos on BIG-IP
###################################################################################
# tmos_install.py
# v 0.1 - INCOMPLETE
#
# author: jason rahm
#
# usage: tmos_install.py [-h] [-a] inventory user password
#
# positional arguments:
# inventory inventory file (host IP/FQDN,image path)
import bigsuds
b = bigsuds.BIGIP(hostname='ltm3.test.local')
zone_view = {'view_name': 'external',
'zone_name': 'dctest1.local.'
}
b.Management.Zone.zone_exist([zone_view])
# [0]
@f5-rahm
f5-rahm / afm_policy_rules_xlsx_export.py
Created July 21, 2022 20:43
Export AFM policies to Excel
from bigrest.bigip import BIGIP
import argparse
import getpass
import sys
import xlsxwriter
def build_parser():
parser = argparse.ArgumentParser()
parser.add_argument("host", help="BIG-IP IP/FQDN")
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'}
@f5-rahm
f5-rahm / runtime_calc_v2.py
Created September 1, 2022 15:43
Excel output of iRule performance
# coding=utf-8
#
# Copyright 2015-2019 F5 Networks Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#