forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.go
175 lines (155 loc) · 5.36 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"fmt"
"github.com/gophercloud/gophercloud/functiontest/common"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/ims/v2/cloudimages"
)
func main() {
fmt.Println("main start...")
provider, err := common.AuthAKSK()
//provider, err := common.AuthToken()
if err != nil {
fmt.Println("get provider client failed")
fmt.Println(err.Error())
return
}
//获取ims服务客户端
sc, err := openstack.NewIMSV2(provider, gophercloud.EndpointOpts{})
if err != nil {
fmt.Println("get ims client failed")
fmt.Println(err.Error())
return
}
TestList(sc)
//TestCreateByFile(sc)
//TestCreateByServer(sc)
//TestGetJobResult(sc)
fmt.Println("main end...")
}
func TestList(sc *gophercloud.ServiceClient) {
allPages, err := cloudimages.List(sc, cloudimages.ListOpts{}).AllPages()
if err != nil {
fmt.Println("err:", err)
if se, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", se.ErrorCode())
fmt.Println("Message:", se.Message())
}
return
}
allImages, err := cloudimages.ExtractImages(allPages)
if err != nil {
fmt.Println(err)
}
fmt.Println("len:", len(allImages))
fmt.Println("File:", allImages[0].File)
fmt.Println("Owner:", allImages[0].Owner)
fmt.Println("ID:", allImages[0].ID)
fmt.Println("Size:", allImages[0].Size)
fmt.Println("Self:", allImages[0].Self)
fmt.Println("Schema:", allImages[0].Schema)
fmt.Println("Status:", allImages[0].Status)
fmt.Println("Tags:", allImages[0].Tags)
fmt.Println("Visibility:", allImages[0].Visibility)
fmt.Println("Name:", allImages[0].Name)
fmt.Println("Checksum:", allImages[0].Checksum)
fmt.Println("Deleted:", allImages[0].Deleted)
fmt.Println("Protected:", allImages[0].Protected)
fmt.Println("ContainerFormat:", allImages[0].ContainerFormat)
fmt.Println("MinRam:", allImages[0].MinRam)
fmt.Println("UpdatedAt:", allImages[0].UpdatedAt)
fmt.Println("OsBit:", allImages[0].OsBit)
fmt.Println("OsVersion:", allImages[0].OsVersion)
fmt.Println("Description:", allImages[0].Description)
fmt.Println("DiskFormat:", allImages[0].DiskFormat)
fmt.Println("Isregistered:", allImages[0].Isregistered)
fmt.Println("Platform:", allImages[0].Platform)
fmt.Println("OsType:", allImages[0].OsType)
fmt.Println("MinDisk:", allImages[0].MinDisk)
fmt.Println("VirtualEnvType:", allImages[0].VirtualEnvType)
fmt.Println("ImageSourceType:", allImages[0].ImageSourceType)
fmt.Println("Imagetype:", allImages[0].Imagetype)
fmt.Println("CreatedAt:", allImages[0].CreatedAt)
fmt.Println("VirtualSize:", allImages[0].VirtualSize)
fmt.Println("DeletedAt:", allImages[0].DeletedAt)
fmt.Println("Originalimagename:", allImages[0].Originalimagename)
fmt.Println("BackupID:", allImages[0].BackupID)
fmt.Println("Productcode:", allImages[0].Productcode)
fmt.Println("ImageSize:", allImages[0].ImageSize)
fmt.Println("DataOrigin:", allImages[0].DataOrigin)
fmt.Println("SupportKvm:", allImages[0].SupportKvm)
fmt.Println("SupportXen:", allImages[0].SupportXen)
fmt.Println("SupportDiskintensive:", allImages[0].SupportDiskintensive)
fmt.Println("SupportHighperformance:", allImages[0].SupportHighperformance)
fmt.Println("SupportXenGpuType:", allImages[0].SupportXenGpuType)
fmt.Println("IsConfigInit:", allImages[0].IsConfigInit)
fmt.Println("SystemSupportMarket:", allImages[0].SystemSupportMarket)
}
func TestCreateByFile(sc *gophercloud.ServiceClient) {
createOpts := cloudimages.CreateByFileOpts{
Name: "ims_obs_xx4",
Description: "OBS文件制作镜像",
ImageUrl: "obs-xx2:Ubuntu14.04_Server_64bit_WebService_Picture.qcow2",
OsVersion: "Ubuntu 14.04 server 64bit",
IsConfigInit: true,
MinDisk: 40,
IsConfig: true,
Tags: []string{
"aaa.111",
"bbb.333",
"ccc.444",
},
}
job, err := cloudimages.CreateImageByFile(sc, createOpts).ExtractJob()
if err != nil {
if se, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", se.ErrorCode())
fmt.Println("Message:", se.Message())
}
return
}
fmt.Println("create image by file success!")
fmt.Println("jobId:", job.Id)
}
func TestCreateByServer(sc *gophercloud.ServiceClient) {
createOpts := cloudimages.CreateByServerOpts{
Name: "image_from_ecs_xx1",
Description: "云服务器制作镜像",
InstanceId: "2251f59c-b1ef-4398-bfa8-321782f670a5",
Tags: []string{
"aaa.111",
"bbb.333",
"ccc.444",
},
}
job, err := cloudimages.CreateImageByServer(sc, createOpts).ExtractJob()
if err != nil {
if se, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", se.ErrorCode())
fmt.Println("Message:", se.Message())
}
return
}
fmt.Println("create image by server success!")
fmt.Println("jobId:", job.Id)
}
func TestGetJobResult(sc *gophercloud.ServiceClient) {
jr, err := cloudimages.GetJobResult(sc, "ff8080826446419a0164495a436941df").ExtractJobResult()
if err != nil {
if se, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", se.ErrorCode())
fmt.Println("Message:", se.Message())
}
return
}
fmt.Println("Id:", jr.Id)
fmt.Println("Type:", jr.Type)
fmt.Println("Status:", jr.Status)
fmt.Println("BeginTime:", jr.BeginTime)
fmt.Println("EndTime:", jr.EndTime)
fmt.Println("ErrorCode:", jr.ErrorCode)
fmt.Println("FailReason:", jr.FailReason)
fmt.Println("Entities:", jr.Entities)
fmt.Println("Entities.ImageId:", jr.Entities.ImageId)
}