func (s Filestore) NewHost(driver drivers.Driver) (*host.Host, error) { certDir := filepath.Join(s.Path, "certs") hostOptions := &host.Options{ AuthOptions: &auth.Options{ CertDir: certDir, CaCertPath: filepath.Join(certDir, "ca.pem"), CaPrivateKeyPath: filepath.Join(certDir, "ca-key.pem"), ClientCertPath: filepath.Join(certDir, "cert.pem"), ClientKeyPath: filepath.Join(certDir, "key.pem"), ServerCertPath: filepath.Join(s.getMachinesDir(), "server.pem"), ServerKeyPath: filepath.Join(s.getMachinesDir(), "server-key.pem"), }, EngineOptions: &engine.Options{ InstallURL: "https://get.docker.com", StorageDriver: "aufs", TLSVerify: true, }, SwarmOptions: &swarm.Options{ Host: "tcp://0.0.0.0:3376", Image: "swarm:latest", Strategy: "spread", }, } return &host.Host{ ConfigVersion: version.ConfigVersion, Name: driver.GetMachineName(), Driver: driver, DriverName: driver.DriverName(), HostOptions: hostOptions, }, nil }
// SetupCerts gets the generated credentials required to talk to the APIServer. func SetupCerts(d drivers.Driver) error { localPath := constants.Minipath ipStr, err := d.GetIP() if err != nil { return err } ip := net.ParseIP(ipStr) publicPath := filepath.Join(localPath, "apiserver.crt") privatePath := filepath.Join(localPath, "apiserver.key") if err := GenerateCerts(publicPath, privatePath, ip); err != nil { return err } client, err := sshutil.NewSSHClient(d) if err != nil { return err } for _, cert := range certs { p := filepath.Join(localPath, cert) data, err := ioutil.ReadFile(p) if err != nil { return err } if err := sshutil.Transfer(data, util.DefaultCertPath, cert, "0644", client); err != nil { return err } } return nil }
func configureDriver(driver drivers.Driver, driverOpts map[string]interface{}) error { opts := &rpcdriver.RPCFlags{Values: driverOpts} for _, c := range driver.GetCreateFlags() { val, ok := opts.Values[c.String()] if !ok { opts.Values[c.String()] = c.Default() if c.Default() == nil { opts.Values[c.String()] = false } } else { if strVal, ok := val.(string); ok { switch c.(type) { case *mcnflag.StringSliceFlag, mcnflag.StringSliceFlag: opts.Values[c.String()] = strings.Split(strVal, ",") case *mcnflag.IntFlag, mcnflag.IntFlag: v, err := strconv.Atoi(strVal) if err != nil { return errors.Wrapf(err, "failed to set %s flag: %s is not an int", c.String(), strVal) } opts.Values[c.String()] = v case *mcnflag.BoolFlag, mcnflag.BoolFlag: v, err := strconv.ParseBool(strVal) if err != nil { return errors.Wrapf(err, "failed to set %s flag: %s is not a bool", c.String(), strVal) } opts.Values[c.String()] = v } } } } err := driver.SetConfigFromFlags(opts) return errors.Wrap(err, "failed to set driver configuration") }
func (creator *StandardSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh.Client, error) { addr, err := d.GetSSHHostname() if err != nil { return ssh.ExternalClient{}, err } port, err := d.GetSSHPort() if err != nil { return ssh.ExternalClient{}, err } auth := &ssh.Auth{} if d.GetSSHKeyPath() != "" { auth.Keys = []string{d.GetSSHKeyPath()} } return ssh.NewClient(d.GetSSHUsername(), addr, port, auth) }
// SetupCerts gets the generated credentials required to talk to the APIServer. func SetupCerts(d drivers.Driver) error { localPath := constants.Minipath ipStr, err := d.GetIP() if err != nil { return errors.Wrap(err, "Error getting ip from driver") } glog.Infoln("Setting up certificates for IP: %s", ipStr) ip := net.ParseIP(ipStr) caCert := filepath.Join(localPath, "ca.crt") caKey := filepath.Join(localPath, "ca.key") publicPath := filepath.Join(localPath, "apiserver.crt") privatePath := filepath.Join(localPath, "apiserver.key") if err := GenerateCerts(caCert, caKey, publicPath, privatePath, ip); err != nil { return errors.Wrap(err, "Error generating certs") } client, err := sshutil.NewSSHClient(d) if err != nil { return errors.Wrap(err, "Error creating new ssh client") } for _, cert := range certs { p := filepath.Join(localPath, cert) data, err := ioutil.ReadFile(p) if err != nil { return errors.Wrapf(err, "Error reading file: %s", p) } perms := "0644" if strings.HasSuffix(cert, ".key") { perms = "0600" } if err := sshutil.Transfer(bytes.NewReader(data), len(data), util.DefaultCertPath, cert, perms, client); err != nil { return errors.Wrapf(err, "Error transferring data: %s", string(data)) } } return nil }
// SetupCerts gets the generated credentials required to talk to the APIServer. func SetupCerts(d drivers.Driver) error { localPath := constants.Minipath ipStr, err := d.GetIP() if err != nil { return err } glog.Infoln("Setting up certificates for IP: %s", ipStr) ip := net.ParseIP(ipStr) caCert := filepath.Join(localPath, "ca.crt") caKey := filepath.Join(localPath, "ca.key") publicPath := filepath.Join(localPath, "apiserver.crt") privatePath := filepath.Join(localPath, "apiserver.key") if err := GenerateCerts(caCert, caKey, publicPath, privatePath, ip); err != nil { return err } client, err := sshutil.NewSSHClient(d) if err != nil { return err } for _, cert := range certs { p := filepath.Join(localPath, cert) data, err := ioutil.ReadFile(p) if err != nil { return err } perms := "0644" if strings.HasSuffix(cert, ".key") { perms = "0600" } if err := sshutil.Transfer(data, util.DefaultCertPath, cert, perms, client); err != nil { return err } } return nil }
func newSSHHost(d drivers.Driver) (*sshHost, error) { ip, err := d.GetSSHHostname() if err != nil { return nil, errors.Wrap(err, "Error getting ssh host name for driver") } port, err := d.GetSSHPort() if err != nil { return nil, errors.Wrap(err, "Error getting ssh port for driver") } return &sshHost{ IP: ip, Port: port, SSHKeyPath: d.GetSSHKeyPath(), Username: d.GetSSHUsername(), }, nil }
func (detector StandardDetector) DetectProvisioner(d drivers.Driver) (Provisioner, error) { log.Info("Waiting for SSH to be available...") if err := drivers.WaitForSSH(d); err != nil { return nil, err } log.Info("Detecting the provisioner...") if d.GetOS() == drivers.WINDOWS { p := provisioners[drivers.WINDOWS] provisioner := p.New(d) return provisioner, nil } osReleaseOut, err := drivers.RunSSHCommandFromDriver(d, "cat /etc/os-release") if err != nil { return nil, fmt.Errorf("Error getting SSH command: %s", err) } osReleaseInfo, err := NewOsRelease([]byte(osReleaseOut)) if err != nil { return nil, fmt.Errorf("Error parsing /etc/os-release file: %s", err) } for _, p := range provisioners { provisioner := p.New(d) provisioner.SetOsReleaseInfo(osReleaseInfo) if provisioner.CompatibleWithHost() { log.Debugf("found compatible host: %s", osReleaseInfo.ID) return provisioner, nil } } return nil, ErrDetectionFailed }
func newSSHHost(d drivers.Driver) (*sshHost, error) { ip, err := d.GetSSHHostname() if err != nil { return nil, err } port, err := d.GetSSHPort() if err != nil { return nil, err } return &sshHost{ IP: ip, Port: port, SSHKeyPath: d.GetSSHKeyPath(), Username: d.GetSSHUsername(), }, nil }