initial work to get amazonec2 and none drivers to upgrade driver interface

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-03-09 12:50:40 -04:00
parent e43da502f3
commit 0577f66f5d
No known key found for this signature in database
GPG Key ID: A519480096146526
2 changed files with 49 additions and 84 deletions

View File

@ -7,7 +7,6 @@ import (
"io"
"io/ioutil"
"net/url"
"os/exec"
"path/filepath"
"strconv"
"strings"
@ -16,6 +15,7 @@ import (
"github.com/codegangsta/cli"
"github.com/docker/machine/drivers"
"github.com/docker/machine/drivers/amazonec2/amz"
"github.com/docker/machine/hypervisor"
"github.com/docker/machine/ssh"
"github.com/docker/machine/state"
"github.com/docker/machine/utils"
@ -27,7 +27,6 @@ const (
defaultInstanceType = "t2.micro"
defaultRootSize = 16
ipRange = "0.0.0.0/0"
dockerConfigDir = "/etc/docker"
machineSecurityGroupName = "docker-machine"
)
@ -65,7 +64,7 @@ type Driver struct {
SwarmDiscovery string
storePath string
keyPath string
sshPort int
SSHPort int
}
type CreateFlags struct {
@ -162,7 +161,25 @@ func GetCreateFlags() []cli.Flag {
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
id := generateId()
return &Driver{Id: id, MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil
return &Driver{
Id: id,
MachineName: machineName,
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil
}
func (d *Driver) GetHypervisorType() hypervisor.HypervisorType {
return hypervisor.Remote
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
@ -192,6 +209,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
d.SSHPort = 22
if d.AccessKey == "" {
return fmt.Errorf("amazonec2 driver requires the --amazonec2-access-key option")
@ -223,6 +241,10 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
}
func (d *Driver) DriverName() string {
return driverName
}
@ -347,8 +369,6 @@ func (d *Driver) Create() error {
return err
}
log.Info("Configuring Machine...")
log.Debug("Settings tags for instance")
tags := map[string]string{
"Name": d.MachineName,
@ -358,21 +378,6 @@ func (d *Driver) Create() error {
return err
}
log.Debugf("Setting hostname: %s", d.MachineName)
cmd, err := d.GetSSHCommand(fmt.Sprintf(
"echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts && sudo hostname %s && echo \"%s\" | sudo tee /etc/hostname",
d.MachineName,
d.MachineName,
d.MachineName,
))
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
@ -420,7 +425,7 @@ func (d *Driver) GetSSHAddress() (string, error) {
}
func (d *Driver) GetSSHPort() (int, error) {
return d.sshPort, nil
return d.SSHPort, nil
}
func (d *Driver) GetSSHUsername() string {
@ -474,58 +479,6 @@ func (d *Driver) Kill() error {
return nil
}
func (d *Driver) StartDocker() error {
log.Debug("Starting Docker...")
cmd, err := d.GetSSHCommand("sudo service docker start")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (d *Driver) StopDocker() error {
log.Debug("Stopping Docker...")
cmd, err := d.GetSSHCommand("sudo service docker stop")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (d *Driver) GetDockerConfigDir() string {
return dockerConfigDir
}
func (d *Driver) Upgrade() error {
log.Debugf("Upgrading Docker")
cmd, err := d.GetSSHCommand("sudo apt-get update && sudo apt-get install --upgrade lxc-docker")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return cmd.Run()
}
func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) {
return ssh.GetSSHCommand(d.IPAddress, d.GetSSHPort(), "ubuntu", d.sshKeyPath(), args...), nil
}
func (d *Driver) getClient() *amz.EC2 {
auth := amz.GetAuth(d.AccessKey, d.SecretKey, d.SessionToken)
return amz.NewEC2(auth, d.Region)
@ -535,10 +488,6 @@ func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}
func (d *Driver) publicSSHKeyPath() string {
return d.sshKeyPath() + ".pub"
}
func (d *Driver) getInstance() (*amz.EC2Instance, error) {
instance, err := d.getClient().GetInstance(d.InstanceId)
if err != nil {
@ -569,11 +518,11 @@ func (d *Driver) waitForInstance() error {
func (d *Driver) createKeyPair() error {
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}

View File

@ -2,11 +2,11 @@ package none
import (
"fmt"
"os/exec"
"github.com/codegangsta/cli"
"github.com/docker/docker/api"
"github.com/docker/machine/drivers"
"github.com/docker/machine/hypervisor"
"github.com/docker/machine/state"
)
@ -38,10 +38,18 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s
return &Driver{}, nil
}
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) Create() error {
return nil
}
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}
func (d *Driver) DriverName() string {
return "none"
}
@ -50,7 +58,11 @@ func (d *Driver) GetIP() (string, error) {
return "", nil
}
func (d *Driver) GetSSHHostname() (string, error) {
func (d *Driver) GetMachineName() string {
return ""
}
func (d *Driver) GetSSHAddress() (string, error) {
return "", nil
}
@ -58,8 +70,8 @@ func (d *Driver) GetSSHKeyPath() string {
return ""
}
func (d *Driver) GetSSHPort() int {
return 0
func (d *Driver) GetSSHPort() (int, error) {
return 0, nil
}
func (d *Driver) GetSSHUsername() string {
@ -74,6 +86,10 @@ func (d *Driver) GetState() (state.State, error) {
return state.None, nil
}
func (d *Driver) GetHypervisorType() hypervisor.HypervisorType {
return hypervisor.None
}
func (d *Driver) Kill() error {
return fmt.Errorf("hosts without a driver cannot be killed")
}