阅读752 返回首页    go 阿里云 go 技术社区[云栖]


导入镜像__镜像相关接口_API 参考_云服务器 ECS-阿里云

导入自定义镜像

描述

导入镜像是把客户线下的一个镜像文件导入到ECS环境中生成一个自定义镜像。可以使用这个镜像来创建ECS实例和更换系统盘。

  • 请先将镜像文件上传到OSS。
  • 导入镜像的地域必须跟镜像文件存放的OSS的同一个账号同一个地域。
  • DiskDeviceMapping.N 暂时只支持1,也就是只支持系统盘镜像,暂时不支持数据盘做镜像。
  • 镜像没有导入完成,是不能进行删除操作,可以进行取消导入镜像任务操作。
  • 需要通过RAM给阿里云ECS官方服务账号授权读取OSS的权限。
  1. 1.创建角色:AliyunECSImageImportDefaultRole(必须是这个名称,否则导入镜像会失败),角色的策略:
  2. {
  3. "Statement": [
  4. {
  5. "Action": "sts:AssumeRole",
  6. "Effect": "Allow",
  7. "Principal": {
  8. "Service": [
  9. "ecs.aliyuncs.com"
  10. ]
  11. }
  12. }
  13. ],
  14. "Version": "1"
  15. }
  16. 2.在该角色下直接加入默认的系统权限策略:AliyunECSImageImportRolePolicy,这个策略是ECS提供导入镜像的默认策略,你也可以创建自定义策略,权限需要包含:
  17. {
  18. "Version": "1",
  19. "Statement": [
  20. {
  21. "Action": [
  22. "oss:GetObject",
  23. "oss:GetBucketLocation"
  24. ],
  25. "Resource": "*",
  26. "Effect": "Allow"
  27. }
  28. ]
  29. }

请求参数

名称 类型 是否必须 描述
Action String 系统规定参数,取值:ImportImage
RegionId String 源自定义镜像的regionId
ImageName String 镜像名称,[2,128]英文或中文字符,必须以大小字母或中文开头,可包含数字,”_”或”-”。不能以https://和https://开头。
Description String 镜像的描述信息,长度限制在0~256 个字符,不填则为空,默认为空。不能以https://和https://开头。
Architecture String 系统架构,取值范围:i386 | x86_64
默认值:x86_64
OSType String 操作系统平台类型,取值范围:windows | linux
默认值:linux
Platform String 操作系统发行版,
取值:
  • CentOS
  • Ubuntu
  • SUSE
  • OpenSUSE
  • RedHat
  • Debian
  • CoreOS
  • Aliyun Linux
  • Windows Server 2003
  • Windows Server 2008
  • Windows Server 2012
  • Windows 7
  • Others Linux
  • Customized Linux
默认值:Others Linux
DiskDeviceMapping.n.Format String 镜像格式,暂时只支持:RAW 和 VHD
默认值:RAW
DiskDeviceMapping.n.OSSBucket String 镜像文件所在用户的OSS Bucket
DiskDeviceMapping.n.OSSObject String 镜像文件所在用户的OSS Object的key
DiskDeviceMapping.n.DiskImageSize String 镜像文件创建系统盘的大小,一定要确保系统盘的空间大于或者等于文件系统的空间。
  • linux类型,取值范围:20GB-1TB 默认:20GB
  • windows类型,取值范围:40GB-1TB 默认:40GB

返回参数

名称 类型 描述
RegionId String 地域 Id
ImageId String 镜像的ID
ImportTaskId String 导入镜像任务Id

错误码

错误代码 描述 Http 状态码 语义
MissingParameter An input parameter ”RegionId” that is mandatory for processing the request is not supplied. 400 缺少RegionId值
MissingParameter An input parameter ”DiskDeviceMapping.n.OSSBucket” that is mandatory for processing the request is not supplied. 400 缺少OSSBucket的值
MissingParameter An input parameter ”DiskDeviceMapping.n.OSSObject” that is mandatory for processing the request is not supplied. 400 缺少OSSObject值
InvalidImageName.Malformed The specified destination Image name is wrongly formed. 400 指定的镜像名称不合法
InvalidDescription.Malformed The specified destination image description is wrongly formed. 400 指定的目标镜像描述不合法
RegionId.NotFound The specified region is not found. 400 指定的镜像的regionId不存在
IncorrectImageStatus The specified image is not available. 400 指定的镜像状态不正确
InvalidImageName.Duplicated The destination image is exist. 400 镜像名称已经重复
QuotaExceed.Image The Image Quota exceeds. 403 已经超过自定义镜像配额限制,不能再进行导入镜像
QuotaExceed.Snapshot The Snapshot Quota exceeds. 403 已经超过快照的配额限制,不能再进行导入镜像。
Forbbiden User not authorized to operate on the specified resource 400 没有权限进行导入镜像
InvalidArchitecture.Malformed The specified Architecture is wrongly formed. 400 指定的平台架构不合法
InvalidPlatform.Malformed The specified Platform is wrongly formed. 400 指定的操作系统发行版类型不合法
InvalidOSType.Malformed The specified OSType is wrongly formed. 400 指定的操作系统类型不合法
InvalidFormat.Malformed The specified Image format is wrongly formed. 400 指定的镜像文件格式不合法
InvalidImageSize The specified “DiskDeviceMapping.n.DiskImageSize” should be not less than system device size. 400 指定的镜像的磁盘大小不合法
ImageIsImporting The specified Image is importing. 403 指定的镜像正在复制中
InvalidRegion.NotSupport The specified region does not support image import or export. 403 指定的region暂时不支持导入镜像

示例

请求示例

  1. https://ecs.aliyuncs.com/?Action=ImportImage
  2. &RegionId=cn-hangzhou
  3. &DiskDeviceMapping.1.OSSBucket=ecsimageos
  4. &DiskDeviceMapping.1.OSSObject=CentOS_5.4_32.raw
  5. &<公共请求参数>

返回示例

XML格式

  1. <ImportImageResponse>
  2. <RequestId>C8B26B44-0189-443E-9816-D951F59623A9</RequestId>
  3. <ImageId>Img-231234567</ImageId>
  4. <ImportTaskId>123-345-2332-22323</ImportTaskId>
  5. </ImportImageResponse>

JSON格式

  1. {
  2. "RequestId": "C8B26B44-0189-443E-9816-D951F59623A9",
  3. "ImageId": "Img-231234567",
  4. "ImportTaskId":"123-345-2332-22323"
  5. }

最后更新:2016-12-12 16:41:28

  上一篇:go 查询镜像共享__镜像相关接口_API 参考_云服务器 ECS-阿里云
  下一篇:go 分配公网 IP 地址__网络相关接口_API 参考_云服务器 ECS-阿里云