Go Library for CoprHD
Go Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


gocoprhd Build Status

Go bindings for CoprHD


gocoprhd represents API bindings for Go that allow you to manage CoprHD. Not all functions available on CoprHD API were implemented on this library. The intended functions are a direct implementation of what's available within the ViPR REST API.

The methods always start with a verb, such as:

  • List
  • Show
  • Create
  • Update
  • Delete
  • Expand

The following REST and methods implementations are part of this release:


operationId: Login


operationId: CreateVolume


operationId: CreateVolumeSnapshot

operationId: ListVolumeSnapshots


operationId: ListVolumes


operationId: ShowVolume


operationId: CreateVolumeFullCopy


operationId: ListVolumeExports


operationId: ExpandVolume


operationId: DeleteVolume


operationId: CreateExport


operationId: UpdateExport


operationId: DeleteExport


operationId: ListSnapshots


operationId: ShowSnapshot


operationId: DeleteSnapshot


operationId: CreateSnapshotFullCopy


operationId: ListTasks


operationId: ShowTask


operationId: ListVolumeSearch


gocoprhd is created using go-swagger client generator. The local swagger specification is created adopting EMC ViPR API documentation.

Installation of the client

To install the client:

$ go get github.com/victorock/gocoprhd

Generation of the client

The client relies on a swagger spec file that is manually specified at /swagger-spec/coprhd.yml. As the REST API evolves, this specification requires manual update.

The client is found within the /client folder which is generated by go-swagger. To generate the client:

$ cd $GOPATH/src/github.com/victorock/gocoprhd
$ make

The Makefile utilizes glide to reference git commit 6b712512cbe1f of go-swagger that has been tested and known to be working. The Makefile will generate a go-swagger directory in /vendor/github.com/ and then create the client.

Environment Variables

Name Description
GOCOPRHD_ENDPOINT the API endpoint. localhost:4443 is used by default if not set
GOCOPRHD_USERNAME The Username for Authentication/Login
GOCOPRHD_PASSWORD The password for authentication/Login
GOCOPRHD_TOKEN The token provided by CoprHD/ViPR administrator

Using the client

This sample script will retrieve (List) all volumes. Take a look at gocoprhd_test.go for more

package main

