diff --git a/diagrams/__init__.py b/diagrams/__init__.py
index 57c92133..2e41b4e8 100644
--- a/diagrams/__init__.py
+++ b/diagrams/__init__.py
@@ -209,6 +209,9 @@ class Cluster:
"fontsize": "12",
}
+ _icon = None
+ _icon_size = 0
+
# fmt: on
# FIXME:
@@ -230,8 +233,10 @@ class Cluster:
"""
self.label = label
self.name = "cluster_" + self.label
- self.icon = icon
- self.icon_size = icon_size
+ if not self._icon:
+ self.icon = icon
+ if not self._icon_size:
+ self._icon_size = icon_size
self.dot = Digraph(self.name)
@@ -241,11 +246,11 @@ class Cluster:
# if an icon is set, try to find and instantiate a Node without calling __init__()
# then find it's icon by calling _load_icon()
- if self.icon:
- _node = self.icon(_no_init=True)
+ if self._icon:
+ _node = self._icon(_no_init=True)
if isinstance(_node,Node):
- self.icon_label = '<
 + ') | ' + self.label + ' |
>'
- self.dot.graph_attr["label"] = self.icon_label
+ self._icon_label = '< + ') | ' + self.label + ' |
>'
+ self.dot.graph_attr["label"] = self._icon_label
else:
self.dot.graph_attr["label"] = self.label
diff --git a/diagrams/aws/__init__.py b/diagrams/aws/__init__.py
index 1550a0df..8c912ba4 100644
--- a/diagrams/aws/__init__.py
+++ b/diagrams/aws/__init__.py
@@ -2,7 +2,7 @@
AWS provides a set of services for Amazon Web Service provider.
"""
-from diagrams import Node
+from diagrams import Node, Cluster
class _AWS(Node):
diff --git a/diagrams/aws/cluster.py b/diagrams/aws/cluster.py
new file mode 100644
index 00000000..6ecbabcb
--- /dev/null
+++ b/diagrams/aws/cluster.py
@@ -0,0 +1,104 @@
+from diagrams import Cluster
+from diagrams.aws.compute import EC2, ApplicationAutoScaling
+from diagrams.aws.network import VPC, PrivateSubnet, PublicSubnet
+
+class Region(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "dotted",
+ "labeljust": "l",
+ "pencolor": "#AEB6BE",
+ "fontname": "Sans-Serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+
+class AvailabilityZone(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "dashed",
+ "labeljust": "l",
+ "pencolor": "#27a0ff",
+ "fontname": "sans-serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+
+class VirtualPrivateCloud(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "",
+ "labeljust": "l",
+ "pencolor": "#00D110",
+ "fontname": "sans-serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = VPC
+
+class PrivateSubnet(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "",
+ "labeljust": "l",
+ "pencolor": "#329CFF",
+ "fontname": "sans-serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = PrivateSubnet
+
+class PublicSubnet(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "",
+ "labeljust": "l",
+ "pencolor": "#00D110",
+ "fontname": "sans-serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = PublicSubnet
+
+class SecurityGroup(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "dashed",
+ "labeljust": "l",
+ "pencolor": "#FF361E",
+ "fontname": "Sans-Serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+
+class AutoScalling(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "dashed",
+ "labeljust": "l",
+ "pencolor": "#FF7D1E",
+ "fontname": "Sans-Serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = ApplicationAutoScaling
+
+class EC2Contents(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "",
+ "labeljust": "l",
+ "pencolor": "#FFB432",
+ "fontname": "Sans-Serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = EC2
diff --git a/diagrams/onprem/cluster.py b/diagrams/onprem/cluster.py
new file mode 100644
index 00000000..4fd62f04
--- /dev/null
+++ b/diagrams/onprem/cluster.py
@@ -0,0 +1,15 @@
+from diagrams import Cluster
+from diagrams.onprem.compute import Server
+
+class ServerContents(Cluster):
+ # fmt: off
+ _default_graph_attrs = {
+ "shape": "box",
+ "style": "rounded,dotted",
+ "labeljust": "l",
+ "pencolor": "#A0A0A0",
+ "fontname": "Sans-Serif",
+ "fontsize": "12",
+ }
+ # fmt: on
+ _icon = Server
diff --git a/examples/__init__.py b/examples/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/examples/aws.png b/examples/aws.png
new file mode 100644
index 00000000..f762f76a
Binary files /dev/null and b/examples/aws.png differ
diff --git a/examples/aws.py b/examples/aws.py
new file mode 100644
index 00000000..3599a5c3
--- /dev/null
+++ b/examples/aws.py
@@ -0,0 +1,26 @@
+from diagrams import Diagram, Edge
+from diagrams.aws.cluster import *
+from diagrams.aws.compute import EC2
+from diagrams.onprem.container import Docker
+from diagrams.onprem.cluster import *
+from diagrams.aws.network import ELB
+
+with Diagram(name="", direction="TB", show=True):
+ with Cluster("AWS"):
+ with Region("eu-west-1"):
+ with AvailabilityZone("eu-west-1a"):
+ with VirtualPrivateCloud(""):
+ with PrivateSubnet("Private"):
+ with SecurityGroup("web sg"):
+ with AutoScalling(""):
+ with EC2Contents("A"):
+ d1 = Docker("Container")
+ with ServerContents("A1"):
+ d2 = Docker("Container")
+
+ with PublicSubnet("Public"):
+ with SecurityGroup("elb sg"):
+ lb = ELB()
+
+ lb >> Edge(forward=True, reverse=True) >> d1
+ lb >> Edge(forward=True, reverse=True) >> d2