client

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2018 License: Apache-2.0 Imports: 15 Imported by: 29

README

Quick Start for Learning How OpenSDS Client Works

To better learn how opensds client works for connecting with OpenSDS service, here is a three-step example showing how to use the client.

Before these three steps, you have to make sure client package has been imported in your local repo.

Step 1: Initialize Client object

It's a simple and easy step for user to create a new Client object like below:

package main

import (
	"fmt"
	
	"github.com/opensds/opensds/client"
)

func main() {
	c1 := client.NewClient(&client.Config{})
	c2 := client.NewClient(&client.Config{
		Endpoint: ":8080",
	})
	
	fmt.Printf("c1 is %v, c2 is %v\n", c1, c2)
}

As you can see from code above, user has two ways to create Client object: parsing Config object or fetching the endpoint from environment variable (os.Getenv("OPENSDS_ENDPOINT")), you can choose one with your reference.

Step 2: Call method in Client object

In the second step, you can just call method in Client object which is created in step 1 like this:

package main

import(
	"fmt"
	
	"github.com/opensds/opensds/client"
	"github.com/opensds/opensds/pkg/model"
)

func main() {
	c := client.NewClient(&client.Config{
		Endpoint: ":8080",
	})
	
	vol, err := c.CreateVolume(&model.VolumeSpec{
		Name: "test",
		Description: "This is a volume for test",
	})
	if err != nil {
		fmt.Println(err)
	}
	
	result, err := c.GetVolume(vol.Id)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("Volume created, get result:", result)
	
	if err = c.DeleteVolume(vol.Id, nil); err != nil {
		fmt.Println(err)
	}
}

Step 3: Destory Client object

If you want to reset the Client object, just run c.Reset() and it will clear all data in it and return a empty object.

Documentation

Index

Constants

View Source
const (
	//Opensds Auth ENVs
	OpensdsAuthStrategy = "OPENSDS_AUTH_STRATEGY"
	OpensdsTenantId     = "OPENSDS_TENANT_ID"

	// Keystone Auth ENVs
	OsAuthUrl      = "OS_AUTH_URL"
	OsUsername     = "OS_USERNAME"
	OsPassword     = "OS_PASSWORD"
	OsTenantName   = "OS_TENANT_NAME"
	OsProjectName  = "OS_PROJECT_NAME"
	OsUserDomainId = "OS_USER_DOMAIN_ID"

	Keystone = "keystone"
	Noauth   = "noauth"
)
View Source
const (
	OpensdsEndpoint = "OPENSDS_ENDPOINT"
)

Variables

This section is empty.

Functions

func NewHttpError added in v0.1.4

func NewHttpError(code int, msg string) error

Types

type AuthOptions added in v0.1.4

type AuthOptions interface {
	GetTenantId() string
}

type Client

type Client struct {
	*ProfileMgr
	*DockMgr
	*PoolMgr
	*VolumeMgr
	*VersionMgr
	*ReplicationMgr
	// contains filtered or unexported fields
}

Client is a struct for exposing some operations of opensds resources.

func NewClient

func NewClient(c *Config) *Client

NewClient method creates a new Client.

func (*Client) Reset

func (c *Client) Reset() *Client

Reset method is defined to clean Client struct.

type Config

type Config struct {
	Endpoint    string
	AuthOptions AuthOptions
}

Config is a struct that defines some options for calling the Client.

type DockMgr

type DockMgr struct {
	Receiver
	Endpoint string
	TenantId string
}

func NewDockMgr

func NewDockMgr(r Receiver, edp string, tenantId string) *DockMgr

func (*DockMgr) GetDock

func (d *DockMgr) GetDock(dckID string) (*model.DockSpec, error)

func (*DockMgr) ListDocks

func (d *DockMgr) ListDocks(args ...interface{}) ([]*model.DockSpec, error)

type ExtendVolumeBuilder added in v0.1.1

type ExtendVolumeBuilder *model.ExtendVolumeSpec

ExtendVolumeBuilder contains request body of handling a extend volume request. Currently it's assigned as the pointer of ExtendVolumeSpec struct, but it could be discussed if it's better to define an interface.

type ExtraBuilder

type ExtraBuilder *model.ExtraSpec

ExtraBuilder contains request body of handling a profile extra request. Currently it's assigned as the pointer of Extra struct, but it could be discussed if it's better to define an interface.

type FailoverReplicationBuilder added in v0.1.8

type FailoverReplicationBuilder *model.FailoverReplicationSpec

