Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/l2fprod/vpc-diagram-exporter
Generates a diagram of IBM Cloud VPC resources
https://github.com/l2fprod/vpc-diagram-exporter
Last synced: 1 day ago
JSON representation
Generates a diagram of IBM Cloud VPC resources
- Host: GitHub
- URL: https://github.com/l2fprod/vpc-diagram-exporter
- Owner: l2fprod
- License: apache-2.0
- Created: 2019-03-12T15:55:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-28T16:17:34.000Z (almost 2 years ago)
- Last Synced: 2023-03-10T20:56:12.129Z (over 1 year ago)
- Language: Jinja
- Homepage: https://cloud.ibm.com/vpc/overview
- Size: 485 KB
- Stars: 15
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Generates a diagram of IBM Cloud VPC resources
[![Build Status](https://travis-ci.org/l2fprod/vpc-diagram-exporter.svg?branch=master)](https://travis-ci.org/l2fprod/vpc-diagram-exporter)
Use this tool to export a visual representation of the existing VPC resources in your IBM Cloud account.
`ibmcloud is` :arrow_right: JSON :arrow_right: [GraphViz](https://www.graphviz.org/) :arrow_right: PNG
![VPC diagram](example.png)
## 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
```
1. Once the container is running, log in your IBM Cloud account inside the container:
```
ibmcloud login
```
1. Set the VPC target generation:
```
ibmcloud is target --gen 2
```
1. Change to a directory under the `home` volume
```
cd /home/...path-to-my-project-where-files-will-be-created/
```
1. Run the export script, it will create an `output` folder in the current directory:
```
vpc-diagram-exporter
```
1. Find your exported diagrams (one PNG per VPC) in the `output` folder.## Or go manual
### Prerequisites
You will need:
* Python 3
* pip3
* [graphviz](https://www.graphviz.org/) (`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](https://github.com/l2fprod/bxshell) ;)
### 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:
```sh
pip3 install -r requirements.txt
```1. Make sure your VPC environment is correctly configured:
```sh
ibmcloud is vpcs
```1. Unset the current target resource group so that all VPC elements are returned:
```sh
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.
```sh
python3 dump.py
```The script runs a few commands and produces `output/all.json`
### Convert the JSON into GraphViz
`json2gv.py` produces a [Graphviz](https://www.graphviz.org/) 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:
```sh
python3 json2gv.py
```### Generate PNG images
To generate a PNG for all VPCs (all graphvizs in the folder):
```sh
find output -name '*.gv' -exec dot {} -Tpng -o{}.png \;
```Or to generate a PNG for a specific VPC:
```sh
dot vpcname.gv -Tpng -ovpcname.png
```### One liner
**PNG**
```sh
python3 dump.py && rm -f output/*.gv output/*.gv.png && python3 json2gv.py && find output -name '*.gv' -exec dot {} -Tpng -o{}.png \;
```**SVG**
```sh
python3 dump.py && rm -f output/*.gv output/*.gv.svg && python3 json2gv.py && find output -name '*.gv' -exec dot {} -Tsvg -o{}.svg \;
```## Documentation
- [IBM Cloud Virtual Private Cloud](https://cloud.ibm.com/docs/vpc?topic=vpc-getting-started)
## License
This project is licensed under the Apache License Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).