F5 Automation Toolchain: Upload the Components with BIGREST!

If you've ever flown in earshot of a pilot or been handed a to-do list from your mommy or significant other, then you are quite familiar with eleventy billion step processes. I may be rounding up there a little. But that is similar to using an imperative approach to automation. The F5 Automation Toolchain, however, is a declarative approach to automation. You throw a big blob (technical term) of JSON data at the BIG-IP in a single declaration and BIG-IP does all the work for you. We will not use the components of the toolchain in this article, but we will get them all installed for use.

Prerequisites

In order to install the components of the toolchain, you need to download them first. You can find them in the releases of each respective repository on GitHub. I chose the latest release, but there are LTS versions as well if that’s important to your organization.

Process

The upload and installation procedures are defined in each respective components clouddocs documentation.

The process is made super simple for you though: upload, install, verify.

Upload

To upload each component, you need to send the data to the /mgmt/shared/file-transfer/uploads endpoint in iControl REST. This puts the files in /var/config/rest/downloads on the BIG-IP host system. With the python BIGREST library, I’m using the following function to achieve this.

def upload_file(obj, file_name):
    try:
        obj.upload(f"/mgmt/shared/file-transfer/uploads/", file_name)
    except Exception as e:
        print(f"Failed to upload the component due to {type(e).__name__}:\n")
        print(f"{e}")
        sys.exit()

Install

Installing each component requires a call to the /mgmt/shared/iapp/package-management-tasks endpoint with a JSON blob stating the INSTALL operation and the path to the component we uploaded. This is the function for this:

def install_package(obj, file_name):
    try:
        data = {"operation": "INSTALL", "packageFilePath": f"/var/config/rest/downloads/{Path(file_name).name}"}
        obj.command("/mgmt/shared/iapp/package-management-tasks", data)
    except Exception as e:
        print(f"Failed to install the component due to {type(e).__name__}:\n")
        print(f"{e}")
        sys.exit()

Verify

Verification takes a little more customization as each is different and one of the component’s data format for the version is different as well. But the basic endpoint that needs to be queried to validate that the package is installed and available for service is /mgmt/shared/$component/info, where $component is updated accordingly like so:

  • /mgmt/shared/declarative-onboarding/info
  • /mgmt/shared/appsvcs/info
  • /mgmt/shared/telemetry/info

The function for verification:

def verify_package(obj, file_name):
    component = Path(file_name).name
    if "f5-declarative-onboarding" in component:
        try:
            result = obj.load("/mgmt/shared/declarative-onboarding/info")
            if result.properties[0].get('version') in component:
                return True
            else:
                return False
        except RESTAPIError:
            return False
    elif "f5-appsvcs" in component:
        try:
            result = obj.load("/mgmt/shared/appsvcs/info")
            if result.properties.get('version') in component:
                return True
            else:
                return False
        except RESTAPIError:
            return False
    elif "f5-telemetry" in component:
        try:
            result = obj.load("/mgmt/shared/telemetry/info")
            if result.properties.get('version') in component:
                return True
            else:
                return False
        except RESTAPIError:
            return False
    else:
        return False

Success!

Putting it all together, when I run the script, I get the following feedback

(venv) me@mine scripts % python toolchain_prep.py 10.0.2.26 admin admin

Instantiating BIG-IP (host 10.0.2.26)

Uploading packages
        Uploading f5-declarative-onboarding-1.20.0-2.noarch.rpm
        Uploading f5-appsvcs-3.27.0-3.noarch.rpm
        Uploading f5-telemetry-1.19.0-3.noarch.rpm

Installing packages
        Installing f5-declarative-onboarding-1.20.0-2.noarch.rpm
        Installing f5-appsvcs-3.27.0-3.noarch.rpm
        Installing f5-telemetry-1.19.0-3.noarch.rpm

Quick break to register packages...

Verifying packages
        f5-declarative-onboarding-1.20.0-2.noarch.rpm installed and verified
        f5-appsvcs-3.27.0-3.noarch.rpm installed and verified
        f5-telemetry-1.19.0-3.noarch.rpm installed and verified


---complete---

The full source for this script is in the codeshare. Note that you'll need to be at least at version 1.3.3 of BIGREST for this to work.

Conclusion

You are now free to move about the cabin. And start declaring your BIG-IP configurations like a boss. And bonus news: the AS3 Configuration Converter, or ACC, was recently released and is available on GitHub. This takes the guess work out of converting your configuration to the proper AS3 declaration schema. Join us on DevCentral Connects this Thursday for a conversation with Ben Gordon on how to accomplish all this in VS Code.

Published May 05, 2021
Version 1.0
No CommentsBe the first to comment