type HeaderOption added in v0.1.4

type HeaderOption map[string]string

ParamOption

type HttpError added in v0.1.4

type HttpError struct {
	Code int
	Msg  string
}

func (*HttpError) Decode added in v0.1.5

func (e *HttpError) Decode()

func (*HttpError) Error added in v0.1.4

func (e *HttpError) Error() string

type KeystoneAuthOptions added in v0.1.4

type KeystoneAuthOptions struct {
	IdentityEndpoint string
	Username         string
	UserID           string
	Password         string
	DomainID         string
	DomainName       string
	TenantID         string
	TenantName       string
	AllowReauth      bool
	TokenID          string
}

func LoadKeystoneAuthOptionsFromEnv added in v0.1.10

func LoadKeystoneAuthOptionsFromEnv() *KeystoneAuthOptions

func NewKeystoneAuthOptions added in v0.1.4

func NewKeystoneAuthOptions() *KeystoneAuthOptions

func (*KeystoneAuthOptions) GetTenantId added in v0.1.4

func (k *KeystoneAuthOptions) GetTenantId() string

type KeystoneReciver added in v0.1.4

type KeystoneReciver struct {
	// contains filtered or unexported fields
}

func (*KeystoneReciver) GetToken added in v0.1.4

func (k *KeystoneReciver) GetToken() error

func (*KeystoneReciver) Recv added in v0.1.4

func (k *KeystoneReciver) Recv(url string, method string, body interface{}, output interface{}) error

type NoAuthOptions added in v0.1.4

type NoAuthOptions struct {
	TenantID string
}

func LoadNoAuthOptionsFromEnv added in v0.1.10

func LoadNoAuthOptionsFromEnv() *NoAuthOptions

func NewNoauthOptions added in v0.1.4

func NewNoauthOptions(tenantId string) *NoAuthOptions

func (*NoAuthOptions) GetTenantId added in v0.1.4

func (n *NoAuthOptions) GetTenantId() string

type PoolMgr

type PoolMgr struct {
	Receiver
	Endpoint string
	TenantId string
}

PoolMgr

func NewPoolMgr

func NewPoolMgr(r Receiver, edp string, tenantId string) *PoolMgr

NewPoolMgr

func (*PoolMgr) GetPool

func (p *PoolMgr) GetPool(polID string) (*model.StoragePoolSpec, error)

GetPool

func (*PoolMgr) ListPools

func (p *PoolMgr) ListPools(args ...interface{}) ([]*model.StoragePoolSpec, error)

ListPools

type ProfileBuilder

type ProfileBuilder *model.ProfileSpec

ProfileBuilder contains request body of handling a profile request. Currently it's assigned as the pointer of ProfileSpec struct, but it could be discussed if it's better to define an interface.

type ProfileMgr

type ProfileMgr struct {
	Receiver
	Endpoint string
	TenantId string
}

ProfileMgr

func NewProfileMgr

func NewProfileMgr(r Receiver, edp string, tenantId string) *ProfileMgr

NewProfileMgr

func (*ProfileMgr) AddExtraProperty

func (p *ProfileMgr) AddExtraProperty(prfID string, body ExtraBuilder) (*model.ExtraSpec, error)

AddExtraProperty

func (*ProfileMgr) CreateProfile

func (p *ProfileMgr) CreateProfile(body ProfileBuilder) (*model.ProfileSpec, error)

CreateProfile

func (*ProfileMgr) DeleteProfile

func (p *ProfileMgr) DeleteProfile(prfID string) error

DeleteProfile

func (*ProfileMgr) GetProfile

func (p *ProfileMgr) GetProfile(prfID string) (*model.ProfileSpec, error)

GetProfile

func (*ProfileMgr) ListExtraProperties

func (p *ProfileMgr) ListExtraProperties(prfID string) (*model.ExtraSpec, error)

ListExtraProperties

func (*ProfileMgr) ListProfiles

func (p *ProfileMgr) ListProfiles(args ...interface{}) ([]*model.ProfileSpec, error)

ListProfiles

func (*ProfileMgr) RemoveExtraProperty

func (p *ProfileMgr) RemoveExtraProperty(prfID, extraKey string) error

RemoveExtraProperty

func (*ProfileMgr) UpdateProfile added in v0.1.9

func (p *ProfileMgr) UpdateProfile(prfID string, body ProfileBuilder) (*model.ProfileSpec, error)

UpdateProfile ...

type Receiver

type Receiver interface {
	Recv(url string, method string, input interface{}, output interface{}) error
}

