镜像
更新时间:2020-04-23
通过实例创建自定义镜像
- 用于创建自定义镜像,默认每个账号配额20个,创建后的镜像可用于创建实例
- 只有 Running 或 Stopped 状态的实例才可以执行成功
使用以下代码可以从指定的实例创建镜像
Go
1// 用于创建镜像的实例ID
2instanceId := "i-3EavdPl8"
3// 设置创建镜像的名称
4imageName := "testCreateImage"
5queryArgs := &CreateImageArgs{
6 ImageName: testImageName,
7 InstanceId: testInstanceId,
8}
9if res, err := bbcClient.CreateImageFromInstanceId(queryArgs); err != nil {
10 fmt.Println("Create image failed: ", err)
11} else {
12 fmt.Println("Create image success, result: ", res)
13}
查询镜像列表
- 用于查询用户所有的镜像信息
- 查询的镜像信息中包括系统镜像、自定义镜像和服务集成镜像
- 支持按 imageType 来过滤查询,此参数非必需,未设置时默认为 All,即查询所有类型的镜像
使用以下代码可以查询镜像列表
Go
1// 指定要查询何种类型的镜像
2// All(所有)
3// System(系统镜像/公共镜像)
4// Custom(自定义镜像)
5// Integration(服务集成镜像)
6// Sharing(共享镜像)
7imageType := "All"
8// 批量获取列表的查询的起始位置
9marker := "your-marker"
10// 每页包含的最大数量
11maxKeys := 100
12queryArgs := &ListImageArgs{
13 Marker: marker,
14 MaxKeys: maxKeys,
15 ImageType: imageType,
16}
17if res, err := bbcClient.ListImage(queryArgs); err != nil {
18 fmt.Println("List image failed: ", err)
19} else {
20 fmt.Println("List image success, result: ", res)
21}
查询镜像详情
- 用于根据指定镜像ID查询单个镜像的详细信息
使用以下代码可以查询镜像详情
Go
1// 待查询镜像ID
2image_id :="your-choose-image-id"
3if res, err := bbcClient.GetImageDetail(testImageId); err != nil {
4 fmt.Println("Get image failed: ", err)
5} else {
6 fmt.Println("Get image success, result: ", res)
7}
删除自定义镜像
- 用于删除用户自己的指定的自定义镜像,仅限自定义镜像,系统镜像和服务集成镜像不能删除
- 镜像删除后无法恢复,不能再用于创建、重置实例
使用以下代码可以删除指定镜像
Go
1imageId := "your-choose-image-id"
2if err := bbcClient.DeleteImage(testImageId); err != nil {
3 fmt.Println("Delete image failed: ", err)
4}