ibm-cloud-infrastructureiscsiblock-storage

How to order and delete a iscsi block storage on SoftLayer using the api's?


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?


Solution

  • 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:

    // Verify Order for VSI
    //
    // This script verifies an order for vsi
    //
    // important manual pages:
    // http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
    // http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
    //
    // @License: http://sldn.softlayer.com/article/License
    // @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    
    
    package main
    
    import (
        "fmt"
        "net/http"
        "bytes"
        "io/ioutil"
    )
    
    
    func main() {
        url := "https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder"
        fmt.Println("URL:>", url)
    
        // Define the json to send
        var jsonStr = []byte(`{"parameters":[{"location":"AMSTERDAM","packageId":46,"quantity":1,"hardware":[{"domain":"softlayer.com","hostname":"rcvtest"}],"prices":[{"id":50231},{"id":52135},{"id":51639},{"id":51569},{"id":52363},{"id":61019},{"id":55},{"id":57},{"id":175777},{"id":273},{"id":21},{"id":51481},{"id":905},{"id":58},{"id":420},{"id":418}]}]}`)
        req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
        req.Header.Set("Content-Type", "application/json")
    
        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            panic(err)
        }
    
        defer resp.Body.Close()
    
        fmt.Println("response Status:", resp.Status)
        fmt.Println("response Headers:", resp.Header)
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Println("response Body:", string(body))
    }
    

    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:

    // This script get virtual guest through id using object filter and mask
    //
    // important manual pages:
    // http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests
    // http://sldn.softlayer.com/article/object-filters
    // http://sldn.softlayer.com/article/object-masks
    //
    // @License: http://sldn.softlayer.com/article/License
    // @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    
    
    package main
    
    import (
        "fmt"
        "net/http"
         "io/ioutil"
    )
    
    func main() {
        url := `https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={"virtualGuests":{"id":{"operation":27497599}}}&objectMask=mask[billingItem]`
        fmt.Println("URL:>", url)
    
        req, err := http.NewRequest("GET", url, nil)
    
    
        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            panic(err)
        }
        defer resp.Body.Close()
    
        fmt.Println("response Status:", resp.Status)
        fmt.Println("response Headers:", resp.Header)
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Println("response Body:", string(body))
    }
    

    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

    // Retrieve product item prices for performance storage space using objectFilter
    //
    // important manual pages:
    // http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
    // http://sldn.softlayer.com/article/object-filters
    //
    // @License: http://sldn.softlayer.com/article/License
    // @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    
    package main
    
    import (
        "fmt"
        "log"
        "net/http"
         "io/ioutil"
    )
    
    func main() {
        url := `https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Package/240/getItemPrices?objectFilter={"itemPrices":{"item":{"capacity":{"operation":40}},"attributes":{"value":{"operation":300}},"categories":{"categoryCode":{"operation":"performance_storage_space"}},"locationGroupId":{"operation":"is+null"}}}`
        fmt.Println("URL:>", url)
    
        req, err := http.NewRequest("GET", url, nil)
    
        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            log.Fatal("Do: ", err)
            return
        }
    
        defer resp.Body.Close()
    
        fmt.Println("response Status:", resp.Status)
        fmt.Println("response Headers:", resp.Header)
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Println("response Body:", string(body))
    }
    

    Replace: username and apiKey in the request

    I hope this scripts can help you, let me know if you have any issue or doubt