重置节点
功能介绍
该API用于在指定集群下重置节点。
集群管理的URL格式为:https://Endpoint/uri。其中uri为资源路径,也即API访问的路径。
调用方法
请参见如何调用API。
URI
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/reset
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见如何获取接口URI中参数。 |
cluster_id |
是 |
String |
集群ID,获取方式请参见如何获取接口URI中参数。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
Content-Type |
是 |
String |
消息体的类型(格式) |
X-Auth-Token |
是 |
String |
调用接口的认证方式分为Token和AK/SK两种,如果您使用的Token方式,此参数为必填,请填写Token的值,获取方式请参见获取token。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
apiVersion |
是 |
String |
API版本,固定值“v3”。 |
kind |
是 |
String |
API类型,固定值“List”。 |
nodeList |
是 |
Array of ResetNode objects |
重置节点列表,当前最多支持同时重置200个节点。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
nodeID |
是 |
String |
节点ID,获取方式请参见如何获取接口URI中参数。 |
spec |
是 |
ReinstallNodeSpec object |
节点重装配置参数。节点池内节点不支持外部指定,将以节点池配置进行重装,默认节点池中节点此参数必选。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
os |
是 |
String |
操作系统。指定自定义镜像场景将以IMS镜像的实际操作系统版本为准。请选择当前集群支持的操作系统版本。例如Huawei Cloud EulerOS 2.0、Ubuntu 22.04、EulerOS 2.9、CentOS 7.6、EulerOS 2.8。 |
login |
是 |
Login object |
节点的登录方式。密钥对和密码登录方式二者必选其一。 |
name |
否 |
String |
节点名称 说明:
重装时指定将修改节点名称,且服务器名称会同步修改。默认以服务器当前名称作为节点名称。 命名规则:以小写字母开头,由小写字母、数字、中划线(-)、点(.)组成,长度范围1-56位。 |
serverConfig |
否 |
ReinstallServerConfig object |
服务器配置 |
volumeConfig |
否 |
ReinstallVolumeConfig object |
卷管理配置 |
runtimeConfig |
否 |
ReinstallRuntimeConfig object |
容器运行时配置 |
k8sOptions |
否 |
ReinstallK8sOptionsConfig object |
Kubernetes节点配置 |
lifecycle |
否 |
NodeLifecycleConfig object |
节点自定义生命周期配置 |
initializedConditions |
否 |
Array of strings |
自定义初始化标记。 CCE节点在初始化完成之前,会打上初始化未完成污点(node.cloudprovider.kubernetes.io/uninitialized)防止pod调度到节点上。 cce支持自定义初始化标记,在接收到initializedConditions参数后,会将参数值转换成节点标签,随节点下发,例如:cloudprovider.openvessel.io/inject-initialized-conditions=CCEInitial_CustomedInitial。 当节点上设置了此标签,会轮询节点的status.Conditions,查看conditions的type是否存在标记名,如CCEInitial、CustomedInitial标记,如果存在所有传入的标记,且状态为True,认为节点初始化完成,则移除初始化污点。
|
extendParam |
否 |
ReinstallExtendParam object |
重装拓展参数,已废弃 |
hostnameConfig |
否 |
HostnameConfig object |
K8S节点名称配置参数,支持的集群版本为v1.23.6-r0到v1.25或者v1.25.2-r0及以上。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
sshKey |
否 |
String |
选择密钥对方式登录时的密钥对名称。 |
userPassword |
否 |
UserPassword object |
选择密码方式登录时的账号密码信息,之后可通过此账号密码登录节点。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
username |
否 |
String |
登录账号,默认为“root” |
password |
是 |
String |
登录密码,若创建节点通过用户名密码方式,即使用该字段,则响应体中该字段作屏蔽展示。 密码复杂度要求:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
userTags |
否 |
Array of UserTag objects |
云服务器标签(资源标签),键必须唯一,CCE支持的最大用户自定义标签数量依region而定,自定义标签数上限为8个。 |
rootVolume |
否 |
ReinstallVolumeSpec object |
系统盘重装配置 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
否 |
String |
云服务器标签的键。不得以"CCE-"或"__type_baremetal"开头 |
value |
否 |
String |
云服务器标签的值 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
imageID |
否 |
String |
用户自定义镜像ID |
cmkID |
否 |
String |
用户主密钥ID。默认为空时,表示云硬盘不加密。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
lvmConfig |
否 |
String |
Docker数据盘配置项。 默认配置示例如下: "lvmConfig":"dockerThinpool=vgpaas/90%VG;kubernetesLV=vgpaas/10%VG;diskType=evs;lvType=linear" 包含如下字段:
|
storage |
否 |
Storage object |
磁盘初始化配置管理参数。 该参数配置逻辑较为复杂,详细说明请参见节点磁盘挂载。 该参数缺省时,按照extendParam中的DockerLVMConfigOverride(已废弃)参数进行磁盘管理。此参数对1.15.11及以上集群版本支持。 说明:
说明:
说明:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
storageSelectors |
是 |
Array of StorageSelectors objects |
磁盘选择,根据matchLabels和storageType对匹配的磁盘进行管理。磁盘匹配存在先后顺序,靠前的匹配规则优先匹配。 |
storageGroups |
是 |
Array of StorageGroups objects |
由多个存储设备组成的存储组,用于各个存储空间的划分。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
selector的名字,作为storageGroup中selectorNames的索引,因此各个selector间的名字不能重复。 |
storageType |
是 |
String |
存储类型,当前仅支持evs(云硬盘)或local(本地盘);local存储类型不支持磁盘选择,所有本地盘将被组成一个VG,因此也仅允许只有一个local类型的storageSelector。 |
matchLabels |
否 |
matchLabels object |
evs盘的匹配字段,支持DataVolume中的size、volumeType、metadataEncrypted、metadataCmkid、count五个字段。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
size |
否 |
String |
匹配的磁盘大小,不填则无磁盘大小限制。例如:100. |
volumeType |
否 |
String |
云硬盘类型,目前支持SSD\GPSSD\SAS\ESSD\SATA等,不填则无云硬盘类型限制。 |
metadataEncrypted |
否 |
String |
磁盘加密标识符,0代表不加密,1代表加密,不填则无磁盘加密标识符限制。 |
metadataCmkid |
否 |
String |
加密磁盘的用户主密钥ID,长度为36字节的字符串,不填则无磁盘密钥ID限制。 |
count |
否 |
String |
磁盘选择个数,不填则选择所有此类磁盘。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
storageGroups的名字,作为虚拟存储组的名字,因此各个group名字不能重复。 说明:
|
cceManaged |
否 |
Boolean |
k8s及runtime所属存储空间。有且仅有一个group被设置为true,不填默认false。 |
selectorNames |
是 |
Array of strings |
对应storageSelectors中的name,一个group可选择多个selector;但一个selector只能被一个group选择。 |
virtualSpaces |
是 |
Array of VirtualSpace objects |
group中空间配置的详细管理。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
virtualSpace的名称,当前仅支持四种类型:share、kubernetes、runtime、user。
|
size |
是 |
String |
virtualSpace的大小,仅支持整数百分比。例如:90%。 说明:
一个group中所有virtualSpace的百分比之和不得超过100% |
lvmConfig |
否 |
LVMConfig object |
lvm配置管理,适用于share、kubernetes和user空间配置。 需要注意:一个virtualSpace仅支持一个config配置。 |
runtimeConfig |
否 |
RuntimeConfig object |
runtime配置管理,适用于运行时空间配置。 需要注意:一个virtualSpace仅支持一个config配置。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
lvType |
是 |
String |
LVM写入模式:linear、striped。linear:线性模式;striped:条带模式,使用多块磁盘组成条带模式,能够提升磁盘性能。 |
path |
否 |
String |
磁盘挂载路径。仅在用户配置中生效。支持包含:数字、大小写字母、点、中划线、下划线的绝对路径。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
lvType |
是 |
String |
LVM写入模式:linear、striped。linear:线性模式;striped:条带模式,使用多块磁盘组成条带模式,能够提升磁盘性能。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
dockerBaseSize |
否 |
Integer |
节点上单容器的可用磁盘空间大小(已废弃,请优先使用containerBaseSize参数),单位G。 不配置该值或值为0时将使用默认值,Devicemapper模式下默认值为10;OverlayFS模式默认不限制单容器可用空间大小,且dockerBaseSize设置仅在新版本集群的EulerOS/HCEOS2.0节点上生效。 CCE节点容器运行时空间配置请参考数据盘空间分配说明。 Devicemapper模式下建议dockerBaseSize配置不超过80G,设置过大时可能会导致容器运行时初始化时间过长而启动失败,若对容器磁盘大小有特殊要求,可考虑使用挂载外部或本地存储方式代替。 |
containerBaseSize |
否 |
Integer |
节点上单容器的可用磁盘空间大小,单位G。 不配置该值或值为0时将使用默认值,OverlayFS模式默认不限制单容器可用空间大小;Devicemapper模式下默认值为10,且containerBaseSize设置仅在新版本集群(v1.23.14-r0/v1.25.9-r0/v1.27.6-r0/v1.28.4-r0及以上)的EulerOS/HCEOS2.0节点上生效。 CCE节点容器运行时空间配置请参考数据盘空间分配说明。 Devicemapper模式下建议containerBaseSize配置不超过80G,设置过大时可能会导致容器运行时初始化时间过长而启动失败,若对容器磁盘大小有特殊要求,可考虑使用挂载外部或本地存储方式代替;Devicemapper模式在新版中仅有共池裸机使用,已逐步废弃。 |
runtime |
否 |
Runtime object |
容器运行时, 默认场景:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
容器运行时,默认场景:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
labels |
否 |
Map<String,String> |
格式为key/value键值对。键值对个数不超过20条。
示例: "k8sTags": { "key": "value" } |
taints |
否 |
Array of Taint objects |
支持给创建出来的节点加Taints来设置反亲和性,taints配置不超过20条。每条Taints包含以下3个参数:
示例: "taints": [{ "key": "status", "value": "unavailable", "effect": "NoSchedule" }, { "key": "looks", "value": "bad", "effect": "NoSchedule" }] |
maxPods |
否 |
Integer |
节点最大允许创建的实例数(Pod),该数量包含系统默认实例,取值范围为16~256。 该设置的目的为防止节点因管理过多实例而负载过重,请根据您的业务需要进行设置。 |
nicMultiqueue |
否 |
String |
"[{\"queue\":4}]" 包含如下字段:
|
nicThreshold |
否 |
String |
"0.3:0.6"
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
preInstall |
否 |
String |
安装前执行脚本,转码后的字符总数不能超过10240。 说明:
输入的值需要经过Base64编码,方法如下: echo -n "待编码内容" | base64 |
postInstall |
否 |
String |
安装后执行脚本,转码后的字符总数不能超过10240。 说明:
输入的值需要经过Base64编码,方法如下: echo -n "待编码内容" | base64 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
alpha.cce/NodeImageID |
否 |
String |
指定待切换目标操作系统所使用的用户镜像ID,已废弃。 指定此参数等价于指定ReinstallVolumeSpec中imageID,原取值将被覆盖。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
K8S节点名称配置类型, 默认为“privateIp”。
说明:
|
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
jobid |
String |
提交任务成功后返回的任务ID,用户可以使用该ID对任务执行情况进行查询。 |
请求示例
重置默认节点池中节点,操作系统为EulerOS 2.5。
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/reset { "kind" : "List", "apiVersion" : "v3", "nodeList" : [ { "nodeID" : "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "spec" : { "name" : "my-ecs-0001", "os" : "EulerOS 2.5", "login" : { "sshKey" : "KeyPair-001" } } } ] }
重置节点池中节点(spec参数无效)
POST /api/v3/projects/{project_id}/clusters/{cluster_id}/nodes/reset { "kind" : "List", "apiVersion" : "v3", "nodeList" : [ { "nodeID" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "spec" : { "name" : "my-ecs-0001", "os" : "EulerOS 2.5", "login" : { "sshKey" : "KeyPair-001" } } } ] }
响应示例
状态码: 200
表示在指定集群下重置节点的作业下发成功。
{ "jobid" : "2ec9b78d-9368-46f3-8f29-d1a95622a568" }
SDK代码示例
SDK代码示例如下。
重置默认节点池中节点,操作系统为EulerOS 2.5。
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 57 58 59 60 61 62 63 64 65 66 67 68
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.cce.v3.region.CceRegion; import com.huaweicloud.sdk.cce.v3.*; import com.huaweicloud.sdk.cce.v3.model.*; import java.util.UUID; import java.util.List; import java.util.ArrayList; public class ResetNodeSolution { 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); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("<YOUR REGION>")) .build(); ResetNodeRequest request = new ResetNodeRequest(); request.withClusterId("{cluster_id}"); ResetNodeList body = new ResetNodeList(); Login loginSpec = new Login(); loginSpec.withSshKey("KeyPair-001"); ReinstallNodeSpec specNodeList = new ReinstallNodeSpec(); specNodeList.withOs("EulerOS 2.5") .withLogin(loginSpec) .withName("my-ecs-0001"); List<ResetNode> listbodyNodeList = new ArrayList<>(); listbodyNodeList.add( new ResetNode() .withNodeID(UUID.fromString("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy")) .withSpec(specNodeList) ); body.withNodeList(listbodyNodeList); body.withKind("List"); body.withApiVersion("v3"); request.withBody(body); try { ResetNodeResponse response = client.resetNode(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()); } } }
重置节点池中节点(spec参数无效)
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 57 58 59 60 61 62 63 64 65 66 67 68
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.cce.v3.region.CceRegion; import com.huaweicloud.sdk.cce.v3.*; import com.huaweicloud.sdk.cce.v3.model.*; import java.util.UUID; import java.util.List; import java.util.ArrayList; public class ResetNodeSolution { 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); CceClient client = CceClient.newBuilder() .withCredential(auth) .withRegion(CceRegion.valueOf("<YOUR REGION>")) .build(); ResetNodeRequest request = new ResetNodeRequest(); request.withClusterId("{cluster_id}"); ResetNodeList body = new ResetNodeList(); Login loginSpec = new Login(); loginSpec.withSshKey("KeyPair-001"); ReinstallNodeSpec specNodeList = new ReinstallNodeSpec(); specNodeList.withOs("EulerOS 2.5") .withLogin(loginSpec) .withName("my-ecs-0001"); List<ResetNode> listbodyNodeList = new ArrayList<>(); listbodyNodeList.add( new ResetNode() .withNodeID(UUID.fromString("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")) .withSpec(specNodeList) ); body.withNodeList(listbodyNodeList); body.withKind("List"); body.withApiVersion("v3"); request.withBody(body); try { ResetNodeResponse response = client.resetNode(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()); } } }
重置默认节点池中节点,操作系统为EulerOS 2.5。
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcce.v3.region.cce_region import CceRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcce.v3 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 = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("<YOUR REGION>")) \ .build() try: request = ResetNodeRequest() request.cluster_id = "{cluster_id}" loginSpec = Login( ssh_key="KeyPair-001" ) specNodeList = ReinstallNodeSpec( os="EulerOS 2.5", login=loginSpec, name="my-ecs-0001" ) listNodeListbody = [ ResetNode( node_id="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", spec=specNodeList ) ] request.body = ResetNodeList( node_list=listNodeListbody, kind="List", api_version="v3" ) response = client.reset_node(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
重置节点池中节点(spec参数无效)
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcce.v3.region.cce_region import CceRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcce.v3 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 = CceClient.new_builder() \ .with_credentials(credentials) \ .with_region(CceRegion.value_of("<YOUR REGION>")) \ .build() try: request = ResetNodeRequest() request.cluster_id = "{cluster_id}" loginSpec = Login( ssh_key="KeyPair-001" ) specNodeList = ReinstallNodeSpec( os="EulerOS 2.5", login=loginSpec, name="my-ecs-0001" ) listNodeListbody = [ ResetNode( node_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", spec=specNodeList ) ] request.body = ResetNodeList( node_list=listNodeListbody, kind="List", api_version="v3" ) response = client.reset_node(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
重置默认节点池中节点,操作系统为EulerOS 2.5。
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 57 58 59
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/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 := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ResetNodeRequest{} request.ClusterId = "{cluster_id}" sshKeyLogin:= "KeyPair-001" loginSpec := &model.Login{ SshKey: &sshKeyLogin, } nameSpec:= "my-ecs-0001" specNodeList := &model.ReinstallNodeSpec{ Os: "EulerOS 2.5", Login: loginSpec, Name: &nameSpec, } var listNodeListbody = []model.ResetNode{ { NodeID: "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", Spec: specNodeList, }, } request.Body = &model.ResetNodeList{ NodeList: listNodeListbody, Kind: "List", ApiVersion: "v3", } response, err := client.ResetNode(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
重置节点池中节点(spec参数无效)
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 57 58 59
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/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 := cce.NewCceClient( cce.CceClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ResetNodeRequest{} request.ClusterId = "{cluster_id}" sshKeyLogin:= "KeyPair-001" loginSpec := &model.Login{ SshKey: &sshKeyLogin, } nameSpec:= "my-ecs-0001" specNodeList := &model.ReinstallNodeSpec{ Os: "EulerOS 2.5", Login: loginSpec, Name: &nameSpec, } var listNodeListbody = []model.ResetNode{ { NodeID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", Spec: specNodeList, }, } request.Body = &model.ResetNodeList{ NodeList: listNodeListbody, Kind: "List", ApiVersion: "v3", } response, err := client.ResetNode(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
表示在指定集群下重置节点的作业下发成功。 |
错误码
请参见错误码。