创建镜像
更新时间:
接口
createImage
参数
| 参数 | 类型 | 是否必需 | 说明 |
|---|---|---|---|
| imageDescription | ImageDescription | 是 | 创建镜像的描述。 |
imageDescription的属性
| 属性 | 类型 | 是否必需 | 说明 |
|---|---|---|---|
| name | String | 是 | 镜像名称 |
| description | String | 是 | 简短描述 |
| ecsImageId | String | 是 | ECS镜像ID |
| platform | String | 是 | 操作系统, Image.LINUX 或者 Image.WINDOWS |
返回值
创建成功后返回一个 CreateImageResponse 实例,可以通过 response.getImageId() 获取创建的镜像ID。创建失败后,抛出异常:ClientException 。
例子
Java 源码:
import com.aliyuncs.batchcompute.main.v20151111.*;import com.aliyuncs.batchcompute.model.v20151111.*;import com.aliyuncs.batchcompute.pojo.v20151111.*;import com.aliyuncs.exceptions.ClientException;public class CreateImage {static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyIdstatic String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecretstatic String REGION_ID = "cn-xxx"; //这里填写regionpublic static void main(String[] args) {BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);try {ImageDescription imageDescription = new ImageDescription();imageDescription.setDescription("JavaSdkImage");imageDescription.setEcsImageId("m-wz91f71l9kcjxj6bm74n");imageDescription.setPlatform("Linux");imageDescription.setName("JavaSdkImage");CreateImageResponse response = client.createImage(imageDescription);String imageId = response.getImageId();//创建成功System.out.println("GotImageId: " + imageId);} catch (ClientException e) {e.printStackTrace();//创建失败}}}
执行结果:
{GotImageId: img-6kie8e832lnov8gg50k00b}
该文章对您有帮助吗?