|
Este documento foi traduzido usando tecnologia de tradução automática de máquina. Sempre trabalhamos para apresentar traduções precisas, mas não oferecemos nenhuma garantia em relação à integridade, precisão ou confiabilidade do conteúdo traduzido. Em caso de qualquer discrepância, a versão original em inglês prevalecerá e constituirá o texto official. |
|
Esta é uma documentação não divulgada para SUSE® Storage 1.12 (Dev). |
Cliente Python
Você pode acessar a API Longhorn usando a ligação Python.
-
Obtenha o endpoint do Longhorn
Uma maneira de se comunicar com o Longhorn é através do
longhorn-frontendserviço.Se você executar sua ferramenta de automação/scripting dentro do mesmo cluster em que o Longhorn está instalado, conecte-se ao endpoint
http://longhorn-frontend.longhorn-system/v1Se você executar sua ferramenta de automação/scripting em sua máquina local, use
kubectl port-forwardpara encaminhar olonghorn-frontendserviço para o host local:kubectl port-forward services/longhorn-frontend 8080:http -n longhorn-system
e conecte-se ao endpoint
http://localhost:8080/v1 -
Usando o Cliente Python
Importe o arquivo longhorn.py que contém o cliente Python em seu script Python e crie um cliente a partir do endpoint:
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