From 79ec523e3f28cee252e734babeacb315f2741668 Mon Sep 17 00:00:00 2001 From: Silvan Kaiser Date: Thu, 14 Dec 2017 13:45:21 +0100 Subject: [PATCH] Added configuration_name, tenant_id and retry RPC parameters This fixes rpc issues by adding configuration_name and tenant_id parameters to the createVolume rpc. Furthermore the retry parameter is set in all rpc calls for improved robustness. This also updates the Readme file to the current state. --- README.md | 28 ++++++++++++++------- main.go | 4 ++- quobyte_driver.go | 22 +++++++++++++--- systemd/docker-quobyte-plugin.service | 6 ++--- vendor/github.com/quobyte/api/rpc_client.go | 2 ++ vendor/github.com/quobyte/api/types.go | 3 +++ 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 12d50ed..7960d7a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ tar xfz docker-quobyte-plugin.tar.gz ### Create a user in Quobyte for the plug-in: -This step is optional. +This step is optional and should only be used if Quobytes build-in user database is used. ``` $ qmgmt -u user config add docker @@ -51,21 +51,31 @@ $ systemctl status docker-quobyte-plugin ``` $ bin/docker-quobyte-plugin -h -Usage of /opt/bin/docker-quobyte-plugin: +Usage of docker-quobyte-plugin: -api string - URL to the API server(s) in the form http(s)://host[:port][,host:port] or SRV record name (default "http://localhost:7860") + URL to the API server(s) in the form http(s)://host[:port][,host:port] or SRV record name (default "http://localhost:7860") + -configuration_name string + Name of the volume configuration of new volumes (default "BASE") -group string - Group to create the unix socket (default "root") + Group to create the unix socket (default "root") + -max-fs-checks int + Maximimum number of filesystem checks when a Volume is created before returning an error (default 5) + -max-wait-time float + Maximimum wait time for filesystem checks to complete when a Volume is created before returning an error (default 30) -options string - Fuse options to be used when Quobyte is mounted (default "-o user_xattr") + Fuse options to be used when Quobyte is mounted (default "-o user_xattr") -password string - Password for the user to connect to the Quobyte API server (default "quobyte") + Password for the user to connect to the Quobyte API server (default "quobyte") -path string - Path where Quobyte is mounted on the host (default "/run/docker/quobyte/mnt") + Path where Quobyte is mounted on the host (default "/run/docker/quobyte/mnt") -registry string - URL to the registry server(s) in the form of host[:port][,host:port] or SRV record name (default "localhost:7861") + URL to the registry server(s) in the form of host[:port][,host:port] or SRV record name (default "localhost:7861") + -tenant_id string + Id of the Quobyte tenant in whose domain the operation takes place (default "default") -user string - User to connect to the Quobyte API server (default "root") + User to connect to the Quobyte API server (default "root") + -version + Shows version string ``` ## Examples diff --git a/main.go b/main.go index 3ef1de2..4e3c9eb 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,10 @@ func main() { quobyteUser := flag.String("user", "root", "User to connect to the Quobyte API server") quobytePassword := flag.String("password", "quobyte", "Password for the user to connect to the Quobyte API server") + quobyteConfigName := flag.String("configuration_name", "BASE", "Name of the volume configuration of new volumes") quobyteAPIURL := flag.String("api", "http://localhost:7860", "URL to the API server(s) in the form http(s)://host[:port][,host:port] or SRV record name") quobyteRegistry := flag.String("registry", "localhost:7861", "URL to the registry server(s) in the form of host[:port][,host:port] or SRV record name") + quobyteTenantId := flag.String("tenant_id", "default", "Id of the Quobyte tenant in whose domain the operation takes place") group := flag.String("group", "root", "Group to create the unix socket") maxWaitTime := flag.Float64("max-wait-time", 30, "Maximimum wait time for filesystem checks to complete when a Volume is created before returning an error") @@ -48,7 +50,7 @@ func main() { mountAll(*quobyteMountOptions, *quobyteRegistry, *quobyteMountPath) } - qDriver := newQuobyteDriver(*quobyteAPIURL, *quobyteUser, *quobytePassword, *quobyteMountPath, *maxFSChecks, *maxWaitTime) + qDriver := newQuobyteDriver(*quobyteAPIURL, *quobyteUser, *quobytePassword, *quobyteMountPath, *maxFSChecks, *maxWaitTime, *quobyteConfigName, *quobyteTenantId) handler := volume.NewHandler(qDriver) log.Println(handler.ServeUnix(*group, quobyteID)) diff --git a/quobyte_driver.go b/quobyte_driver.go index e445a2b..f6a8ca6 100644 --- a/quobyte_driver.go +++ b/quobyte_driver.go @@ -22,7 +22,7 @@ type quobyteDriver struct { maxWaitTime float64 } -func newQuobyteDriver(apiURL string, username string, password string, quobyteMount string, maxFSChecks int, maxWaitTime float64) quobyteDriver { +func newQuobyteDriver(apiURL string, username string, password string, quobyteMount string, maxFSChecks int, maxWaitTime float64, configName string, tenantId string) quobyteDriver { driver := quobyteDriver{ client: quobyte_api.NewQuobyteClient(apiURL, username, password), quobyteMount: quobyteMount, @@ -40,6 +40,9 @@ func (driver quobyteDriver) Create(request volume.Request) volume.Response { defer driver.m.Unlock() user, group := "root", "root" + configuration_name := "BASE" + retry_policy := "INTERACTIVE" + tenant_id := "default" if usr, ok := request.Options["user"]; ok { user = usr @@ -49,10 +52,21 @@ func (driver quobyteDriver) Create(request volume.Request) volume.Response { group = grp } + if conf, ok := request.Options["configuration_name"]; ok { + configuration_name = conf + } + + if tenant, ok := request.Options["tenant_id"]; ok { + tenant_id = tenant + } + if _, err := driver.client.CreateVolume(&quobyte_api.CreateVolumeRequest{ - Name: request.Name, - RootUserID: user, - RootGroupID: group, + Name: request.Name, + RootUserID: user, + RootGroupID: group, + ConfigurationName: configuration_name, + TenantID: tenant_id, + Retry: retry_policy, }); err != nil { log.Println(err) diff --git a/systemd/docker-quobyte-plugin.service b/systemd/docker-quobyte-plugin.service index f69c721..d58d6c7 100644 --- a/systemd/docker-quobyte-plugin.service +++ b/systemd/docker-quobyte-plugin.service @@ -1,13 +1,13 @@ [Unit] Description=Docker Quobyte Plugin -Documentation=https://github.com/johscheuer/go-quobyte-docker -Before=docker.service +Documentation=https://github.com/quobyte/docker-volume + After=network.target docker.service Requires=docker.service [Service] EnvironmentFile=/etc/quobyte/docker-quobyte.env -ExecStart=/usr/local/bin/docker-quobyte-plugin --user ${QUOBYTE_API_USER} --password ${QUOBYTE_API_PASSWORD} --api ${QUOBYTE_API_URL} --registry ${QUOBYTE_REGISTRY} +ExecStart=/usr/local/bin/docker-quobyte-plugin --user ${QUOBYTE_API_USER} --password ${QUOBYTE_API_PASSWORD} --api ${QUOBYTE_API_URL} --registry ${QUOBYTE_REGISTRY} --configuration_name ${QUOBYTE_CONFIGURATION_NAME} [Install] WantedBy=multi-user.target diff --git a/vendor/github.com/quobyte/api/rpc_client.go b/vendor/github.com/quobyte/api/rpc_client.go index 7c7326c..a538b5e 100644 --- a/vendor/github.com/quobyte/api/rpc_client.go +++ b/vendor/github.com/quobyte/api/rpc_client.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io" "math/rand" "net/http" @@ -92,6 +93,7 @@ func (client QuobyteClient) sendRequest(method string, request interface{}, resp if err != nil { return err } + fmt.Printf("Sending JsonRPC message: %[1]s \n", message) req, err := http.NewRequest("POST", client.url, bytes.NewBuffer(message)) if err != nil { return err diff --git a/vendor/github.com/quobyte/api/types.go b/vendor/github.com/quobyte/api/types.go index 2ed5698..99931f9 100644 --- a/vendor/github.com/quobyte/api/types.go +++ b/vendor/github.com/quobyte/api/types.go @@ -9,11 +9,13 @@ type CreateVolumeRequest struct { ConfigurationName string `json:"configuration_name,omitempty"` AccessMode uint32 `json:"access_mode,string,omitempty"` TenantID string `json:"tenant_id,omitempty"` + Retry string `json:"retry,omitempty"` } type resolveVolumeNameRequest struct { VolumeName string `json:"volume_name,omitempty"` TenantDomain string `json:"tenant_domain,omitempty"` + Retry string `json:"retry,omitempty"` } type volumeUUID struct { @@ -22,6 +24,7 @@ type volumeUUID struct { type getClientListRequest struct { TenantDomain string `json:"tenant_domain,omitempty"` + Retry string `json:"retry,omitempty"` } type GetClientListResponse struct {