文档

创建镜像

接口

createImage

参数

参数 类型 是否必需 说明
imageDescription ImageDescription 创建镜像的描述。

imageDescription的属性

属性 类型 是否必需 说明
name String 镜像名称
description String 简短描述
ecsImageId String ECS镜像ID
platform String 操作系统, Image.LINUX 或者 Image.WINDOWS

返回值

创建成功后返回一个 CreateImageResponse 实例,可以通过 response.getImageId() 获取创建的镜像ID。创建失败后,抛出异常:ClientException

例子

Java 源码:

  1. import com.aliyuncs.batchcompute.main.v20151111.*;
  2. import com.aliyuncs.batchcompute.model.v20151111.*;
  3. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  4. import com.aliyuncs.exceptions.ClientException;
  5. public class CreateImage {
  6. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  7. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  8. static String REGION_ID = "cn-xxx"; //这里填写region
  9. public static void main(String[] args) {
  10. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  11. try {
  12. ImageDescription imageDescription = new ImageDescription();
  13. imageDescription.setDescription("JavaSdkImage");
  14. imageDescription.setEcsImageId("m-wz91f71l9kcjxj6bm74n");
  15. imageDescription.setPlatform("Linux");
  16. imageDescription.setName("JavaSdkImage");
  17. CreateImageResponse response = client.createImage(imageDescription);
  18. String imageId = response.getImageId();
  19. //创建成功
  20. System.out.println("GotImageId: " + imageId);
  21. } catch (ClientException e) {
  22. e.printStackTrace();
  23. //创建失败
  24. }
  25. }
  26. }

执行结果:

  1. {
  2. GotImageId: img-6kie8e832lnov8gg50k00b
  3. }
  • 本页导读 (0)
文档反馈