본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Longhorn Python 클라이언트

원문 보기 위키 갱신

Longhorn Python 클라이언트 (Longhorn Client: Python)

현재는 Longhorn UI로 Longhorn을 운용할 수 있어요. 다가오는 릴리스에서 전용 Longhorn CLI를 만들 계획이에요.

그때까지는 아래에서 보여 주듯 Python 바인딩으로 Longhorn API에 접근할 수 있어요.

출처: 문서

본문

Longhorn 엔드포인트 얻기 (Get Longhorn endpoint)

Longhorn과 통신하는 한 가지 방법은 longhorn-frontend 서비스를 통하는 거예요.

자동화/스크립팅 도구를 Longhorn이 설치된 것과 같은 클러스터 안에서 실행한다면, 엔드포인트 http://longhorn-frontend.longhorn-system/v1 에 연결하세요.

자동화/스크립팅 도구를 로컬 머신에서 실행한다면, kubectl port-forward로 longhorn-frontend 서비스를 localhost로 포워드하세요:

kubectl port-forward services/longhorn-frontend 8080:http -n longhorn-system

그리고 엔드포인트 http://localhost:8080/v1 에 연결해요.

Python 클라이언트 사용하기 (Using Python Client)

Python 클라이언트가 들어 있는 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 통합 테스트 https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests 에서 찾을 수 있어요.

더 알아보기 (Learn more)