本文整理匯總了Golang中github.com/mitchellh/packer/packer.Communicator.Download方法的典型用法代碼示例。如果您正苦於以下問題:Golang Communicator.Download方法的具體用法?Golang Communicator.Download怎麽用?Golang Communicator.Download使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mitchellh/packer/packer.Communicator
的用法示例。
在下文中一共展示了Communicator.Download方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ProvisionDownload
func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) error {
for _, src := range p.config.Sources {
ui.Say(fmt.Sprintf("Downloading %s => %s", src, p.config.Destination))
if strings.HasSuffix(p.config.Destination, "/") {
err := os.MkdirAll(p.config.Destination, os.FileMode(0755))
if err != nil {
return err
}
return comm.DownloadDir(src, p.config.Destination, nil)
}
f, err := os.OpenFile(p.config.Destination, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
err = comm.Download(src, f)
if err != nil {
ui.Error(fmt.Sprintf("Download failed: %s", err))
return err
}
}
return nil
}
示例2: ProvisionDownload
func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) error {
for _, src := range p.config.Sources {
ui.Say(fmt.Sprintf("Downloading %s => %s", src, p.config.Destination))
// ensure destination dir exists. p.config.Destination may either be a file or a dir.
dir := p.config.Destination
// if it doesn't end with a /, set dir as the parent dir
if !strings.HasSuffix(p.config.Destination, "/") {
dir = filepath.Dir(dir)
}
if dir != "" {
err := os.MkdirAll(dir, os.FileMode(0755))
if err != nil {
return err
}
}
// if the config.Destination was a dir, download the dir
if strings.HasSuffix(p.config.Destination, "/") {
return comm.DownloadDir(src, p.config.Destination, nil)
}
f, err := os.OpenFile(p.config.Destination, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
err = comm.Download(src, f)
if err != nil {
ui.Error(fmt.Sprintf("Download failed: %s", err))
return err
}
}
return nil
}
示例3: ProvisionDownload
func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) error {
ui.Say(fmt.Sprintf("Downloading %s => %s", p.config.Source, p.config.Destination))
f, err := os.OpenFile(p.config.Destination, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
err = comm.Download(p.config.Source, f)
if err != nil {
ui.Error(fmt.Sprintf("Download failed: %s", err))
}
return err
}
示例4: scpDownloadSession
func scpDownloadSession(opts []byte, rest string, in io.Reader, out io.Writer, comm packer.Communicator) error {
rest = strings.TrimSpace(rest)
if len(rest) == 0 {
fmt.Fprintf(out, scpEmptyError)
return errors.New("no scp source specified")
}
d, err := ioutil.TempDir("", "packer-ansible-download")
if err != nil {
fmt.Fprintf(out, scpEmptyError)
return err
}
defer os.RemoveAll(d)
if bytes.Contains([]byte{'d'}, opts) {
// the only ansible module that supports downloading via scp is fetch,
// fetch only supports file downloads as of Ansible 2.1.
fmt.Fprintf(out, scpEmptyError)
return errors.New("directory downloads not supported")
}
f, err := os.Create(filepath.Join(d, filepath.Base(rest)))
if err != nil {
fmt.Fprintf(out, scpEmptyError)
return err
}
defer f.Close()
err = comm.Download(rest, f)
if err != nil {
fmt.Fprintf(out, scpEmptyError)
return err
}
state := &scpDownloadState{srcRoot: d}
return state.Protocol(bufio.NewReader(in), out)
}