Skip to content

iaburton/go-containerstation

Repository files navigation

containerstation

import "github.com/iaburton/containerstation"

Package containerstation implements a Go API client for QNAP's ContainerStation API found here.

http://qnap-dev.github.io/container-station-api/index.html

The package name is just 'containerstation' not go-containerstation as the url/repo implies, and importing under a shorter alias such a cstation is recommended. Please note this package is a work in progress; more endpoints, tests and comments need to be added. A licence will be added and the package opensourced as it gets closer to an initial version/release.

client_container.go client_system.go client_tls.go containerstation.go json_reflect.go json_types.go

const (
    DOCKER cType = iota + 1
    LXC
)
const (
    //TCP enum to be used with client.NetworkPort
    TCP protocol = iota
    //UDP enum to be used with client.NetworkPort
    UDP
)
type Client struct {
    // contains filtered or unexported fields
}

Client is the type that implements the Container Station client v1 API found here http://qnap-dev.github.io/container-station-api/system.html. Testing has noted differences between what the API document says and the types returned by the various endpoints.

func NewClient(baseURL string, hc *http.Client) Client

NewClient returns a newly initialized Client using hc as the underlying http client and baseURL for requests. If hc is nil than a new http client is created using similar defaults as the http.DefaultClient but with a CookieJar. Note that it does not use the http.DefaultClient and hc must have a CookieJar set, or one will be set.

func (c Client) DownloadTLSCertificate(ctx context.Context, file string, perm os.FileMode) (err error)
func (c Client) ExportTLSCertificate(ctx context.Context, w io.Writer) error
func (c Client) GetContainer(ctx context.Context, ctype cType, id string) (*Container, error)
func (c Client) ListContainers(ctx context.Context) ([]*Container, error)

func (Client) Login

func (c Client) Login(ctx context.Context, user, pass string) (*LoginResponse, error)

Login authenticates the Client with the NAS and should normally be run before other methods. It takes a context for http request propagation, as well as the username and password of the account with access to Container Station.

func (c Client) LoginRefresh(ctx context.Context) (*LoginResponse, error)

LoginRefresh presumably refreshes the session belonging to this Client. Unfortunately the Container Station API docs don't explicitly state what this does, when or how often it should be called.

func (Client) Logout

func (c Client) Logout(ctx context.Context) (*LogoutResponse, error)

Logout invalidates the session of the Client with the NAS if it has one. It should be called when work with the Client is finished.

func (Client) NetworkPort

func (c Client) NetworkPort(ctx context.Context, proto protocol, port int) (bool, error)

NetworkPort reports whether or not a given protocol and port are being used. Protocol must be one of TCP or UDP constants defined in this package. If an invalid protocol or port is set an error is returned.

func (c Client) RemoveContainer(ctx context.Context, ctype cType, id string) (*Container, error)

TODO mention nil error and "zero" value Container struct on success

func (c Client) ResourceUsage(ctx context.Context) (*ResourceUsage, error)

ResourceUsage returns resource usage information on the system that is running container station.

func (c Client) RestartContainer(ctx context.Context, ctype cType, id string) (*Container, error)
func (c Client) StartContainer(ctx context.Context, ctype cType, id string) (*Container, error)
func (c Client) StopContainer(ctx context.Context, ctype cType, id string) (*Container, error)
func (c Client) SystemInformation(ctx context.Context) (*SystemInformation, error)

SystemInformation returns information on the system that is running container station.

type Container struct {
    CPU       float64  `json:"cpu"`
    ID        string   `json:"id"`
    Image     string   `json:"image"`
    ImageID   string   `json:"imageID"`
    Ipaddress []string `json:"ipaddress"`
    Memory    int      `json:"memory"`
    Name      string   `json:"name"`
    Rx        int      `json:"rx"`
    State     string   `json:"state"`
    TCPPort   []int    `json:"tcpPort"`
    Tx        int      `json:"tx"`
    Type      cType    `json:"type"`
}

Container is the JSON returned when getting basic information on a container or list of containers.

type LoginResponse struct {
    Anonymous bool   `json:"anonymous"`
    IsAdmin   bool   `json:"isAdmin"`
    Time      string `json:"loginime"`
    Username  string `json:"username"`
}

LoginResponse is the JSON returned for a login or login refresh.

type LogoutResponse struct {
    Username string `json:"username"`
}

LogoutResponse is the JSON returned for a logout request.

type ResourceUsage struct {
    CPU    string `json:"cpu_usage"`
    Memory struct {
        Buffers        int `json:"buffers"`
        Cached         int `json:"cached"`
        Percent        int `json:"percent"`
        PercentBuffers int `json:"percent_buffers"`
        PercentCached  int `json:"percent_cached"`
        Total          int `json:"total"`
        Used           int `json:"used"`
    } `json:"memory_usage"`
}

ResourceUsage is the JSON returned for a resource usage request.

type SystemInformation struct {
    CPUCore   int      `json:"cpuCore"`
    CPUThread int      `json:"cpuThread"`
    Features  []string `json:"features"`
    Gpu       struct {
        CsMode          bool          `json:"cs_mode"`
        Device          []interface{} `json:"device"`
        DriverInstalled bool          `json:"driver_installed"`
    } `json:"gpu"`
    GpuDriver   bool   `json:"gpuDriver"`
    Hostname    string `json:"hostname"`
    Machine     string `json:"machine"`
    NeedRestart bool   `json:"needRestart"`
    Processor   string `json:"processor"`
    Status      string `json:"status"`
    Version     struct {
        DockerVersion string `json:"dockerVersion"`
        Firmware      string `json:"firmware"`
        LxcVersion    string `json:"lxcVersion"`
        Qpkg          string `json:"qpkg"`
        Web           string `json:"web"`
    } `json:"version"`
}

SystemInformation is the JSON returned for a system information request.


Generated by godoc2md

About

A Go API client for QNAP's Container Station.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages