Skip to content

Instantly share code, notes, and snippets.

@aravindavk
Last active August 31, 2017 08:21
Show Gist options
  • Save aravindavk/bacfa3e7bdf15e63e431b650048607f0 to your computer and use it in GitHub Desktop.
Save aravindavk/bacfa3e7bdf15e63e431b650048607f0 to your computer and use it in GitHub Desktop.
Glusterd2 CLI and Plugin

Gd2 exposes REST APIs and CLI is one consumer of these APIs.

+------------+                                          +--------------------+
|    gd2     |------REST APIs---------------------------| restclient --- CLI |
+------------+                                          +--------------------+

restclient is a Go library available in github.com/gluster/glusterd2/pkg/restclient

To add a CLI subcommand,

  • Make sure REST API is available for that task from gd2. For example, POST /v1/peers to probe a peer
  • Add entry in restclient pkg to interact with respective REST API Example, PeerProbe() function in $SRC/pkg/restclient/peer.go
  • Consume restclient function from CLI code. Example in $SRC/cli/cmd/peer.go

To test, run make cli in $SRC which will generate a binary in $SRC/build directory.

cd build
./glustercli peer probe hostname
./glustercli --help
./glustercli peer --help

Initialize plugin code using the tool available in scripts directory.

./scripts/new-gd2-plugin.py <plugin-dir> <plugin-name>

Example,

./scripts/new-gd2-plugin.py plugins quota

This will create two files and adds necessory details to $SRC/plugins/plugins.go file. You can see the changes using git status command.

$SRC/plugins/
    - quota/
        - init.go
          rest.go

Build gd2 and check the newly added plugin using curl command.

cd $SRC
make
cd ./build
sudo ./glusterd2

To check plugin, run

curl -i -XGET http://localhost:24007/v1/quota/help

Reference plugins:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment