Skip to content

l2fprod/vpc-diagram-exporter

Repository files navigation

Generates a diagram of IBM Cloud VPC resources

Build Status

Use this tool to export a visual representation of the existing VPC resources in your IBM Cloud account.

ibmcloud is ➡️ JSON ➡️ GraphViz ➡️ PNG

VPC diagram

Try it now with the Docker image

  1. The Docker image has all required dependencies. Just run:
    docker run --rm --volume $HOME:/home -it l2fprod/vpc-diagram-exporter
    
  2. Once the container is running, log in your IBM Cloud account inside the container:
    ibmcloud login
    
  3. Set the VPC target generation:
    ibmcloud is target --gen 2
    
  4. Change to a directory under the home volume
    cd /home/...path-to-my-project-where-files-will-be-created/
    
  5. Run the export script, it will create an output folder in the current directory:
    vpc-diagram-exporter
    
  6. Find your exported diagrams (one PNG per VPC) in the output folder.

Or go manual

Prerequisites

You will need:

  • Python 3
  • pip3
  • graphviz (brew install graphviz) on a mac
  • vpc-infrastructure plugin for ibmcloud (ibmcloud plugin install vpc-infrastructure)

If you want to save yourself some time in the future, use my IBM Cloud CLI docker image ;)

Before you begin

The tool is written in Python with a small set of helpers to wrap the ibmcloud CLI so you can benefit from Python language features to interact with the VPC API.

  1. Install Python requirements:

    pip3 install -r requirements.txt
  2. Make sure your VPC environment is correctly configured:

    ibmcloud is vpcs
  3. Unset the current target resource group so that all VPC elements are returned:

    ibmcloud target --unset-resource-group

Export all VPC resources into one big JSON file

dump.py exports all VPC resources into a big JSON files. It calls the ibmcloud command and requires the is plugin. If ibmcloud is vpcs works in your environment, the script should work too.

python3 dump.py

The script runs a few commands and produces output/all.json

Convert the JSON into GraphViz

json2gv.py produces a Graphviz diagram of the elements in output/all.json. It uses a Jinja2 template to convert the JSON exported earlier into one Graphviz file per VPC (vpcname.gv) under the output folder.

To get the Graphviz input:

python3 json2gv.py

Generate PNG images

To generate a PNG for all VPCs (all graphvizs in the folder):

find output -name '*.gv' -exec dot {} -Tpng -o{}.png \;

Or to generate a PNG for a specific VPC:

dot vpcname.gv -Tpng -ovpcname.png

One liner

PNG

python3 dump.py && rm -f output/*.gv output/*.gv.png && python3 json2gv.py && find output -name '*.gv' -exec dot {} -Tpng -o{}.png \;

SVG

python3 dump.py && rm -f output/*.gv output/*.gv.svg && python3 json2gv.py && find output -name '*.gv' -exec dot {} -Tsvg -o{}.svg \;

Documentation

License

This project is licensed under the Apache License Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).

About

Generates a diagram of IBM Cloud VPC resources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published