mirror of
https://github.com/linuxkit/linuxkit.git
synced 2026-01-24 17:34:45 +00:00
- The tools directory ideally should not contain source code - Removes double vendoring of packagages - Makes it easer to hook the build into the top-level Makefile Eventually, the plugin should be moved to the infrakit repo. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package metadata
|
|
|
|
import (
|
|
rpc_client "github.com/docker/infrakit/pkg/rpc/client"
|
|
"github.com/docker/infrakit/pkg/spi/metadata"
|
|
"github.com/docker/infrakit/pkg/types"
|
|
)
|
|
|
|
// NewClient returns a plugin interface implementation connected to a remote plugin
|
|
func NewClient(socketPath string) (metadata.Plugin, error) {
|
|
rpcClient, err := rpc_client.New(socketPath, metadata.InterfaceSpec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &client{client: rpcClient}, nil
|
|
}
|
|
|
|
// Adapt converts a rpc client to a Metadata plugin object
|
|
func Adapt(rpcClient rpc_client.Client) metadata.Plugin {
|
|
return &client{client: rpcClient}
|
|
}
|
|
|
|
type client struct {
|
|
client rpc_client.Client
|
|
}
|
|
|
|
// List returns a list of nodes under path.
|
|
func (c client) List(path metadata.Path) ([]string, error) {
|
|
req := ListRequest{Path: path}
|
|
resp := ListResponse{}
|
|
err := c.client.Call("Metadata.List", req, &resp)
|
|
return resp.Nodes, err
|
|
}
|
|
|
|
// Get retrieves the metadata at path.
|
|
func (c client) Get(path metadata.Path) (*types.Any, error) {
|
|
req := GetRequest{Path: path}
|
|
resp := GetResponse{}
|
|
err := c.client.Call("Metadata.Get", req, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Value, err
|
|
}
|