内容来源于官方 Longhorn 1.1.2 英文技术手册。

系列

目前,您可以使用 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-forwardlonghorn-frontend service 转发到 localhost

    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

    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
公众号:黑客下午茶

最新文章

  1. 12小时包你学会基于ReactMix框架的ReactNativeApp开发(二)基于Css+HTML写第一个app页面
  2. 54. Android中adb常用命令及应用常用目录
  3. How to retrieve instance parameters from an uninstantiated (uninserted) family
  4. 用C#访问SSRS自动导出SSRS报表
  5. TClientDataSet中关于TField、TFieldDef动态创立字段的应用
  6. hbase thrift 定义
  7. SSM项目目录结构
  8. codeforces589I
  9. JavaScript学习之路-为什么要学习JavaScript语法
  10. JavaSE-关键字final
  11. NSObject
  12. jieba分词(1)
  13. tensorflow 在同一个GPU同时加载多张相同的图
  14. js设计模式总结1
  15. 使用Nexus管理maven仓库,setting文件理解
  16. 如何修改 VIM 制表符的空格数?
  17. 题目1004:Median(qsort函数自定义cmp函数)
  18. 十七、curator recipes之DistributedPriorityQueue
  19. matlab画直线,指定斜率与x坐标范围
  20. SQL注入文件读取通过from for分页读取

热门文章

  1. C语言学习之基本数据类型【一】
  2. Python自动化测试面试题-Python基础篇
  3. Webstorm 快速补全
  4. 浅谈MySQL与mongodb的区别
  5. html页面自动跳转
  6. bugku-web3
  7. 37岁Android程序员裸辞,四个月被497家公司拒绝,问猎头后懵了
  8. 阿里、腾讯、百度、网易、美团Android面试经验分享,拿到了百度、腾讯offer
  9. 第6篇-Java方法新栈帧的创建
  10. 解决SecureCRT中删除会话后无法重建问题