0
func getPrivateVlan(env string) (string, error) {
// 1. Create a session
sess := session.New(user, pass)
// 2. Get a service
accountService := services.GetAccountService(sess)
// 3. Invoke a method:
vlans, err := accountService.GetNetworkVlans()
vlan := vlans[0]
log.Println(*vlan.Name)           //works
log.Println(*vlan.PrimaryRouter)  //Doesn't work
}

The object returned is an array of vlans of type SoftLayer_Network_Vlan, https://sldn.softlayer.com/reference/datatypes/softlayer_network_vlan. I am able to access the properties in column "Local Properties" (ie Name) but am unable to access the properties in column "Relational & Count Properties" (ie PrimaryRouter). How can I add an object mask to my call in order to see these properties?

Dennis
  • 51
  • 1
  • 8

2 Answers2

0

The reason is that in order to obtain relational data from an object in the API you must declare an object mask in your API call, as far as I can see, it is not declared in your code, it should be something like this:

func getPrivateVlan(env string) (string, error) {
// 1. Create a session
sess := session.New(user, pass)
// 2. Get a service
accountService := services.GetAccountService(sess)

//declare Mask
object_mask := "id;name;primaryRouter"

// 3. Invoke a method including the Object mask:
vlans, err := accountService.Mask(object_mask).GetNetworkVlans()

vlan := vlans[0]
log.Println(*vlan.Name)           //works
log.Println(*vlan.PrimaryRouter)  //
}

Try the following code for example:

package main

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

func main() {
// SoftLayer API username and key
username := "set-me"
apikey   := "set-me"

// Create a session
sess := session.New(username, apikey)

// Get SoftLayer_Account service
service := services.GetAccountService(sess)

// Object-Mask to get specific Vlan's information
mask := "id;name;primaryRouter"

// Call to getNetworkVlans in order to retrieve vlans according to filter.
result, err := service.Mask(mask).GetNetworkVlans()
if err != nil {
    fmt.Printf("\n Unable to retrieve vlans:\n - %s\n", err)
    return
}

// 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))
}

For more information please see below:

https://sldn.softlayer.com/article/object-masks#Property_Set

Fernando Iquiza
  • 531
  • 3
  • 7
  • I ran the code you provided and although it runs, it does not appear that the mask does anything. Below is a sample entry of what is returned: { "accountId": ####, "id": ####, "modifyDate": "2017-12-01T05:11:45-06:00", "name": "Name", "primarySubnetId": ####, "vlanNumber": #### } Things that are not specified in the mask (modifyDate) are returned and things that are specified in the mask (primaryRouter) are not returned. If I take out the mask the same data is returned. – Dennis Dec 04 '17 at 22:58
  • Were you able to fix this issue? I am facing the same issue – codec Aug 22 '18 at 08:59
0

source: Unable to get itemCategory info from call GetConfiguration when called from golang

F.Ojeda: The default endpoint is REST but in your environment you are using xmlrpc, which is probably due to the existence of the ~ / .softlayer file and in this it is configured as an XMLRPC enpoint.

For more information you can see the following documentation: https://github.com/softlayer/softlayer-go

This issue happens for the XMLRPC enpoint and you can report it in the go GitHub. https://github.com/softlayer/softlayer-go/issues/

Try in your code with the REST endpoint, like this example:

endpoint := "https://api.softlayer.com/rest/v3"

// Create a session
sess := session.New(username, apikey, endpoint)
Dennis
  • 51
  • 1
  • 8