更新时间:2024-10-23 GMT+08:00
分享

修改实例信息

功能介绍

修改设备接入实例信息。

调用方法

请参见如何调用API

URI

PUT /v5/iot/{project_id}/iotda-instances/{instance_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数说明:项目ID。获取方法请参见 获取项目ID

instance_id

String

参数说明:实例ID。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数说明:用户Token。通过调用IAM服务 获取IAM用户Token接口获取,接口返回的响应消息头中“X-Subject-Token”就是需要获取的用户Token。简要的获取方法样例请参见 Token认证

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

参数说明:实例名称。

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

description

String

参数说明:设备接入实例的描述信息。

取值范围:长度不超过256,只允许中文、字母、数字、以及_,,.。、&-等字符的组合

operate_window

OperateWindow object

实例维护时间窗,用户在变更实例规格时,可以指定在该时间窗内进行变更。

forwarding_info

UpdateForwardingInfo object

企业版实例的SNAT配置,配置开启后,企业版实例可以在公共网络中进行外部通信。

约束:只有企业版实例支持修改流转配置。

access_info

UpdateAccessInfo object

设备接入实例的接入信息。用户可以使用该结构体中的信息将应用服务器和设备接入到物联网平台。

约束:只有企业版实例支持自定义接入信息。

表4 OperateWindow

参数

是否必选

参数类型

描述

start_time

String

参数说明:变更时间窗开始时间,UTC时间,格式为:"HH:mm"

end_time

String

参数说明:变更时间窗结束时间,UTC时间,格式为:"HH:mm"

表5 UpdateForwardingInfo

参数

是否必选

参数类型

描述

enable_snat

Boolean

参数说明:是否启用SNAT配置。企业版实例开启SNAT配置后,可以在公共网络中进行外部通信。

约束:只有企业版实例支持配置SNAT配置,SNAT配置开启后将不支持关闭。

取值范围

  • true: 启用SNAT配置

表6 UpdateAccessInfo

参数

是否必选

参数类型

描述

access_type

String

参数说明:接入地址的类型,如应用接入的HTTPS协议的取值为:APP_HTTPS,设备接入的MQTT协议的取值为:DEVICE_MQTT。

取值范围

  • APP_HTTPS:应用接入HTTPS协议

  • APP_AMQP:应用接入AMQP协议

  • APP_MQTT:应用接入MQTT协议

  • DEVICE_COAP:设备接入COAP协议

  • DEVICE_MQTT:设备接入MQTT协议

  • DEVICE_HTTPS:设备接入HTTPS协议

domain_name

String

参数说明:接入域名,如果需要更新域名,则携带该字段。

public_addresses_enable

Boolean

参数说明:是否配置公网接入地址。

取值范围

  • true:配置公网接入地址,平台将自动分配公网接入地址。约束:分配地址后将不能修改或删除。

ip_whitelist

IPWhiteList object

IP白名单

约束:只有企业版实例的APP_HTTPS协议支持配置IP白名单。

表7 IPWhiteList

参数

是否必选

参数类型

描述

enable

Boolean

参数说明:启用Ip白名单访问控制。

allow_list

Array of IpAllowList objects

参数说明:允许访问企业版实例的IP地址列表。

表8 IpAllowList

参数

是否必选

参数类型

描述

address

String

参数说明:白名单ip地址。

description

String

参数说明:描述。

响应参数

状态码: 200

表9 响应Body参数

参数

参数类型

描述

instance_type

String

参数说明:实例类型。

取值范围

  • standard:标准版实例

  • enterprise:企业版实例

instance_id

String

参数说明:实例ID。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

charge_mode

String

参数说明:实例的付费方式。

取值范围

  • prePaid:包年/包月

  • postPaid:按需计费

name

String

参数说明:实例名称。

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

flavor

Flavor object

参数说明:设备接入实例的规格参数。

status

String

参数说明:实例状态。

取值范围

  • CREATING:实例正在创建

  • ACTIVE:实例正常

  • FROZEN:实例冻结

  • TRADING: 实例正在进行交易

  • MODIFYING:实例正在变更规格

  • FAILED:实例创建失败

region_id

String

参数说明:实例所属region。

description

String

参数说明:设备接入实例的描述信息。

取值范围:长度不超过256,只允许中文、字母、数字、以及_,,.。、&-等字符的组合。

access_infos

Array of AccessInfo objects

参数说明:设备接入实例的接入信息。

create_time

String

参数说明:实例的创建时间。时间格式例如:2023-01-28T06:57:52Z。

update_time

String

参数说明:实例的最近一次更新的时间。时间格式例如:2023-01-28T06:57:52Z。

enterprise_project_id

String

参数说明:企业项目Id。

tags

Array of Tag objects

参数说明: 设备接入实例的标签信息。如果实例有标签,则会有该字段,否则该字段为空。

order_id

String

参数说明:订单号,仅包年包月实例返回该参数。查看订单详情请参考查询订单详情

operate_window

OperateWindow object

实例维护时间窗,用户在变更实例规格时,可以指定在该时间窗内进行变更。

additional_params

AdditionalParamsResp object

企业版附加参数信息。

表10 Flavor

参数

参数类型

描述

type

String

参数说明:待创建设备接入实例的规格名称。详情请参见产品规格说明中的规格编码。

size

Integer

参数说明:待创建设备接入标准版实例的单元数量。详情请参见产品规格说明。当instance_type是standard时,该参数必填。

表11 AccessInfo

参数

参数类型

描述

type

String

参数说明:接入地址的类型,如应用接入的HTTPS协议的取值为:APP_HTTPS,设备接入的MQTT协议的取值为:DEVICE_MQTT。

取值范围

  • APP_HTTPS:应用接入HTTPS协议

  • APP_AMQP:应用接入AMQP协议

  • APP_MQTT:应用接入MQTT协议

  • DEVICE_COAP:设备接入COAP协议

  • DEVICE_MQTT:设备接入MQTT协议

  • DEVICE_HTTPS:设备接入HTTPS协议

port

Integer

参数说明:实例的应用/设备的安全接入端口。

non_tls_port

Integer

参数说明:实例的应用/设备的非安全接入端口。返回null时表示该类型的接入地址不支持非安全端口接入。

websocket_port

Integer

参数说明:基于WebSocket的MQTT接入端口。返回null时表示该类型的接入地址不支持WebSocket端口接入。

domain_name

String

参数说明:实例的接入域名。

private_addresses

Array of strings

参数说明:实例的私网接入地址列表。

public_address

Array of strings

参数说明:实例的公网接入地址。

ipv6_address

Array of strings

参数说明:实例的ipv6接入地址列表。

ip_whitelist

IPWhiteList object

IP白名单

约束:只有企业版实例的APP_HTTPS协议支持配置IP白名单。

表12 IPWhiteList

参数

参数类型

描述

enable

Boolean

参数说明:启用Ip白名单访问控制。

allow_list

Array of IpAllowList objects

参数说明:允许访问企业版实例的IP地址列表。

表13 IpAllowList

参数

参数类型

描述

address

String

参数说明:白名单ip地址。

description

String

参数说明:描述。

表14 Tag

参数

参数类型

描述

key

String

参数说明:标签键,标签的键可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@,首尾不能有空格字符。

value

String

参数说明:标签值,可为空字符串和null,标签的值可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@。

表15 OperateWindow

参数

参数类型

描述

start_time

String

参数说明:变更时间窗开始时间,UTC时间,格式为:"HH:mm"

end_time

String

参数说明:变更时间窗结束时间,UTC时间,格式为:"HH:mm"

表16 AdditionalParamsResp

参数

参数类型

描述

vpc_id

String

参数说明:企业版实例的VPCID。

subnet_id

String

参数说明:企业版实例的子网ID。

security_group_id

String

参数说明:企业版实例的安全组ID。

ciphering_algorithm

String

参数说明:实例支持的加密算法。

取值范围

  • COMMON_ALGORITHM: 通用加密算法(支持RSA,SHA256等国际通用的密码算法)

  • SM_ALGORITHM: 支持SM系列商密算法(支持SM2,SM3,SM4等国密算法)

forwarding_info

ForwardingInfo object

企业版实例的SNAT配置信息。

表17 ForwardingInfo

参数

参数类型

描述

eip

String

参数说明:NAT网关绑定的EIP。

enable_snat

Boolean

参数说明:是否启用SNAT配置。

取值范围

  • true: SNAT配置已启用

  • false: SNAT配置未启用

请求示例

  • 修改实例名称、描述和操作时间窗。

    PUT https://{endpoint}/v5/iot/{project_id}/iotda-instances/{instance_id}
    
    {
      "name" : "iotda_instance01",
      "description" : "IoTDA instance for test.",
      "operate_window" : {
        "start_time" : "18:00",
        "end_time" : "22:00"
      }
    }
  • 企业版实例启用公网流转SNAT配置。

    PUT https://{endpoint}/v5/iot/{project_id}/iotda-instances/{instance_id}
    
    {
      "forwarding_info" : {
        "enable_snat" : "true"
      }
    }
  • 企业版实例修改实例接入信息。

    PUT https://{endpoint}/v5/iot/{project_id}/iotda-instances/{instance_id}
    
    {
      "access_info" : {
        "access_type" : "APP_HTTPS",
        "domain_name" : "example.myhuaweicloud.com",
        "public_addresses_enable" : true
      }
    }

响应示例

状态码: 200

OK

{
  "instance_type" : "standard",
  "instance_id" : "8561675c-d8a3-4956-9884-9cf9cbdd3134",
  "charge_mode" : "prePaid",
  "name" : "iotda_instance",
  "flavor" : {
    "type" : "iotda.standard.s1",
    "size" : 1
  },
  "status" : "ACTIVE",
  "region_id" : "cn-north-4",
  "create_time" : "2023-01-28T06:57:52Z",
  "update_time" : "2023-01-28T06:58:52Z",
  "description" : "IoTDA instance for production.",
  "access_infos" : [ {
    "type" : "APP_AMQP",
    "port" : 5671,
    "non_tls_port" : null,
    "websocket_port" : null,
    "domain_name" : "example.myhuaweicloud.com",
    "public_address" : [ ],
    "ipv6_address" : [ ],
    "ip_whitelist" : null
  }, {
    "type" : "APP_HTTPS",
    "port" : 443,
    "non_tls_port" : null,
    "websocket_port" : null,
    "domain_name" : "example1.myhuaweicloud.com",
    "public_address" : [ ],
    "ipv6_address" : [ ],
    "ip_whitelist" : null
  }, {
    "type" : "DEVICE_MQTT",
    "port" : 8883,
    "non_tls_port" : 1883,
    "websocket_port" : 443,
    "domain_name" : "example2.myhuaweicloud.com",
    "public_address" : [ ],
    "ipv6_address" : [ ],
    "ip_whitelist" : null
  }, {
    "type" : "DEVICE_COAP",
    "port" : 5684,
    "non_tls_port" : 5683,
    "websocket_port" : null,
    "domain_name" : "example3.myhuaweicloud.com",
    "public_address" : [ ],
    "ipv6_address" : [ ],
    "ip_whitelist" : null
  } ],
  "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d",
  "tags" : [ {
    "key" : "testTagName",
    "value" : "testTagValue"
  } ],
  "order_id" : "CS22121614500ABCD",
  "operate_window" : {
    "start_time" : "22:00",
    "end_time" : "24:00"
  },
  "additional_params" : null
}

SDK代码示例

SDK代码示例如下。

  • 修改实例名称、描述和操作时间窗。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    
    public class UpdateInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateInstanceRequest request = new UpdateInstanceRequest();
            request.withInstanceId("{instance_id}");
            UpdateInstance body = new UpdateInstance();
            OperateWindow operateWindowbody = new OperateWindow();
            operateWindowbody.withStartTime("18:00")
                .withEndTime("22:00");
            body.withOperateWindow(operateWindowbody);
            body.withDescription("IoTDA instance for test.");
            body.withName("iotda_instance01");
            request.withBody(body);
            try {
                UpdateInstanceResponse response = client.updateInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 企业版实例启用公网流转SNAT配置。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    
    public class UpdateInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateInstanceRequest request = new UpdateInstanceRequest();
            request.withInstanceId("{instance_id}");
            UpdateInstance body = new UpdateInstance();
            UpdateForwardingInfo forwardingInfobody = new UpdateForwardingInfo();
            forwardingInfobody.withEnableSnat(true);
            body.withForwardingInfo(forwardingInfobody);
            request.withBody(body);
            try {
                UpdateInstanceResponse response = client.updateInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 企业版实例修改实例接入信息。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    
    public class UpdateInstanceSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            UpdateInstanceRequest request = new UpdateInstanceRequest();
            request.withInstanceId("{instance_id}");
            UpdateInstance body = new UpdateInstance();
            UpdateAccessInfo accessInfobody = new UpdateAccessInfo();
            accessInfobody.withAccessType("APP_HTTPS")
                .withDomainName("example.myhuaweicloud.com")
                .withPublicAddressesEnable(true);
            body.withAccessInfo(accessInfobody);
            request.withBody(body);
            try {
                UpdateInstanceResponse response = client.updateInstance(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 修改实例名称、描述和操作时间窗。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateInstanceRequest()
            request.instance_id = "{instance_id}"
            operateWindowbody = OperateWindow(
                start_time="18:00",
                end_time="22:00"
            )
            request.body = UpdateInstance(
                operate_window=operateWindowbody,
                description="IoTDA instance for test.",
                name="iotda_instance01"
            )
            response = client.update_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 企业版实例启用公网流转SNAT配置。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateInstanceRequest()
            request.instance_id = "{instance_id}"
            forwardingInfobody = UpdateForwardingInfo(
                enable_snat=True
            )
            request.body = UpdateInstance(
                forwarding_info=forwardingInfobody
            )
            response = client.update_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 企业版实例修改实例接入信息。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = UpdateInstanceRequest()
            request.instance_id = "{instance_id}"
            accessInfobody = UpdateAccessInfo(
                access_type="APP_HTTPS",
                domain_name="example.myhuaweicloud.com",
                public_addresses_enable=True
            )
            request.body = UpdateInstance(
                access_info=accessInfobody
            )
            response = client.update_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 修改实例名称、描述和操作时间窗。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateInstanceRequest{}
    	request.InstanceId = "{instance_id}"
    	operateWindowbody := &model.OperateWindow{
    		StartTime: "18:00",
    		EndTime: "22:00",
    	}
    	descriptionUpdateInstance:= "IoTDA instance for test."
    	nameUpdateInstance:= "iotda_instance01"
    	request.Body = &model.UpdateInstance{
    		OperateWindow: operateWindowbody,
    		Description: &descriptionUpdateInstance,
    		Name: &nameUpdateInstance,
    	}
    	response, err := client.UpdateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 企业版实例启用公网流转SNAT配置。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateInstanceRequest{}
    	request.InstanceId = "{instance_id}"
    	forwardingInfobody := &model.UpdateForwardingInfo{
    		EnableSnat: true,
    	}
    	request.Body = &model.UpdateInstance{
    		ForwardingInfo: forwardingInfobody,
    	}
    	response, err := client.UpdateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 企业版实例修改实例接入信息。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateInstanceRequest{}
    	request.InstanceId = "{instance_id}"
    	domainNameAccessInfo:= "example.myhuaweicloud.com"
    	publicAddressesEnableAccessInfo:= true
    	accessInfobody := &model.UpdateAccessInfo{
    		AccessType: "APP_HTTPS",
    		DomainName: &domainNameAccessInfo,
    		PublicAddressesEnable: &publicAddressesEnableAccessInfo,
    	}
    	request.Body = &model.UpdateInstance{
    		AccessInfo: accessInfobody,
    	}
    	response, err := client.UpdateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

错误码

请参见错误码

相关文档