栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 前沿技术 > 云计算 > Docker/k8s

Longhorn 云原生容器分布式存储 - Python Client

Docker/k8s 更新时间:发布时间: 百科书网 趣学号

 

本文转载自微信公众号「黑客下午茶」,作者为少。转载本文请联系黑客下午茶公众号。

目前,您可以使用 Longhorn UI 操作 Longhorn。同时,您可以使用 Python 访问 Longhorn API,如下所示。

1.获取 Longhorn API 端点

与 Longhorn 通信的一种方式是通过 longhorn-frontend service。

如果您在安装 Longhorn 的同一集群中运行自动化/脚本(automation/scripting)工具,请连接到端点 http://longhorn-frontend.longhorn-system/v1

如果您在本地机器上运行自动化/脚本(automation/scripting)工具,请使用 kubectl port-forward 将 longhorn-frontend service 转发到 localhost:

  1. kubectl port-forward services/longhorn-frontend 8080:http -n longhorn-system 

并连接到端点 http://localhost:8080/v1

2.使用 Python Client

将 longhorn.py 文件(包含 Python client)导入到以下 Python 脚本中,并从 API 端点创建一个 client:

https://github.com/longhorn/longhorn-tests/blob/master/manager/integration/tests/longhorn.py

  1. import longhorn  
  2. # If automation/scripting tool is inside the same cluster in which Longhorn is installed longhorn_url = 'http://longhorn-frontend.longhorn-system/v1' 
  3. # If forwarding `longhorn-frontend` service to localhost longhorn_url = 'http://localhost:8080/v1' 
  4.  client = longhorn.Client(url=longhorn_url) 
  5.  # Volume operations 
  6. # List all volumes volumes = client.list_volume() 
  7. # Get volume by NAME/ID testvol1 = client.by_id_volume(id="testvol1") 
  8. # Attach TESTVOL1 testvol1 = testvol1.attach(hostId="worker-1") 
  9. # Detach TESTVOL1 testvol1.detach() 
  10. # Create a snapshot of TESTVOL1 with NAME snapshot1 = testvol1.snapshotCreate(name="snapshot1") 
  11. # Create a backup from a snapshot NAME testvol1.snapshotBackup(name=snapshot1.name) 
  12. # Update the number of replicas of TESTVOL1 testvol1.updateReplicaCount(replicaCount=2) 
  13. # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests  
  14. # Node operations # List all nodes 
  15. nodes = client.list_node() # Get node by NAME/ID 
  16. node1 = client.by_id_node(id="worker-1") # Disable scheduling for NODE1 
  17. client.update(node1, allowScheduling=False) # Enable scheduling for NODE1 
  18. client.update(node1, allowScheduling=True) # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 
  19.  # Setting operations 
  20. # List all settings settings = client.list_setting() 
  21. # Get setting by NAME/ID backupTargetsetting = client.by_id_setting(id="backup-target") 
  22. # Update a setting backupTargetsetting = client.update(backupTargetsetting, value="s3://backupbucket@us-east-1/") 
  23. # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 

 

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/796784.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号