Client library for automating DataCentred account management in Go.
Run:
go get github.com/datacentred/datacentred-go
In your code:
import(
"github.com/datacentred/datacentred-go"
)
This SDK allows you to automate operations against your DataCentred account.
Operations include:
- Creating and managing users;
- Creating and managing roles for users;
- Managing OpenStack Project creation, quota adjustments, and user assignments;
- Viewing detailed usage/billing information for your account.
The API used by this SDK uses two pieces of information to authenticate access.
A unique access key specific to your DataCentred account, and a secret key which is generated once.
To get started:
- Find your API access key and secret key at my.datacentred.io
- Set your credentials by exporting your access key and secret key as environment variables in your shell:
export DATACENTRED_ACCESS="my_access"
export DATACENTRED_SECRET="my_secret"
Or set your keys manually using the following code:
datacentred.Config.AccessKey = "my_access"
datacentred.Config.SecretKey = "my_secret"
users, err := datacentred.Users()
fmt.Println(users)
// => [{2bd21ee25cde40fdb9454954e4fbb4b5 [email protected] Bill Preston 2015-02-13 11:07:00 +0000 UTC 2017-09-26 09:11:38 +0000 UTC } {69a34c127dcb439fa9366762234687ac [email protected] Ted Logan 2014-08-22 14:32:31 +0000 UTC 2017-09-21 14:55:43 +0000 UTC }]
user, err := datacentred.FindUser("2bd21ee25cde40fdb9454954e4fbb4b5")
fmt.Println(user)
// => {2bd21ee25cde40fdb9454954e4fbb4b5 [email protected] Bill Preston 2015-02-13 11:07:00 +0000 UTC 2017-09-26 09:11:38 +0000 UTC }
project, err := datacentred.FindProject("37033518a4514f12adeb8346ac3f188c")
project.QuotaSet.Compute.Instances = 50
_, err = project.Save()
fmt.Println(project)
// => [{37033518a4514f12adeb8346ac3f188c seancentred {{40 50 60000} {40 10 5} {0 10 50 10 10 100 10}} 2015-04-09 08:14:19 +0000 UTC 2016-12-08 11:44:05 +0000 UTC}
params := map[string]string{
"name": "Wyld Stallyns",
}
role, err := CreateRole(params)
fmt.Println(role)
// => {5713b281-b9f7-41d7-bc8c-9eb92920d1d3 Wyld Stallyns false [] 2017-09-26 09:42:56 +0000 UTC 2017-09-26 09:42:56 +0000 UTC}
user, _ := datacentred.Users()[0]
result, err := role.AddUser(user.Id)
fmt.Println(result)
// => true
users, _ := datacentred.Users()
user := users[0]
result, err = project.RemoveUser(user.Id)
fmt.Println(result)
// => true
usage, err := datacentred.FindUsage(2017, 9)
fmt.Println(usage.Projects[0].Usage.Instances[0].Usage.Value)
// => 744
fmt.Println(usage.Projects[0].Usage.Instances[0].Usage.Unit)
// => "hours"
https://godoc.org/github.com/datacentred/datacentred-go
Please check out the DataCentred API Documentation for a comprehensive description of the API itself.