本文整理匯總了Golang中github.com/mitchellh/packer/packer.Communicator.Upload方法的典型用法代碼示例。如果您正苦於以下問題:Golang Communicator.Upload方法的具體用法?Golang Communicator.Upload怎麽用?Golang Communicator.Upload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mitchellh/packer/packer.Communicator
的用法示例。
在下文中一共展示了Communicator.Upload方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: uploadManifests
func (p *Provisioner) uploadManifests(ui packer.Ui, comm packer.Communicator) (string, error) {
// Create the remote manifests directory...
ui.Message("Uploading manifests...")
remoteManifestsPath := fmt.Sprintf("%s/manifests", p.config.StagingDir)
if err := p.createDir(ui, comm, remoteManifestsPath); err != nil {
return "", fmt.Errorf("Error creating manifests directory: %s", err)
}
// Upload the main manifest
f, err := os.Open(p.config.ManifestFile)
if err != nil {
return "", err
}
defer f.Close()
manifestFilename := p.config.ManifestFile
if fi, err := os.Stat(p.config.ManifestFile); err != nil {
return "", fmt.Errorf("Error inspecting manifest file: %s", err)
} else if !fi.IsDir() {
manifestFilename = filepath.Base(manifestFilename)
} else {
ui.Say("WARNING: manifest_file should be a file. Use manifest_dir for directories")
}
remoteManifestFile := fmt.Sprintf("%s/%s", remoteManifestsPath, manifestFilename)
if err := comm.Upload(remoteManifestFile, f, nil); err != nil {
return "", err
}
return remoteManifestFile, nil
}
示例2: createKnifeConfig
func (p *Provisioner) createKnifeConfig(ui packer.Ui, comm packer.Communicator, nodeName string, serverUrl string, clientKey string, sslVerifyMode string) (string, error) {
ui.Message("Creating configuration file 'knife.rb'")
// Read the template
tpl := DefaultKnifeTemplate
ctx := p.config.ctx
ctx.Data = &ConfigTemplate{
NodeName: nodeName,
ServerUrl: serverUrl,
ClientKey: clientKey,
SslVerifyMode: sslVerifyMode,
}
configString, err := interpolate.Render(tpl, &ctx)
if err != nil {
return "", err
}
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "knife.rb"))
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString)), nil); err != nil {
return "", err
}
return remotePath, nil
}
示例3: createJson
func (p *Provisioner) createJson(ui packer.Ui, comm packer.Communicator) (string, error) {
ui.Message("Creating JSON attribute file")
jsonData := make(map[string]interface{})
// Copy the configured JSON
for k, v := range p.config.Json {
jsonData[k] = v
}
// Set the run list if it was specified
if len(p.config.RunList) > 0 {
jsonData["run_list"] = p.config.RunList
}
jsonBytes, err := json.MarshalIndent(jsonData, "", " ")
if err != nil {
return "", err
}
// Upload the bytes
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "node.json"))
if err := comm.Upload(remotePath, bytes.NewReader(jsonBytes), nil); err != nil {
return "", err
}
return remotePath, nil
}
示例4: UploadLocalDirectory
func UploadLocalDirectory(localDir string, comm packer.Communicator) (err error) {
visitPath := func(path string, f os.FileInfo, err error) (err2 error) {
var remotePath = RemoteStagingPath + "/" + path
if f.IsDir() {
// Make remote directory
err = CreateRemoteDirectory(remotePath, comm)
if err != nil {
return err
}
} else {
// Upload file to existing directory
file, err := os.Open(path)
if err != nil {
return fmt.Errorf("Error opening file: %s", err)
}
err = comm.Upload(remotePath, file)
if err != nil {
return fmt.Errorf("Error uploading file: %s", err)
}
}
return
}
log.Printf("Uploading directory %s", localDir)
err = filepath.Walk(localDir, visitPath)
if err != nil {
return fmt.Errorf("Error uploading modules %s: %s", localDir, err)
}
return nil
}
示例5: createConfig
func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, localCookbooks []string) (string, error) {
ui.Message("Creating configuration file 'solo.rb'")
cookbook_paths := make([]string, len(p.config.RemoteCookbookPaths)+len(localCookbooks))
for i, path := range p.config.RemoteCookbookPaths {
cookbook_paths[i] = fmt.Sprintf(`"%s"`, path)
}
for i, path := range localCookbooks {
i = len(p.config.RemoteCookbookPaths) + i
cookbook_paths[i] = fmt.Sprintf(`"%s"`, path)
}
configString, err := p.config.tpl.Process(DefaultConfigTemplate, &ConfigTemplate{
CookbookPaths: strings.Join(cookbook_paths, ","),
})
if err != nil {
return "", err
}
remotePath := filepath.Join(p.config.StagingDir, "solo.rb")
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString))); err != nil {
return "", err
}
return remotePath, nil
}
示例6: uploadDeploymentManifest
func (p *Provisioner) uploadDeploymentManifest(ui packer.Ui, comm packer.Communicator) error {
ui.Say(fmt.Sprintf("Uploading manifest: %s", p.config.Manifest))
err := runCmd("mkdir ~/deployments", ui, comm)
if err != nil {
return err
}
f, err := os.Open(p.config.Manifest)
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return err
}
err = comm.Upload(fmt.Sprintf("~/deployments/%s", p.config.Manifest), f, &fi)
if err != nil {
return err
}
cmd := fmt.Sprintf("sed -i \"s/director_uuid: .*/director_uuid: $(bosh status --uuid)/\" ~/deployments/%s", p.config.Manifest)
return runCmd(cmd, ui, comm)
}
示例7: ProvisionUpload
func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) error {
ui.Say(fmt.Sprintf("Uploading %s => %s", p.config.Source, p.config.Destination))
info, err := os.Stat(p.config.Source)
if err != nil {
return err
}
// If we're uploading a directory, short circuit and do that
if info.IsDir() {
return comm.UploadDir(p.config.Destination, p.config.Source, nil)
}
// We're uploading a file...
f, err := os.Open(p.config.Source)
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return err
}
err = comm.Upload(p.config.Destination, f, &fi)
if err != nil {
ui.Error(fmt.Sprintf("Upload failed: %s", err))
}
return err
}
示例8: uploadSingle
func (s *StepUploadX509Cert) uploadSingle(comm packer.Communicator, dst, src string) error {
f, err := os.Open(src)
if err != nil {
return err
}
defer f.Close()
return comm.Upload(dst, f, nil)
}
示例9: uploadFile
func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst string, src string) error {
f, err := os.Open(src)
if err != nil {
return err
}
defer f.Close()
return comm.Upload(dst, f, nil)
}
示例10: Provision
func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
ui.Say(fmt.Sprintf("Uploading %s => %s", p.config.Source, p.config.Destination))
f, err := os.Open(p.config.Source)
if err != nil {
return err
}
defer f.Close()
return comm.Upload(p.config.Destination, f)
}
示例11: ProvisionUpload
func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) error {
ui.Say(fmt.Sprintf("Uploading %s => %s", p.config.Source, p.config.Destination))
info, _ := os.Stat(p.config.Source)
if info != nil {
// If we're uploading a directory, short circuit and do that
if info.IsDir() {
return comm.UploadDir(p.config.Destination, p.config.Source, nil)
}
}
pwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("Couldn't get the current working directory")
}
det, err := gg.Detect(p.config.Source, pwd, gg.Detectors)
if err != nil {
return fmt.Errorf("Couldn't detect file source type: %v", err)
}
if len(det) == 0 {
return errors.New("Don't recognise the source type")
}
dir, err := ioutil.TempDir("", "packer")
if err != nil {
return errors.New("Unable to create temp dir")
}
defer os.RemoveAll(dir)
source := filepath.Join(dir, filepath.Base(p.config.Source))
if err := gg.GetFile(source, p.config.Source); err != nil {
return fmt.Errorf("There was a problem getting the file: %v", err)
}
// We're uploading a file...
f, err := os.Open(source)
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return err
}
err = comm.Upload(p.config.Destination, f, &fi)
if err != nil {
ui.Error(fmt.Sprintf("Upload failed: %s", err))
}
return err
}
示例12: createConfig
func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, localCookbooks []string, rolesPath string, dataBagsPath string, encryptedDataBagSecretPath string, environmentsPath string, chefEnvironment string) (string, error) {
ui.Message("Creating configuration file 'solo.rb'")
cookbook_paths := make([]string, len(p.config.RemoteCookbookPaths)+len(localCookbooks))
for i, path := range p.config.RemoteCookbookPaths {
cookbook_paths[i] = fmt.Sprintf(`"%s"`, path)
}
for i, path := range localCookbooks {
i = len(p.config.RemoteCookbookPaths) + i
cookbook_paths[i] = fmt.Sprintf(`"%s"`, path)
}
// Read the template
tpl := DefaultConfigTemplate
if p.config.ConfigTemplate != "" {
f, err := os.Open(p.config.ConfigTemplate)
if err != nil {
return "", err
}
defer f.Close()
tplBytes, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
tpl = string(tplBytes)
}
p.config.ctx.Data = &ConfigTemplate{
CookbookPaths: strings.Join(cookbook_paths, ","),
RolesPath: rolesPath,
DataBagsPath: dataBagsPath,
EncryptedDataBagSecretPath: encryptedDataBagSecretPath,
EnvironmentsPath: environmentsPath,
HasRolesPath: rolesPath != "",
HasDataBagsPath: dataBagsPath != "",
HasEncryptedDataBagSecretPath: encryptedDataBagSecretPath != "",
HasEnvironmentsPath: environmentsPath != "",
ChefEnvironment: chefEnvironment,
}
configString, err := interpolate.Render(tpl, &p.config.ctx)
if err != nil {
return "", err
}
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "solo.rb"))
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString)), nil); err != nil {
return "", err
}
return remotePath, nil
}
示例13: createConfig
func (p *Provisioner) createConfig(
ui packer.Ui,
comm packer.Communicator,
nodeName string,
serverUrl string,
clientKey string,
encryptedDataBagSecretPath,
remoteKeyPath string,
validationClientName string,
chefEnvironment string,
sslVerifyMode string) (string, error) {
ui.Message("Creating configuration file 'client.rb'")
// Read the template
tpl := DefaultConfigTemplate
if p.config.ConfigTemplate != "" {
f, err := os.Open(p.config.ConfigTemplate)
if err != nil {
return "", err
}
defer f.Close()
tplBytes, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
tpl = string(tplBytes)
}
ctx := p.config.ctx
ctx.Data = &ConfigTemplate{
NodeName: nodeName,
ServerUrl: serverUrl,
ClientKey: clientKey,
ValidationKeyPath: remoteKeyPath,
ValidationClientName: validationClientName,
ChefEnvironment: chefEnvironment,
SslVerifyMode: sslVerifyMode,
EncryptedDataBagSecretPath: encryptedDataBagSecretPath,
}
configString, err := interpolate.Render(tpl, &ctx)
if err != nil {
return "", err
}
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "client.rb"))
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString)), nil); err != nil {
return "", err
}
return remotePath, nil
}
示例14: uploadFile
func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, remotePath string, localPath string) error {
ui.Message(fmt.Sprintf("Uploading %s...", localPath))
f, err := os.Open(localPath)
if err != nil {
return err
}
defer f.Close()
return comm.Upload(remotePath, f, nil)
}
示例15: uploadFile
func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst, src string) error {
f, err := os.Open(src)
if err != nil {
return fmt.Errorf("Error opening: %s", err)
}
defer f.Close()
if err = comm.Upload(dst, f, nil); err != nil {
return fmt.Errorf("Error uploading %s: %s", src, err)
}
return nil
}