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

存储 存储软件 云原生 分布式
如果您在本地机器上运行自动化/脚本(automation/scripting)工具,请使用 kubectl port-forward 将 longhorn-frontend service 转发到 localhost。

 [[421320]]

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

目前,您可以使用 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.  
  3. # If automation/scripting tool is inside the same cluster in which Longhorn is installed 
  4. longhorn_url = 'http://longhorn-frontend.longhorn-system/v1' 
  5. # If forwarding `longhorn-frontend` service to localhost 
  6. longhorn_url = 'http://localhost:8080/v1' 
  7.  
  8. client = longhorn.Client(url=longhorn_url) 
  9.  
  10. # Volume operations 
  11. # List all volumes 
  12. volumes = client.list_volume() 
  13. # Get volume by NAME/ID 
  14. testvol1 = client.by_id_volume(id="testvol1"
  15. # Attach TESTVOL1 
  16. testvol1 = testvol1.attach(hostId="worker-1"
  17. # Detach TESTVOL1 
  18. testvol1.detach() 
  19. Create a snapshot of TESTVOL1 with NAME 
  20. snapshot1 = testvol1.snapshotCreate(name="snapshot1"
  21. Create a backup from a snapshot NAME 
  22. testvol1.snapshotBackup(name=snapshot1.name
  23. Update the number of replicas of TESTVOL1 
  24. testvol1.updateReplicaCount(replicaCount=2) 
  25. # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 
  26.  
  27. # Node operations 
  28. # List all nodes 
  29. nodes = client.list_node() 
  30. # Get node by NAME/ID 
  31. node1 = client.by_id_node(id="worker-1"
  32. # Disable scheduling for NODE1 
  33. client.update(node1, allowScheduling=False
  34. # Enable scheduling for NODE1 
  35. client.update(node1, allowScheduling=True
  36. # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 
  37.  
  38. # Setting operations 
  39. # List all settings 
  40. settings = client.list_setting() 
  41. # Get setting by NAME/ID 
  42. backupTargetsetting = client.by_id_setting(id="backup-target"
  43. Update a setting 
  44. backupTargetsetting = client.update(backupTargetsetting, value="s3://backupbucket@us-east-1/"
  45. # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 

 

责任编辑:武晓燕 来源: 黑客下午茶
相关推荐

2021-08-29 23:53:32

存储Air Gap安装

2021-10-18 23:49:50

云原生分布式存储

2021-08-26 00:23:14

分布式存储高可用

2021-08-24 05:02:34

云原生容器分布式

2021-08-17 00:24:38

块存储云原生分布式

2022-02-21 10:17:33

Rancher开源云原生

2021-08-25 05:05:26

存储 备份恢复

2021-08-26 23:54:46

分布式存储负载

2021-08-28 05:04:19

存储云原生分布式

2021-08-17 12:36:21

Longhorn云原生存储

2021-08-18 14:33:53

存储云原生容器

2023-09-14 15:38:55

云原生分布式架构

2017-10-27 08:40:44

分布式存储剪枝系统

2022-10-10 17:21:50

固态硬盘分布式云存储

2022-09-15 21:04:20

JuiceFS云原生

2020-02-20 11:56:38

容器云分布式存储哪种更好

2020-09-02 16:39:00

青云QingCloud存储QingStor

2015-05-12 13:03:54

开源分布式存储HDFS

2018-02-22 08:42:04

分布式存储安全
点赞
收藏

51CTO技术栈公众号