mirror of https://github.com/docker/docs.git
Moved `vmwarevsphere` driver to main b2d release tree
Signed-off-by: Fabio Rapposelli <fabio@vmware.com>
This commit is contained in:
parent
19d3bdd389
commit
c4be194d41
|
@ -61,17 +61,17 @@ func (conn VcConn) DatastoreMkdir(dirName string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (conn VcConn) DatastoreUpload(localPath string) error {
|
||||
stdout, err := conn.DatastoreLs(DatastoreDir)
|
||||
func (conn VcConn) DatastoreUpload(localPath, destination string) error {
|
||||
stdout, err := conn.DatastoreLs(destination)
|
||||
if err == nil && strings.Contains(stdout, B2DISOName) {
|
||||
log.Infof("boot2docker ISO already uploaded, skipping upload... ")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Infof("Uploading %s to %s on datastore %s of vCenter %s... ",
|
||||
localPath, DatastoreDir, conn.driver.Datastore, conn.driver.IP)
|
||||
localPath, destination, conn.driver.Datastore, conn.driver.IP)
|
||||
|
||||
dsPath := fmt.Sprintf("%s/%s", DatastoreDir, B2DISOName)
|
||||
dsPath := fmt.Sprintf("%s/%s", destination, B2DISOName)
|
||||
args := []string{"datastore.upload"}
|
||||
args = conn.AppendConnectionString(args)
|
||||
args = append(args, fmt.Sprintf("--ds=%s", conn.driver.Datastore))
|
||||
|
@ -203,7 +203,7 @@ func (conn VcConn) VMDiskCreate() error {
|
|||
args = append(args, fmt.Sprintf("--dc=%s", conn.driver.Datacenter))
|
||||
args = append(args, fmt.Sprintf("--vm=%s", conn.driver.MachineName))
|
||||
args = append(args, fmt.Sprintf("--ds=%s", conn.driver.Datastore))
|
||||
args = append(args, fmt.Sprintf("--name=%s", conn.driver.MachineName))
|
||||
args = append(args, fmt.Sprintf("--name=%s/%s", conn.driver.MachineName, conn.driver.MachineName))
|
||||
diskSize := strconv.Itoa(conn.driver.DiskSize)
|
||||
args = append(args, fmt.Sprintf("--size=%sMiB", diskSize))
|
||||
|
||||
|
|
|
@ -7,9 +7,7 @@ package vmwarevsphere
|
|||
import (
|
||||
"archive/tar"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -27,8 +25,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
DatastoreDir = "boot2docker-iso"
|
||||
isoFilename = "boot2docker-1.6.0-vmw.iso"
|
||||
isoFilename = "boot2docker.iso"
|
||||
B2DISOName = isoFilename
|
||||
DefaultCPUNumber = 2
|
||||
B2DUser = "docker"
|
||||
|
@ -52,15 +49,13 @@ type Driver struct {
|
|||
Datacenter string
|
||||
Pool string
|
||||
HostIP string
|
||||
StorePath string
|
||||
storePath string
|
||||
ISO string
|
||||
CaCertPath string
|
||||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
|
||||
storePath string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -141,7 +136,7 @@ func GetCreateFlags() []cli.Flag {
|
|||
}
|
||||
|
||||
func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
|
||||
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 {
|
||||
|
@ -262,64 +257,9 @@ func (d *Driver) Create() error {
|
|||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
isoURL string
|
||||
)
|
||||
|
||||
b2dutils := utils.NewB2dUtils("", "")
|
||||
|
||||
imgPath := utils.GetMachineCacheDir()
|
||||
commonIsoPath := filepath.Join(imgPath, isoFilename)
|
||||
// just in case boot2docker.iso has been manually deleted
|
||||
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(imgPath, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if d.Boot2DockerURL != "" {
|
||||
isoURL = d.Boot2DockerURL
|
||||
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
|
||||
if err := b2dutils.DownloadISO(d.storePath, isoFilename, isoURL); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: until vmw tools are merged into b2d master
|
||||
// we will use the iso from the vmware team
|
||||
//// todo: check latest release URL, download if it's new
|
||||
//// until then always use "latest"
|
||||
//isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
|
||||
//if err != nil {
|
||||
// log.Warnf("Unable to check for the latest release: %s", err)
|
||||
|
||||
//}
|
||||
|
||||
// see https://github.com/boot2docker/boot2docker/pull/747
|
||||
isoURL := "https://github.com/cloudnativeapps/boot2docker/releases/download/v1.6.0-vmw/boot2docker-1.6.0-vmw.iso"
|
||||
|
||||
if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
|
||||
log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath)
|
||||
// just in case boot2docker.iso has been manually deleted
|
||||
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(imgPath, 0700); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
isoDest := filepath.Join(d.storePath, isoFilename)
|
||||
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Generating SSH Keypair...")
|
||||
|
@ -329,7 +269,7 @@ func (d *Driver) Create() error {
|
|||
|
||||
vcConn := NewVcConn(d)
|
||||
log.Infof("Uploading Boot2docker ISO ...")
|
||||
if err := vcConn.DatastoreMkdir(DatastoreDir); err != nil {
|
||||
if err := vcConn.DatastoreMkdir(d.MachineName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -338,11 +278,11 @@ func (d *Driver) Create() error {
|
|||
return errors.NewIncompleteVsphereConfigError(d.ISO)
|
||||
}
|
||||
|
||||
if err := vcConn.DatastoreUpload(d.ISO); err != nil {
|
||||
if err := vcConn.DatastoreUpload(d.ISO, d.MachineName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isoPath := fmt.Sprintf("%s/%s", DatastoreDir, isoFilename)
|
||||
isoPath := fmt.Sprintf("%s/%s", d.MachineName, isoFilename)
|
||||
if err := vcConn.VMCreate(isoPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -508,33 +448,6 @@ func (d *Driver) checkVsphereConfig() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Download boot2docker ISO image for the given tag and save it at dest.
|
||||
func downloadISO(dir, file, url string) error {
|
||||
rsp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
|
||||
// Download to a temp file first then rename it to avoid partial download.
|
||||
f, err := ioutil.TempFile(dir, file+".tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
if _, err := io.Copy(f, rsp.Body); err != nil {
|
||||
// TODO: display download progress?
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(f.Name(), path.Join(dir, file)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Make a boot2docker userdata.tar key bundle
|
||||
func (d *Driver) generateKeyBundle() error {
|
||||
log.Debugf("Creating Tar key bundle...")
|
||||
|
@ -589,3 +502,20 @@ func (d *Driver) generateKeyBundle() error {
|
|||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (d *Driver) UpgradeISO() error {
|
||||
|
||||
vcConn := NewVcConn(d)
|
||||
|
||||
if _, err := os.Stat(d.ISO); os.IsNotExist(err) {
|
||||
log.Errorf("Unable to find boot2docker ISO at %s", d.ISO)
|
||||
return errors.NewIncompleteVsphereConfigError(d.ISO)
|
||||
}
|
||||
|
||||
if err := vcConn.DatastoreUpload(d.ISO, d.MachineName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue