全部產品
Search
文件中心

Data Online Migration:資料地址

更新時間:Jun 20, 2025

本文介紹如何使用SDK調用資料地址相關的方法。

建立資料地址

以下範例程式碼用於建立OSS類型的資料地址。

重要
  • 建立OSS類型的資料地址前需要先進行角色配置,並擷取到角色(rolename)。

  • 是否需要關聯代理需要根據具體情況而定,請參見文檔 使用代理遷移-概述。建立其它類型資料地址關聯代理的方法與該樣本相同。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)

        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "oss"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        region_id = "oss-cn-beijing"
        bucket = "examplebucket"
        prefix = "***/"
        role_name = "rolename_xxxxx"
        # 代理列表,無需關聯代理則不用指定。
        agent_list = "agent1,agent2,agent3"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                bucket=bucket,
                region_id=region_id,
                prefix=prefix,
                role=role_name,
                agent_list=agent_list
            )
        )))
    except Exception as e:
        print(e)

以下範例程式碼用於建立Oss Inventory類型的資料地址。

重要

建立Oss Inventory類型的資料地址前需要先進行角色配置,並擷取到角色和清單角色 (rolename 和 invrolename)。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "ossinv"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        prefix = "***/"
        region_id = "oss-cn-beijing"
        bucket = "examplebucket"
        role_name = "rolename_xxxxx"
        # 以下參數為清單相關資訊。
        inv_location = "oss"
        inv_bucket = "exampleinvbucket"
        inv_region_id = "oss-cn-beijing"
        inv_role = "invrolename_*******"
        inv_path = "***/manifest.json"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                bucket=bucket,
                region_id=region_id,
                prefix=prefix,
                role=role_name,
                inv_role=inv_role,
                inv_location=inv_location,
                inv_bucket=inv_bucket,
                inv_path=inv_path,
                inv_region_id=inv_region_id
            )
        )))
    except Exception as e:
        print(e)     

以下範例程式碼用於建立第三方源類型的資料地址。

s3

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "s3"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "s3.ap-southeast-1.amazonaws.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

cos

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "cos"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "cos.ap-nanjing.myqcloud.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

obs

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "obs"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "obs.cn-north-1.myhuaweicloud.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

tos

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "tos"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "tos-s3-cn-beijing.volces.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

qiniu

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "qiniu"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        # 網域名稱說明請參見https://developer.qiniu.com/kodo/8527/kodo-domain-name-management
        domain = "http://xxxx.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

gcp

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "gcp"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        # domain請根據實際值填寫。
        domain = "Cloud Storage URI"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

azure

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "azure"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_secret = "******"
        domain = "https://<儲存帳號>.blob.core.windows.net"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

ks3

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "ks3"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "ks3-cn-beijing.ksyuncs.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

bos

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "bos"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "bj.bcebos.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

ucloud s3

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "us3"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "cn-bj.ufileos.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

youpai

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
         
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "youpai"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        access_id = "***"
        access_secret = "******"
        domain = "s3.api.upyun.com"
        bucket = "examplebucket"
        prefix = "***/"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                access_id=access_id,
                access_secret=access_secret,
                bucket=bucket,
                domain=domain,
                prefix=prefix
            )
        )))
    except Exception as e:
        print(e)

以下範例程式碼用於建立HTTP類型的資料地址。

重要

建立HTTP類型的資料地址前需要先進行角色配置,並擷取到清單角色(invrolename)。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "http"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        inv_domain = "oss-cn-beijing.aliyuncs.com"
        inv_bucket = "exampleinvbucket"
        inv_location = "oss"
        inv_path = "dir/manifest.json"
        inv_role = "invrolename_*******"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                inv_domain=inv_domain,
                inv_location=inv_location,
                inv_path=inv_path,
                inv_role=inv_role,
                inv_bucket=inv_bucket
            )
        )))
    except Exception as e:
        print(e)

以下範例程式碼用於建立LocalFS類型的資料地址,LocalFS類型資料地址必須關聯代理。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import CreateAddressRequest, CreateAddressInfo, AddressDetail
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        address_type = "local"
        # 以下參數為待遷移資料相關資訊,請根據實際值填寫。
        prefix = "/***/"
        # 代理列表。
        agent_list = "agent1,agent2,agent3"

        client.create_address(userid, CreateAddressRequest(CreateAddressInfo(
            name=address_name,
            address_detail=AddressDetail(
                address_type=address_type,
                prefix=prefix,
                agent_list=agent_list
            )
        )))
    except Exception as e:
        print(e)

擷取資料地址詳情

以下範例程式碼用於擷取資料地址詳情資訊。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        response = client.get_address(userid, address_name)
        print(response.body.import_address)
    except Exception as e:
        print(e)

正常返回樣本