import (

    httptransport "github.com/go-openapi/runtime/client"

    apiclient "github.com/victorock/gocoprhd/client"

// Test Get Volumes
func TestListVolumes(t *testing.T) {

  // create the transport
  transport := httptransport.New("localhost:4443", "/", []string{"https"})
  authInfo := httptransport.BasicAuth( "root", "password")

  // Set insecure SSL
  transport.Transport = &http.Transport{
                TLSClientConfig: &tls.Config{
                    InsecureSkipVerify: true,

  // If not using the Vagrant image, set this environment variable to something other than localhost:4443
  if os.Getenv("GOCOPRHD_ENDPOINT") != "" {
      transport.Host = os.Getenv("GOCOPRHD_ENDPOINT")

  // Get the token to populate header for requests
  if os.Getenv("GOCOPRHD_TOKEN") != "" {
      authInfo = httptransport.APIKeyAuth( "X-SDS-AUTH-TOKEN",

  // Basic Authentication to get the user Token
  if os.Getenv("GOCOPRHD_USERNAME") != "" {
    if os.Getenv("GOCOPRHD_PASSWORD") != "" {
      authInfo := httptransport.BasicAuth(os.Getenv("GOCOPRHD_USERNAME"),

  // create the API client, with the transport
  client := apiclient.New(transport, strfmt.Default)

  // Login to get our Token
  login, err := client.Authentication.Login(nil, authInfo)
  if err != nil {

  // Populate the Header with token from now on
  authInfo := httptransport.APIKeyAuth( "X-SDS-AUTH-TOKEN",

  //use any function to do REST operations
  resp, err := client.Block.ListVolumes(nil, authInfo)
  if err != nil {
  fmt.Printf("%#v\n", resp.Payload)
  for _, v := range resp.Payload.ID {
    fmt.Printf("Volume ID: %#v\n", v)


Use the client to import the Service

Import the library for the Client:

import (
    client "github.com/emccode/gocoprhd/client"

Import the library for the Services:

import (
    client "github.com/emccode/gocoprhd/client/block"
    client "github.com/emccode/gocoprhd/client/compute"
    client "github.com/emccode/gocoprhd/client/vdc"

Import the Models Library (See Definitions)

import (

Create the transport objects

Create the transport and point to the API Gateway Service:

  // create the transport
  transport := httptransport.New("localhost:4443", "/", []string{"https"})

  // Set insecure SSL
  transport.Transport = &http.Transport{
        TLSClientConfig: &tls.Config{
          InsecureSkipVerify: true,

  // create the API client, with the transport
  client := apiclient.New(transport, strfmt.Default)

Create the authentication object

Login with Basic Authentication and get the TOKEN for further requests:

  authInfo := httptransport.BasicAuth( "root", "password")

  // Login to get our Token
  resp, err := client.Authentication.Login(nil, authInfo)
  if err != nil {

  // Populate the Header with token from now on
  authInfo := transport.APIKeyAuth( "X-SDS-AUTH-TOKEN",

Create the Body with the object of your request

Populate the struct params, and create the object to use in your request:

  // Construct Request Parameters
  b := &models.CreateVolume {
          ConsistencyGroup: "",
          Count: 1,
          Name: "gocoprhd_test_vol01",
          Project: "urn:storageos:Project:7d46540b-140c-4f39-91b8-52d276356cf0:global",
          Size: 10,
          Varray: "urn:storageos:VirtualArray:ad18dd81-99c6-415d-9081-6091db3df599:vdc1",
          Vpool: "urn:storageos:VirtualPool:7e036b4a-9cba-4357-9afc-3aa7539f10c0:vdc1",

  // Create the New Params and Populate the Body
  CreateVolumeParams := block.NewCreateVolumeParams().

Execute the request

Execute the request with the populated struct:

    resp, err := client.Block.CreateVolume(CreateVolumeParams, authInfo)
    if err != nil {
    fmt.Printf("%#v\n", resp.Payload)


  • Virtual Arrays and Virtual Pools are already configured and operational to consume.
  • The Host and Initiator entries already exists in the Interface.


1- Extend the APIs coverage in the swagger-spec/coprhd.yml for Compute:


  • Create Host
  • Show Host
  • List Hosts


  • Create Initiator
  • Show Initiator
  • List Initiators

2- Extend the API to cover File Services


Create a fork of the project into your own repository.

Run the tests provided in gocoprhd_test.go to verify GET/POST/DELETE still function:

env DEBUG=1 go test -run TestCreateExport -v
env DEBUG=1 go test -run TestCreateSnapshotFullCopy -v
env DEBUG=1 go test -run TestCreateVolume -v
env DEBUG=1 go test -run TestCreateVolumeFullCopy -v
env DEBUG=1 go test -run TestCreateVolumeSnapshot -v
env DEBUG=1 go test -run TestDeleteExport -v
env DEBUG=1 go test -run TestDeleteSnapshot -v
env DEBUG=1 go test -run TestDeleteVolume -v
env DEBUG=1 go test -run TestExpandVolume -v
env DEBUG=1 go test -run TestListSnapshots -v
env DEBUG=1 go test -run TestListTasks -v
env DEBUG=1 go test -run TestListVolumeExports -v
env DEBUG=1 go test -run TestListVolumeSearch -v
env DEBUG=1 go test -run TestListVolumeSnapshots -v
env DEBUG=1 go test -run TestListVolumes -v
env DEBUG=1 go test -run TestLogin -v
env DEBUG=1 go test -run TestShowSnapshot -v
env DEBUG=1 go test -run TestShowTask -v
env DEBUG=1 go test -run TestShowVolume -v

If tests do not pass, please create an issue so it can be addressed or fix and create a PR.

If all tests pass, make changes and create a pull request with a description on what was added or removed and details explaining the changes in lines of code. If approved, project owners will merge it.


gocoprhd is freely distributed under the MIT License. See LICENSE for details.


Please file bugs and issues on the Github issues page for this project. This is to help keep track and document everything related to this repo. For general discussions and further support you can join the EMC {code} Community slack team and join the #coprhd channel. Lastly, for questions asked on Stackoverflow.com please tag them with EMC. The code and documentation are released with no warranties or SLAs and are intended to be supported through a community driven process.