Longhorn 云原生容器分布式存储 - Python Client
内容来源于官方 Longhorn 1.1.2
英文技术手册。
系列
- Longhorn 是什么?
- Longhorn 云原生容器分布式存储 - 设计架构和概念
- Longhorn 云原生容器分布式存储 - 部署篇
- Longhorn 云原生容器分布式存储 - 券和节点
- Longhorn 云原生容器分布式存储 - K8S 资源配置示例
- Longhorn 云原生容器分布式存储 - 监控(Prometheus)
- Longhorn 云原生容器分布式存储 - 备份与恢复
- Longhorn 云原生容器分布式存储 - 高可用
- Longhorn 云原生容器分布式存储 - 支持 ReadWriteMany (RWX) 工作负载
- Longhorn 云原生容器分布式存储 - 定制部署默认设置
- Longhorn云原生容器分布式存储 - Air Gap 安装
目前,您可以使用 Longhorn UI
操作 Longhorn
。同时,您可以使用 Python
访问 Longhorn API
,如下所示。
-
获取
Longhorn API
端点与
Longhorn
通信的一种方式是通过longhorn-frontend
service。如果您在安装
Longhorn
的同一集群中运行自动化/脚本(automation/scripting
)工具,请连接到端点http://longhorn-frontend.longhorn-system/v1
如果您在本地机器上运行自动化/脚本(
automation/scripting
)工具,请使用kubectl port-forward
将longhorn-frontend
service
转发到localhost
:kubectl port-forward services/longhorn-frontend 8080:http -n longhorn-system
并连接到端点
http://localhost:8080/v1
-
使用
Python Client
将 longhorn.py 文件(包含
Python client
)导入到以下Python
脚本中,并从API
端点创建一个client
:https://github.com/longhorn/longhorn-tests/blob/master/manager/integration/tests/longhorn.py
import longhorn # If automation/scripting tool is inside the same cluster in which Longhorn is installed longhorn_url = 'http://longhorn-frontend.longhorn-system/v1' # If forwarding `longhorn-frontend` service to localhost longhorn_url = 'http://localhost:8080/v1' client = longhorn.Client(url=longhorn_url) # Volume operations # List all volumes volumes = client.list_volume() # Get volume by NAME/ID testvol1 = client.by_id_volume(id="testvol1") # Attach TESTVOL1 testvol1 = testvol1.attach(hostId="worker-1") # Detach TESTVOL1 testvol1.detach() # Create a snapshot of TESTVOL1 with NAME snapshot1 = testvol1.snapshotCreate(name="snapshot1") # Create a backup from a snapshot NAME testvol1.snapshotBackup(name=snapshot1.name) # Update the number of replicas of TESTVOL1 testvol1.updateReplicaCount(replicaCount=2) # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests # Node operations # List all nodes nodes = client.list_node() # Get node by NAME/ID node1 = client.by_id_node(id="worker-1") # Disable scheduling for NODE1 client.update(node1, allowScheduling=False) # Enable scheduling for NODE1 client.update(node1, allowScheduling=True) # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests # Setting operations # List all settings settings = client.list_setting() # Get setting by NAME/ID backupTargetsetting = client.by_id_setting(id="backup-target") # Update a setting backupTargetsetting = client.update(backupTargetsetting, value="s3://backupbucket@us-east-1/") # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests
公众号:黑客下午茶
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南