You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node.md 4.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ---
  2. id: node
  3. title: Nodes
  4. ---
  5. `Node` is an object representing a node or system component.
  6. ## Basic
  7. `Node` is an abstract concept that represents a single system component object.
  8. A node object consists of three parts: **provider**, **resource type** and **name**. You may already have seen each part in the previous example.
  9. ```python
  10. from diagrams import Diagram
  11. from diagrams.aws.compute import EC2
  12. with Diagram("Simple Diagram"):
  13. EC2("web")
  14. ```
  15. In the example above, the `EC2` is a node of resource type `compute` which is provided by the `aws` provider.
  16. You can use other node objects in a similar manner:
  17. ```python
  18. # aws resources
  19. from diagrams.aws.compute import ECS, Lambda
  20. from diagrams.aws.database import RDS, ElastiCache
  21. from diagrams.aws.network import ELB, Route53, VPC
  22. ...
  23. # azure resources
  24. from diagrams.azure.compute import FunctionApps
  25. from diagrams.azure.storage import BlobStorage
  26. ...
  27. # alibaba cloud resources
  28. from diagrams.alibabacloud.compute import ECS
  29. from diagrams.alibabacloud.storage import ObjectTableStore
  30. ...
  31. # gcp resources
  32. from diagrams.gcp.compute import AppEngine, GKE
  33. from diagrams.gcp.ml import AutoML
  34. ...
  35. # k8s resources
  36. from diagrams.k8s.compute import Pod, StatefulSet
  37. from diagrams.k8s.network import Service
  38. from diagrams.k8s.storage import PV, PVC, StorageClass
  39. ...
  40. # oracle resources
  41. from diagrams.oci.compute import VirtualMachine, Container
  42. from diagrams.oci.network import Firewall
  43. from diagrams.oci.storage import FileStorage, StorageGateway
  44. ```
  45. You can find lists of all available nodes for each provider in the sidebar on the left.
  46. For example, [here](https://diagrams.mingrammer.com/docs/nodes/aws) is the list of all available AWS nodes.
  47. ## Data Flow
  48. You can represent data flow by connecting the nodes with the operators `>>`, `<<`, and `-`.
  49. - **>>** connects nodes in left to right direction.
  50. - **<<** connects nodes in right to left direction.
  51. - **-** connects nodes in no direction. Undirected.
  52. ```python
  53. from diagrams import Diagram
  54. from diagrams.aws.compute import EC2
  55. from diagrams.aws.database import RDS
  56. from diagrams.aws.network import ELB
  57. from diagrams.aws.storage import S3
  58. with Diagram("Web Services", show=False):
  59. ELB("lb") >> EC2("web") >> RDS("userdb") >> S3("store")
  60. ELB("lb") >> EC2("web") >> RDS("userdb") << EC2("stat")
  61. (ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb")
  62. ```
  63. > Be careful when using `-` and any shift operators together. It can cause unexpected results due to Python's operator precedence, so you might have to use parentheses.
  64. ![web services diagram](/img/web_services_diagram.png)
  65. > The order of rendered diagrams is the reverse of the declaration order.
  66. You can change the data flow direction with the `direction` parameter. The default is **LR**.
  67. > Allowed values are: TB, BT, LR, and RL
  68. ```python
  69. from diagrams import Diagram
  70. from diagrams.aws.compute import EC2
  71. from diagrams.aws.database import RDS
  72. from diagrams.aws.network import ELB
  73. with Diagram("Workers", show=False, direction="TB"):
  74. lb = ELB("lb")
  75. db = RDS("events")
  76. lb >> EC2("worker1") >> db
  77. lb >> EC2("worker2") >> db
  78. lb >> EC2("worker3") >> db
  79. lb >> EC2("worker4") >> db
  80. lb >> EC2("worker5") >> db
  81. ```
  82. ![workers diagram](/img/workers_diagram.png)
  83. ## Group Data Flow
  84. The above worker example has too many redundant flows. To avoid this, you can group nodes into a list so that all nodes are connected to other nodes at once:
  85. ```python
  86. from diagrams import Diagram
  87. from diagrams.aws.compute import EC2
  88. from diagrams.aws.database import RDS
  89. from diagrams.aws.network import ELB
  90. with Diagram("Grouped Workers", show=False, direction="TB"):
  91. ELB("lb") >> [EC2("worker1"),
  92. EC2("worker2"),
  93. EC2("worker3"),
  94. EC2("worker4"),
  95. EC2("worker5")] >> RDS("events")
  96. ```
  97. ![grouped workers diagram](/img/grouped_workers_diagram.png)
  98. > You can't connect two **lists** directly because shift/arithmetic operations between lists are not allowed in Python.