diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ca14a53b477..1e0d41597e6 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -2528,7 +2528,7 @@ }, { "ImportPath": "github.com/quobyte/api", - "Rev": "f2b94aa4aa4f8fcf279fe667ccd916abe6a064d5" + "Rev": "206ef832283c1a0144bbc762be2634d49987b5ff" }, { "ImportPath": "github.com/rancher/go-rancher/client", diff --git a/vendor/github.com/quobyte/api/quobyte.go b/vendor/github.com/quobyte/api/quobyte.go index 66e51fd8132..a9b18e22346 100644 --- a/vendor/github.com/quobyte/api/quobyte.go +++ b/vendor/github.com/quobyte/api/quobyte.go @@ -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 +} diff --git a/vendor/github.com/quobyte/api/rpc_client.go b/vendor/github.com/quobyte/api/rpc_client.go index 77e929e766b..7cab3842ae0 100644 --- a/vendor/github.com/quobyte/api/rpc_client.go +++ b/vendor/github.com/quobyte/api/rpc_client.go @@ -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) } diff --git a/vendor/github.com/quobyte/api/types.go b/vendor/github.com/quobyte/api/types.go index 2e18bd7278e..6682012c610 100644 --- a/vendor/github.com/quobyte/api/types.go +++ b/vendor/github.com/quobyte/api/types.go @@ -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"` }