DEV Community

Alain Airom
Alain Airom

Posted on

Making Cloud Drawings with Python

My first experience in writing a sample code in Python to make cloud drawings!

Usually, when I intend to build professional drawings for my projects, I use ‘draw.io’ (https://app.diagrams.net/) which I find a fantastic tool. It could be used either online or as a desktop application and the available shapes library is huge. All the major hyper scalers/cloud providers are available (AWS, Azure, GCP, and for sure the most important one for me, IBM)

Image description
So building a sketch like the following is done in under a minute!

Image description

But recently, I saw a post on a Python library; ‘Diagrams’ (https://diagrams.mingrammer.com/docs/getting-started/installation) that generates diagrams by code!

The installation is quite straightforward;

# using pip (pip3)
$ pip install diagrams

# using pipenv
$ pipenv install diagrams

# using poetry
$ poetry add diagrams
Enter fullscreen mode Exit fullscreen mode

You also need to install Graphviz to render the diagrams (https://www.graphviz.org/) otherwise it won’t work. The documentation for ‘Diagrams’ is quite clear and some very nice samples are provided. Packages for making diagrams are provided for all major players.

Image description

It is also very easy to add custom icons/images to the existing sets (which I did for my test).

Once the installations are done, it is quite easy, even for me who is a novice Python coder. I was able to provide the following code in less than 30 minutes to make a basic diagram.

#custom
from diagrams import Diagram, Cluster
from diagrams.custom import Custom

#k8s
from diagrams.k8s.infra import Master, Node


with Diagram("IBM Cloud Compute Services", show=False, filename="custom_local", direction="TB"):
  ibm_cloud = Custom("IBM Cloud", "./my_resources/CloudTag.png")

  with Cluster("Compute"):
    with Cluster("Kubernetes Services"):
      iks = Custom("IKS", "./my_resources/GeneralClusterTag.png")
      k8s = Custom("k8s", "./my_resources/KubeClusterTag.png")
      iks_classic = Custom("IKS Classic", "./my_resources/iks-classic.png")
      iks_vpc = Custom("IKS VPC", "./my_resources/iks-vpc.png")
      ocp = Custom("OpenShift", "./my_resources/OpenShiftClusterTag.png")
      ocp_classic = Custom("OpenShift Classic", "./my_resources/ocp-classic.png")
      ocp_vpc = Custom("OpenShift VPC", "./my_resources/ocp-vpc.png")
      ocp_satellite = Custom("OpenShift Satelliet", "./my_resources/ocp-satellite.png")

    with Cluster("Virtual Servers"):
      vsi = Custom("Classic VSI", "./my_resources/ClassicTag.png")
      vpc = Custom("VPC", "./my_resources/VPCTag.png")
      vpcarch = Custom("VPC", "./my_resources/ibm_vpc_architecture_drawio.png")

    with Cluster("Bare Metam"):
      baremetal = Custom("Bare Metal", "./my_resources/BareMetalServerTag.png")

    #with Cluster("PaaS"):
    #  paas = Custom("PaaS", "./my_resources/FoundryTag.png")

    with Cluster("VMWare"):
      vmware_svc = Custom("VMWare Services", "./my_resources/vmware-svc.png")
      vmware = Custom("VMWare Services", "./my_resources/vmware.png")

    with Cluster("Power"):
      powervs = Custom("Power VS", "./my_resources/powervs.png")

    with Cluster("Serverless"):
      codeengine = Custom("Code Engine", "./my_resources/codeengine.png")

  ibm_cloud >> iks >> k8s
  k8s >> iks_classic
  k8s >> iks_vpc
  ibm_cloud >> ocp
  ocp >> ocp_classic
  ocp >> ocp_vpc
  ocp >> ocp_satellite
  #ibm_cloud >> paas
  ibm_cloud >> codeengine 
  ibm_cloud >> vmware_svc
  vmware_svc >> vmware
  ibm_cloud >> baremetal
  ibm_cloud >> vsi
  ibm_cloud >> vpc >> vpcarch
  ibm_cloud >> powervs
Enter fullscreen mode Exit fullscreen mode

The result is great! 👍 (okay for me only maybe 😊).

Image description

This is my first step. Stay tuned for more work to come and thanks for reading.

Top comments (1)

Collapse
 
mmascioni profile image
Matt Mascioni

This is so cool! TIL this package exists, will look at using it in a future project 🚀 Reminds me a lot of Mermaid, big fan of diagrams-as-code as they're way easier to maintain for cases like this.