全部产品
Search
文档中心

云服务器 ECS:ModifyInstanceAttribute - 修改一台实例的部分信息

更新时间:Mar 19, 2024

调用ModifyInstanceAttribute修改一台ECS实例的部分信息,包括密码、名称、描述、主机名、所属安全组、实例的MTU以及自定义数据等。如果是突发性能实例,还可以切换性能突发模式。

接口说明

查询 ECS 实例信息时,如果返回数据中包含{"OperationLocks": {"LockReason" : "security"}},则禁止一切操作。

调用该接口完成以下操作时,您需要注意:

  • 修改主机名(HostName):重启实例后,修改生效,且必须是在 ECS 控制台重启(具体操作,请参见重启实例)或者调用 RebootInstance 重启,新主机名才能生效。在操作系统内部重启不保证能生效。

  • 重置密码(Password):

    • 实例状态不能为启动中Starting)。
    • 重启实例后,重置生效,且必须是在 ECS 控制台重启(具体操作,请参见重启实例)或者调用 RebootInstance 重启,新密码才能生效。在操作系统内部重启不能生效。
  • 修改自定义数据(UserData):

    • 实例状态必须为已停止Stopped)。

    • 实例必须满足自定义数据使用限制。更多信息,请参见生成实例自定义数据

    说明 重启实例后,实例上将展示新的用户数据,但不会运行用户数据脚本。
  • 更换实例安全组(SecurityGroupIds.N):

    • 支持切换安全组类型。 当 ECS 实例跨类型切换安全组时,您需要充分了解两种安全组规则的配置区别,避免影响实例网络。
    • 不支持经典网络类型实例。 其他注意事项请参见SecurityGroupIds.N的参数说明。
  • 修改主网卡队列数(NetworkInterfaceQueueNumber):

    • 实例必须为已停止(Stopped)状态。
    • 不能超过实例规格允许的单块网卡最大队列数。
    • 实例的所有网卡累加队列数不能超过实例规格允许的队列数总配额。实例规格的单块网卡最大队列数和总配额可以通过 DescribeInstanceTypes 查询MaximumQueueNumberPerEniTotalEniQueueQuantity字段。
    • 当取值为-1 时,将重置主网卡队列数为对应实例规格的默认值。实例规格的弹性网卡默认队列数可以通过 DescribeInstanceTypes 查询PrimaryEniQueueNumber字段。
  • 实例开启/关闭 Jumbo frame 特性(EnableJumboFrame)。更多信息,请参见ECS 实例 MTU

    • 实例必须为运行中(Running)或者已停止(Stopped)状态。
    • 实例必须为虚拟专有网络(Virtual Private Cloud, VPC)下的 ECS 实例。
    • 开启 Jumbo Frame 特性后,实例的 MTU 值将变为 8500,关闭后则回退为 1500 。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用背景高亮的方式表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