{
  "ImportAddress": {
    "Owner": "test_owner",
    "Name": "test_name",
    "AddressDetail": {
      "AddressType": "ossinv",
      "Bucket": "test_bucket",
      "Domain": "test_domain",
      "Prefix": "test_prefix",
      "AccessId": "test_access_id",
      "AccessSecret": "test_secret_key",
      "Role": "test_role",
      "InvDomain": "test_inv_domain",
      "InvBucket": "test_inv_bucket",
      "InvAccessId": "test_inv_access_id",
      "InvAccessSecret": "test_inv_secret_key",
      "InvPath": "manifest.json",
      "InvRole": "test_inv_role",
      "InvLocation": "oss",
      "AgentList": "agent1,agent2",
      "RegionId": "test_region_id",
      "InvRegionId": "test_inv_region_id"
    },
    "CreateTime": "2024-05-01T12:00:00.000Z",
    "ModifyTime": "2024-05-01T12:00:00.000Z",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "Version": "test_id",
    "Tags": "K1:V1,K2:V2",
    "Status": "avaliable",
    "VerifyResult": {
      "HttpCode": "400",
      "ErrorCode": "InvalidArgument",
      "ErrorMsg": "Invalid argument."
    }
  }
}

校正資料地址

以下範例程式碼用於驗證指定的資料地址是否可用。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        response = client.verify_address(userid, address_name)
        print(response.body)
    except Exception as e:
        print(e)
               

正常返回地址可用樣本

{
  "VerifyAddressResponse": {
    "Status": "available",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "",
    "ErrorMessage": ""
  }
}

正常返回地址不可用樣本

{
  "VerifyAddressResponse": {
    "Status": "unavailable",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "400",
    "ErrorMessage": "Invalid argument."
  }
}

列舉資料地址

以下範例程式碼用於列舉帳號下所有資料地址資訊。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import ListAddressRequest
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)

        #根據實際填寫marker, count。
        count = 1
        marker = ""
        response = client.list_address(userid, ListAddressRequest(
            marker=marker,
            count=count,
        ))
        for import_address in response.body.import_address_list.import_address:
            print(import_address)
    except Exception as e:
        print(e)

正常返回樣本

{
  "ImportAddressList": {
    "Truncated": true,
    "NextMarker": "test_marker",
    "ImportAddress": [
      {
        "Owner": "test_owner",
        "Name": "test_name",
        "AddressDetail": {
          "AddressType": "ossinv",
          "Bucket": "test_bucket",
          "Domain": "test_domain",
          "Prefix": "test_prefix",
          "AccessId": "test_access_id",
          "AccessSecret": "test_secret_key",
          "Role": "test_role",
          "InvDomain": "test_inv_domain",
          "InvBucket": "test_inv_bucket",
          "InvAccessId": "test_inv_access_id",
          "InvAccessSecret": "test_inv_secret_key",
          "InvPath": "manifest.json",
          "InvRole": "test_inv_role",
          "InvLocation": "oss",
          "AgentList": "agent1,agent2",
          "RegionId": "test_region_id",
          "InvRegionId": "test_inv_region_id"
        },
        "CreateTime": "2024-05-01T12:00:00.000Z",
        "ModifyTime": "2024-05-01T12:00:00.000Z",
        "VerifyTime": "2024-05-01T12:00:00.000Z",
        "Version": "test_id",
        "Tags": "K1:V1,K2:V2",
        "Status": "avaliable",
        "VerifyResult": {
          "HttpCode": "400",
          "ErrorCode": "InvalidArgument",
          "ErrorMsg": "Invalid argument."
        }
      }
    ]
  }
}

更新資料地址

以下範例程式碼用於代理需要擴容或縮容的情境,更新指定資料地址關聯的代理。

重要

至少需要填寫一個代理名稱,並且代理的通道不允許更改,否則更新失敗。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_hcs_mgw20240626.models import UpdateAddressRequest, UpdateAddressInfo
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        # 填寫代理列表,以,分隔, 不可為空白。
        agent_list = "exampleagent1,exampleagent2"
        client.update_address(userid, address_name, UpdateAddressRequest(UpdateAddressInfo(
            agent_list=agent_list
        )))
    except Exception as e:
        print(e)

刪除資料地址

以下範例程式碼用於刪除指定資料地址。

import os

from alibabacloud_hcs_mgw20240626.client import Client
from alibabacloud_tea_openapi.models import Config

if __name__ == "__main__":
    try:
        # 填寫主帳號ID。
        userid = "11470***876***55"
        # 這裡以北京地區為例。
        endpoint = "cn-beijing.mgw.aliyuncs.com"
        config = Config(
            endpoint=endpoint,
            access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        )
        client = Client(config)
        
        # 填寫資料位址名稱。
        address_name = "exampleaddress"
        client.delete_address(userid, address_name)
    except Exception as e:
        print(e)         

後續步驟

資料地址建立完成後,您可以選擇繼續執行建立任務操作。詳情請參見任務