Making Cloud Drawings with Python
Tags: cloud, drawings, python
Published: 2023-10-30 16:50:21

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jakm5al9mt7sediigh4u.png)
So building a sketch like the following is done in under a minute!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w992yvy6bmmvieupdfaj.png)

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
```
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/back8x77k36h9j3px7ao.png)

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
```
The result is great! 👍 (okay for me only maybe 😊).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv9sa3lqpdo33l9jmntj.png)

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