mirror of https://github.com/docker/docs.git
hyperv: updated for new driver interface
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
ec91959979
commit
7e362cf4a3
|
|
@ -19,7 +19,7 @@ import (
|
||||||
_ "github.com/docker/machine/drivers/azure"
|
_ "github.com/docker/machine/drivers/azure"
|
||||||
_ "github.com/docker/machine/drivers/digitalocean"
|
_ "github.com/docker/machine/drivers/digitalocean"
|
||||||
_ "github.com/docker/machine/drivers/google"
|
_ "github.com/docker/machine/drivers/google"
|
||||||
//_ "github.com/docker/machine/drivers/hyperv"
|
_ "github.com/docker/machine/drivers/hyperv"
|
||||||
_ "github.com/docker/machine/drivers/none"
|
_ "github.com/docker/machine/drivers/none"
|
||||||
//_ "github.com/docker/machine/drivers/openstack"
|
//_ "github.com/docker/machine/drivers/openstack"
|
||||||
//_ "github.com/docker/machine/drivers/rackspace"
|
//_ "github.com/docker/machine/drivers/rackspace"
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/docker/machine/drivers"
|
"github.com/docker/machine/drivers"
|
||||||
|
"github.com/docker/machine/provider"
|
||||||
"github.com/docker/machine/ssh"
|
"github.com/docker/machine/ssh"
|
||||||
"github.com/docker/machine/state"
|
"github.com/docker/machine/state"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
|
|
@ -23,6 +23,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
|
SSHUser string
|
||||||
|
SSHPort int
|
||||||
storePath string
|
storePath string
|
||||||
boot2DockerURL string
|
boot2DockerURL string
|
||||||
boot2DockerLoc string
|
boot2DockerLoc string
|
||||||
|
|
@ -83,6 +85,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
||||||
d.SwarmMaster = flags.Bool("swarm-master")
|
d.SwarmMaster = flags.Bool("swarm-master")
|
||||||
d.SwarmHost = flags.String("swarm-host")
|
d.SwarmHost = flags.String("swarm-host")
|
||||||
d.SwarmDiscovery = flags.String("swarm-discovery")
|
d.SwarmDiscovery = flags.String("swarm-discovery")
|
||||||
|
d.SSHUser = "docker"
|
||||||
|
d.SSHPort = 22
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,6 +94,38 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s
|
||||||
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil
|
return &Driver{MachineName: machineName, storePath: storePath, CaCertPath: caCert, PrivateKeyPath: privateKey}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetMachineName() string {
|
||||||
|
return d.MachineName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetSSHHostname() (string, error) {
|
||||||
|
return d.GetIP()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetSSHKeyPath() string {
|
||||||
|
return filepath.Join(d.storePath, "id_rsa")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetSSHPort() (int, error) {
|
||||||
|
return d.SSHPort, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetSSHUsername() string {
|
||||||
|
return d.SSHUser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) GetProviderType() provider.ProviderType {
|
||||||
|
return provider.Local
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Driver) DriverName() string {
|
func (d *Driver) DriverName() string {
|
||||||
return "hyper-v"
|
return "hyper-v"
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +231,7 @@ func (d *Driver) Create() error {
|
||||||
|
|
||||||
log.Infof("Creating SSH key...")
|
log.Infof("Creating SSH key...")
|
||||||
|
|
||||||
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {
|
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,21 +289,6 @@ func (d *Driver) Create() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Setting hostname...")
|
|
||||||
cmd, err := d.GetSSHCommand(fmt.Sprintf(
|
|
||||||
"sudo hostname %s && echo \"%s\" | sudo tee /var/lib/boot2docker/etc/hostname",
|
|
||||||
d.MachineName,
|
|
||||||
d.MachineName,
|
|
||||||
))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
|
|
||||||
}
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,77 +433,8 @@ func (d *Driver) GetIP() (string, error) {
|
||||||
return resp[0], nil
|
return resp[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) GetSSHCommand(args ...string) (*exec.Cmd, error) {
|
|
||||||
ip, err := d.GetIP()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ssh.GetSSHCommand(ip, 22, "docker", d.sshKeyPath(), args...), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Driver) Upgrade() error {
|
|
||||||
log.Infof("Stopping machine...")
|
|
||||||
if err := d.Stop(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
b2dutils := utils.NewB2dUtils("", "")
|
|
||||||
isoURL, err := b2dutils.GetLatestBoot2DockerReleaseURL()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Downloading boot2docker...")
|
|
||||||
if err := b2dutils.DownloadISO(d.storePath, "boot2docker.iso", isoURL); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Starting machine...")
|
|
||||||
if err := d.Start(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Driver) StartDocker() error {
|
|
||||||
log.Debug("Starting Docker...")
|
|
||||||
|
|
||||||
cmd, err := d.GetSSHCommand("sudo /etc/init.d/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("if [ -e /var/run/docker.pid ]; then sudo /etc/init.d/docker stop ; fi")
|
|
||||||
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) sshKeyPath() string {
|
|
||||||
return filepath.Join(d.storePath, "id_rsa")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Driver) publicSSHKeyPath() string {
|
func (d *Driver) publicSSHKeyPath() string {
|
||||||
return d.sshKeyPath() + ".pub"
|
return d.GetSSHKeyPath() + ".pub"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) generateDiskImage() error {
|
func (d *Driver) generateDiskImage() error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue