当前位置:首页 >综合 >Longhorn 云原生容器分布式存储

Longhorn 云原生容器分布式存储

2024-06-30 21:59:51 [百科] 来源:避面尹邢网

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

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

 [[421320]]

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

Longhorn 云原生容器分布式存储

目前,云原您可以使用 Longhorn UI 操作 Longhorn。生容同时,器分您可以使用 Python 访问 Longhorn API,布式如下所示。存储

Longhorn 云原生容器分布式存储

1.获取 Longhorn API 端点

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

Longhorn 云原生容器分布式存储

如果您在安装 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 

 

责任编辑:武晓燕 来源: 黑客下午茶 分布式存储云原生

(责任编辑:综合)

    推荐文章
    热点阅读