Documentation ¶
Overview ¶
go-vagrant is a golang wrapper around the vagrant command-line utility. Full documentation can be found in the README on github:
https://github.com/bmatcuk/go-vagrant
Example ¶
client, err := NewVagrantClient("example") if err != nil { fmt.Println("Got error while creating client:", err) os.Exit(-1) } // Let's start bringing up the vm upcmd := client.Up() upcmd.Verbose = true fmt.Println("Bringing up the vm") if err := upcmd.Start(); err != nil { fmt.Println("Error bringing up vm:", err) os.Exit(-1) } // while we're waiting, let's get version info vercmd := client.Version() if err := vercmd.Run(); err != nil { fmt.Println("Error retrieving version info:", err) } // now wait for up to finish if err := upcmd.Wait(); err != nil { fmt.Println("Error waiting for up:", err) os.Exit(-1) } fmt.Println("\n\nInstalled Vagrant version:", vercmd.InstalledVersion) // Get vm status statuscmd := client.Status() if err := statuscmd.Run(); err != nil { fmt.Println("Error getting status:", err) } else { for vm, status := range statuscmd.Status { fmt.Printf("%v: %v\n", vm, status) } } // Destroy vm if err := client.Destroy().Run(); err != nil { fmt.Println("Error destroying vm:", err) os.Exit(-1) }
Output:
Index ¶
- type BaseCommand
- type DestroyCommand
- type ErrorResponse
- type ForwardedPort
- type HaltCommand
- type OutputParser
- type PortCommand
- type PortResponse
- type ProvisionCommand
- type ProvisionersArgument
- type ProvisioningArgument
- type ProvisioningOption
- type ReloadCommand
- type ResumeCommand
- type SSHConfig
- type SSHConfigCommand
- type SSHConfigResponse
- type StatusCommand
- type StatusResponse
- type SuspendCommand
- type UpCommand
- type UpResponse
- type VMInfo
- type VagrantClient
- func (client *VagrantClient) Destroy() *DestroyCommand
- func (client *VagrantClient) Halt() *HaltCommand
- func (client *VagrantClient) Port() *PortCommand
- func (client *VagrantClient) Provision() *ProvisionCommand
- func (client *VagrantClient) Reload() *ReloadCommand
- func (client *VagrantClient) Resume() *ResumeCommand
- func (client *VagrantClient) SSHConfig() *SSHConfigCommand
- func (client *VagrantClient) Status() *StatusCommand
- func (client *VagrantClient) Suspend() *SuspendCommand
- func (client *VagrantClient) Up() *UpCommand
- func (client *VagrantClient) Version() *VersionCommand
- type VersionCommand
- type VersionResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCommand ¶
type BaseCommand struct { OutputParser // Context for the running command - nil means none Context context.Context // Additional arguments to pass to the command. go-vagrant attempts to define // each argument as a field on the struct, but future versions of vagrant may // add options that didn't exist at the time of authoring. You can use this // to pass options to vagrant that go-vagrant doesn't know about. AdditionalArgs []string // Env is merged with the current process's environment and passed to the // vagrant command. Each entry is a "key=value" pair with later keys taking // precedence in the case of duplicates (keys here will take precedence over // keys in the current environment, too). Env []string // The underlying process, once it has been started with Run() or Start() Process *os.Process // ProcessState contains information about the process after it has exited. // Available after Run() or Wait(). ProcessState *os.ProcessState // contains filtered or unexported fields }
Base functionality and fields for all commands constructed from the VagrantClient.
func (*BaseCommand) Start ¶
func (b *BaseCommand) Start() error
Start the command. You must call Wait() to complete execution.
func (*BaseCommand) Wait ¶
func (b *BaseCommand) Wait() error
If execution was started with Start(), you must Wait() for it to finish.
type DestroyCommand ¶
type DestroyCommand struct { BaseCommand ErrorResponse // Destroy without confirmation (defaults to true because, when false, // vagrant will try to ask for confirmation, but can't because it's running // without a TTY so it errors). Force bool // Enable parallelism if the provider supports it (automatically enables // force, default: false) Parallel bool }
A DestroyCommand specifies the options and output of vagrant destroy.
func (*DestroyCommand) Start ¶
func (cmd *DestroyCommand) Start() error
Start the command. You must call Wait() to complete execution.
type ErrorResponse ¶ added in v1.1.0
type ErrorResponse struct { // If set, there was an error while running the vagrant command. Error error }
type ForwardedPort ¶
type HaltCommand ¶
type HaltCommand struct { BaseCommand ErrorResponse // Force shutdown (equivalent to pulling the power from the machine, default: // false) Force bool }
A HaltCommand specifies the options and output of vagrant halt.
func (*HaltCommand) Start ¶
func (cmd *HaltCommand) Start() error
Start the command. You must call Wait() to complete execution.
type OutputParser ¶
type OutputParser struct { // If true, vagrant output will be echoed to stdout. Default: false Verbose bool }
type PortCommand ¶
type PortCommand struct { BaseCommand PortResponse }
PortCommand specifies the options and output of vagrant port.
func (*PortCommand) Start ¶
func (cmd *PortCommand) Start() error
Start the command. You must call Wait() to complete execution.
type PortResponse ¶
type PortResponse struct { ErrorResponse // List of forwarded ports by VM. The keys of the may are Vagrant VM names // (ex: default) and the values are arrays of ForwardedPort structs. ForwardedPorts map[string][]ForwardedPort }
type ProvisionCommand ¶
type ProvisionCommand struct { BaseCommand ErrorResponse ProvisionersArgument }
ProvisionCommand specifies the options and output of vagrant provision
func (*ProvisionCommand) Start ¶
func (cmd *ProvisionCommand) Start() error
Start the command. You must call Wait() to complete execution.
type ProvisionersArgument ¶ added in v1.1.0
type ProvisionersArgument struct { // Enabled provisioners by type or name (default: blank which means they're // all enable or disabled depending on the Provisioning flag) Provisioners []string }
Adds a Provisioners argument to a command
type ProvisioningArgument ¶ added in v1.1.0
type ProvisioningArgument struct { ProvisionersArgument // Enable or disable provisioning Provisioning ProvisioningOption }
Adds Provisioning and Provisioners arguments to a Command
type ProvisioningOption ¶ added in v1.1.0
type ProvisioningOption uint8
const ( // By default, provisioning will only run if it hasn't run already. "always" // provisioners will always run, however. DefaultProvisioning ProvisioningOption = iota // Force provisioning, even if it has already run. ForceProvisioning // Disable provisioning DisableProvisioning )
type ReloadCommand ¶
type ReloadCommand struct { BaseCommand ErrorResponse ProvisioningArgument }
ReloadCommand specifies the options and output of vagrant reload
func (*ReloadCommand) Start ¶
func (cmd *ReloadCommand) Start() error
Start the command. You must call Wait() to complete execution.
type ResumeCommand ¶ added in v1.1.0
type ResumeCommand struct { BaseCommand ErrorResponse ProvisioningArgument }
A ResumeCommand specifies the options and output of vagrant resume.
func (*ResumeCommand) Start ¶ added in v1.1.0
func (cmd *ResumeCommand) Start() error
Start the command. You must call Wait() to complete execution.
type SSHConfig ¶
type SSHConfig struct { // Any additional fields returned from the ssh-config command. AdditionalFields map[string]string // Whether or not to enable ForwardAgent - "yes" or "no" ForwardAgent string // The Host matches the vagrant machine name (ex: default) Host string // The HostName to connect to (ex: 127.0.0.1) HostName string // Whether or not to enable IdentitiesOnly - "yes" or "no" IdentitiesOnly string // Path to a private key file to use for the connection (ex: ~/.ssh/id_rsa) IdentityFile string // Level of logging to enable (ex: FATAL) LogLevel string // Whether or not to enable password authentication - "yes" or "no" PasswordAuthentication string // Port to connect to (ex: 22) Port int // Whether or not to enable StrictHostKeyChecking - "yes" or "no" StrictHostKeyChecking string // User to connect as (ex: root) User string // Path to a known hosts file (ex: /dev/null) UserKnownHostsFile string }
The fields and values in this struct match the fields and values in an SSH config file. For example, you could build a SSH config file like:
Host ... HostName ... Port ... User ... IdentityFile ...
type SSHConfigCommand ¶
type SSHConfigCommand struct { BaseCommand SSHConfigResponse // Name of a specific host to get SSH config info for. If not set, info for // all VMs will be pulled. Host string }
SSHConfigCommand specifies options and output from vagrant ssh-config
func (*SSHConfigCommand) Start ¶
func (cmd *SSHConfigCommand) Start() error
Start the command. You must call Wait() to complete execution.
type SSHConfigResponse ¶
type SSHConfigResponse struct { ErrorResponse // SSH Configs per VM. Map keys match vagrant VM names (ex: default) and // the values are configs. Configs map[string]SSHConfig }
type StatusCommand ¶
type StatusCommand struct { BaseCommand StatusResponse }
StatusCommand specifies options and output from vagrant status
func (*StatusCommand) Start ¶
func (cmd *StatusCommand) Start() error
Start the command. You must call Wait() to complete execution.
type StatusResponse ¶
type StatusResponse struct { ErrorResponse // Status per Vagrant VM. Keys are Vagrant VM names (ex: default) and values // are the status of the VM. Status map[string]string }
type SuspendCommand ¶
type SuspendCommand struct { BaseCommand ErrorResponse }
SuspendCommand specifies options and output from vagrant suspend
func (*SuspendCommand) Start ¶
func (cmd *SuspendCommand) Start() error
Start the command. You must call Wait() to complete execution.
type UpCommand ¶
type UpCommand struct { BaseCommand UpResponse ProvisioningArgument // Destroy on error (default: true) DestroyOnError bool // Enable parallel execution if the provider supports it (default: true) Parallel bool // Provider to use (default: blank which means vagrant will use the default // provider) Provider string // Install the provider if it isn't installed, if possible (default: false) InstallProvider bool }
UpCommand specifies options and output from vagrant up.
type UpResponse ¶
type UpResponse struct { ErrorResponse // Info about all of the VMs constructed by the Vagrantfile. The map keys are // vagrant VM names (ex: default) and the values are VMInfo's. VMInfo map[string]*VMInfo }
type VagrantClient ¶
type VagrantClient struct { // Directory where the Vagrantfile can be found. // // Normally this would be set by NewVagrantClient() and shouldn't // be changed afterward. VagrantfileDir string // contains filtered or unexported fields }
Library users should construct a new VagrantClient using NewVagrantClient(). From the client, vagrant commands can be constructed such as: client.Up().
func NewVagrantClient ¶
func NewVagrantClient(vagrantfileDir string) (*VagrantClient, error)
Create a new VagrantClient.
vagrantfileDir should be the path to a directory where the Vagrantfile exists.
func (*VagrantClient) Destroy ¶
func (client *VagrantClient) Destroy() *DestroyCommand
Run vagrant destroy. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) Halt ¶
func (client *VagrantClient) Halt() *HaltCommand
Run vagrant halt. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) Port ¶
func (client *VagrantClient) Port() *PortCommand
Run vagrant port. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Output will be in ForwardedPorts with any error in Error.
func (*VagrantClient) Provision ¶
func (client *VagrantClient) Provision() *ProvisionCommand
Run vagrant provision. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) Reload ¶
func (client *VagrantClient) Reload() *ReloadCommand
Run vagrant reload. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) Resume ¶ added in v1.1.0
func (client *VagrantClient) Resume() *ResumeCommand
Run vagrant resume. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) SSHConfig ¶
func (client *VagrantClient) SSHConfig() *SSHConfigCommand
Run vagrant ssh-config. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Output will be in Configs and any error will be in Error.
func (*VagrantClient) Status ¶
func (client *VagrantClient) Status() *StatusCommand
Run vagrant status. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Output will be in Status and any error will be in Error.
func (*VagrantClient) Suspend ¶
func (client *VagrantClient) Suspend() *SuspendCommand
Run vagrant suspend. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Errors will be recorded in Error.
func (*VagrantClient) Up ¶
func (client *VagrantClient) Up() *UpCommand
Run vagrant up. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Output will be in VMInfo or Error.
func (*VagrantClient) Version ¶
func (client *VagrantClient) Version() *VersionCommand
Run vagrant version. After setting options as appropriate, you must call Run() or Start() followed by Wait() to execute. Output will be in InstalledVersion and LatestVersion and any error will be in Error.
type VersionCommand ¶
type VersionCommand struct { BaseCommand VersionResponse }
VersionCommand specifies options and output from vagrant version
func (*VersionCommand) Start ¶
func (cmd *VersionCommand) Start() error
Start the command. You must call Wait() to complete execution.
type VersionResponse ¶
type VersionResponse struct { ErrorResponse // The current version InstalledVersion string // The latest version LatestVersion string }
Source Files ¶
- base_command.go
- command_destroy.go
- command_halt.go
- command_port.go
- command_port_response.go
- command_provision.go
- command_reload.go
- command_resume.go
- command_sshconfig.go
- command_sshconfig_response.go
- command_status.go
- command_status_response.go
- command_suspend.go
- command_up.go
- command_up_response.go
- command_version.go
- command_version_response.go
- doc.go
- error_response.go
- output_handler.go
- output_parser.go
- provisioners_argument.go
- provisioning_argument.go
- vagrant_client.go