No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

node.md 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. # gcp resources
  28. from diagrams.gcp.compute import AppEngine, GKE
  29. from diagrams.gcp.ml import AutoML
  30. ...
  31. # k8s resources
  32. from diagrams.k8s.compute import Pod, StatefulSet
  33. from diagrams.k8s.network import Service
  34. from diagrams.k8s.storage import PV, PVC, StorageClass
  35. ```
  36. ## Data Flow
  37. You can represent data flow by connecting the nodes with these operators: `>>`, `<<` and `-`.
  38. * **>>**: Connect nodes in left to right direction.
  39. * **<<**: Connect nodes in right to left direction.
  40. * **-**: Connect nodes in no direction. Undirected.
  41. ```python
  42. from diagrams import Diagram
  43. from diagrams.aws.compute import EC2
  44. from diagrams.aws.database import RDS
  45. from diagrams.aws.network import ELB
  46. from diagrams.aws.storage import S3
  47. with Diagram("Web Services", show=False):
  48. ELB("lb") >> EC2("web") >> RDS("userdb") >> S3("store")
  49. ELB("lb") >> EC2("web") >> RDS("userdb") << EC2("stat")
  50. (ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb")
  51. ```
  52. > Be careful when using the `-` and any shift operators together, which could cause unexpected results due to operator precedence.
  53. ![web services diagram](/img/web_services_diagram.png)
  54. > The order of rendered diagrams is the reverse of the declaration order.
  55. You can change the data flow direction with `direction` parameter. Default is **LR**.
  56. > (TB, BT, LR and RL) are allowed.
  57. ```python
  58. from diagrams import Diagram
  59. from diagrams.aws.compute import EC2
  60. from diagrams.aws.database import RDS
  61. from diagrams.aws.network import ELB
  62. with Diagram("Workers", show=False, direction="TB"):
  63. lb = ELB("lb")
  64. db = RDS("events")
  65. lb >> EC2("worker1") >> db
  66. lb >> EC2("worker2") >> db
  67. lb >> EC2("worker3") >> db
  68. lb >> EC2("worker4") >> db
  69. lb >> EC2("worker5") >> db
  70. ```
  71. ![workers diagram](/img/workers_diagram.png)
  72. ## Group Data Flow
  73. 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.
  74. ```python
  75. from diagrams import Diagram
  76. from diagrams.aws.compute import EC2
  77. from diagrams.aws.database import RDS
  78. from diagrams.aws.network import ELB
  79. with Diagram("Grouped Workers", show=False, direction="TB"):
  80. ELB("lb") >> [EC2("worker1"),
  81. EC2("worker2"),
  82. EC2("worker3"),
  83. EC2("worker4"),
  84. EC2("worker5")] >> RDS("events")
  85. ```
  86. ![grouped workers diagram](/img/grouped_workers_diagram.png)
  87. > You can't connect two **lists** directly because shift/arithmetic operations between lists are not allowed in Python.