Using examples in Go SDK
with Username and apikey
returned
{"error":"Access Denied. ","code":"SoftLayer_Exception_Public"}
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
)
func main() {
userName := "xxxx"
apikey := "xxxx"
sess := session.New(userName, apikey)
sess.Debug = true
doListAccountVMsTest(sess)
}
func doListAccountVMsTest(sess *session.Session) {
service := services.GetAccountService(sess)
vms, err := service.Mask("id;hostname;domain").Limit(10).GetVirtualGuests()
if err != nil {
fmt.Printf("Error retrieving Virtual Guests from Account: %s
", err)
return
} else {
fmt.Println("VMs under Account:")
}
for _, vm := range vms {
fmt.Printf("\t[%d]%s.%s
", *vm.Id, *vm.Hostname, *vm.Domain)
}
}
func handleError(err error) {
apiErr := err.(sl.Error)
fmt.Printf(
"Exception: %s
Message: %s
HTTP Status Code: %d
",
apiErr.Exception,
apiErr.Message,
apiErr.StatusCode)
}