使用 CycleCloud REST API

Cyclecloud 提供 REST API 來新增自動化和程式設計叢集管理。 自訂自動調整和自訂排程器整合需要評估工作負載佇列的工具,並啟動虛擬機器 (VM) 等於工作負載需求。 CycleCloud REST API 是這類工具的適當端點,並支援可能包含高輸送量或緊密結合 VM 排列的工作負載需求。

判斷叢集狀態

您可以查詢 CycleCloud 來判斷指出每個叢集組態中 VM 可用性的叢集狀態。

curl --location --request GET '${CC-URL}/clusters/${CLUSTER}/status' \
--header 'Authorization: Basic ****************************'

注意

CycleCloud API 會使用使用者名稱和密碼組合來接受基本驗證。 這些 curl API 範例是 base64 編碼字串 'user:password'。

回應的格式如下。 回應包含一組完整的節點屬性,但為了簡單起見,這裡省略許多屬性。

{
  "state": "Started",
  "targetState": "Started",
  "maxCount": 100,
  "maxCoreCount": 10000,
  "nodearrays": [
    {
      "name": "ondemand",
      "maxCount": 100,
      "maxCoreCount": 500,
      "buckets": [
        {
        "bucketId": "cd56af52-abcd-1234-a4e7-e6a91ca519a2",
        "definition": {
            "machineType": "Standard_Fs32_v2"
          },
          "maxCount": 3,
          "maxCoreCount": 96,
          "activeCount": 0,
          "activeCoreCount": 0,
          "availableCount": 3,
          "availableCoreCount": 96,
          "quotaCount": 3,
          "quotaCoreCount": 100,
          "consumedCoreCount": 0,
          "maxPlacementGroupSize": 40,
          "maxPlacementGroupCoreSize": 1280,
          "valid": true,
          "placementGroups": [],
          "virtualMachine": {
            "vcpuCount": 32,
            "memory": 64.0,
            "infiniband": false
          }
          },
        {
        "bucketId": "d81e001a-abcd-1234-9754-79815cb7b225",
        "definition": {
            "machineType": "Standard_Hc44rs"
          },
          "maxCount": 11,
          "maxCoreCount": 484,
          "activeCount": 0,
          "activeCoreCount": 0,
          "availableCount": 11,
          "availableCoreCount": 484,
          "quotaCount": 200,
          "quotaCoreCount": 8800,
          "consumedCoreCount": 44,
          "maxPlacementGroupSize": 40,
          "maxPlacementGroupCoreSize": 1760,
          "valid": true,
          "placementGroups": [],
          "virtualMachine": {
            "vcpuCount": 44,
            "memory": 327.83,
            "infiniband": true
          }
        }
    ]
}

建立節點

API 提供啟動節點的絕佳彈性。 建立節點的唯一必要屬性是 nodearraycount 。 使用最小必要屬性的呼叫會繼承所有現有的節點組態,並放在第一個可滿足要求的值區中。

curl --location --request POST '${CC-URL}/clusters/${CLUSTER}/nodes/create' \
--header 'Authorization: Basic ****************************' \
--header 'Content-Type: text/plain' \
--data-raw '{ "requestId" : "463270ca-abcd-1234-98d6-431ee3ef8ed5",
    "sets" : [
        {
            "count" : 1,
            "nodearray" : "ondemand"
        }
    ]
}'

此呼叫的回應會提供作業識別碼。

{
  "operationId": "3b53d621-abcd-1234-8876-6ec1158897ac",
  "sets": [
    {
      "added": 1
    }
  ]
}

您可以使用 作業 API來追蹤作業狀態。 您可以設定 request_id 參數來篩選 GET 節點回應。 這可提供您使用建立要求建立之所有節點的詳細資料。

curl --location --request GET '${CC-URL}/clusters/${CLUSTER}/nodes?request_id=463270ca-abcd-1234-98d6-431ee3ef8ed5' \

新增緊密結合的節點

CycleCloud nodearrays 可以使用清單中的多個有效電腦類型來定義。 ondemand假設 nodearray 同時 Standard_F32s_v2_ 已定義 和 Standard_Hc44rs 。 叢集狀態 API 會針對每個 VM 大小顯示至少兩 buckets 個節點陣列。 觀察值區指出 Standard_Hc44rsinfiniband 服務可供使用。 某些量化軟體會寫入,以跨節點相應放大,並利用節點之間的低延遲連線。

假設您正在執行這類工作負載,以及 Azure Infiniband 網路所連線四個節點的作業呼叫。 為了確保四個節點最後會位於相同的放置群組中,因此在相同的 Infiniband 網路上,您將使用 建立節點 API 呼叫 搭配 placementGroupId

curl --location --request POST '${CC-URL}/clusters/${CLUSTER}/nodes/create' \
--header 'Authorization: Basic ****************************' \
--header 'Content-Type: text/plain' \
--data-raw '{ "requestId" : "463270ca-abcd-1234-98d6-431ee3ef8ed5",
    "sets" : [
        {
            "count" : 4,
            "nodearray" : "ondemand",
            "placementGroupId" : "pg0",
            "definition" : { "machineType" : "Standard_Hc44rs" }
        }
    ]
}'

placementGroupId不一定參考既有的放置群組。 這是 CycleCloud 中使用的邏輯群組,如果提出要求時沒有特定放置群組,則 CycleCloud 會建立新的放置群組。 您可以在其他建立節點要求中,將其他 VM 新增至相同的放置群組。

刪除節點

有時候,管理員服務會想要終止已建立 的節點

curl --location --request POST '${CC-URL}/clusters/${CLUSTER}/nodes/terminate' \
--header 'Authorization: Basic ****************************' \
--header 'Content-Type: text/plain' \
--data-raw '{
 "ids" : ["62a1b116-abcd-1234-b290-b54ea23f1b68"]
}'
{
  "operationId": "15aaa844-abcd-1234-9591-8904c546028d",
  "nodes": [
    {
      "name": "ondemand-3",
      "id": "62a1b116-abcd-1234-b290-b54ea23f1b68",
      "status": "OK"
    }
  ]
}