Receiver

func NewKeystoneReciver added in v0.1.4

func NewKeystoneReciver(auth *KeystoneAuthOptions) Receiver

func NewReceiver

func NewReceiver() Receiver

NewReceiver

type ReplicationBuilder added in v0.1.8

type ReplicationBuilder *model.ReplicationSpec

type ReplicationMgr added in v0.1.8

type ReplicationMgr struct {
	Receiver
	Endpoint string
	TenantId string
}

ReplicationMgr

func NewReplicationMgr added in v0.1.8

func NewReplicationMgr(r Receiver, edp string, tenantId string) *ReplicationMgr

NewReplicationMgr

func (*ReplicationMgr) CreateReplication added in v0.1.8

func (v *ReplicationMgr) CreateReplication(body ReplicationBuilder) (*model.ReplicationSpec, error)

CreateReplication

func (*ReplicationMgr) DeleteReplication added in v0.1.8

func (v *ReplicationMgr) DeleteReplication(replicaId string, body ReplicationBuilder) error

DeleteReplication

func (*ReplicationMgr) DisableReplication added in v0.1.8

func (v *ReplicationMgr) DisableReplication(replicaId string) error

EnableReplication

func (*ReplicationMgr) EnableReplication added in v0.1.8

func (v *ReplicationMgr) EnableReplication(replicaId string) error

EnableReplication

func (*ReplicationMgr) FailoverReplication added in v0.1.8

func (v *ReplicationMgr) FailoverReplication(replicaId string, body FailoverReplicationBuilder) error

EnableReplication

func (*ReplicationMgr) GetReplication added in v0.1.8

func (v *ReplicationMgr) GetReplication(replicaId string) (*model.ReplicationSpec, error)

GetReplication

func (*ReplicationMgr) ListReplications added in v0.1.8

func (v *ReplicationMgr) ListReplications(args ...interface{}) ([]*model.ReplicationSpec, error)

ListReplications

func (*ReplicationMgr) UpdateReplication added in v0.1.8

func (v *ReplicationMgr) UpdateReplication(replicaId string, body ReplicationBuilder) (*model.ReplicationSpec, error)

UpdateReplication

type VersionBuilder added in v0.1.1

type VersionBuilder *model.VersionSpec

VersionBuilder contains request body of handling a version request. Currently it's assigned as the pointer of VersionSpec struct, but it could be discussed if it's better to define an interface.

type VersionMgr added in v0.1.1

type VersionMgr struct {
	Receiver
	Endpoint string
	// contains filtered or unexported fields
}

VersionMgr ...

func NewVersionMgr added in v0.1.1

func NewVersionMgr(r Receiver, edp string, tenantId string) *VersionMgr

NewVersionMgr ...

func (*VersionMgr) GetVersion added in v0.1.1

func (v *VersionMgr) GetVersion(apiVersion string) (*model.VersionSpec, error)

GetVersion ...

func (*VersionMgr) ListVersions added in v0.1.1

func (v *VersionMgr) ListVersions() ([]*model.VersionSpec, error)

ListVersions ...

type VolumeAttachmentBuilder

type VolumeAttachmentBuilder *model.VolumeAttachmentSpec

VolumeAttachmentBuilder contains request body of handling a volume request. Currently it's assigned as the pointer of VolumeSpec struct, but it could be discussed if it's better to define an interface.

type VolumeBuilder

type VolumeBuilder *model.VolumeSpec

VolumeBuilder contains request body of handling a volume request. Currently it's assigned as the pointer of VolumeSpec struct, but it could be discussed if it's better to define an interface.

type VolumeGroupBuilder added in v0.1.8

type VolumeGroupBuilder *model.VolumeGroupSpec

VolumeGroupBuilder contains request body of handling a volume group request. Currently it's assigned as the pointer of VolumeGroupSpec struct, but it could be discussed if it's better to define an interface.

type VolumeMgr

type VolumeMgr struct {
	Receiver
	Endpoint string
	TenantId string
}

VolumeMgr

func NewVolumeMgr

func NewVolumeMgr(r Receiver, edp string, tenantId string) *VolumeMgr

NewVolumeMgr

func (*VolumeMgr) CreateVolume

func (v *VolumeMgr) CreateVolume(body VolumeBuilder) (*model.VolumeSpec, error)

CreateVolume

func (*VolumeMgr) CreateVolumeAttachment

func (v *VolumeMgr) CreateVolumeAttachment(body VolumeAttachmentBuilder) (*model.VolumeAttachmentSpec, error)

