mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
39.27k stars 2.52k forks source link

Creating variables without making a node on the diagram #745

Open rerouch opened 2 years ago

rerouch commented 2 years ago

Hello,

I'm trying to make a design with Diagrams but I've ran into an issue which is blocking my progress. To solve this I would need to do one of three things:

I think the most realistic solution would be the first one. This is basically the part of the code that's causing me issues right now.

Excel sheet with one row containing local IP's and another row containing destination IP's.

workbook = pandas.read_excel("C:/test.xlsx")

from diagrams.aws.compute import EC2

empty dictionary

dic = {}

graph_attr={ "splines": "spline", }

create the diagram itself going from top to bottom

with Diagram("Web Service", show=True, filename='TEST', direction='TB', graph_attr=graph_attr):

loop over the excel sheet

 for i, row in workbook.iterrows():
        local_ip = ""
        source = row['LOCAL_IP']
        destination = row['DESTINATION_IP']
        local_hostname_src = row['SOURCE']

Every row gets added to a dictionary. And I create an entry in my dictionary that links this object to a Diagrams object.

I do this so I'm able to reuse the same variable in my script without having 4 different instances of the same object.

        dic[f"{source}"] = EC2(local_hostname_src)

        local_hostname_dst = row['DESTINATION']
        dic[f"{destination}"] = EC2(local_hostname_dst)

The issue I'm running into is that when I run this code: dic[f"{destination}"] = EC2(local_hostname_dst), a node gets created on my diagram. This node is not connected to anything but just stands in the way. Is there a way to assign this variable without anything being created on the diagram itself?

Thanks in advance for your help.

clayms commented 2 years ago

see if these will help

https://github.com/mingrammer/diagrams/issues/436#issuecomment-800563909

https://github.com/mingrammer/diagrams/issues/516#issuecomment-838382910

https://github.com/mingrammer/diagrams/issues/487#issuecomment-800517538