Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoOutput = errors.New("no output")
ErrNoOutput signals that zfs did not write any output to stdout.
Functions ¶
Types ¶
type Adapter ¶
type Adapter CmdFunc
Adapter wraps the CmdFunc for a zfs executable.
func (Adapter) CreateSnapshot ¶
CreateSnapshot creates a snapshot with the name.
As described in the zfs(8) man page name must be of the format filesystem@snapname or volume@snapname. filesystem must be an existing zfs filesystem, volume an existing zfs volume. snapname will be the name of the snapshot.
func (Adapter) Destroy ¶
Destroy removes the zfs object with name.
Destroy merely calls zfs destroy. Provided all conditions for destroying an object are met, the object will be destroyed.
func (Adapter) List ¶
List returns a slice containing the names of all available zfs objects of the passed type.
List does not make any guarantees about the ordering of the names in the returned slice. In fact, callers must expect to be shuffled.
The following caveats for the various supported types apply:
FileSystem
List returns the names of all file systems in path notation. In the case of nested file systems, children are prefixed with the name of their parent file system. The topmost file system is usually the zfs pool itself. It is up to the caller to re-construct this hierarchical structure if required.
List returns an error if calling the zfs CmdFunc fails or the output could not be parsed.
type CmdFunc ¶
CmdFunc is a function that creates an *exec.Cmd.
It allows to abstract from an installed program for testing purposes.
When the Run method of the returned Cmd is called the program is executed with all args appended to its call.
args must not contain the program to execute.
func NewCmdFunc ¶
NewCmdFunc creates a new CmdFunc for the named program.
The returned CmdFunc takes the args passed to NewCmdFunc as well as the args passed to the CmdFunc itself into account.
Internally the returned CmdFunc uses exec.Command. Everything about exec.Command applies here as well.
Example ¶
package main import ( "bytes" "fmt" "log" "strings" "github.com/fhofherr/zsm/internal/zfs" ) func main() { var out bytes.Buffer cmdFunc := zfs.NewCmdFunc("tr", "a-z") cmd := cmdFunc("A-Z") cmd.Stdin = strings.NewReader("some input") cmd.Stdout = &out // Execution equivalent to // // echo "some input" | tr "a-z" "A-Z" if err := cmd.Run(); err != nil { log.Fatalf("run cmd: %v", err) } fmt.Printf("output: %q", out.String()) }
Output:
func SwallowFurtherArgs ¶
SwallowFurtherArgs returns a CmdFunc that does not pass any args it it received on to the program, but instead writes them to swallowed.
type ListType ¶
type ListType string
ListType defines the type of items the caller of List is interested in.
type TestCase ¶
type TestCase struct { Name string // Call calls the respective adapter function; should return any error // returned by the zfs adapter. May use the passed *testing.T to do further // assertions on the result of calling zsf. Call func(*testing.T, Adapter) error ZFSArgs []string // expected arguments ZFSExitCode int // expected exit code of zfs Stdin func(t *testing.T) []byte // returns stdin expected to be sent to zfs Stdout func(t *testing.T) []byte // returns stdout expected to be sent by zfs Stderr func(t *testing.T) []byte // returns stderr expected to be sent by zfs }
TestCase represents a test case for a call to the zfs adapter.