add AuthorizePort and DeauthorizePort

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-03-09 10:50:48 -04:00
parent ae439188a0
commit b8ef936e90
No known key found for this signature in database
GPG Key ID: A519480096146526
2 changed files with 29 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import (
"io/ioutil"
"net/url"
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
@ -65,6 +65,7 @@ type Driver struct {
SwarmDiscovery string
storePath string
keyPath string
sshPort int
}
type CreateFlags struct {
@ -413,6 +414,19 @@ func (d *Driver) GetState() (state.State, error) {
return state.None, nil
}
func (d *Driver) GetSSHAddress() (string, error) {
// TODO: use @nathanleclaire retry func here (ehazlett)
return d.GetIP()
}
func (d *Driver) GetSSHPort() (int, error) {
return d.sshPort, nil
}
func (d *Driver) GetSSHUsername() string {
return "ubuntu"
}
func (d *Driver) Start() error {
if err := d.getClient().StartInstance(d.InstanceId); err != nil {
return err
@ -509,7 +523,7 @@ func (d *Driver) Upgrade() error {
}
func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) {
return ssh.GetSSHCommand(d.IPAddress, 22, "ubuntu", d.sshKeyPath(), args...), nil
return ssh.GetSSHCommand(d.IPAddress, d.GetSSHPort(), "ubuntu", d.sshKeyPath(), args...), nil
}
func (d *Driver) getClient() *amz.EC2 {
@ -517,8 +531,8 @@ func (d *Driver) getClient() *amz.EC2 {
return amz.NewEC2(auth, d.Region)
}
func (d *Driver) sshKeyPath() string {
return path.Join(d.storePath, "id_rsa")
func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) publicSSHKeyPath() string {

View File

@ -9,19 +9,27 @@ import (
"github.com/docker/machine/state"
)
type Port struct {
Protocol string
Port int
}
// Driver defines how a host is created and controlled. Different types of
// driver represent different ways hosts can be created (e.g. different
// hypervisors, different cloud providers)
type Driver interface {
// AuthorizePort authorizes a port for machine access
AuthorizePort(port Port) error
// Create a host using the driver's config
Create() error
// DeauthorizePort removes a port for machine access
DeauthorizePort(port Port) error
// DriverName returns the name of the driver as it is registered
DriverName() string
// GetDockerPort returns the port specified for Docker
GetDockerPort() int
// GetIP returns an IP or hostname that this host is available at
// e.g. 1.2.3.4 or docker-host-d60b70a14d3a.cloudapp.net
GetIP() (string, error)