mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +00:00
Quobyte API update
This commit is contained in:
parent
15cd355281
commit
6eef91b7cf
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -2528,7 +2528,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/quobyte/api",
|
||||
"Rev": "f2b94aa4aa4f8fcf279fe667ccd916abe6a064d5"
|
||||
"Rev": "206ef832283c1a0144bbc762be2634d49987b5ff"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/rancher/go-rancher/client",
|
||||
|
33
vendor/github.com/quobyte/api/quobyte.go
generated
vendored
33
vendor/github.com/quobyte/api/quobyte.go
generated
vendored
@ -2,7 +2,9 @@
|
||||
package quobyte
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// retry policy codes
|
||||
@ -43,6 +45,17 @@ func NewQuobyteClient(url string, username string, password string) *QuobyteClie
|
||||
// CreateVolume creates a new Quobyte volume. Its root directory will be owned by given user and group
|
||||
func (client QuobyteClient) CreateVolume(request *CreateVolumeRequest) (string, error) {
|
||||
var response volumeUUID
|
||||
|
||||
if request.TenantID != "" && !IsValidUUID(request.TenantID) {
|
||||
log.Printf("Tenant name resolution: Resolving %s to UUID\n", request.TenantID)
|
||||
tenantUUID, err := client.ResolveTenantNameToUUID(request.TenantID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
request.TenantID = tenantUUID
|
||||
}
|
||||
|
||||
if err := client.sendRequest("createVolume", request, &response); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -168,3 +181,23 @@ func (client *QuobyteClient) SetTenant(tenantName string) (string, error) {
|
||||
|
||||
return response.TenantID, nil
|
||||
}
|
||||
|
||||
// IsValidUUID Validates given uuid
|
||||
func IsValidUUID(uuid string) bool {
|
||||
r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
|
||||
return r.MatchString(uuid)
|
||||
}
|
||||
|
||||
// ResolveTenantNameToUUID Returns UUID for given name, error if not found.
|
||||
func (client *QuobyteClient) ResolveTenantNameToUUID(name string) (string, error) {
|
||||
request := &resolveTenantNameRequest{
|
||||
TenantName: name,
|
||||
}
|
||||
|
||||
var response resolveTenantNameResponse
|
||||
err := client.sendRequest("resolveTenantName", request, &response)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return response.TenantID, nil
|
||||
}
|
||||
|
4
vendor/github.com/quobyte/api/rpc_client.go
generated
vendored
4
vendor/github.com/quobyte/api/rpc_client.go
generated
vendored
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@ -110,5 +111,8 @@ func (client QuobyteClient) sendRequest(method string, request interface{}, resp
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
log.Printf("Warning: HTTP status code for request is %s\n", strconv.Itoa(resp.StatusCode))
|
||||
}
|
||||
return decodeResponse(resp.Body, &response)
|
||||
}
|
||||
|
8
vendor/github.com/quobyte/api/types.go
generated
vendored
8
vendor/github.com/quobyte/api/types.go
generated
vendored
@ -22,6 +22,14 @@ type resolveVolumeNameRequest struct {
|
||||
retryPolicy
|
||||
}
|
||||
|
||||
type resolveTenantNameRequest struct {
|
||||
TenantName string `json:"tenant_name,omitempty"`
|
||||
}
|
||||
|
||||
type resolveTenantNameResponse struct {
|
||||
TenantID string `json:"tenant_id,omitempty"`
|
||||
}
|
||||
|
||||
type volumeUUID struct {
|
||||
VolumeUUID string `json:"volume_uuid,omitempty"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user