すべてのプロダクト
Search
ドキュメントセンター

Compute Nest:サービスインスタンスの有効期間を確認する

最終更新日:Jun 08, 2025

このトピックでは、CheckOutLicense 操作を呼び出すことによって、サービスインスタンスの有効期間を確認する方法について説明します。

制限

次の要件のいずれかを満たす必要があります。

  • Compute Nest サービスがカスタム販売用に構成されている。

  • Compute Nest サービスが Alibaba Cloud Marketplace に掲載されている。

検証の原則

Compute Nest で作成されたリソースの場合、Compute Nest はサービスインスタンス ID(ServiceInstanceId)やサービス ID(ServiceId)などのタグをリソースに追加します。CheckOutLicense は、リソースタグに基づいて、リソースが属するサービスインスタンスを特定するために使用されます。

  1. サービスプロバイダーは、Compute Nest コンソールから対応するサービスインスタンスの ServiceId 値を取得する必要があります。

  2. CheckOutLicense 操作を呼び出すと、ServiceId パラメーターが Compute Nest に渡されます。Compute Nest は、渡されたコンテンツがリソース内のコンテンツと一致するかどうかを確認します。

呼び出し例

Elastic Compute Service(ECS)インスタンスを作成し、制限に基づいて CheckOutLicense 操作を呼び出します。

  1. ECS リージョン情報を取得します。

    CheckOutLicense 操作を呼び出す前に、ECS インスタンスとそのアプリケーションがデプロイされているリージョンの ID を取得します。取得したリージョン ID は、後続のステップで使用され、サービスプロバイダーによって適切に保持されます。

    1. 次の URL にアクセスして、リージョン ID を取得します。

      curl http://100.100.100.200/latest/meta-data/region-id
    2. リージョン ID を含むサンプルレスポンス:

      cn-hangzhou
  2. コンソールから ServiceId を取得します。

    image

  3. リクエストの例。

    この例では、中国 (杭州) リージョンで呼び出しが行われます。リージョン ID を実際のリージョン ID に置き換えてください。

    # ServiceId の値を実際の状況に合わせて置き換えてください。
    curl -H "Content-Type: application/json" -XPOST https://cn-hangzhou.axt.aliyun.com/computeNest/license/check_out_license -d '{"ServiceId":"service-8fff945fe6844906****"}'
  4. レスポンスの例。

    {
        "code":200,
        "requestId":"6af1efb7-c59c-4cee-9094-e1e3bbefb639",
        "instanceId":"i-0jl957dfri612gxxxxxx",
        "result":{
            "RequestId":"B22723B7-FC31-18F5-A33E-1AF4C82736AA",
            "ServiceInstanceId":"si-0f14037f30c14292****",
            "LicenseMetadata":"{\"TemplateName\":\"Custom_Image_Ecs\",\"SpecificationName\":\"\",\"CustomData\":\"xxxx\"}",
            "TrialType":"NotTrial",
            "Token":"58d4574bd0d967bb431cd8936b5e80c4",
            "ExpireTime":"2024-08-28T06:27:08Z",
            "ServiceId":"service-8fff945fe6844906****",
            "Components":"{\"package_version\":\"yuncode55xxxxxxxx\",\"SystemDiskSize\":\"40\",\"DataDiskSize\":\"100\"}"
        }
     }

    次の表にパラメーターを示します。

    パラメーター

    説明

    ServiceInstanceId

    サービスインスタンスの ID。

    si-0f14037f30c14292****

    ServiceId

    サービス ID。

    service-8fff945fe6844906****

    ExpireTime

    サービスインスタンスの有効期限。

    2024-08-28T06:27:08Z

    LicenseMetadata

    メタデータ。

    このデータは、カスタム販売構成で定義する必要があります。

    {\"TemplateName\":\"Custom_Image_Ecs\",\"SpecificationName\":\"\",\"CustomData\":\"xxxx\"}

    Components

    Alibaba Cloud Marketplace からの追加の課金項目情報。

    {\"package_version\":\"yuncode55xxxxxxxx\",\"SystemDiskSize\":\"40\",\"DataDiskSize\":\"100\"}

サンプルコード

Python

import requests
import json
import hashlib
import time
from urllib.request import urlopen

def get_region_id():
    """リージョン ID ( cn-hangzhou など) を Alibaba Cloud メタデータサービスを使用して取得します""" # 翻訳済み
    try:
        with urlopen(
            "http://100.100.100.200/latest/meta-data/region-id",
            timeout=2
        ) as response:
            return response.read().decode().strip()
    except Exception as e:
        print(f"Failed to get region ID: {str(e)}", file=sys.stderr) # コメントは原文のまま
        sys.exit(1)

def checkout_license():
    # リージョン ID を動的に取得し、URL を構築します # 翻訳済み
    region_id = get_region_id()
    url = f"https://{region_id}.axt.aliyun.com/computeNest/license/check_out_license"

    # POST リクエストを送信します # 翻訳済み
    try:
        response = requests.post(
            url,
            json={
              # オプションパラメータ # 翻訳済み
              # "ServiceId": "service-ec9cbf77f9be443db938" # コメントは原文のまま
            },
            headers={"Content-Type": "application/json"}
        )
        print(f"Request URL: {url}") # コメントは原文のまま
        print(f"Status Code: {response.status_code}") # コメントは原文のまま
        print(f"Response: {response.text}") # コメントは原文のまま
    except Exception as e:
        print(f"Request Failed: {str(e)}", file=sys.stderr) # コメントは原文のまま

if __name__ == "__main__":
    import sys
    # 関数を呼び出します # 翻訳済み
    checkout_license()

例。

image

Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;     

public class CheckoutLicense {
    public static void main(String[] args) {
        try {
            // === リージョン ID を動的に取得する === # 翻訳済み
            String regionId = getRegionId();
            System.out.println("Detected Region ID: " + regionId); // コメントは原文のまま

            String checkoutLicenseString = "{}";
            // オプションパラメータ # 翻訳済み
            // String checkoutLicenseString = "{\"ServiceId\": \"service-ec9cbf77f9be443db938\"}"; // コメントは原文のまま

            // === POST リクエストを送信する === # 翻訳済み
            String urlStr = "https://" + regionId + ".axt.aliyun.com/computeNest/license/check_out_license";
            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoOutput(true);

            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = checkoutLicenseString.getBytes("UTF-8");
                os.write(input, 0, input.length);
            }

            // === レスポンスを読み取る === # 翻訳済み
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder response = new StringBuilder();
            String responseLine;
            while ((responseLine = br.readLine()) != null) {
                response.append(responseLine);
            }
            conn.disconnect();
            System.out.println("Response: " + response.toString()); // コメントは原文のまま
            System.out.println("Request URL: " + urlStr); // コメントは原文のまま

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // === リージョン ID を動的に取得する (Alibaba Cloud メタデータサービス) === # 翻訳済み
    private static String getRegionId() throws Exception {
        String regionIdUrl = "http://100.100.100.200/latest/meta-data/region-id";
        HttpURLConnection conn = (HttpURLConnection) new URL(regionIdUrl).openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(2000); // 2 seconds timeout # コメントは原文のまま
        conn.setReadTimeout(2000);

        try (BufferedReader in = new BufferedReader(
            new InputStreamReader(conn.getInputStream()))) {
            return in.readLine().trim();
        }
    }
}

例。

image