zfsd

package module
v0.0.0-...-f91f418 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2014 License: Apache-2.0 Imports: 4 Imported by: 0

README

zfsd

Simple HTTP interface for ZFS.

Needs a new name as the name "zfsd" is already in us by at least one other project.

After struggling with working with ZFS in various languages, a few of us said "it would be nice if there was an HTTP interface that worked across all supported platform." That was a few months ago and we never did anything about it. So, I decided to start this in the hope others had the same itch.

Current Plan

  • HTTP API for common ZFS tasks, including snapshots and clones.
  • endpoints for gathering metrics
  • Just listen on a unix socket for now and use file permissions.
  • Write it in Go. I like being able to deploy a single binary. I don't have strong feelings about this, however.

Future

  • Add real AAA

RPC

This branch includes some initial playing using JSON-RPC. Why JSON-RPC? I used this on a project and it was very easy thanks to the Gorilla package. Also, ZFS names are "filepath like" so doing them in a traditional REST way is a little interesting. Imagine a path like POST /my/zfs/snapshot/has/a/long/name@mysnapshot. You could do this by passing query strings or form values, but then you may as well parse json, and the Gorilla libraries do that very well. It is easy enough to add a REST veneer to the calls here, so I'll continue experiementing using JSON-RPC. Perhaps we can just do both?

Examples

If you just use the provisioning done in the Vagrantfile:

List
curl --compressed -H "Content-Type: application/json" \
-X POST -sv http://localhost:9373/_zfs_ \
--data-binary '{"id": 1, "params": [], "method": "ZFS.List" }'

Output snippet:


  "result": [
    {
      "name": "testing",
      "used": 568040,
      "available": 8389991704,
      "mountpoint": "/testing",
      "compression": "lz4",
      "type": "filesystem",
      "written": 50716
    },
    {
      "name": "testing/A",
      "used": 45808,
      "available": 8389991704,
      "mountpoint": "/testing/A",
      "compression": "lz4",
      "type": "filesystem"
    },

You can also "filter" results to a specific prefix or type. To just get snapshots in testing/A, do:

curl --compressed -H "Content-Type: application/json" \
-X POST -sv http://localhost:9373/_zfs_ \
--data-binary '{"id": 1, "params": [{"type":"snapshot", "prefix": "testing/A"} ],"method": "ZFS.List" }'
Create Snapshot
curl --compressed -H "Content-Type: application/json" \
-X POST -sv http://localhost:9373/_zfs_ \
--data-binary '{"id": 1, "params":[{"name": "testing/A", "snapshot": "987654321"}], "method":"ZFS.Snapshot" }'

Output:

{
  "result": {
    "name": "testing/A@987654321",
    "type": "snapshot"
  },
  "error": null,
  "id": 1
}
Clone Snapshot
curl --compressed -H "Content-Type: application/json" \
-X POST -sv http://localhost:9373/_zfs_ \
--data-binary '{"id": 1, "params":[{"name": "testing/A", "snapshot": "987654321", "target": "testing/baz"}],"method": "ZFS.Clone" }'

Output:

{
  "result": {
    "name": "testing/baz",
    "used": 1636,
    "available": 8389955712,
    "mountpoint": "/testing/baz",
    "compression": "lz4",
    "type": "filesystem",
    "written": 1636,
    "origin": "testing/A@987654321"
  },
  "error": null,
  "id": 1
  }

Documentation

Overview

Package zfsd implements a simple HTTP interface for zfs management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloneRequest

type CloneRequest struct {
	Name       string            `json:"name"`
	Snapshot   string            `json:"snapshot"`
	Target     string            `json:"target"`
	Properties map[string]string `json:"properties,omitempty"`
}

CloneRequest is used to clone a ZFS snapshot

type DestroyRequest

type DestroyRequest struct {
	Name      string `json:"name"`
	Recursive bool   `json:"recursive"`
}

DestroyRequest is used to destroy a ZFS dataset

type GetRequest

type GetRequest struct {
	Name string `json:"name"`
}

GetRequest is used to get a single ZFS dataset

type ListRequest

type ListRequest struct {
	Type   string `json:"type"`
	Prefix string `json:"prefix"`
}

ListRequest is used to list ZFS datasets

type RollbackRequest

type RollbackRequest struct {
	Name      string `json:"name"`
	Snapshot  string `json:"snapshot"`
	Recursive bool   `json:"recursive"`
}

RollbackRequest is used to rollback a ZFS snapshot

type SetRequest

type SetRequest struct {
	Name       string            `json:"name"`
	Properties map[string]string `json:"properties,omitempty"`
}

SetRequest is used to set properties on a ZFS dataset

type SnapshotRequest

type SnapshotRequest struct {
	Name     string `json:"name"`
	Snapshot string `json:"snapshot"`
}

SnapshotRequest is used to create a ZFS snapshot

type ZFS

type ZFS struct {
}

ZFS is used for RPC services

func (*ZFS) Clone

func (z *ZFS) Clone(r *http.Request, req *CloneRequest, resp *zfs.Dataset) error

Clone clones a ZFS snapshot

func (*ZFS) Destroy

func (z *ZFS) Destroy(r *http.Request, req *DestroyRequest, resp *zfs.Dataset) error

Destroy removes a ZFS dataset

func (*ZFS) Get

func (z *ZFS) Get(r *http.Request, req *GetRequest, resp *zfs.Dataset) error

Get retrieves a single ZFS dataset.

func (*ZFS) List

func (z *ZFS) List(r *http.Request, req *ListRequest, resp *[]*zfs.Dataset) error

List retrieves a list of all ZFS datasets, optionally only of a certain type or prefix

func (*ZFS) Rollback

func (z *ZFS) Rollback(r *http.Request, req *RollbackRequest, resp *zfs.Dataset) error

Rollback rolls the given dataset to back a previous snapshot.

func (*ZFS) Set

func (z *ZFS) Set(r *http.Request, req *SetRequest, resp *zfs.Dataset) error

Set sets properties on a ZFS dataset.

func (*ZFS) Snapshot

func (z *ZFS) Snapshot(r *http.Request, req *SnapshotRequest, resp *zfs.Dataset) error

Snapshot creates a snapshot of a ZFS dataset.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL