commands

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2015 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package commands contains the workflows behind each commands of the CLI (run, attach, start, exec, commit, ...)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSSHKeyToTags

func AddSSHKeyToTags(ctx CommandContext, tags *[]string, image string) error

AddSSHKeyToTags adds the ssh key in the tags

func Run

func Run(ctx CommandContext, args RunArgs) error

Run is the handler for 'scw run'

Example
ctx := testCommandContext()
args := RunArgs{
	Image: "ubuntu-trusuty",
}
Run(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := RunArgs{
	Attach:     false,
	Bootscript: "rescue",
	Command:    []string{"ls", "-la"},
	Detach:     false,
	Gateway:    "my-gateway",
	Image:      "ubuntu-trusty",
	Name:       "my-test-server",
	Tags:       []string{"testing", "fake"},
	Volumes:    []string{"50G", "1G"},
}
Run(ctx, args)
Output:

func RunAttach

func RunAttach(ctx CommandContext, args AttachArgs) error

RunAttach is the handler for 'scw attach'

func RunCommit

func RunCommit(ctx CommandContext, args CommitArgs) error

RunCommit is the handler for 'scw commit'

func RunCp

func RunCp(ctx CommandContext, args CpArgs) error

RunCp is the handler for 'scw cp'

func RunCreate

func RunCreate(ctx CommandContext, args CreateArgs) error

RunCreate is the handler for 'scw create'

Example
ctx := testCommandContext()
args := CreateArgs{}
RunCreate(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := CreateArgs{
	Name:       "test",
	Bootscript: "rescue",
	Tags:       []string{"tag1", "tag2"},
	Volumes:    []string{},
	Image:      "ubuntu-vivid",
	TmpSSHKey:  false,
}
RunCreate(ctx, args)
Output:

func RunEvents

func RunEvents(ctx CommandContext, args EventsArgs) error

RunEvents is the handler for 'scw events'

func RunExec

func RunExec(ctx CommandContext, args ExecArgs) error

RunExec is the handler for 'scw exec'

func RunHistory

func RunHistory(ctx CommandContext, args HistoryArgs) error

RunHistory is the handler for 'scw history'

Example
ctx := testCommandContext()
args := HistoryArgs{}
RunHistory(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := HistoryArgs{
	NoTrunc: false,
	Quiet:   false,
	Image:   "",
}
RunHistory(ctx, args)
Output:

func RunImages

func RunImages(ctx CommandContext, args ImagesArgs) error

RunImages is the handler for 'scw images'

Example
ctx := testCommandContext()
args := ImagesArgs{}
RunImages(ctx, args)
Output:

Example (All)
ctx := testCommandContext()
args := ImagesArgs{
	All:     true,
	NoTrunc: false,
	Quiet:   false,
}
RunImages(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := ImagesArgs{
	All:     false,
	NoTrunc: false,
	Quiet:   false,
}
RunImages(ctx, args)
Output:

Example (Notrunc)
ctx := testCommandContext()
args := ImagesArgs{
	All:     false,
	NoTrunc: true,
	Quiet:   false,
}
RunImages(ctx, args)
Output:

Example (Quiet)
ctx := testCommandContext()
args := ImagesArgs{
	All:     false,
	NoTrunc: false,
	Quiet:   true,
}
RunImages(ctx, args)
Output:

func RunInfo

func RunInfo(ctx CommandContext, args InfoArgs) error

RunInfo is the handler for 'scw info'

func RunInspect

func RunInspect(ctx CommandContext, args InspectArgs) error

RunInspect is the handler for 'scw inspect'

Example
ctx := testCommandContext()
args := InspectArgs{}
RunInspect(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := InspectArgs{
	Format:      "",
	Browser:     false,
	Identifiers: []string{},
}
RunInspect(ctx, args)
Output:

func RunKill

func RunKill(ctx CommandContext, args KillArgs) error

RunKill is the handler for 'scw kill'

func RunLogin

func RunLogin(ctx CommandContext, args LoginArgs) error

RunLogin is the handler for 'scw login'

func RunLogout

func RunLogout(ctx CommandContext, args LogoutArgs) error

RunLogout is the handler for 'scw logout'

func RunLogs

func RunLogs(ctx CommandContext, args LogsArgs) error

RunLogs is the handler for 'scw logs'

func RunPort

func RunPort(ctx CommandContext, args PortArgs) error

RunPort is the handler for 'scw port'

func RunPs

func RunPs(ctx CommandContext, args PsArgs) error

RunPs is the handler for 'scw ps'

func RunRename

func RunRename(ctx CommandContext, args RenameArgs) error

RunRename is the handler for 'scw rename'

func RunRestart

func RunRestart(ctx CommandContext, args RestartArgs) error

RunRestart is the handler for 'scw restart'

func RunRm

func RunRm(ctx CommandContext, args RmArgs) error

RunRm is the handler for 'scw rm'

func RunRmi

func RunRmi(ctx CommandContext, args RmiArgs) error

RunRmi is the handler for 'scw rmi'

func RunSearch

func RunSearch(ctx CommandContext, args SearchArgs) error

RunSearch is the handler for 'scw search'

Example
ctx := testCommandContext()
args := SearchArgs{}
RunSearch(ctx, args)
Output:

Example (Complex)
ctx := testCommandContext()
args := SearchArgs{
	Term:    "",
	NoTrunc: false,
}
RunSearch(ctx, args)
Output:

func RunStart

func RunStart(ctx CommandContext, args StartArgs) error

RunStart is the handler for 'scw start'

func RunStop

func RunStop(ctx CommandContext, args StopArgs) error

RunStop is the handler for 'scw stop'

func RunTag

func RunTag(ctx CommandContext, args TagArgs) error

RunTag is the handler for 'scw tag'

func RunTop

func RunTop(ctx CommandContext, args TopArgs) error

RunTop is the handler for 'scw top'

func RunWait

func RunWait(ctx CommandContext, args WaitArgs) error

RunWait is the handler for 'scw wait'

func TarFromSource

func TarFromSource(ctx CommandContext, source string, gateway string) (*io.ReadCloser, error)

TarFromSource creates a stream buffer with the tarballed content of the user source

func UntarToDest

func UntarToDest(ctx CommandContext, sourceStream *io.ReadCloser, destination string, gateway string) error

UntarToDest writes to user destination the streamed tarball in input

func Version

func Version(ctx CommandContext, args VersionArgs) error

Version is the handler for 'scw version'

Example
ctx := testCommandContext()
args := VersionArgs{}
Version(ctx, args)
Output:

Types

type AttachArgs

type AttachArgs struct {
	NoStdin bool
	Server  string
}

AttachArgs are flags for the `RunAttach` function

type CommandContext

type CommandContext struct {
	Streams

	Env     []string
	RawArgs []string
	API     *api.ScalewayAPI
}

CommandContext is passed to all commands and contains streams, environment, api and arguments

Example
apiClient, err := api.NewScalewayAPI("https://example.org/", "https://example.org/", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
if err != nil {
	panic(err)
}

ctx := CommandContext{
	Streams: Streams{
		Stdin:  os.Stdin,
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	},
	Env: []string{
		"HOME" + os.Getenv("HOME"),
	},
	RawArgs: []string{},
	API:     apiClient,
}

// Do stuff
fmt.Println(ctx)
Output:

func RealAPIContext

func RealAPIContext() *CommandContext

func (*CommandContext) Getenv

func (c *CommandContext) Getenv(key string) string

Getenv returns the equivalent of os.Getenv for the CommandContext.Env

type CommitArgs

type CommitArgs struct {
	Volume int
	Server string
	Name   string
}

CommitArgs are flags for the `RunCommit` function

type CpArgs

type CpArgs struct {
	Gateway     string
	Source      string
	Destination string
}

CpArgs are arguments passed to `RunCp`

type CreateArgs

type CreateArgs struct {
	Name       string
	Bootscript string
	Tags       []string
	Volumes    []string
	Image      string
	TmpSSHKey  bool
	IP         string
}

CreateArgs are arguments passed to `RunCreate`

type EventsArgs

type EventsArgs struct{}

EventsArgs are arguments passed to `RunEvents`

type ExecArgs

type ExecArgs struct {
	Timeout float64
	Wait    bool
	Gateway string
	Server  string
	Command []string
}

ExecArgs are flags for the `RunExec` function

type HistoryArgs

type HistoryArgs struct {
	NoTrunc bool
	Quiet   bool
	Image   string
}

HistoryArgs are flags for the `RunHistory` function

type ImagesArgs

type ImagesArgs struct {
	All     bool
	NoTrunc bool
	Quiet   bool
	Filters map[string]string
}

ImagesArgs are flags for the `RunImages` function

type InfoArgs

type InfoArgs struct{}

InfoArgs are flags for the `RunInfo` function

type InspectArgs

type InspectArgs struct {
	Format      string
	Browser     bool
	Identifiers []string
}

InspectArgs are flags for the `RunInspect` function

type KillArgs

type KillArgs struct {
	Gateway string
	Server  string
}

KillArgs are flags for the `RunKill` function

type LoginArgs

type LoginArgs struct {
	Organization string
	Token        string
	SSHKey       string
	SkipSSHKey   bool
}

LoginArgs are arguments passed to `RunLogin`

type LogoutArgs

type LogoutArgs struct{}

LogoutArgs are flags for the `RunLogout` function

type LogsArgs

type LogsArgs struct {
	Gateway string
	Server  string
}

LogsArgs are flags for the `RunLogs` function

type PortArgs

type PortArgs struct {
	Gateway string
	Server  string
}

PortArgs are flags for the `RunPort` function

type PsArgs

type PsArgs struct {
	All     bool
	Latest  bool
	NLast   int
	NoTrunc bool
	Quiet   bool
	Filters map[string]string
}

PsArgs are flags for the `RunPs` function

type RenameArgs

type RenameArgs struct {
	Server  string
	NewName string
}

RenameArgs are flags for the `RunRename` function

type RestartArgs

type RestartArgs struct {
	Wait    bool
	Timeout float64
	Servers []string
}

RestartArgs are flags for the `RunRestart` function

type RmArgs

type RmArgs struct {
	Servers []string
	Force   bool
}

RmArgs are flags for the `RunRm` function

type RmiArgs

type RmiArgs struct {
	Images []string
}

RmiArgs are flags for the `RunRmi` function

type RunArgs

type RunArgs struct {
	Attach     bool
	Bootscript string
	Command    []string
	Detach     bool
	Gateway    string
	Image      string
	Name       string
	IP         string
	Tags       []string
	Volumes    []string
	AutoRemove bool
	TmpSSHKey  bool
	ShowBoot   bool
}

RunArgs are flags for the `Run` function

type SearchArgs

type SearchArgs struct {
	Term    string
	NoTrunc bool
}

SearchArgs are flags for the `RunSearch` function

type StartArgs

type StartArgs struct {
	Servers []string
	Wait    bool
	Timeout float64
}

StartArgs are flags for the `RunStart` function

type StopArgs

type StopArgs struct {
	Terminate bool
	Wait      bool
	Servers   []string
}

StopArgs are flags for the `RunStop` function

type Streams

type Streams struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Streams is used to redirects the streams

type TagArgs

type TagArgs struct {
	Snapshot   string
	Bootscript string
	Name       string
}

TagArgs are flags for the `RunTag` function

type TopArgs

type TopArgs struct {
	Server  string
	Gateway string
}

TopArgs are flags for the `RunTop` function

type VersionArgs

type VersionArgs struct{}

VersionArgs are flags for the `RunVersion` function

type WaitArgs

type WaitArgs struct {
	Servers []string
}

WaitArgs are flags for the `RunWait` function

Jump to

Keyboard shortcuts

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