I am trying to create an Endurance storage for iSCSI volume (Block Storage). I am using the SoftLayer api's in go. what is the procedure for creating an deleting the storage?
How to order and delete a iscsi block storage on SoftLayer using the api's?
313 views Asked by Akhil Reddy At
2
There are 2 answers
25
On
To create a Block Storage - Endurance you can try the following script:
// Order Block Storage - Endurance
// This script creates an order for Block Storage - Endurance
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/datatypes"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
"encoding/json"
)
func main() {
username := "set me"
apikey := "set me"
complexType := "SoftLayer_Container_Product_Order_Network_Storage_Enterprise"
quantity := 1
location := "265592"
packageId := 240
osKeyName := "LINUX"
quote := false
// 1. Create a session
sess := session.New(username, apikey)
// 2. Get a service
service := services.GetProductOrderService(sess)
osFormatType := &datatypes.Network_Storage_Iscsi_OS_Type{
KeyName: sl.String(osKeyName),
}
prices := []datatypes.Product_Item_Price{
datatypes.Product_Item_Price{ Id: sl.Int(45098) }, // Block Storage
datatypes.Product_Item_Price{ Id: sl.Int(45058) }, // Endurance Storage
datatypes.Product_Item_Price{ Id: sl.Int(45148) }, // 40 GB Storage Space
datatypes.Product_Item_Price{ Id: sl.Int(45068) }, // 0.25 IOPS per GB
}
cpo := datatypes.Container_Product_Order {
ComplexType : sl.String(complexType),
Quantity : sl.Int(quantity),
Location : sl.String(location),
PackageId : sl.Int(packageId),
Prices : prices,
}
cponp := datatypes.Container_Product_Order_Network_Storage_Enterprise {
Container_Product_Order : cpo,
OsFormatType : osFormatType,
}
// 4. Invoke a method
containerProductOrder, err := service.PlaceOrder(&cponp,"e)
if err != nil {
fmt.Printf("%s\n", err)
return
}
cpoMarshed, errMarsh := json.Marshal(containerProductOrder)
if errMarsh != nil {
fmt.Println(errMarsh)
return
}
fmt.Println(string(cpoMarshed))
}
If you need assistance with prices, this method can help:
An important reference for prices:
To cancel the storage
// Cancel Storage
//
// This script cancels the storage, passing a storage billing ID to
// SoftLayer_Billing_Item::cancelService method.
//
// See below references for more details.
// Important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelService
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
)
func main() {
username := "set me"
apikey := "set me"
storageId := 19771755
sess := session.New(username, apikey)
networkService := services.GetNetworkStorageService(sess)
billingService := services.GetBillingItemService(sess)
mask := "billingItem"
network, err := networkService.Id(storageId).Mask(mask).GetObject()
if err != nil {
fmt.Printf("%s\n", err)
return
}
result, err := billingService.Id(*network.BillingItem.Id).CancelService()
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Println(result)
}
References:
To get storage lun name and target address through storage's orderId
// Get Storage through orderId
//
// See below references for more details.
// Important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)
func main() {
username := "set me"
apikey := "set me"
orderId := "6199311"
sess := session.New(username, apikey)
accountService := services.GetAccountService(sess)
filter := `{"networkStorage": {"billingItem": {"orderItem": {"order": {"id": {"operation": `+orderId+`}}}}}}`
mask := "username;serviceResourceBackendIpAddress"
result, err := accountService.Mask(mask).Filter(filter).GetNetworkStorage()
if err != nil {
fmt.Printf("%s\n", err)
return
}
storage, errMarsh := json.Marshal(result)
if errMarsh != nil {
fmt.Println(errMarsh)
return
}
fmt.Println(string(storage))
}
// Get Storage through orderId
//
// See below references for more details.
// Important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)
func main() {
username := "set me"
apikey := "set me"
orderId := "6199311"
sess := session.New(username, apikey)
accountService := services.GetAccountService(sess)
filter := `{"networkStorage": {"billingItem": {"orderItem": {"order": {"id": {"operation": `+orderId+`}}}}}}`
mask := "username;serviceResourceBackendIpAddress"
result, err := accountService.Mask(mask).Filter(filter).GetNetworkStorage()
if err != nil {
fmt.Printf("%s\n", err)
return
}
storage, errMarsh := json.Marshal(result)
if errMarsh != nil {
fmt.Println(errMarsh)
return
}
fmt.Println(string(storage))
}
Replace: username, apikey and 6199311 with your own information
References:
To get standard prices (location group = null)
// Retrieve product item prices which location group is null
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)
func main() {
username := "set me"
apikey := "set me"
packageId := 240
// 1. Create a session
sess := session.New(username, apikey)
// 2. Get a service
packageService := services.GetProductPackageService(sess)
// Declare a filter to get standard prices
filter := `{"itemPrices":{"locationGroupId":{"operation": "is null"}}}`
packageResult, err := packageService.Id(packageId).Filter(filter).GetItemPrices()
if err != nil {
fmt.Print("%s\n", err)
return
}
prices, errMarsh := json.Marshal(packageResult)
if errMarsh != nil {
fmt.Println(errMarsh)
return
}
fmt.Println(string(prices))
}
Retrieve product item prices (standard) for performance storage space
// Retrieve product item prices for performance storage space
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <[email protected]>
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)
func main() {
username := "set me"
apikey := "set me"
packageId := 240
// 1. Create a session
sess := session.New(username, apikey)
// 2. Get a service
packageService := services.GetProductPackageService(sess)
// Declare a filter to get standard prices
filter := `{"itemPrices":{"item":{"capacity":{"operation":40}}, "attributes":{"value":{"operation":300}}, "locationGroupId":{"operation": "is null"}, "categories":{"categoryCode":{"operation":"performance_storage_space"}}}}`
packageResult, err := packageService.Id(packageId).Filter(filter).GetItemPrices()
if err != nil {
fmt.Print("%s\n", err)
return
}
prices, errMarsh := json.Marshal(packageResult)
if errMarsh != nil {
fmt.Println(errMarsh)
return
}
fmt.Println(string(prices))
}
SoftLayer_Account/getObject without using softlayer-go
Perhaps something like this can help you:
I tried with that and I created the following script to get a part of data from SoftLayer_Account::getObject response:
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type Account struct {
Id int `json:"id"`
Address1 string `json:"address1"`
FirstName string `json:"firstName"`
}
func main() {
url := fmt.Sprintf("https://username:[email protected]/rest/v3/SoftLayer_Account/getObject")
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal("NewRequest: ", err)
return
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("Do: ", err)
return
}
defer resp.Body.Close()
var record Account
// Use json.Decode for reading streams of JSON data
if err := json.NewDecoder(resp.Body).Decode(&record); err != nil {
log.Println(err)
}
fmt.Println("Response = ", record)
fmt.Println("FirstName = ", record.FirstName)
}
Replace: username and apiKey with your credentials
As I understand Golang, it's necessary to define the response's structure (I'm not sure, but that's the only way that I had success to decode the response) see type Account struct in the script, you can review the following datatypes(structs) for that in softlayer-go, to get a clear idea about that:
SoftLayer_Product_Order::verifyOrder - POST request without softlayer-go
Finally I found a easy way to decode the responses :), here a post request for SoftLayer_Product_Order::verifyOrder, I defined the json in jsonStr as you can see:
Replace: username and apiKey with your own information in the request
SoftLayer_Account::getVirtualGuests - Script with Object Filter and Object Masks
Here a script with objectFilter and objectMasks defined in the request for SoftLayer_Account::getVirtualGuests method, to get virtual guest:
Replace: username, apiKey and 27497599 with your own information in the request
SoftLayer_Product_Package::getItemPrices - Request using objetFilter
Here a script with objectFilter to SoftLayer_Product_Package::getItemPrices to Retrieve product item prices (standard) for performance storage space (script provided in my other answer using softlayer-go),
As you can see I set is+null because the space raised an exception, but it works fine
Replace: username and apiKey in the request
I hope this scripts can help you, let me know if you have any issue or doubt