cleanup: Remove quobyte volume plugins from k8s codebase

This commit is contained in:
Jiawei Wang
2022-08-02 00:34:27 +00:00
parent 83591a1196
commit 9c869b3dfc
17 changed files with 1 additions and 1465 deletions

View File

@@ -1,28 +0,0 @@
Copyright (c) 2016, Quobyte Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of quobyte-automation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,40 +0,0 @@
# Quobyte API Clients
Get the quobyte api client
```bash
go get github.com/quobyte/api
```
## Usage
```go
package main
import (
"log"
quobyte_api "github.com/quobyte/api"
)
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",
RootGroupID: "root",
ConfigurationName: "BASE",
Labels: []quobyte_api.Label{
{Name: "label1", Value: "value1"},
{Name: "label2", Value: "value2"},
},
}
volumeUUID, err := client.CreateVolume(req)
if err != nil {
log.Fatalf("Error:", err)
}
log.Printf("%s", volumeUUID)
}
```

View File

@@ -1,245 +0,0 @@
// Package quobyte represents a golang API for the Quobyte Storage System
package quobyte
import (
"net/http"
"regexp"
)
// retry policy codes
const (
RetryNever string = "NEVER"
RetryInteractive string = "INTERACTIVE"
RetryInfinitely string = "INFINITELY"
RetryOncePerTarget string = "ONCE_PER_TARGET"
)
var UUIDValidator = 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}$")
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
}
func (client *QuobyteClient) SetTransport(t http.RoundTripper) {
client.client.Transport = t
}
// 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,
apiRetryPolicy: RetryInteractive,
}
}
// 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
tenantUUID, err := client.GetTenantUUID(request.TenantID)
if err != nil {
return "", err
}
request.TenantID = tenantUUID
if err = client.sendRequest("createVolume", request, &response); err != nil {
return "", err
}
return response.VolumeUUID, nil
}
// GetVolumeUUID resolves the volumeUUID for the given volume and tenant name.
// This method should be used when it is not clear if the given string is volume UUID or Name.
func (client QuobyteClient) GetVolumeUUID(volume, tenant string) (string, error) {
if len(volume) != 0 && !IsValidUUID(volume) {
tenantUUID, err := client.GetTenantUUID(tenant)
if err != nil {
return "", err
}
volUUID, err := client.ResolveVolumeNameToUUID(volume, tenantUUID)
if err != nil {
return "", err
}
return volUUID, nil
}
return volume, nil
}
// GetTenantUUID resolves the tenatnUUID for the given name
// This method should be used when it is not clear if the given string is Tenant UUID or Name.
func (client QuobyteClient) GetTenantUUID(tenant string) (string, error) {
if len(tenant) != 0 && !IsValidUUID(tenant) {
tenantUUID, err := client.ResolveTenantNameToUUID(tenant)
if err != nil {
return "", err
}
return tenantUUID, nil
}
return tenant, nil
}
// ResolveVolumeNameToUUID resolves a volume name to a UUID
func (client *QuobyteClient) ResolveVolumeNameToUUID(volumeName, tenant string) (string, error) {
request := &resolveVolumeNameRequest{
VolumeName: volumeName,
TenantDomain: tenant,
}
var response volumeUUID
if err := client.sendRequest("resolveVolumeName", request, &response); err != nil {
return "", err
}
return response.VolumeUUID, nil
}
// DeleteVolumeByResolvingNamesToUUID deletes the volume by resolving the volume name and tenant name to
// respective UUID if required.
// This method should be used if the given volume, tenant information is name or UUID.
func (client *QuobyteClient) DeleteVolumeByResolvingNamesToUUID(volume, tenant string) error {
volumeUUID, err := client.GetVolumeUUID(volume, tenant)
if err != nil {
return err
}
return client.DeleteVolume(volumeUUID)
}
// DeleteVolume deletes a Quobyte volume
func (client *QuobyteClient) DeleteVolume(UUID string) error {
return client.sendRequest(
"deleteVolume",
&volumeUUID{
VolumeUUID: UUID,
},
nil)
}
// DeleteVolumeByName deletes a volume by a given name
func (client *QuobyteClient) DeleteVolumeByName(volumeName, tenant string) error {
uuid, err := client.ResolveVolumeNameToUUID(volumeName, tenant)
if err != nil {
return err
}
return client.DeleteVolume(uuid)
}
// GetClientList returns a list of all active clients
func (client *QuobyteClient) GetClientList(tenant string) (GetClientListResponse, error) {
request := &getClientListRequest{
TenantDomain: tenant,
}
var response GetClientListResponse
if err := client.sendRequest("getClientListRequest", request, &response); err != nil {
return response, err
}
return response, nil
}
// SetVolumeQuota sets a Quota to the specified Volume
func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize uint64) error {
request := &setQuotaRequest{
Quotas: []*quota{
&quota{
Consumer: []*consumingEntity{
&consumingEntity{
Type: "VOLUME",
Identifier: volumeUUID,
},
},
Limits: []*resource{
&resource{
Type: "LOGICAL_DISK_SPACE",
Value: quotaSize,
},
},
},
},
}
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
}
// IsValidUUID Validates the given uuid
func IsValidUUID(uuid string) bool {
return UUIDValidator.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
}

