Merge pull request #54631 from venkat-443/master

Automatic merge from submit-queue (batch tested with PRs 60376, 55584, 60358, 54631, 60291). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Update vendored Quobyte API

This update patch includes Quobyte API improvements.
[JSON API fix](https://github.com/quobyte/api/issues/12)
[API Tenant calls](https://github.com/quobyte/api/pull/10)
This commit is contained in:
Kubernetes Submit Queue 2018-02-28 03:37:33 -08:00 committed by GitHub
commit 4dd458163a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 133 additions and 21 deletions

2
Godeps/Godeps.json generated
View File

@ -2515,7 +2515,7 @@
},
{
"ImportPath": "github.com/quobyte/api",
"Rev": "cb10db90715b14d4784465d2fa3b915dfacc0628"
"Rev": "f2b94aa4aa4f8fcf279fe667ccd916abe6a064d5"
},
{
"ImportPath": "github.com/rancher/go-rancher/client",

View File

@ -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",

View File

@ -5,11 +5,28 @@ 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
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
@ -19,6 +36,7 @@ func NewQuobyteClient(url string, username string, password string) *QuobyteClie
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
}

View File

@ -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

View File

@ -1,5 +1,9 @@
package quobyte
type retryPolicy struct {
RetryPolicy string `json:"retry,omitempty"`
}
// CreateVolumeRequest represents a CreateVolumeRequest
type CreateVolumeRequest struct {
Name string `json:"name,omitempty"`
@ -9,11 +13,13 @@ type CreateVolumeRequest struct {
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"`
retryPolicy
}
type volumeUUID struct {
@ -22,6 +28,7 @@ type volumeUUID struct {
type getClientListRequest struct {
TenantDomain string `json:"tenant_domain,omitempty"`
retryPolicy
}
type GetClientListResponse struct {
@ -53,4 +60,36 @@ type quota struct {
type setQuotaRequest struct {
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"`
}