diagrams GCP 节点类全参考:从 _GCP 基类到 93 个 Google Cloud 图标节点
本篇基于 docs/nodes/gcp.md 整理 diagrams 项目中 diagrams.gcp provider 的完整节点类目录,并结合 diagrams/gcp/init.py 与 diagrams/init.py 的源码说明其类层次结构、图标加载机制与别名(alias)约定。读完后你可以:完整查找到 GCP 各产品线对应的节点类与 Python 类名、理解节点如何加载 PNG 图标并渲染到 Graphviz 图中、并在自己的架构图中正确使用这些节点类与别名。
GCP provider 的入口与基类
diagrams/gcp/__init__.py 是整个 GCP 节点目录的入口,内容非常精简,定义了一个 provider 基类:
"""
GCP provides a set of services for Google Cloud Platform provider.
"""
from diagrams import Node
class _GCP(Node):
_provider = "gcp"
_icon_dir = "resources/gcp"
fontcolor = "#2d3436"
从源码结构看,这个类承担了三个职责:
- 声明 provider 身份:
_provider = "gcp"使任意 GCP 节点的__repr__呈现为<gcp.<type>.<ClassName>>格式(见下文); - 声明图标根目录:
_icon_dir = "resources/gcp",所有具体节点的图标都按“根目录 + 子目录 + 文件名”的规则解析; - 设置默认字体颜色:
fontcolor = "#2d3436",保证节点标签在浅色 GCP 图标上可读。
所有子模块(gcp.analytics、gcp.compute 等)都不直接继承 Node,而是先继承 _GCP,再叠加各自的 _type 与 _icon_dir,形成两层继承结构。
节点类的生成模式:子类 = 一行图标声明
以 diagrams/gcp/analytics.py 为例,可以看到每个子模块的标准写法:
# This module is automatically generated by autogen.sh. DO NOT EDIT.
from . import _GCP
class _Analytics(_GCP):
_type = "analytics"
_icon_dir = "resources/gcp/analytics"
class Bigquery(_Analytics):
_icon = "bigquery.png"
class Composer(_Analytics):
_icon = "composer.png"
# ... 其余类省略
# Aliases
BigQuery = Bigquery
PubSub = Pubsub
模式可以概括为三段式:
- 中间层
_Analytics:把_type设为analytics,把_icon_dir细化为resources/gcp/analytics。_type同时参与__repr__输出,用于在调试时区分节点所属产品线; - 具体节点类:每个类只做一件事——声明
_icon文件名。渲染时图标路径由基类Node._load_icon()拼出; - 别名区(Aliases):通过普通变量赋值提供习惯写法,如
BigQuery = Bigquery、PubSub = Pubsub。别名与原类是同一个对象,因此from diagrams.gcp.analytics import BigQuery与import Bigquery完全等价,只是风格不同。
文件首部的 # This module is automatically generated by autogen.sh. DO NOT EDIT. 注释与仓库根目录的 autogen.sh 相互印证:autogen.sh 的 providers 数组中包含 "gcp",会对各 provider 资源执行 svg 转 png、清理资源名等预处理步骤,再生成这些模块文件。因此节点类文件本身是生成产物,不应手工修改;目录的“事实来源”是 GCP 图标资源集合加上生成脚本。
图标如何在运行时被解析
基类 Node 定义在 diagrams/init.py:
class Node:
_provider = None
_type = None
_icon_dir = None
_icon = None
构造节点时(diagrams/init.py),如果类声明了 _icon,就会写入 Graphviz 节点属性:
self._attrs = {
"shape": "none",
"height": str(self._height + padding),
"image": self._load_icon(),
} if self._icon else {}
其中 _load_icon() 的解析逻辑为(diagrams/init.py):
def _load_icon(self):
basedir = Path(os.path.abspath(os.path.dirname(__file__)))
return os.path.join(basedir.parent, self._icon_dir, self._icon)
即图标路径 = 仓库根目录 + resources/gcp/<type>/ + 图标文件名,例如 Bigquery 节点解析为 resources/gcp/analytics/bigquery.png。从源码结构看,resources 目录属于 autogen.sh 预处理出的产物(脚本会对 svg 源图做转换与命名清理),具体 PNG 资源是否随源码检出分发取决于构建流程;若渲染时找不到图标文件,Graphviz 会给出缺失图片的提示。另外注意两点渲染细节:
- 节点形状为
shape=none,只保留图标本身,标签文字(label)显示在图标下方; - 若开启
Diagram的autolabel,标签前会自动拼上类名(如Bigquery\nBigQuery 数据仓库);标签中的换行还会让节点高度自动增加,避免图标与文字重叠。
Node.__repr__(diagrams/init.py)返回 f"<{self._provider}.{self._type}.{_name}>",这正是 docs/nodes/gcp.md 中“diagrams.gcp.analytics.Bigquery”这类全限定名的来源——文档中的类名与实际 import 路径一一对应。
GCP 节点类完整目录
以下目录完整继承自 docs/nodes/gcp.md,覆盖 12 个模块、93 个节点类。列名说明:类名可直接 from diagrams.gcp.<module> import <类名>;别名为同模块下等价导入名;图标资源为类声明的 _icon 文件名,对应图标位于 resources/gcp/<module>/ 下。
gcp.analytics(10 个节点)
数据与分析类产品,包含 BigQuery、Pub/Sub 等。
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.analytics.Bigquery |
BigQuery |
bigquery.png |
diagrams.gcp.analytics.Composer |
— | composer.png |
diagrams.gcp.analytics.DataCatalog |
— | data-catalog.png |
diagrams.gcp.analytics.DataFusion |
— | data-fusion.png |
diagrams.gcp.analytics.Dataflow |
— | dataflow.png |
diagrams.gcp.analytics.Datalab |
— | datalab.png |
diagrams.gcp.analytics.Dataprep |
— | dataprep.png |
diagrams.gcp.analytics.Dataproc |
— | dataproc.png |
diagrams.gcp.analytics.Genomics |
— | genomics.png |
diagrams.gcp.analytics.Pubsub |
PubSub |
pubsub.png |
gcp.api(3 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.api.APIGateway |
— | api-gateway.png |
diagrams.gcp.api.Apigee |
— | apigee.png |
diagrams.gcp.api.Endpoints |
— | endpoints.png |
gcp.compute(8 个节点)
计算与容器产品,是画 GCP 架构图时最常用的模块之一。
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.compute.AppEngine |
GAE |
app-engine.png |
diagrams.gcp.compute.ComputeEngine |
GCE |
compute-engine.png |
diagrams.gcp.compute.ContainerOptimizedOS |
— | container-optimized-os.png |
diagrams.gcp.compute.Functions |
GCF |
functions.png |
diagrams.gcp.compute.GKEOnPrem |
— | gke-on-prem.png |
diagrams.gcp.compute.GPU |
— | gpu.png |
diagrams.gcp.compute.KubernetesEngine |
GKE |
kubernetes-engine.png |
diagrams.gcp.compute.Run |
— | run.png |
gcp.database(6 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.database.Bigtable |
BigTable |
bigtable.png |
diagrams.gcp.database.Datastore |
— | datastore.png |
diagrams.gcp.database.Firestore |
— | firestore.png |
diagrams.gcp.database.Memorystore |
— | memorystore.png |
diagrams.gcp.database.Spanner |
— | spanner.png |
diagrams.gcp.database.SQL |
— | sql.png |
gcp.devtools(15 个节点)
开发者工具,节点数量最多的模块之一。
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.devtools.Build |
— | build.png |
diagrams.gcp.devtools.Code |
— | code.png |
diagrams.gcp.devtools.CodeForIntellij |
— | code-for-intellij.png |
diagrams.gcp.devtools.ContainerRegistry |
GCR |
container-registry.png |
diagrams.gcp.devtools.GradleAppEnginePlugin |
— | gradle-app-engine-plugin.png |
diagrams.gcp.devtools.IdePlugins |
— | ide-plugins.png |
diagrams.gcp.devtools.MavenAppEnginePlugin |
— | maven-app-engine-plugin.png |
diagrams.gcp.devtools.Scheduler |
— | scheduler.png |
diagrams.gcp.devtools.SDK |
— | sdk.png |
diagrams.gcp.devtools.SourceRepositories |
— | source-repositories.png |
diagrams.gcp.devtools.Tasks |
— | tasks.png |
diagrams.gcp.devtools.TestLab |
— | test-lab.png |
diagrams.gcp.devtools.ToolsForEclipse |
— | tools-for-eclipse.png |
diagrams.gcp.devtools.ToolsForPowershell |
— | tools-for-powershell.png |
diagrams.gcp.devtools.ToolsForVisualStudio |
— | tools-for-visual-studio.png |
gcp.iot(1 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.iot.IotCore |
— | iot-core.png |
gcp.migration(1 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.migration.TransferAppliance |
— | transfer-appliance.png |
gcp.ml(21 个节点)
机器学习产品线,是目录中最大的模块,覆盖 AI Platform、AutoML 各垂直能力与 TPU 等。
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.ml.AdvancedSolutionsLab |
— | advanced-solutions-lab.png |
diagrams.gcp.ml.AIHub |
— | ai-hub.png |
diagrams.gcp.ml.AIPlatform |
— | ai-platform.png |
diagrams.gcp.ml.AIPlatformDataLabelingService |
— | ai-platform-data-labeling-service.png |
diagrams.gcp.ml.Automl |
AutoML |
automl.png |
diagrams.gcp.ml.AutomlNaturalLanguage |
— | automl-natural-language.png |
diagrams.gcp.ml.AutomlTables |
— | automl-tables.png |
diagrams.gcp.ml.AutomlTranslation |
— | automl-translation.png |
diagrams.gcp.ml.AutomlVideoIntelligence |
— | automl-video-intelligence.png |
diagrams.gcp.ml.AutomlVision |
— | automl-vision.png |
diagrams.gcp.ml.DialogFlowEnterpriseEdition |
— | dialog-flow-enterprise-edition.png |
diagrams.gcp.ml.InferenceAPI |
— | inference-api.png |
diagrams.gcp.ml.JobsAPI |
— | jobs-api.png |
diagrams.gcp.ml.NaturalLanguageAPI |
NLAPI |
natural-language-api.png |
diagrams.gcp.ml.RecommendationsAI |
— | recommendations-ai.png |
diagrams.gcp.ml.SpeechToText |
STT |
speech-to-text.png |
diagrams.gcp.ml.TextToSpeech |
TTS |
text-to-speech.png |
diagrams.gcp.ml.TPU |
— | tpu.png |
diagrams.gcp.ml.TranslationAPI |
— | translation-api.png |
diagrams.gcp.ml.VideoIntelligenceAPI |
— | video-intelligence-api.png |
diagrams.gcp.ml.VisionAPI |
— | vision-api.png |
gcp.network(17 个节点)
网络与流量类产品,VPC 是其入口节点。
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.network.Armor |
— | armor.png |
diagrams.gcp.network.CDN |
— | cdn.png |
diagrams.gcp.network.DedicatedInterconnect |
— | dedicated-interconnect.png |
diagrams.gcp.network.DNS |
— | dns.png |
diagrams.gcp.network.ExternalIpAddresses |
— | external-ip-addresses.png |
diagrams.gcp.network.FirewallRules |
— | firewall-rules.png |
diagrams.gcp.network.LoadBalancing |
— | load-balancing.png |
diagrams.gcp.network.NAT |
— | nat.png |
diagrams.gcp.network.Network |
— | network.png |
diagrams.gcp.network.PartnerInterconnect |
— | partner-interconnect.png |
diagrams.gcp.network.PremiumNetworkTier |
— | premium-network-tier.png |
diagrams.gcp.network.Router |
— | router.png |
diagrams.gcp.network.Routes |
— | routes.png |
diagrams.gcp.network.StandardNetworkTier |
— | standard-network-tier.png |
diagrams.gcp.network.TrafficDirector |
— | traffic-director.png |
diagrams.gcp.network.VirtualPrivateCloud |
VPC |
virtual-private-cloud.png |
diagrams.gcp.network.VPN |
— | vpn.png |
gcp.operations(2 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.operations.Logging |
— | logging.png |
diagrams.gcp.operations.Monitoring |
— | monitoring.png |
gcp.security(6 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.security.IAP |
— | iap.png |
diagrams.gcp.security.Iam |
— | iam.png |
diagrams.gcp.security.KeyManagementService |
KMS |
key-management-service.png |
diagrams.gcp.security.ResourceManager |
— | resource-manager.png |
diagrams.gcp.security.SecurityCommandCenter |
SCC |
security-command-center.png |
diagrams.gcp.security.SecurityScanner |
— | security-scanner.png |
gcp.storage(3 个节点)
| 类名 | 别名 | 图标资源 |
|---|---|---|
diagrams.gcp.storage.Filestore |
— | filestore.png |
diagrams.gcp.storage.PersistentDisk |
— | persistent-disk.png |
diagrams.gcp.storage.Storage |
GCS |
storage.png |
实战:在 Diagram as Code 中使用 GCP 节点
目录中的类名可以直接落到代码里。一个典型的 GCP 事件处理架构示例如下(在 Diagram 上下文内实例化节点,用 >> 建立有向连接):
from diagrams import Diagram, Cluster, Edge
from diagrams.gcp.compute import GCE, GKE
from diagrams.gcp.database import SQL
from diagrams.gcp.analytics import PubSub, BigQuery
from diagrams.gcp.network import VPC, CDN
from diagrams.gcp.security import Iam
with Diagram("GCP 事件处理架构", show_edges=True) as diag:
with Cluster("VPC 网络"):
with VPC("us-central1") as region:
gce = GCE("Web 层")
k8s = GKE("容器集群")
pubsub = PubSub("订单事件")
sql = SQL("MySQL 实例")
bq = BigQuery("分析仓库")
gce >> pubsub
pubsub >> k8s
k8s >> sql
k8s >> bq
Edge(label="审计", color="#1E88E5") >> gce
使用要点,均可在上文源码中找到依据:
with Diagram(...) as diag建立全局 diagram 上下文;节点构造时通过getdiagram()拿到该上下文并注册自己(diagrams/init.py),脱离上下文实例化节点会抛出EnvironmentError;Cluster用于分组(如 VPC 边界),嵌套 Cluster 可表达多区域/多集群层次;>>、<<、-运算符分别实现前向箭头、反向箭头与无向连接(Node.__rshift__/__lshift__/__sub__,diagrams/init.py),也支持对节点列表批量连边;- 别名按需选用:本例使用
GCE、PubSub、BigQuery、GCS等习惯写法,它们与ComputeEngine、Pubsub、Bigquery、Storage指向同一类; - 节点标签:构造函数第一个参数为
label;autolabel开启时会额外拼上类名,适合快速示意。
渲染时每个节点以 shape=none + 图标图片呈现,连线样式可通过 Edge(color=..., label=...) 等属性覆盖默认值(默认边属性见 diagrams/init.py)。
目录的维护机制与注意事项
结合 autogen.sh 与各模块文件头注释,可以确认这套节点目录的维护方式:
- 自动生成,禁止手改:
diagrams/gcp/*.py均由autogen.sh生成,文件头统一标注DO NOT EDIT。新增 GCP 图标时正确做法是补充图标资源后重新运行生成脚本,而不是直接编辑模块文件; - 资源预处理链路:
autogen.sh依赖round、inkscape、image magick、black等外部工具,对 provider 资源执行 svg 转 png、文件名清理与代码格式化等步骤,gcp在其providers列表中; - 图标路径约定:类声明的
_icon_dir(如resources/gcp/ml)+_icon(如tpu.png)在运行时拼接为渲染路径,因此新增节点类时必须保证同名 PNG 资源存在于对应子目录; - 命名约定:类名与文件名均取自图标资源名(kebab-case 文件名 → PascalCase 类名),高频缩写则通过别名区提供(如
GCE、GKE、GCS、KMS)。
需要说明的是,docs/nodes/gcp.md 中的节点清单与当前 diagrams/gcp/ 源码保持一致;若上游图标集更新后重新运行生成脚本,目录中的类与别名可能随之增减,应以仓库内最新的模块文件为准。
小结
docs/nodes/gcp.md 提供的是 diagrams 项目 GCP provider 的节点类参考页:12 个模块、93 个节点类,覆盖 Google Cloud 的计算、数据、网络、安全与机器学习等核心产品线。其底层实现由 diagrams/gcp/init.py 的 _GCP 基类(provider 标识、图标根目录、字体色)与 diagrams/init.py 中 Node 的图标加载、上下文注册和运算符连边机制共同支撑;各模块文件由 autogen.sh 从图标资源自动生成。掌握“模块 = 产品线、类 = 图标声明、别名 = 习惯写法”这一映射关系,即可把 GCP 节点目录无缝用到自己的 Diagram as Code 架构图中。
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0624
Hy4-previewHy4 preview 是由腾讯混元团队研发的新一代混合专家(MoE)旗舰模型。模型总参数量 770B,每个 token 激活 49B,主干共包含78层,第一层采用标准 FFN,其余 77 层均为 MoE 结构,每层包含 256 个路由专家与 1 个共享专家,每个 token 激活 top-8 路由专家及共享专家。主干之外原生内置 1 层 MTP(总参数量 10B,激活 0.7B)以支持投机解码。Python00
GLM-5.3GLM-5.3 与 GLM-5.2 使用相同的基座模型——所有提升均来自后训练。与 GLM-5.2 相比,它在复杂编程和长程任务上的表现显著提升。Jinja00
GLM-5.3-FlashGLM-5.3-Flash (320B-A18B),是GLM-5系列的首个原生多模态模型。320B总参数,能力超过GLM-5.2Jinja00
Spark-X2.5-4BSpark-X2.5-4B 旨在让强大的 AI 更实用、更高效、更易获得。在广泛日常任务中表现强劲,涵盖对话、写作、翻译、推理、编码、工具调用以及智能体工作流,并在同等规模的开源模型中取得领先成绩。Spark-X2.5 将面向效率的架构与最高 1M tokens 的原生上下文窗口相结合,并支持 200 多种语言。Python00
Spark-X2.5-1.7BSpark-X2.5-1.7B 旨在让强大的 AI 更加实用、高效且易于获取。这些模型在广泛的日常任务中表现出色,涵盖对话、写作、翻译、推理、编程、工具调用和智能体工作流,并在同等规模的开源模型中取得领先结果。Spark-X2.5 将面向效率的架构与最高 1M tokens 的原生上下文窗口相结合,并支持 200 多种语言。Python00