View File

@@ -1,124 +0,0 @@
package quobyte
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"reflect"
"strconv"
)
const (
emptyResponse string = "Empty result and no error occured"
)
type request struct {
ID string `json:"id"`
Version string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params"`
}
type response struct {
ID string `json:"id"`
Version string `json:"jsonrpc"`
Result *json.RawMessage `json:"result"`
Error *json.RawMessage `json:"error"`
}
type rpcError struct {
Code int64 `json:"code"`
Message string `json:"message"`
}
func (err *rpcError) decodeErrorCode() string {
switch err.Code {
case -32600:
return "ERROR_CODE_INVALID_REQUEST"
case -32603:
return "ERROR_CODE_JSON_ENCODING_FAILED"
case -32601:
return "ERROR_CODE_METHOD_NOT_FOUND"
case -32700:
return "ERROR_CODE_PARSE_ERROR"
}
return ""
}
func encodeRequest(method string, params interface{}) ([]byte, error) {
return json.Marshal(&request{
// Generate random ID and convert it to a string
ID: strconv.FormatInt(rand.Int63(), 10),
Version: "2.0",
Method: method,
Params: params,
})
}
func decodeResponse(ioReader io.Reader, reply interface{}) error {
var resp response
if err := json.NewDecoder(ioReader).Decode(&resp); err != nil {
return err
}
if resp.Error != nil {
var rpcErr rpcError
if err := json.Unmarshal(*resp.Error, &rpcErr); err != nil {
return err
}
if rpcErr.Message != "" {
return errors.New(rpcErr.Message)
}
respError := rpcErr.decodeErrorCode()
if respError != "" {
return errors.New(respError)
}
}
if resp.Result != nil && reply != nil {
return json.Unmarshal(*resp.Result, reply)
}
return errors.New(emptyResponse)
}
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
}
req, err := http.NewRequest("POST", client.url, bytes.NewBuffer(message))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(client.username, client.password)
resp, err := client.client.Do(req)
if err != nil {
return err
}
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))
if resp.StatusCode == 401 {
return errors.New("Unable to authenticate with Quobyte API service")
}
return fmt.Errorf("JsonRPC failed with error code %d", resp.StatusCode)
}
return decodeResponse(resp.Body, &response)
}

View File

@@ -1,109 +0,0 @@
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"`
Labels []Label `json:"label,omitempty"`
AccessMode uint32 `json:"access_mode,uint32,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
retryPolicy
}
type Label struct {
Name string `json:"name,string,omitempty"`
Value string `json:"value,string,omitempty"`
}
type resolveVolumeNameRequest struct {
VolumeName string `json:"volume_name,omitempty"`
TenantDomain string `json:"tenant_domain,omitempty"`
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"`
}
type getClientListRequest struct {
TenantDomain string `json:"tenant_domain,omitempty"`
retryPolicy
}
type GetClientListResponse struct {
Clients []Client `json:"client,omitempty"`
}
type Client struct {
MountedUserName string `json:"mount_user_name,omitempty"`
MountedVolumeUUID string `json:"mounted_volume_uuid,omitempty"`
}
type consumingEntity struct {
Type string `json:"type,omitempty"`
Identifier string `json:"identifier,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
}
type resource struct {
Type string `json:"type,omitempty"`
Value uint64 `json:"value,omitempty"`
}
type quota struct {
ID string `json:"id,omitempty"`
Consumer []*consumingEntity `json:"consumer,omitempty"`
Limits []*resource `json:"limits,omitempty"`
Currentusage []*resource `json:"current_usage,omitempty"`
}
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"`
}