ecs:ModifyInstanceAttributeWrite
  • Instance
    acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}
  • SecurityGroup
    acs:ecs:{#regionId}:{#accountId}:securitygroup/{#SecurityGroupId}
  • ecs:tag

请求参数

名称类型必填描述示例值
InstanceIdstring

实例 ID。

i-bp67acfmxazb4ph****
Passwordstring

实例的密码。支持长度为 8~30 个字符,必须同时包含大小写英文字母、数字和特殊符号中的三类字符。特殊符号可以是:

()`~!@#$%^&*-_+=|{}[]:;'<>,.?/

其中,Windows 实例不能以斜线号(/)为密码首字符。

说明 如果传入Password参数,建议您使用 HTTPS 协议发送请求,避免密码泄露。
Test123456
HostNamestring

操作系统的主机名。您需要注意:

  • 修改主机名时,实例不能处于创建中(Pending)或启动中(Starting)的状态,否则可能出现主机名以及/etc/hosts配置失效等情况。您可以调用 DescribeInstances 查询实例当前的状态信息。

  • 修改主机名后,请调用 RebootInstance 重启实例,使修改生效。

不同操作系统主机名存在以下限制:

  • Windows Server 系统:长度为 2-15 个字符,允许使用大小写字母、数字或短划线(-)。不能以短划线(-)开头或结尾,不能连续使用短划线(-),也不能仅使用数字。

  • 其他类型实例(Linux 等):长度为 2-64 个字符,允许使用半角句号(.)分隔字符成多段,每段允许使用大小写字母、数字或连字符(-),但不能连续使用半角句号(.)或短划线(-)。不能以半角句号(.)或短划线(-)开头或结尾。

testHostName
InstanceNamestring

实例名称。长度为 2~128 个英文或中文字符。必须以大小写字母或中文开头,不能以http://https://开头。可以包含数字、半角冒号(:)、下划线(_)或者短划线(-)。

testInstanceName
Descriptionstring

实例描述。长度为 2~256 个英文或中文字符,不能以http://https://开头。

testInstanceDescription
UserDatastring

实例自定义数据,需要以 Base64 编码。

编码前,原始数据不能超过 16KB。建议不要明文传入敏感信息,例如密码和私钥等。如果必须传入敏感信息,建议您加密后再以 Base64 编码传入,在实例内部以同样的方式解密。

ZWNobyBoZWxsbyBlY3Mh
Recyclableboolean
说明 该参数正在邀测中,暂不开放使用。
hide
CreditSpecificationstring

修改突发性能实例的运行模式。取值范围:

  • Standard:标准模式。
  • Unlimited:无性能约束模式。

关于突发性能实例运行模式的更多信息,请参见什么是突发性能实例

Standard
DeletionProtectionboolean

实例释放保护属性。指定是否支持通过控制台或 API( DeleteInstance )释放实例。

说明 该属性仅适用于按量付费实例,且只能限制手动释放操作,对系统释放操作不生效。
false
NetworkInterfaceQueueNumberinteger

主网卡队列数。

8
SecurityGroupIdsarray

实例重新加入的安全组列表。

  • 安全组 ID 不能重复。
  • 实例会离开当前的安全组,如需保留设置,您需要在列表中添加当前的安全组 ID。
  • 支持切换安全组类型,但设置的安全组列表中不能同时包含普通安全组和企业安全组。
  • 安全组必须和实例属于同一个 VPC。
  • N 的取值范围与实例能够加入安全组配额有关。更多信息,请参见使用限制
  • 修改安全组后很快会生效于对应的实例,但可能有较小的延迟。
string

实例重新加入的安全组列表。

  • 安全组 ID 不能重复。
  • 实例会离开当前的安全组,如需保留设置,您需要在列表中添加当前的安全组 ID。
  • 支持切换安全组类型,但设置的安全组列表中不能同时包含普通安全组和企业安全组。
  • 安全组必须和实例属于同一个 VPC。
  • N 的取值范围与实例能够加入安全组配额有关,更多信息,请参见使用限制
  • 修改安全组后很快会生效于对应的实例,但可能有较小的延迟。
sg-bp15ed6xe1yxeycg7o****
RemoteConnectionOptionsobject
说明 该参数正在邀测中,暂不开放使用。
Passwordstring
说明 该参数正在邀测中,暂不开放使用。
hide
Typestring
说明 该参数正在邀测中,暂不开放使用。
hide
EnableJumboFrameboolean

实例 MTU 是否开启 Jumbo frame 通信模式,取值范围:

-true:开启。

-false:不开启。

目前仅部分规格支持开启 Jumbo frame。更多信息,请参见ECS 实例 MTU

false
CpuOptions.TopologyTypestring

实例的 Cpu 拓扑类型。取值范围:

  • ContinuousCoreToHTMapping:当选择ContinuousCoreToHTMapping时,实例的 Cpu 拓扑中,实例的同一个 Core 的 HT 是连续的。
  • DiscreteCoreToHTMapping:当选择DiscreteCoreToHTMapping时,实例的同一个 Core 的 HT 是离散的。

默认值:无。

说明
  • 仅部分实例规格族支持使用本参数,具体支持实例规格族请参见查看和修改 CPU 拓扑结构
  • 使用该参数时实例必须为已停止(Stopped)状态。
  • DiscreteCoreToHTMapping

    返回参数

    名称类型描述示例值
    object
    RequestIdstring

    请求 ID。

    473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

    示例

    正常返回示例

    JSON格式

    {
      "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
    }

    错误码

    HTTP status code错误码错误信息描述
    400InvalidInstanceName.MalformedThe specified parameter "InstanceName" is not valid.InstanceName参数不符合规则。
    400InvalidDescription.MalformedThe specified parameter "Description" is not valid.指定的资源描述格式不合法。长度为2-256个字符,不能以http://和https://开头。
    400InvalidRemoteConnectionOptions.PasswordThe remote connection password is invalid.-
    400InvalidRemoteConnectionOptions.TypeThe remote connection type is invalid.-
    400InstanceType.ValueNotSupportedThe instance type not supported.-
    400OSType.ValueNotSupportedThe OS type is not supported.-
    400InvalidHostPassword.MalformedThe specified parameter "Password" is not valid.-
    400InvalidHostName.MalformedThe specified parameter "HostName" is not valid.-
    400InvalidPassword.MalformedThe specified parameter "Password" is not valid.-
    400InvalidUserData.SizeExceededThe specified parameter "UserData" exceeds the size.-
    400InvalidUserData.NotSupportedTThe specified parameter "UserData" only support the vpc and IoOptimized Instance.-
    400InvalidUserData.NotSupportedThe specified parameter "UserData" only support the vpc and IoOptimized Instance.-
    400ImageNotSupportCloudInitThe specified image does not support cloud-init.该镜像不支持CloudInit。
    400ChargeTypeViolationPay-As-You-Go instances do not support this operation.按量付费实例不支持该操作,检查实例的付费类型是否与该操作冲突。
    400InvalidParameter.RecycleBinYou do not have permission to set recyclable properties.您未被授权执行该操作。
    400InvalidParameter.CreditSpecificationThe specified CreditSpecification is not supported in this region.该地区不支持指定的信贷规范。
    400InvalidInstanceStatus.CreditSpecRestrictedThe current status of the resource does not support this operation.当前资源的状态不支持此操作。
    400InvalidInstanceStatus.NotRunningThe current status of the resource is invalid, you can only do this operation when instance is running.当前实例的状态不支持此操作,当实例状态为 Running 时再进行此操作。
    400InvalidNetworkType.NotSupportedThe classic networkType does not support to modify security group-
    400InvalidOperation.EniCountExceeded=The maximum number of eni in a enterprise security group is exceeded.-
    400JoinedGroupLimitExceed%s指定资源所能加入的安全组数量达到上限。具体信息请参见错误信息%s占位符的实际返回结果。
    400InvalidParameterThe specified parameter is not valid.无效的参数,请检查该参数是否正确。
    400InvalidOperation.InvalidEcsState%s实例当前的状态不支持此操作。
    400InvalidParam.NotSupportJumboFrameNot support jumbo frame.-
    400InvalidOperation.InstanceStatusNotSupportThe instance status is not support modify mtu config.-
    400InvalidOperation.InstanceStatusUnsupportedThe specified instance status does not support modification of cpu topology type.当前实例状态不支持修改CPU拓扑类型
    400InvalidParameter.CpuOptionsTopologyTypeThe specified parameter CpuOptions.TopologyType: %s is not valid.当前CPU拓扑类型的枚举值不合法
    400InvalidInstanceType.NotSupportCpuOptionsTopologyTypeThe specified instance type does not support CpuOptions.TopologyType: %s.当前规格不支持指定的CPU拓扑类型
    403IncorrectInstanceStatusThe current status of the resource does not support this operation.该资源目前的状态不支持此操作。
    403InstanceLockedForSecurityThe specified operation is denied as your instance is locked for security reasons.实例被安全锁定。
    403OperationDeniedThe instance amount in the specified SecurityGroup reach its limit.指定安全组的实例数已达最大值。
    403OperationDeniedThe current status of the resource does not support this operation.该资源状态不支持此类操作。
    403InvalidUserData.ForbiddenUser not authorized to input the parameter "UserData"please apply for permission "UserData"-
    403InvalidUserData.Base64FormatInvalidThe specified UserData is not valid指定的UserData参数编码出错
    403InvalidChargeType.ValueNotSupportedDeletion protection is only valid for postPaid instance, not for prePaid or spot instance.删除保护功能只能使用在按量付费资源上
    403InvalidUser.UnauthorizedThe user is not authorized您当前使用的账号无权限。
    403EnterpriseGroupLimited.MutliGroupTypeThe specified instance can not join multi SecurityGroup types.指定的实例不能同时加入普通安全组和企业安全组。您可以调用 DescribeSecurityGroups 查询指定安全组的类型。
    403SecurityGroupInstanceLimitExceed%s该安全组内已有的实例数量已达到最大限制。
    403InstanceNotInSecurityGroupThe instance not in the group.指定的实例不在安全组内。
    403InvalidOperation.InvalidRegion%s指定的参数 RegionId 无效。
    403OperationDeniedThe specified Image is disabled or is deleted.指定的镜像被禁用或被删除。
    403InvalidOperation.ResourceManagedByCloudProduct%s云产品托管的安全组不支持修改操作。
    403InvalidParameter.InvalidEniQueueNumber%s弹性网卡队列数有误,具体信息请参见错误信息%s占位符的实际返回结果。
    403InvalidOperation.MaxEniQueueNumberExceeded%s弹性网卡队列数超过上限,具体信息请参见错误信息%s占位符的实际返回结果。
    403InvalidOperation.ExceedInstanceTypeQueueNumber%s弹性网卡队列总数超过上限,具体信息请参见错误信息%s占位符的实际返回结果。
    403InvalidOperation.InstanceTypeNotSupportHighPerformanceTrafficMode%s-
    403InvalidParameter.InvalidQueuePairNumber%s-
    403InvalidOperation.MaxEniQueuePairNumberExceed%s-
    403InvalidOperation.EniQueuePairNumberOverflow%s-
    404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.指定的实例ID未找到。
    404InvalidSecurityGroupId.NotFoundThe specified SecurityGroupId does not exist.指定的安全组在该用户账号下不存在,请您检查安全组 ID 是否正确。
    404Credit.NotFoundThe specified credit information does not exist.指定的信用信息不存在。
    404InvalidInstanceStatus.NeedRestartThe current status of the resource is invalid, you can only do this operation after instance is restarted.-
    404InvalidParameter.SecurityGroupIdRepeatedThe specified security group ids has repeated.指定的安全组已重复添加。请检查 SecurityGroupIds 参数值是否正确。
    404InvalidSecurityGroupType.NotSupportClassicThe specified SecurityGroupIds have classic group type.指定的安全组的网络类型为经典网络。请检查 SecurityGroupIds 参数值是否正确。
    404InvalidSecurityGroupVpc.NotBelongToOneVpcThe specified SecurityGroupIds are belong to different vpc.指定的安全组ID属于不同的VPC。请检查 SecurityGroupIds 参数值是否正确。您可以调用 DescribeSecurityGroups 查询指定安全组所属的VPC。
    500InternalErrorThe request processing has failed due to some unknown error.内部错误,请重试。
    500InternalErrorThe request processing has failed due to some unknown error, exception or failure.内部错误,请重试。

    访问错误中心查看更多错误码。

    变更历史

    变更时间变更内容概要操作
    2023-12-14OpenAPI 错误码发生变更、OpenAPI 入参发生变更看变更集
    变更项变更内容
    错误码OpenAPI 错误码发生变更
      错误码 400 变更
      删除错误码:403
      删除错误码:404
      删除错误码:500
    入参OpenAPI 入参发生变更
      新增入参:CpuOptions.TopologyType
    2023-07-17OpenAPI 错误码发生变更看变更集
    变更项变更内容
    错误码OpenAPI 错误码发生变更
      删除错误码:400
      删除错误码:403
      删除错误码:404
      删除错误码:500