Currently, you can operate Longhorn using Longhorn UI. We are planning to build a dedicated Longhorn CLI in the upcoming releases.

    In the meantime, you can access Longhorn API using Python binding, as we demonstrated below.

    1. Using Python Client

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