Cloud Director API - Sample script to export EDGE Gateway Firewall Rules as CSV
search cancel

Cloud Director API - Sample script to export EDGE Gateway Firewall Rules as CSV

book

Article ID: 427019

calendar_today

Updated On:

Products

VMware Cloud Director

Issue/Introduction

Currently, exporting Edge Firewall rules to CSV is not a native function within the Cloud Director UI. However, administrators can use the API to extract this information. This guide includes a script designed to query the Cloud Director API, retrieve rule sets in JSON, and convert them into a CSV format automatically.

Environment

Cloud Director 10.x

Resolution

Prerequisites

  • Python 3.x installed on the local machine.

  • Gateway UUID: The unique identifier of the target Edge Gateway.

  • Access Token: A valid Bearer Token from an active VCD session.

Procedure

Step 1: Prepare the Environment

Ensure the Python requests library is installed:

Bash
pip install requests

Step 2: Retrieve Configuration Data

  1. EDGE Gateway UUID:

    • Navigate to the Edge Gateway in the VCD UI.

    • Extract the UUID from the URL

      • Eg: If the URL is "https://{{vcd_host}}/tenant/{{tennant}}/domain-networking/org-edge-gateways/cloud/urn:vcloud:gateway:7exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe6/config/general", The edge gateway UUID is:  7exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe6
  2. Bearer Token (one of the below): 

    • Browser:

      • Log into the VCD UI.

      • Open Developer Tools (F12) > Network.

      • Locate the Authorization header in any request.

      • Copy the token string (excluding "Bearer ").

    • API: Generate Bearer token by following KB: 320526

Step 3: Configure the Script

  1. Edit the attached export_firewall.py.

  2. Update BEARER_TOKEN AND VCD_HOST with in the script

Step 4: Execution & Output

  1. Run the script: python3 export_firewall.py

  2. Input the EDGE Gateway UUID when prompted.

  3. The script will generate two files in the working directory named after the UUID:

    • <UUID>.csv: The formatted report.

    • <UUID>.json: The raw data dump.

Attachments

export_firewall_1769763847708.py get_app