forked from HariSekhon/Diagrams-as-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_web_architecture.py
executable file
·134 lines (109 loc) · 4.47 KB
/
old_web_architecture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
# coding=utf-8
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2023-04-21 00:32:11 +0100 (Fri, 21 Apr 2023)
#
# https://github.com/HariSekhon/Diagrams-as-Code
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
"""
Old Web Architecture
"""
__author__ = 'Hari Sekhon'
__version__ = '0.1'
import os
from urllib.request import urlretrieve
from diagrams import Diagram, Cluster # , Edge
# ============================================================================ #
# On-premise / Open Source resources:
#
# https://diagrams.mingrammer.com/docs/nodes/onprem
#
from diagrams.onprem.client import Users
# from diagrams.onprem.compute import Server
from diagrams.onprem.database import Cassandra
from diagrams.onprem.inmemory import Memcached # , Redis
from diagrams.onprem.network import Apache, Glassfish
# ============================================================================ #
# Generic - Datacentre, Operating Systems, Virtualization, Mobile Devices:
#
# https://diagrams.mingrammer.com/docs/nodes/generic
#
from diagrams.generic.place import Datacenter
# from diagrams.generic.os import LinuxGeneral
# ============================================================================ #
#
# Programming - flowcharts, programming languages and frameworks
#
# https://diagrams.mingrammer.com/docs/nodes/programming
#
from diagrams.programming.language import Java
# ============================================================================ #
#
# Custom - for creating a custom object using a downloaded image
#
# https://diagrams.mingrammer.com/docs/nodes/custom
#
from diagrams.custom import Custom
# ============================================================================ #
# ============================================================================ #
# pylint: disable=C0103
dns_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTsXGy2J1B7jR56GNfbAhNXC0Nw9bokO9gHqw&usqp=CAU"
dns_icon = "dns.png"
f5_url = "https://upload.wikimedia.org/wikipedia/en/thumb/f/f9/F5_Networks_logo.svg/800px-F5_Networks_logo.svg.png"
f5_icon = "f5.png"
image_dir = 'images'
# NOTE: filename=images/ parameter to Diagram() changes the $PWD so icon path must be local dir,
# but at this point we're still at top level dir so must join to prefix it with the image_dir
# nosemgrep: python.lang.security.audit.dynamic-urllib-use-detected.dynamic-urllib-use-detected
urlretrieve(f5_url, os.path.join(image_dir, f5_icon))
# nosemgrep: python.lang.security.audit.dynamic-urllib-use-detected.dynamic-urllib-use-detected
urlretrieve(dns_url, os.path.join(image_dir, dns_icon))
graph_attr = {
"splines": "spline", # rounded arrows, much nicer
}
# pylint: disable=W0104,W0106
with Diagram('Old Web Architecture',
show=not bool(os.environ.get('CI', 0)),
direction='LR',
filename='images/old_web_architecture', # override the default filename, without the extension
graph_attr=graph_attr,
):
gslb = Custom("DNS GSLB\nGlobal Server Load Balancing\nHealth Check Datacenters", dns_icon)
for n in range(1, 3, 1):
with Cluster(f"Datacenter {n}") as dc:
Datacenter(f"DC{n}")
lb = Custom("F5 Big-IP 8900\nLoad Balancer", f5_icon)
with Cluster("Cassandra") as cassandra:
cassandra_cluster = []
for i in range(2):
cassandra_cluster.append(Cassandra("Cassandra node"))
for i, node in enumerate(cassandra_cluster):
j = i + 1
if j >= len(cassandra_cluster):
j = 0
cassandra_cluster[i] >> cassandra_cluster[j]
for _ in range(2):
with Cluster(f"Server {_}"):
# Server("Server")
# LinuxGeneral("Linux")
httpd = Apache("Apache httpd")
glassfish = Glassfish("Glassfish")
java = Java("Java")
# redis = Redis("Redis")
memcached = Memcached("Memcached")
lb >> httpd >> glassfish
glassfish - java
java >> memcached
java >> cassandra_cluster
gslb >> lb
Users("Internet Users") \
>> gslb