Search code examples
ibm-cloud-infrastructure

Snapshotcapacity not being fetched by softlayer-go object mask


I am trying to fetch SnapshotCapacityGb relational datatype in go. Here is what I have:

package main

import (
        "fmt"
        "github.com/softlayer/softlayer-go/session"
        "github.com/softlayer/softlayer-go/services"
        "github.com/softlayer/softlayer-go/filter"
        "encoding/json"
)

func main() {
    sess := session.New("XXXXXXXX", "XXXXXX")
    accountService := services.GetAccountService(sess)
    filters := filter.New(
        filter.Path("networkStorage.id").Eq(39283541),
    )
     result, err :=  accountService.Mask("id;capacityGb;snapshotCapacityGb").Filter(filters.Build()).GetNetworkStorage()
     fmt.Println(err)
    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(result,"","     ")
    if jsonErr != nil {
        fmt.Println(jsonErr)
        return
    }
    fmt.Println(string(jsonFormat))    
}

But this prints all the default properties(id,capacityGB) and skips the relational datatypes(snapshotCapacityGb). Any reason why relational datatypes are not seen?

Same works when I use rest api https://{{sluser}}:{{slkey}}@api.softlayer.com/rest/v3.1/SoftLayer_Account/getNetworkStorage/39283541/getObject?objectMask=id;snapshotCapacityGb;capacityGb

I am on Ubuntu VERSION="14.04.5 LTS, Trusty Tahr"


Solution

  • Some network storage devices have not a snapshot, so the snapshotCapacityGb value isn’t present in the response or it is null. Since you are able to retrieve that value by using REST, probably the go-client is using XML-RPC endpoint so I suggest trying with the REST endpoint:

    endpoint := "https://api.softlayer.com/rest/v3"
    
    sess := session.New(username, apikey, endpoint)