• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Go
  6. EVS Go SDK User Guide

EVS Go SDK User Guide

Service Client

To interact with OpenStack APIs, transfer the identity credentials to the provider. After that, if you want to retrieve any information about the block storage service, you need to make a call to NewBlockStorageV2 to create a block storage service client and then use required SDKs.

client, err := openstack.NewBlockStorageV2(provider, gophercloud.EndpointOpts{
 Region: "RegionName",
})

Volumes

A volume is a block storage device that can be detached. A volume can be attached to only one instance at a time.

Create a volume.

You can use Create to create a volume based on the value of CreateOpts. This operation invokes the Extract method of CreateResult to extract volume information from the response.

import (    "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"   ) 

func TestVolumeCreateFromImage(t *testing.T) {
    createOpts := volumes.CreateOpts{
           ImageID: "image_id",
           AvailabilityZone: "AvailabilityZone",
           Description: "creating volume from image",
           Size:40,
           Name:"volumeName",
           VolumeType:"SATA",
    }
    volume, err := volumes.Create(client, createOpts).Extract()
}

List volumes.

You can use List to obtain the volume list. The filter criteria are provided by ListOpts.

func TestVolumesListName(t *testing.T) {
    ListOps:= volumes.ListOpts{
           Name: "VolumeName",
    }
    // Retrieve a pager (i.e. a paginated collection)
    allPages, err := volumes.List(client, ListOps).AllPages()
    
    // Define an anonymous function to be executed on each page's iteration
    allVolumes, err := volumes.ExtractVolumes(allPages)

    for _, volume := range allVolumes {
           // " volume " will be a volumes.Volume
    }
}

Update a volume.

You can use Update to update volume information. This operation invokes the Extract method of UpdateResult to extract updated volume information from the response.

func TestVolumeUpdate(t *testing.T){
    updateOpts :=volumes.UpdateOpts{
           Name: "volumeName",
           Description:"it is updating",
           Metadata:map[string]string{
                  "update": "testing",
           },
    }
    volume, err = volumes.Update(client, "volume_id",updateOpts).Extract()
}

Get details about a specific volume.

You can use Get to retrieve a volume based on the specified volume ID. This operation invokes the Extract method of GetResult to extract volume information from the response.

func TestVolumeShow(t *testing.T) {
    volume,err:= volumes.Get(client,"volume_id").Extract()
}

Delete a volume.

You can use Delete to delete an existing volume based on the volume ID.

func TestVolumeDelete(t *testing.T){
    err = volumes.Delete(client, "volume_id").ExtractErr()
}