1
1
---
2
2
title : " order_endurance_storage.go"
3
3
description : " order_endurance_storage.go"
4
- date : " 2018-04-25 "
4
+ date : " 2023-03-10 "
5
5
classes :
6
6
- " SoftLayer_Product_Item_Price"
7
7
- " SoftLayer_Product_Package"
@@ -46,45 +46,100 @@ func main() {
46
46
username := " "
47
47
apikey := " apikey_goes_here"
48
48
49
+ // Create a session.
50
+ sess := session.New (username, apikey)
51
+
52
+ // To get item prices and regions and order an endurance storage package ID is required
53
+ enduranceStoragePackageID := 240
54
+
55
+ // This method will return all regions where the package is available
56
+ getRegions (sess, enduranceStoragePackageID)
57
+ // This method will return all item prices that endurance storage package has available
58
+ getItemPrices (sess, enduranceStoragePackageID)
59
+ // This method will build a template to order an endurance storage and verify it
60
+ VerifyOrder (sess, enduranceStoragePackageID)
61
+
62
+ }
63
+
64
+ func getRegions (sess *session .Session , enduranceStoragePackageID int ) {
65
+ // Get SoftLayer_Product_Package service.
66
+ service := services.GetProductPackageService (sess)
67
+
68
+ // Use GetRegions() method to return all regions where the package is available
69
+ regions , err := service.Id (enduranceStoragePackageID).GetRegions ()
70
+ if err != nil {
71
+ fmt.Printf (" \n Unable to get regions:\n - %s \n " , err)
72
+ return
73
+ }
74
+
75
+ // Following helps to print the result in json format.
76
+ jsonFormat , jsonErr := json.MarshalIndent (regions, " " , " " )
77
+ if jsonErr != nil {
78
+ fmt.Println (jsonErr)
79
+ return
80
+ }
81
+
82
+ fmt.Println (string (jsonFormat))
83
+ }
84
+
85
+ func getItemPrices (sess *session .Session , enduranceStoragePackageID int ) {
86
+ // Get SoftLayer_Product_Package service.
87
+ service := services.GetProductPackageService (sess)
88
+
89
+ // Use GetItemPrices() method to return all item prices that endurance storage package has available
90
+ itemPrices , err := service.Id (enduranceStoragePackageID).GetItemPrices ()
91
+ if err != nil {
92
+ fmt.Printf (" \n Unable to get item prices:\n - %s \n " , err)
93
+ return
94
+ }
95
+
96
+ // Following helps to print the result in json format.
97
+ jsonFormat , jsonErr := json.MarshalIndent (itemPrices, " " , " " )
98
+ if jsonErr != nil {
99
+ fmt.Println (jsonErr)
100
+ return
101
+ }
102
+
103
+ fmt.Println (string (jsonFormat))
104
+ }
105
+
106
+ func VerifyOrder (sess *session .Session , enduranceStoragePackageID int ) {
107
+ // Get SoftLayer_Product_Order service.
108
+ service := services.GetProductOrderService (sess)
109
+
49
110
// Declare the location, packageId and quantity for the storage you wish to order
111
+ // Use getRegions method to see other locations
50
112
quantity := 1
51
- location := " MEXICO "
113
+ location := " TORONTO "
52
114
packageId := 240
53
115
osKeyName := " LINUX"
54
116
55
117
// Build a skeleton SoftLayer_Product_Item_Price objects. To get the list of valid
56
118
// prices for the package use the SoftLayer_Product_Package:getItemPrices method
57
- prices := []datatypes.Product_Item_Price {
58
- { Id: sl.Int (45098 ) }, // Block Storage
59
- { Id: sl.Int (45058 ) }, // Endurance Storage
60
- { Id: sl.Int (45148 ) }, // 40 GB Storage Space
61
- { Id: sl.Int (45068 ) }, // 0.25 IOPS per GB
119
+ prices := []datatypes.Product_Item_Price {
120
+ {Id: sl.Int (45098 )}, // Block Storage
121
+ {Id: sl.Int (45058 )}, // Endurance Storage
122
+ {Id: sl.Int (45148 )}, // 40 GB Storage Space
123
+ {Id: sl.Int (45068 )}, // 0.25 IOPS per GB
62
124
}
63
125
64
126
// This should match the OS type of the host(s) that will connect to the volume.
65
127
// The only required property is the keyName.
66
- osFormatType := &datatypes.Network_Storage_Iscsi_OS_Type {
128
+ osFormatType := &datatypes.Network_Storage_Iscsi_OS_Type {
67
129
KeyName: sl.String (osKeyName),
68
-
69
130
}
70
131
71
132
// Build a Container_Product_Order_Network_PerformanceStorage object
72
- templateOrder := datatypes.Container_Product_Order_Network_Storage_Enterprise {
73
- Container_Product_Order : datatypes.Container_Product_Order {
74
- Quantity : sl.Int (quantity),
75
- Location : sl.String (location),
76
- PackageId : sl.Int (packageId),
77
- Prices : prices,
133
+ templateOrder := datatypes.Container_Product_Order_Network_Storage_Enterprise {
134
+ Container_Product_Order: datatypes.Container_Product_Order {
135
+ Quantity: sl.Int (quantity),
136
+ Location: sl.String (location),
137
+ PackageId: sl.Int (packageId),
138
+ Prices: prices,
78
139
},
79
140
OsFormatType: osFormatType,
80
141
}
81
142
82
- // Create a session.
83
- sess := session.New (username, apikey)
84
-
85
- // Get SoftLayer_Product_Order service.
86
- service := services.GetProductOrderService (sess)
87
-
88
143
// Use verifyOrder() method to check for errors. Replace this with placeOrder() when
89
144
// you are ready to order.
90
145
receipt , err := service.VerifyOrder (&templateOrder)
@@ -94,7 +149,7 @@ func main() {
94
149
}
95
150
96
151
// Following helps to print the result in json format.
97
- jsonFormat , jsonErr := json.MarshalIndent (receipt," " ," " )
152
+ jsonFormat , jsonErr := json.MarshalIndent (receipt, " " , " " )
98
153
if jsonErr != nil {
99
154
fmt.Println (jsonErr)
100
155
return
0 commit comments