CreateVolumeAttachment

func (*VolumeMgr) CreateVolumeGroup added in v0.1.8

func (v *VolumeMgr) CreateVolumeGroup(body VolumeGroupBuilder) (*model.VolumeGroupSpec, error)

CreateVolumeGroup

func (*VolumeMgr) CreateVolumeSnapshot

func (v *VolumeMgr) CreateVolumeSnapshot(body VolumeSnapshotBuilder) (*model.VolumeSnapshotSpec, error)

CreateVolumeSnapshot

func (*VolumeMgr) DeleteVolume

func (v *VolumeMgr) DeleteVolume(volID string, body VolumeBuilder) error

DeleteVolume

func (*VolumeMgr) DeleteVolumeAttachment

func (v *VolumeMgr) DeleteVolumeAttachment(atcID string, body VolumeAttachmentBuilder) error

DeleteVolumeAttachment

func (*VolumeMgr) DeleteVolumeGroup added in v0.1.8

func (v *VolumeMgr) DeleteVolumeGroup(vgId string, body VolumeGroupBuilder) error

DeleteVolumeGroup

func (*VolumeMgr) DeleteVolumeSnapshot

func (v *VolumeMgr) DeleteVolumeSnapshot(snpID string, body VolumeSnapshotBuilder) error

DeleteVolumeSnapshot

func (*VolumeMgr) ExtendVolume added in v0.1.1

func (v *VolumeMgr) ExtendVolume(volID string, body ExtendVolumeBuilder) (*model.VolumeSpec, error)

ExtendVolume ...

func (*VolumeMgr) GetVolume

func (v *VolumeMgr) GetVolume(volID string) (*model.VolumeSpec, error)

GetVolume

func (*VolumeMgr) GetVolumeAttachment

func (v *VolumeMgr) GetVolumeAttachment(atcID string) (*model.VolumeAttachmentSpec, error)

GetVolumeAttachment

func (*VolumeMgr) GetVolumeGroup added in v0.1.8

func (v *VolumeMgr) GetVolumeGroup(vgId string) (*model.VolumeGroupSpec, error)

GetVolumeGroup

func (*VolumeMgr) GetVolumeSnapshot

func (v *VolumeMgr) GetVolumeSnapshot(snpID string) (*model.VolumeSnapshotSpec, error)

GetVolumeSnapshot

func (*VolumeMgr) ListVolumeAttachments

func (v *VolumeMgr) ListVolumeAttachments(args ...interface{}) ([]*model.VolumeAttachmentSpec, error)

ListVolumeAttachments

func (*VolumeMgr) ListVolumeGroups added in v0.1.8

func (v *VolumeMgr) ListVolumeGroups(args ...interface{}) ([]*model.VolumeGroupSpec, error)

ListVolumeGroups

func (*VolumeMgr) ListVolumeSnapshots

func (v *VolumeMgr) ListVolumeSnapshots(args ...interface{}) ([]*model.VolumeSnapshotSpec, error)

ListVolumeSnapshots

func (*VolumeMgr) ListVolumes

func (v *VolumeMgr) ListVolumes(args ...interface{}) ([]*model.VolumeSpec, error)

ListVolumes

func (*VolumeMgr) UpdateVolume

func (v *VolumeMgr) UpdateVolume(volID string, body VolumeBuilder) (*model.VolumeSpec, error)

UpdateVolume

func (*VolumeMgr) UpdateVolumeAttachment

func (v *VolumeMgr) UpdateVolumeAttachment(atcID string, body VolumeAttachmentBuilder) (*model.VolumeAttachmentSpec, error)

UpdateVolumeAttachment

func (*VolumeMgr) UpdateVolumeGroup added in v0.1.8

func (v *VolumeMgr) UpdateVolumeGroup(vgId string, body VolumeGroupBuilder) (*model.VolumeGroupSpec, error)

UpdateVolumeSnapshot

func (*VolumeMgr) UpdateVolumeSnapshot

func (v *VolumeMgr) UpdateVolumeSnapshot(snpID string, body VolumeSnapshotBuilder) (*model.VolumeSnapshotSpec, error)

UpdateVolumeSnapshot

type VolumeSnapshotBuilder

type VolumeSnapshotBuilder *model.VolumeSnapshotSpec

VolumeSnapshotBuilder contains request body of handling a volume snapshot request. Currently it's assigned as the pointer of VolumeSnapshotSpec struct, but it could be discussed if it's better to define an interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL