本文整理匯總了Golang中github.com/docker/machine/ssh.GenerateSSHKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang GenerateSSHKey函數的具體用法?Golang GenerateSSHKey怎麽用?Golang GenerateSSHKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GenerateSSHKey函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createSSHKey
func (d *Driver) createSSHKey() error {
log.Debug("Creating Key Pair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
return nil
}
示例2: generateCertForAzure
func (d *Driver) generateCertForAzure() error {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
cmd := exec.Command("openssl", "req", "-x509", "-key", d.GetSSHKeyPath(), "-nodes", "-days", "365", "-newkey", "rsa:2048", "-out", d.azureCertPath(), "-subj", "/C=AU/ST=Some-State/O=InternetWidgitsPtyLtd/CN=\\*")
return cmd.Run()
}
示例3: createSSHKey
func (d *Driver) createSSHKey() (string, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return "", err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return "", err
}
return string(publicKey), nil
}
示例4: createSSHKey
func (d *Driver) createSSHKey() error {
log.Info("Creating SSH Key Pair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
d.PublicKey = publicKey[0 : len(publicKey)-1]
log.Debugf("------------%s\n")
log.Debug(string(publicKey))
return nil
}
示例5: createKeyPair
func (d *Driver) createKeyPair() error {
log.Debug("SSH key path: ", d.GetSSHKeyPath())
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}
d.PublicKey = publicKey
return nil
}
示例6: createSSHKey
func (d *Driver) createSSHKey() (*SshKey, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
key, err := d.getClient().SshKey().Create(d.deviceConfig.Hostname, string(publicKey))
if err != nil {
return nil, err
}
return key, nil
}
示例7: createKeyPair
func (d *Driver) createKeyPair() (string, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return "", err
}
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return "", err
}
keyName := d.MachineName
log.Debugf("creating key pair: %s", keyName)
return d.importKeyPair(keyName, string(publicKey))
}
示例8: createSSHKey
func (d *Driver) createSSHKey() error {
log.WithField("Name", d.KeyPairName).Debug("Creating Key Pair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
if err := d.initCompute(); err != nil {
return err
}
if err := d.client.CreateKeyPair(d, d.KeyPairName, string(publicKey)); err != nil {
return err
}
return nil
}
示例9: Create
// Create creates a GCE VM instance acting as a docker host.
func (d *Driver) Create() error {
c, err := newComputeUtil(d)
if err != nil {
return err
}
log.Infof("Creating host...")
// Check if the instance already exists. There will be an error if the instance
// doesn't exist, so just check instance for nil.
if instance, _ := c.instance(); instance != nil {
return fmt.Errorf("Instance %v already exists.", d.MachineName)
}
log.Infof("Generating SSH Key")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
return c.createInstance(d)
}
示例10: createSSHKey
func (d *Driver) createSSHKey() (*godo.Key, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
createRequest := &godo.KeyCreateRequest{
Name: d.MachineName,
PublicKey: string(publicKey),
}
key, _, err := d.getClient().Keys.Create(createRequest)
if err != nil {
return key, err
}
return key, nil
}
示例11: createKeyPair
func (d *Driver) createKeyPair() error {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}
keyName := d.MachineName
log.Debugf("creating key pair: %s", keyName)
if err := d.getClient().ImportKeyPair(keyName, string(publicKey)); err != nil {
return err
}
d.KeyName = keyName
return nil
}
示例12: createKeyPair
func (d *Driver) createKeyPair() error {
if err := ssh.GenerateSSHKey(d.sshKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
keyName := fmt.Sprintf("docker-machine-%s", d.Id)
log.Debugf("creating key pair: %s", keyName)
if err := d.getClient().ImportKeyPair(keyName, string(publicKey)); err != nil {
return err
}
d.KeyName = keyName
return nil
}
示例13: Create
func (d *Driver) Create() error {
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
c, err := NewClient("http://localhost:" + strconv.Itoa(d.APIPort))
if err != nil {
return err
}
log.Infof("Creating VM...")
_, err = c.CloneVM(d.MachineName, d.MachineName, "photon")
if err != nil {
return err
}
// Set memory amount
if err = d.setVMXValue("memsize", strconv.Itoa(d.Memory)); err != nil {
return err
}
// Set cpu number
if err = d.setVMXValue("numvcpus", strconv.Itoa(d.CPU)); err != nil {
return err
}
log.Infof("Starting %s...", d.MachineName)
_, err = c.PowerVM(d.MachineName, "on")
if err != nil {
return err
}
if _, err := d.GetIP(); err != nil {
return err
}
// Add SSH Key to photon user
log.Infof("Replacing insecure SSH key...")
if err := d.replaceInsecureSSHKey(); err != nil {
return err
}
var shareName, shareDir string // TODO configurable at some point
switch runtime.GOOS {
case "darwin":
shareName = "Users"
shareDir = "/Users"
// TODO "linux" and "windows"
}
if shareDir != "" {
if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) {
return err
} else if !os.IsNotExist(err) {
// add shared folder, create mountpoint and mount it.
// Enable Shared Folders
if _, err := c.SetVMSharedFolders(d.MachineName, "true"); err != nil {
return err
}
// Add shared folder to VM
if _, err := c.AddVMSharedFolder(d.MachineName, shareName, shareDir, 4); err != nil {
return err
}
// create mountpoint and mount shared folder
if err := d.mountSharedFolder(shareDir, shareName); err != nil {
return err
}
}
}
return nil
}
示例14: Create
func (d *Driver) Create() error {
var (
isoURL string
err error
)
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/1.5.0-GH747/boot2docker-1.5.0-GH747.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
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.storePath, 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := filepath.Join(d.storePath, fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
if err := d.Start(); err != nil {
return err
}
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.getIPfromDHCPLease()
if err != nil {
//.........這裏部分代碼省略.........
示例15: Create
func (d *Driver) Create() error {
b2dutils := utils.NewB2dUtils("", "")
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
// download cloud-init config drive
if d.ConfigDriveURL != "" {
log.Infof("Downloading %s from %s", isoConfigDrive, d.ConfigDriveURL)
if err := b2dutils.DownloadISO(d.ResolveStorePath("."), isoConfigDrive, d.ConfigDriveURL); err != nil {
return err
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.getIPfromDHCPLease()
if err != nil {
log.Debugf("Not there yet %d/%d, error: %s", i, 60, err)
time.Sleep(2 * time.Second)
continue
}
if ip != "" {
log.Debugf("Got an ip: %s", ip)
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, 22), time.Duration(2*time.Second))
if err != nil {
log.Debugf("SSH Daemon not responding yet: %s", err)
time.Sleep(2 * time.Second)
continue
}
conn.Close()
break
}
}
if ip == "" {
return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting")
}
// we got an IP, let's copy ssh keys over
d.IPAddress = ip
// Do not execute the rest of boot2docker specific configuration
// The uplaod of the public ssh key uses a ssh connection,
// this works without installed vmware client tools
if d.ConfigDriveURL != "" {
var keyfh *os.File
var keycontent []byte
log.Infof("Copy public SSH key to %s [%s]", d.MachineName, d.IPAddress)
// create .ssh folder in users home
if err := executeSSHCommand(fmt.Sprintf("mkdir -p /home/%s/.ssh", d.SSHUser), d); err != nil {
return err
}
// read generated public ssh key
if keyfh, err = os.Open(d.publicSSHKeyPath()); err != nil {
return err
//.........這裏部分代碼省略.........