Giter VIP home page Giter VIP logo

datacentred-go's Introduction

Datacentred

CircleCI Go Report Card GoDoc

Client library for automating DataCentred account management in Go.

www.datacentred.co.uk

Installation

Run:

go get github.com/datacentred/datacentred-go

In your code:

import(
    "github.com/datacentred/datacentred-go"
)

Usage

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.

Authentication

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:

  1. Find your API access key and secret key at my.datacentred.io

API Credentials

  1. 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"

Usage Examples

List all available users

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 }]

Find a user by id

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 } 

Update a project

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}

Create a role

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}

Add a user to a role

user, _ := datacentred.Users()[0]
result, err := role.AddUser(user.Id)
fmt.Println(result)
// => true

Remove a user from a project

users, _ := datacentred.Users()
user := users[0]
result, err = project.RemoveUser(user.Id)
fmt.Println(result)
// => true

Get usage data for a given year and month

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"

Documentation

https://godoc.org/github.com/datacentred/datacentred-go

API Reference Manual

Please check out the DataCentred API Documentation for a comprehensive description of the API itself.

datacentred-go's People

Contributors

seanhandley avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

leehambley

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.