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 3.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ---
  2. id: node
  3. title: Nodes
  4. ---
  5. Node is a second 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 above example, the `EC2` is a node of `compute` resource type which provided by `aws` provider.
  16. You can use other node objects in a similar manner like:
  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 all available nodes list in [Here](https://diagrams.mingrammer.com/docs/nodes/aws).
  46. ## Data Flow
  47. You can represent data flow by connecting the nodes with these operators: `>>`, `<<` and `-`.
  48. * **>>**: Connect nodes in left to right direction.
  49. * **<<**: Connect nodes in right to left direction.
  50. * **-**: Connect nodes in no direction. Undirected.
  51. ```python
  52. from diagrams import Diagram
  53. from diagrams.aws.compute import EC2
  54. from diagrams.aws.database import RDS
  55. from diagrams.aws.network import ELB
  56. from diagrams.aws.storage import S3
  57. with Diagram("Web Services", show=False):
  58. ELB("lb") >> EC2("web") >> RDS("userdb") >> S3("store")
  59. ELB("lb") >> EC2("web") >> RDS("userdb") << EC2("stat")
  60. (ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb")
  61. ```
  62. > Be careful when using the `-` and any shift operators together, which could cause unexpected results due to operator precedence.
  63. ![web services diagram](/img/web_services_diagram.png)
  64. > The order of rendered diagrams is the reverse of the declaration order.
  65. You can change the data flow direction with `direction` parameter. Default is **LR**.
  66. > (TB, BT, LR and RL) are allowed.
  67. ```python
  68. from diagrams import Diagram
  69. from diagrams.aws.compute import EC2
  70. from diagrams.aws.database import RDS
  71. from diagrams.aws.network import ELB
  72. with Diagram("Workers", show=False, direction="TB"):
  73. lb = ELB("lb")
  74. db = RDS("events")
  75. lb >> EC2("worker1") >> db
  76. lb >> EC2("worker2") >> db
  77. lb >> EC2("worker3") >> db
  78. lb >> EC2("worker4") >> db
  79. lb >> EC2("worker5") >> db
  80. ```
  81. ![workers diagram](/img/workers_diagram.png)
  82. ## Group Data Flow
  83. Above worker example has too many redundant flows. In this case, you can group nodes into a list so that all nodes are connected to other nodes at once.
  84. ```python
  85. from diagrams import Diagram
  86. from diagrams.aws.compute import EC2
  87. from diagrams.aws.database import RDS
  88. from diagrams.aws.network import ELB
  89. with Diagram("Grouped Workers", show=False, direction="TB"):
  90. ELB("lb") >> [EC2("worker1"),
  91. EC2("worker2"),
  92. EC2("worker3"),
  93. EC2("worker4"),
  94. EC2("worker5")] >> RDS("events")
  95. ```
  96. ![grouped workers diagram](/img/grouped_workers_diagram.png)
  97. > You can't connect two **lists** directly because shift/arithmetic operations between lists are not allowed in Python.