An incomplete SoftLayer (SL) client API written in Go language.
The best way to get started would be to look at the integration tests for creating a virtual guest and the test helpers. Here is a snippet of what is needed.
//Add necessary imports, e.g., os, slclient, datatypes
// "os"
// slclient "github.com/maximilien/softlayer-go/client"
// datatypes "github.com/maximilien/softlayer-go/data_types"
//Access SoftLayer username and API key from environment variable or hardcode here
username := os.Getenv("SL_USERNAME")
apiKey := os.Getenv("SL_API_KEY")
//Create a softLayer-go client
client := slclient.NewSoftLayerClient(username, apiKey)
//Create a template for the virtual guest (changing properties as needed)
virtualGuestTemplate := datatypes.SoftLayer_Virtual_Guest_Template{
Hostname: "some-hostname",
Domain: "some-domain.com",
StartCpus: 1,
MaxMemory: 1024,
Datacenter: datatypes.Datacenter{
Name: "ams01",
},
SshKeys: []SshKey{}, //or get the necessary keys and add here
HourlyBillingFlag: true,
LocalDiskFlag: true,
OperatingSystemReferenceCode: "UBUNTU_LATEST",
}
//Get the SoftLayer virtual guest service
virtualGuestService, err := client.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return err
}
//Create the virtual guest with the service
virtualGuest, err := virtualGuestService.CreateObject(virtualGuestTemplate)
if err != nil {
return err
}
//Use the virtualGuest or other services...
TBD
Clone this repo and build it. Using the following commands on a Linux or Mac OS X system:
$ mkdir -p softlayer-go/src/github.com/maximilien
$ export GOPATH=$(pwd)/softlayer-go:$GOPATH
$ cd softlayer-go/src/github.com/maximilien
$ git clone https://github.com/maximilien/softlayer-go.git
$ cd softlayer-go
$ export SL_USERNAME=your-username@your-org.com
$ export SL_API_KEY=your-softlayer-api-key
$ ./bin/build
$ ./bin/test-unit
$ ./bin/test-integration
NOTE: you may need to install govendor on your system, if you have not already. You can with this one line command: $ go get github.com/kardianos/govendor
NOTE2: if you get any dependency errors, then use go get path/to/dependency
to get it, e.g., go get github.com/onsi/ginkgo
and go get github.com/onsi/gomega
. You also need to do govendor fetch package
in order for any new or updated dependencies to be reflected into the vendor
directory.
The executable output should now be located in: out/slgo
. It does not do anything currently, expect printing a version number. In time this may change. For now, this project is intended to be a set of useful and reusable Golang libraries to access SoftLayer.
The SoftLayer (SL) Golang client and associated tests and binary distribution depend on you having a real SL account. Get one for free for one month here. From your SL account you can get an API key. Using your account name and API key you will need to set two environment variables: SL_USERNAME
and SL_API_KEY
. You can do so as follows:
$ export SL_USERNAME=your-username@your-org.com
$ export SL_API_KEY=your-softlayer-api-key
You should run the tests to make sure all is well, do this with: $ ./bin/test-unit
and $ ./bin/test-integration
in your cloned repository. Please note that the $ ./bin/test-integration
will spin up real SoftLayer virtual guests (VMs) and associated resources and will also delete them. This integration test may take up to 30 minutes (usually shorter)
The output should of $ ./bin/test-unit
be similar to:
➜ softlayer-go git:(master) bin/test-unit
Cleaning build artifacts...
Formatting packages...
Unit Testing packages:
[1457666427] SoftLayer Client Suite - 14/14 specs - 4 nodes •••••••••••••• SUCCESS! 40.325961ms
[1457666427] Services Suite - 327/327 specs - 4 nodes ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• SUCCESS! 288.0041ms
[1457666427] Common Suite - 4/4 specs - 4 nodes •••• SUCCESS! 13.394673ms
Ginkgo ran 3 suites in 5.387042692s
Test Suite Passed
Vetting packages for potential issues...
SWEET SUITE SUCCESS
go get golang.org/x/tools/cmd/vet
go get github.com/xxx ...
to install test dependencies (as you see errors)bin/test
and watch the test failgovendor
GuidePlease find govendor FAQ in govendor FAQ and developer guide
() these items are in the works, we will remove the once they are available
NOTE: this client is created to support the bosh-softlayer-cpi project and only implements the portion of the SL APIs needed to complete the implementation of the BOSH CPI. You are welcome to use it in your own projects and as you do if you find areas we have not yet implemented but that you need, please submit Pull Requests or engage with us in discussions.