From d5778398e2a4b2ce17e2f4c5c55d97169ef747a4 Mon Sep 17 00:00:00 2001 From: Venkata Subbarao Chunduri Date: Thu, 26 Oct 2017 15:09:37 +0200 Subject: [PATCH] Update Quobyte API --- Godeps/Godeps.json | 2 +- vendor/github.com/quobyte/api/README.md | 3 +- vendor/github.com/quobyte/api/quobyte.go | 82 +++++++++++++++++++-- vendor/github.com/quobyte/api/rpc_client.go | 6 ++ vendor/github.com/quobyte/api/types.go | 61 ++++++++++++--- 5 files changed, 133 insertions(+), 21 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index da9159de680..e360cbf40a6 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -2386,7 +2386,7 @@ }, { "ImportPath": "github.com/quobyte/api", - "Rev": "cb10db90715b14d4784465d2fa3b915dfacc0628" + "Rev": "f2b94aa4aa4f8fcf279fe667ccd916abe6a064d5" }, { "ImportPath": "github.com/rancher/go-rancher/client", diff --git a/vendor/github.com/quobyte/api/README.md b/vendor/github.com/quobyte/api/README.md index 072033b7bde..642468aedbc 100644 --- a/vendor/github.com/quobyte/api/README.md +++ b/vendor/github.com/quobyte/api/README.md @@ -1,6 +1,6 @@ # Quobyte API Clients -Get the quoybte api client +Get the quobyte api client ```bash go get github.com/quobyte/api @@ -18,6 +18,7 @@ import ( func main() { client := quobyte_api.NewQuobyteClient("http://apiserver:7860", "user", "password") + client.SetAPIRetryPolicy(quobyte_api.RetryInfinitely) // Default quobyte_api.RetryInteractive req := &quobyte_api.CreateVolumeRequest{ Name: "MyVolume", RootUserID: "root", diff --git a/vendor/github.com/quobyte/api/quobyte.go b/vendor/github.com/quobyte/api/quobyte.go index 3a2a5fd17a2..66e51fd8132 100644 --- a/vendor/github.com/quobyte/api/quobyte.go +++ b/vendor/github.com/quobyte/api/quobyte.go @@ -5,20 +5,38 @@ import ( "net/http" ) +// retry policy codes +const ( + RetryNever string = "NEVER" + RetryInteractive string = "INTERACTIVE" + RetryInfinitely string = "INFINITELY" + RetryOncePerTarget string = "ONCE_PER_TARGET" +) + type QuobyteClient struct { - client *http.Client - url string - username string - password string + client *http.Client + url string + username string + password string + apiRetryPolicy string +} + +func (client *QuobyteClient) SetAPIRetryPolicy(retry string) { + client.apiRetryPolicy = retry +} + +func (client *QuobyteClient) GetAPIRetryPolicy() string { + return client.apiRetryPolicy } // NewQuobyteClient creates a new Quobyte API client func NewQuobyteClient(url string, username string, password string) *QuobyteClient { return &QuobyteClient{ - client: &http.Client{}, - url: url, - username: username, - password: password, + client: &http.Client{}, + url: url, + username: username, + password: password, + apiRetryPolicy: RetryInteractive, } } @@ -80,6 +98,7 @@ func (client *QuobyteClient) GetClientList(tenant string) (GetClientListResponse return response, nil } +// SetVolumeQuota sets a Quota to the specified Volume func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize uint64) error { request := &setQuotaRequest{ Quotas: []*quota{ @@ -102,3 +121,50 @@ func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize uint64) return client.sendRequest("setQuota", request, nil) } + +// GetTenant returns the Tenant configuration for all specified tenants +func (client *QuobyteClient) GetTenant(tenantIDs []string) (GetTenantResponse, error) { + request := &getTenantRequest{TenantIDs: tenantIDs} + + var response GetTenantResponse + err := client.sendRequest("getTenant", request, &response) + if err != nil { + return response, err + } + + return response, nil +} + +// GetTenantMap returns a map that contains all tenant names and there ID's +func (client *QuobyteClient) GetTenantMap() (map[string]string, error) { + result := map[string]string{} + response, err := client.GetTenant([]string{}) + + if err != nil { + return result, err + } + + for _, tenant := range response.Tenants { + result[tenant.Name] = tenant.TenantID + } + + return result, nil +} + +// SetTenant creates a Tenant with the specified name +func (client *QuobyteClient) SetTenant(tenantName string) (string, error) { + request := &setTenantRequest{ + &TenantDomainConfiguration{ + Name: tenantName, + }, + retryPolicy{client.GetAPIRetryPolicy()}, + } + + var response setTenantResponse + err := client.sendRequest("setTenant", request, &response) + if err != nil { + return "", err + } + + return response.TenantID, nil +} diff --git a/vendor/github.com/quobyte/api/rpc_client.go b/vendor/github.com/quobyte/api/rpc_client.go index 7c7326c57fa..77e929e766b 100644 --- a/vendor/github.com/quobyte/api/rpc_client.go +++ b/vendor/github.com/quobyte/api/rpc_client.go @@ -7,6 +7,7 @@ import ( "io" "math/rand" "net/http" + "reflect" "strconv" ) @@ -88,6 +89,11 @@ func decodeResponse(ioReader io.Reader, reply interface{}) error { } func (client QuobyteClient) sendRequest(method string, request interface{}, response interface{}) error { + etype := reflect.ValueOf(request).Elem() + field := etype.FieldByName("RetryPolicy") + if field.IsValid() { + field.SetString(client.GetAPIRetryPolicy()) + } message, err := encodeRequest(method, request) if err != nil { return err diff --git a/vendor/github.com/quobyte/api/types.go b/vendor/github.com/quobyte/api/types.go index c1a87d33714..2e18bd7278e 100644 --- a/vendor/github.com/quobyte/api/types.go +++ b/vendor/github.com/quobyte/api/types.go @@ -1,19 +1,25 @@ package quobyte +type retryPolicy struct { + RetryPolicy string `json:"retry,omitempty"` +} + // CreateVolumeRequest represents a CreateVolumeRequest type CreateVolumeRequest struct { - Name string `json:"name,omitempty"` - RootUserID string `json:"root_user_id,omitempty"` - RootGroupID string `json:"root_group_id,omitempty"` - ReplicaDeviceIDS []uint64 `json:"replica_device_ids,string,omitempty"` - ConfigurationName string `json:"configuration_name,omitempty"` - AccessMode uint32 `json:"access_mode,string,omitempty"` - TenantID string `json:"tenant_id,omitempty"` + Name string `json:"name,omitempty"` + RootUserID string `json:"root_user_id,omitempty"` + RootGroupID string `json:"root_group_id,omitempty"` + ReplicaDeviceIDS []uint64 `json:"replica_device_ids,string,omitempty"` + ConfigurationName string `json:"configuration_name,omitempty"` + AccessMode uint32 `json:"access_mode,string,omitempty"` + TenantID string `json:"tenant_id,omitempty"` + retryPolicy } type resolveVolumeNameRequest struct { - VolumeName string `json:"volume_name,omitempty"` - TenantDomain string `json:"tenant_domain,omitempty"` + VolumeName string `json:"volume_name,omitempty"` + TenantDomain string `json:"tenant_domain,omitempty"` + retryPolicy } type volumeUUID struct { @@ -21,7 +27,8 @@ type volumeUUID struct { } type getClientListRequest struct { - TenantDomain string `json:"tenant_domain,omitempty"` + TenantDomain string `json:"tenant_domain,omitempty"` + retryPolicy } type GetClientListResponse struct { @@ -52,5 +59,37 @@ type quota struct { } type setQuotaRequest struct { - Quotas []*quota `json:"quotas,omitempty"` + Quotas []*quota `json:"quotas,omitempty"` + retryPolicy +} + +type getTenantRequest struct { + TenantIDs []string `json:"tenant_id,omitempty"` + retryPolicy +} + +type GetTenantResponse struct { + Tenants []*TenantDomainConfiguration `json:"tenant,omitempty"` +} + +type TenantDomainConfiguration struct { + TenantID string `json:"tenant_id,omitempty"` + Name string `json:"name,omitempty"` + RestrictToNetwork []string `json:"restrict_to_network,omitempty"` + VolumeAccess []*TenantDomainConfigurationVolumeAccess `json:"volume_access,omitempty"` +} + +type TenantDomainConfigurationVolumeAccess struct { + VolumeUUID string `json:"volume_uuid,omitempty"` + RestrictToNetwork string `json:"restrict_to_network,omitempty"` + ReadOnly bool `json:"read_only,omitempty"` +} + +type setTenantRequest struct { + Tenants *TenantDomainConfiguration `json:"tenant,omitempty"` + retryPolicy +} + +type setTenantResponse struct { + TenantID string `json:"tenant_id,omitempty"` }