Python API

CycleCloud Python API を使用すると、手動で HTTP 要求を実行しなくても、CycleCloud REST API と対話できます。 API ソースディストリビューションを取得するには、CycleCloud インストールで /about に移動し、[ Python API のダウンロード ] リンクをクリックします。 ソースディストリビューションを入手したら、それを Python 環境に組み込んで開始できます pip install

クライアント オブジェクト

Client オブジェクトは、構成を指定した場合と指定しない場合に構築できます。 構成ディクショナリを指定しない場合、既定の CycleCloud CLI ini ファイル (~/.cycle/config.ini) から構成のプルが自動的に試行されます。

構成は、次のキーと値のペアを持つ dict として提供できます。

  • url - 必要な場合は、CycleCloud インストールへの Web インターフェイスの URL
  • username - 必須
  • password - 必須、ユーザーのプレーン テキスト パスワード
  • timeout - システムとの接続/通信を試行するときにタイムアウト エラーが発生するまでの時間 (秒単位) (既定では 60)
  • verify_certificates - 証明書チェックを有効にする必要があるかどうかを示すブール値 (既定では True)

または、これらの値をコンストラクターにキーワード引数として指定することもできます。

from cyclecloud.client import Client

# configuration read from ~/.cycle/config.ini
cl1 = Client() 

# config provided as dictionary
config = {"url": "http://127.0.0.1:8443",
          "username": "admin",
          "password": "password",
          "timeout": 60,
          "verify_certificates": False}
cl2 = Client(config)

# config provided as keyword arguments
cl3 = Client(url="http://127.0.0.1:8443", username="admin", password="password")

クライアントのプロパティ

  • session- Session オブジェクト - Direct API の呼び出しでのみ使用されます

  • clusters - システム内のクラスター オブジェクトのマップ(クラスター名でキー付け)

クラスター オブジェクト

Cluster オブジェクトを使用すると、CycleCloud インストール内の特定のクラスターを制御できます。

from cyclecloud.client import Client
cl1 = Client()

# gets a Cluster object for a cluster named "test-cluster-1" from the client cl1
cluster_obj = cl1.clusters["test-cluster-1"]

# prints the current state of the cluster
print(cluster_obj.get_status().state)

# start up to 5 new cores
cluster_obj.scale_by_cores("execute", 5)

クラスターのプロパティ

  • name - このオブジェクトが参照するクラスターの名前

  • nodes - このクラスターを構成するノード レコードの iterable リスト

クラスター関数

  • get_status(nodes=False) - クラスターの クラスター状態 オブジェクトを取得します。必要に応じて、ノード 一覧も設定します。

  • scale_by_cores(node_array, total_core_count) - 指定したノード配列を目的の合計コア数にスケーリングするようにシステムを設定します。 ノード配列に既に複数 total_core_count のコアが含まれている場合、呼び出しは無効になります。

  • scale_by_nodes(node_array, total_node_count) - 指定したノード配列を目的の合計ノード数にスケーリングするようにシステムを設定します。 ノード配列に既に複数 total_node_count のノードが含まれている場合、呼び出しは無効になります。

Direct API

rest API には、REST API から直接生成される API を使用して、より直接的な方法でcyclecloud.apicyclecloud.modelアクセスできます。 そのためには、クライアント オブジェクトを構築し、そのオブジェクトに指定されたプロパティを session 使用して呼び出します。

from cyclecloud.client import Client
from cyclecloud.api import clusters

cl1 = Client()

# prints the current state of the cluster
response_status, cluster_status = clusters.get_cluster_status(cl1.session, "test-cluster-1", nodes=False)
print(cluster_status.state)