forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_server_info_by_orderid_demo.go
77 lines (62 loc) · 2.16 KB
/
get_server_info_by_orderid_demo.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
package main
import (
"fmt"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/ecs/v1/cloudserversext"
"github.com/gophercloud/gophercloud/auth/aksk"
)
func main() {
opts := aksk.AKSKOptions{
IdentityEndpoint: "https://iam.xxx.yyy.com/v3",
ProjectID: "{ProjectID}",
AccessKey: "{your AK string}",
SecretKey: "{your SK string}",
Domain: "yyy.com",
Region: "xxx",
DomainID: "{domainID}",
}
var orderID = "CS1811281510AF3Z2"
provider, errAuth := openstack.AuthenticatedClient(opts)
if errAuth != nil {
fmt.Println("Fail to get the provider: ", errAuth)
return
}
client, errClient := openstack.NewECSV1(provider, gophercloud.EndpointOpts{})
if errClient != nil {
fmt.Println("Fail to get the ecs v1 client: ", errClient)
return
}
servers, errGet := cloudserversext.GetPrepaidServerDetailByOrderId(client, orderID)
if errGet != nil {
if se, ok := errGet.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", se.ErrorCode())
fmt.Println("Message:", se.Message())
} else {
fmt.Println("Error:", errGet)
}
return
}
if len(servers) == 0 {
fmt.Println("there is no server info on this order")
}
for _, data := range servers {
//charging info
fmt.Println("Charging ChargingMode:", data.Charging.ChargingMode)
fmt.Println("Charging ExpireTime:", data.Charging.ExpireTime)
fmt.Println("Charging ValidTime:", data.Charging.ValidTime)
//cloud server info
fmt.Println("CloudServer Status:", data.CloudServer.Status)
fmt.Println("CloudServer ID:", data.CloudServer.ID)
fmt.Println("CloudServer Name:", data.CloudServer.Name)
fmt.Println("CloudServer Metadata:", data.CloudServer.Metadata)
fmt.Println("CloudServer LaunchedAt:", data.CloudServer.LaunchedAt)
fmt.Println("CloudServer AvailabilityZone:", data.CloudServer.AvailabilityZone)
//server volume info
for _, volumeData := range data.VolumeAttached {
fmt.Println("VolumeAttached ID:", volumeData.ID)
fmt.Println("VolumeAttached Size:", volumeData.Size)
fmt.Println("VolumeAttached VolumeType:", volumeData.VolumeType)
}
}
}