0

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?

555
  • 147
  • 8
Akhil Reddy
  • 23
  • 1
  • 10
  • Please [edit] your question to show [what you have tried so far](http://whathaveyoutried.com). You should include a [mcve] of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Feb 08 '17 at 10:33

2 Answers2

1

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. <sldn@softlayer.com>

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,&quote)
    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. <sldn@softlayer.com>

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. <sldn@softlayer.com>

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. <sldn@softlayer.com>

    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. <sldn@softlayer.com>

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. <sldn@softlayer.com>

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:apiKey@api.softlayer.com/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:

  • Thank You. Will the prices remain the same or differ from time to time? – Akhil Reddy Feb 08 '17 at 18:56
  • the price identifiers will not change, but you need to take in account, that they are different for each datacenter, so in that case I recommend to use standard prices – Ruber Cuellar Valenzuela Feb 08 '17 at 19:13
  • Is it possible to get the LUN name and target address of the iscsi block using the orderID? – Akhil Reddy Feb 09 '17 at 10:29
  • Please review **To get storage lun name and target address through storage's orderId** section in my answer – Ruber Cuellar Valenzuela Feb 09 '17 at 21:08
  • [{"id":146445,"locationGroupId":503},{"id":45144,"locationGroupId":null}] how to fetch the id of the record whose locationid is null in golang. – Akhil Reddy Feb 13 '17 at 11:34
  • Please try the script that I attached in **To get standard prices (location group = null)** section in my answer – Ruber Cuellar Valenzuela Feb 13 '17 at 19:12
  • url:="https://uname:key@api.softlayer.com/rest/v3/SoftLayer_Product_Package/240/getItemPrices?objectFilter={"itemPrices":{"item":{"capacity":{"operation":40}},"attributes":{"value":{"operation":300}},"locationGroupId":{"operation": "is null"},"categories":{"categoryCode":{"operation":"performance_storage_space"}}}}" how to make this api call from the golang code instead of the way you mentioned above. – Akhil Reddy Feb 14 '17 at 10:45
  • Hi Ruber, Thanks for the help, really appreciate it. I kindly wanna know is there any reference or any source regarding usage of softLayer go library, If so please let us know, even one of my colleagues (BalaSrinivas) has been interacting with you since last month but through python libraries. Both of us would really appreciate if u let us know abt the sources or references where we can go through these libraries and services. thanks in advance – Akhil Reddy Feb 14 '17 at 11:09
  • Akhil, please see **Retrieve product item prices (standard) for performance storage space** section in my answer – Ruber Cuellar Valenzuela Feb 14 '17 at 14:19
  • Of course, I can provide links with some examples, here in **go:** https://softlayer.github.io/go/ **Python:** https://softlayer.github.io/python/ Also I recommend to review the examples in the github: **go** https://github.com/softlayer/softlayer-go **python** https://github.com/softlayer/softlayer-python – Ruber Cuellar Valenzuela Feb 14 '17 at 14:22
  • There are some examples, but if you have an issue or doubt. Feel free to ask, I will be glad you help you – Ruber Cuellar Valenzuela Feb 14 '17 at 14:23
  • Hi Ruber, Thanks for the help. Is it possible to make the softlayer api calls as the normal http request in golang. – Akhil Reddy Feb 16 '17 at 16:06
  • do you want to say similar call like rest? or change the endpoint? – Ruber Cuellar Valenzuela Feb 16 '17 at 16:33
  • Make the similar rest api call without using the softlayer go library – Akhil Reddy Feb 16 '17 at 16:39
  • Please review **SoftLayer_Account/getObject without using softlayer-go** section in my answer, I hope it helps :) – Ruber Cuellar Valenzuela Feb 16 '17 at 18:38
  • Can we do a post request by passing parameters and also providing object filter and mask – Akhil Reddy Feb 17 '17 at 03:39
  • Good question, review my last answer please – Ruber Cuellar Valenzuela Feb 17 '17 at 19:49
  • Hi Ruber. One of my friends have a doubt regarding SL on how to determine which traffic is coming to a particular virtual server and how to know from what source the traffic is coming from, I would also like to know the type of traffic that is coming. which SoftLayer python API's should i use to get that information? Thanks in advance. – Akhil Reddy Feb 27 '17 at 04:44
  • My apologies, there is nothing in the API to retrieve information about which traffic or the source from it, you can use **tcpdump**: http://www.tcpdump.org/tcpdump_man.html – Ruber Cuellar Valenzuela Mar 01 '17 at 20:53
  • Hi Ruber. I tried using the cancelServiceOnAnniversaryDate() method to cancel the block and file storage but it's throwing an error that , these kind of services cannot be cancelled through this method. How to cancel the storage by using cancelServiceOnAnniversaryDate() method – Akhil Reddy Apr 10 '17 at 08:17
  • Unfortunately, the [SoftLayer_Billing_Item::cancelServiceOnAnniversaryDate](http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelServiceOnAnniversaryDate) method doesn't work for some services, please try the request that I posted here: [How to cancel snapshot space only?](http://stackoverflow.com/questions/37312242/how-to-cancel-snapshot-space-only), you only need to change the flag: **"immediateCancellationFlag"** to false – Ruber Cuellar Valenzuela Apr 10 '17 at 21:20
  • Thanks. Will the above request cancels the storage on Anniversary date or will it cancels immediately. – Akhil Reddy Apr 11 '17 at 04:37
  • If you set **"immediateCancellationFlag": true** it will cancel the service immediatly, if you set **"immediateCancellationFlag": false**, it will be cancelled on anniversary date – Ruber Cuellar Valenzuela Apr 11 '17 at 14:21
  • Hi Ruber. Is there any way to authorize the subnets for the Block Storage instead of Authorizing the Virtual Guests, like we do for the File storage where we authorize the Subnets – Akhil Reddy Apr 25 '17 at 09:59
  • It's not possible to add subnets, you can only add devices (BMS/VS) and ip addresses for block storage. My apologies for the inconveniences. Let me know if you need further assistance – Ruber Cuellar Valenzuela Apr 25 '17 at 17:56
0

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