作者:为少 2021-09-03 05:00:28
存储
存储软件
云原生
分布式 如果您在本地机器上运行自动化/脚本(automation/scripting)工具,请使用 kubectl port-forward 将 longhorn-frontend service 转发到 localhost。
成都创新互联于2013年创立,先为眉山等服务建站,眉山等地企业,进行企业商务咨询服务。为眉山企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
[[421320]]
本文转载自微信公众号「黑客下午茶」,作者为少。转载本文请联系黑客下午茶公众号。
目前,您可以使用 Longhorn UI 操作 Longhorn。同时,您可以使用 Python 访问 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
将 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
网站名称:Longhorn云原生容器分布式存储-PythonClient
转载来于:http://www.shufengxianlan.com/qtweb/news43/283743.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联