当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.WrapError函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/errors.WrapError函数的典型用法代码示例。如果您正苦于以下问题:Golang WrapError函数的具体用法?Golang WrapError怎么用?Golang WrapError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了WrapError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateUser

func (p linux) CreateUser(username, password, basePath string) error {
	err := p.fs.MkdirAll(basePath, userBaseDirPermissions)
	if err != nil {
		return bosherr.WrapError(err, "Making user base path")
	}

	args := []string{"-m", "-b", basePath, "-s", "/bin/bash"}

	if password != "" {
		args = append(args, "-p", password)
	}

	args = append(args, username)

	_, _, _, err = p.cmdRunner.RunCommand("useradd", args...)
	if err != nil {
		return bosherr.WrapError(err, "Shelling out to useradd")
	}

	userHomeDir, err := p.fs.HomeDir(username)
	if err != nil {
		return bosherr.WrapErrorf(err, "Unable to retrieve home directory for user %s", username)
	}

	_, _, _, err = p.cmdRunner.RunCommand("chmod", "700", userHomeDir)
	if err != nil {
		return bosherr.WrapError(err, "Shelling out to chmod")
	}
	return nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:30,代码来源:linux_platform.go

示例2: writeOpenIscsiConfBasedOnShellScript

func (vm SoftLayerVM) writeOpenIscsiConfBasedOnShellScript(virtualGuest datatypes.SoftLayer_Virtual_Guest, volume datatypes.SoftLayer_Network_Storage, credential AllowedHostCredential) (bool, error) {
	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("open_iscsid_conf").Parse(etcIscsidConfTemplate))
	if len(credential.Password) == 0 {
		err := t.Execute(buffer, volume)
		if err != nil {
			return false, bosherr.WrapError(err, "Generating config from template")
		}
	} else {
		err := t.Execute(buffer, credential)
		if err != nil {
			return false, bosherr.WrapError(err, "Generating config from template")
		}
	}

	file, err := ioutil.TempFile(os.TempDir(), "iscsid_conf_")
	if err != nil {
		return false, bosherr.WrapError(err, "Generating config from template")
	}

	defer os.Remove(file.Name())

	_, err = file.WriteString(buffer.String())
	if err != nil {
		return false, bosherr.WrapError(err, "Generating config from template")
	}

	if err = vm.uploadFile(virtualGuest, file.Name(), "/etc/iscsi/iscsid.conf"); err != nil {
		return false, bosherr.WrapError(err, "Writing to /etc/iscsi/iscsid.conf")
	}

	return true, nil
}
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:33,代码来源:softlayer_vm.go

示例3: GetDeploymentManifest

func (y DeploymentManifestParser) GetDeploymentManifest(deploymentManifestPath string, releaseSetManifest birelsetmanifest.Manifest, stage biui.Stage) (bideplmanifest.Manifest, error) {
	var deploymentManifest bideplmanifest.Manifest
	err := stage.Perform("Validating deployment manifest", func() error {
		var err error
		deploymentManifest, err = y.DeploymentParser.Parse(deploymentManifestPath)
		if err != nil {
			return bosherr.WrapErrorf(err, "Parsing deployment manifest '%s'", deploymentManifestPath)
		}

		err = y.DeploymentValidator.Validate(deploymentManifest, releaseSetManifest)
		if err != nil {
			return bosherr.WrapError(err, "Validating deployment manifest")
		}

		err = y.DeploymentValidator.ValidateReleaseJobs(deploymentManifest, y.ReleaseManager)
		if err != nil {
			return bosherr.WrapError(err, "Validating deployment jobs refer to jobs in release")
		}

		return nil
	})
	if err != nil {
		return bideplmanifest.Manifest{}, err
	}

	return deploymentManifest, nil
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:27,代码来源:deployment_manifest_parser.go

示例4: writeNetworkInterfaces

func (net UbuntuNetManager) writeNetworkInterfaces(dhcpConfigs DHCPInterfaceConfigurations, staticConfigs StaticInterfaceConfigurations, dnsServers []string) (bool, error) {
	sort.Stable(dhcpConfigs)
	sort.Stable(staticConfigs)

	networkInterfaceValues := networkInterfaceConfig{
		DHCPConfigs:       dhcpConfigs,
		StaticConfigs:     staticConfigs,
		HasDNSNameServers: true,
		DNSServers:        dnsServers,
	}

	buffer := bytes.NewBuffer([]byte{})

	t := template.Must(template.New("network-interfaces").Parse(networkInterfacesTemplate))

	err := t.Execute(buffer, networkInterfaceValues)
	if err != nil {
		return false, bosherr.WrapError(err, "Generating config from template")
	}

	changed, err := net.fs.ConvergeFileContents("/etc/network/interfaces", buffer.Bytes())
	if err != nil {
		return changed, bosherr.WrapError(err, "Writing to /etc/network/interfaces")
	}

	return changed, nil
}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:27,代码来源:ubuntu_net_manager.go

示例5: ReloadOS

func (vm SoftLayerVM) ReloadOS(stemcell bslcstem.Stemcell) error {
	reload_OS_Config := sldatatypes.Image_Template_Config{
		ImageTemplateId: strconv.Itoa(stemcell.ID()),
	}

	virtualGuestService, err := vm.softLayerClient.GetSoftLayer_Virtual_Guest_Service()
	if err != nil {
		return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
	}

	err = bslcommon.WaitForVirtualGuestToHaveNoRunningTransactions(vm.softLayerClient, vm.ID())
	if err != nil {
		return bosherr.WrapError(err, fmt.Sprintf("Waiting for VirtualGuest %d to have no pending transactions before os reload", vm.ID()))
	}
	vm.logger.Info(SOFTLAYER_VM_OS_RELOAD_TAG, fmt.Sprintf("No transaction is running on this VM %d", vm.ID()))

	err = virtualGuestService.ReloadOperatingSystem(vm.ID(), reload_OS_Config)
	if err != nil {
		return bosherr.WrapError(err, "Failed to reload OS on the specified VirtualGuest from SoftLayer client")
	}

	err = vm.postCheckActiveTransactionsForOSReload(vm.softLayerClient)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:28,代码来源:softlayer_vm.go

示例6: PutCustomized

func (c httpClient) PutCustomized(endpoint string, payload []byte, f func(*http.Request)) (*http.Response, error) {
	putPayload := strings.NewReader(string(payload))

	redactedEndpoint := endpoint

	if !c.opts.NoRedactUrlQuery {
		redactedEndpoint = scrubEndpointQuery(endpoint)
	}

	c.logger.Debug(c.logTag, "Sending PUT request to endpoint '%s'", redactedEndpoint)

	request, err := http.NewRequest("PUT", endpoint, putPayload)
	if err != nil {
		return nil, bosherr.WrapError(err, "Creating PUT request")
	}

	if f != nil {
		f(request)
	}

	response, err := c.client.Do(request)
	if err != nil {
		return nil, bosherr.WrapError(scrubErrorOutput(err), "Performing PUT request")
	}

	return response, nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:27,代码来源:http_client.go

示例7: validate

func (c Config) validate() error {
	if c.AssetsDir == "" {
		return bosherr.Error("Must provide non-empty assets_dir")
	}

	if c.ReposDir == "" {
		return bosherr.Error("Must provide non-empty repos_dir")
	}

	err := c.EventLog.Validate()
	if err != nil {
		return bosherr.WrapError(err, "Validating event_log configuration")
	}

	if c.Blobstore.Type != bpprov.BlobstoreConfigTypeLocal {
		return bosherr.Error("Blobstore type must be local")
	}

	err = c.Blobstore.Validate()
	if err != nil {
		return bosherr.WrapError(err, "Validating blobstore configuration")
	}

	return nil
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:25,代码来源:config.go

示例8: SetupHostname

func (p linux) SetupHostname(hostname string) error {
	if !p.state.Linux.HostsConfigured {
		_, _, _, err := p.cmdRunner.RunCommand("hostname", hostname)
		if err != nil {
			return bosherr.WrapError(err, "Setting hostname")
		}

		err = p.fs.WriteFileString("/etc/hostname", hostname)
		if err != nil {
			return bosherr.WrapError(err, "Writing to /etc/hostname")
		}

		buffer := bytes.NewBuffer([]byte{})
		t := template.Must(template.New("etc-hosts").Parse(etcHostsTemplate))

		err = t.Execute(buffer, hostname)
		if err != nil {
			return bosherr.WrapError(err, "Generating config from template")
		}

		err = p.fs.WriteFile("/etc/hosts", buffer.Bytes())
		if err != nil {
			return bosherr.WrapError(err, "Writing to /etc/hosts")
		}

		p.state.Linux.HostsConfigured = true
		err = p.state.SaveState()
		if err != nil {
			return bosherr.WrapError(err, "Setting up hostname")
		}
	}

	return nil
}
开发者ID:teddyking,项目名称:bosh-agent,代码行数:34,代码来源:linux_platform.go

示例9: Create

func (c SoftLayerCreator) Create(size int, cloudProps DiskCloudProperties, virtualGuestId int) (Disk, error) {
	c.logger.Debug(SOFTLAYER_DISK_CREATOR_LOG_TAG, "Creating disk of size '%d'", size)

	vmService, err := c.softLayerClient.GetSoftLayer_Virtual_Guest_Service()
	if err != nil {
		return SoftLayerDisk{}, bosherr.WrapError(err, "Create SoftLayer Virtual Guest Service error.")
	}

	vm, err := vmService.GetObject(virtualGuestId)
	if err != nil || vm.Id == 0 {
		return SoftLayerDisk{}, bosherr.WrapError(err, fmt.Sprintf("Cannot retrieve vitual guest with id: %d.", virtualGuestId))
	}

	storageService, err := c.softLayerClient.GetSoftLayer_Network_Storage_Service()
	if err != nil {
		return SoftLayerDisk{}, bosherr.WrapError(err, "Create SoftLayer Network Storage Service error.")
	}

	disk, err := storageService.CreateIscsiVolume(c.getSoftLayerDiskSize(size), strconv.Itoa(vm.Datacenter.Id))
	if err != nil {
		return SoftLayerDisk{}, bosherr.WrapError(err, "Create SoftLayer iSCSI disk error.")
	}

	return NewSoftLayerDisk(disk.Id, c.softLayerClient, c.logger), nil
}
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:25,代码来源:softlayer_creator.go

示例10: getUserData

func (ms httpMetadataService) getUserData() (UserDataContentsType, error) {
	var userData UserDataContentsType

	err := ms.ensureMinimalNetworkSetup()
	if err != nil {
		return userData, err
	}

	userDataURL := fmt.Sprintf("%s/latest/user-data", ms.metadataHost)
	userDataResp, err := http.Get(userDataURL)
	if err != nil {
		return userData, bosherr.WrapError(err, "Getting user data from url")
	}

	defer func() {
		if err := userDataResp.Body.Close(); err != nil {
			ms.logger.Warn(ms.logTag, "Failed to close response body when getting user data: %s", err.Error())
		}
	}()

	userDataBytes, err := ioutil.ReadAll(userDataResp.Body)
	if err != nil {
		return userData, bosherr.WrapError(err, "Reading user data response body")
	}

	err = json.Unmarshal(userDataBytes, &userData)
	if err != nil {
		return userData, bosherr.WrapError(err, "Unmarshalling user data")
	}

	return userData, nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:32,代码来源:http_metadata_service.go

示例11: GetInstanceID

func (ms httpMetadataService) GetInstanceID() (string, error) {
	err := ms.ensureMinimalNetworkSetup()
	if err != nil {
		return "", err
	}

	url := fmt.Sprintf("%s/latest/meta-data/instance-id", ms.metadataHost)
	resp, err := http.Get(url)
	if err != nil {
		return "", bosherr.WrapError(err, "Getting instance id from url")
	}

	defer func() {
		if err := resp.Body.Close(); err != nil {
			ms.logger.Warn(ms.logTag, "Failed to close response body when getting instance id: %s", err.Error())
		}
	}()

	bytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", bosherr.WrapError(err, "Reading instance id response body")
	}

	return string(bytes), nil
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:25,代码来源:http_metadata_service.go

示例12: Start

func (w *windowsJobSupervisor) Start() error {
	// Set the starttype of the service running the Agent to 'manual'.
	// This will prevent the agent from automatically starting if the
	// machine is rebooted.
	//
	// Do this here, as we know the agent has successfully connected
	// with the director and is healthy.
	w.cmdRunner.RunCommand("-Command", disableAgentAutoStart)

	_, _, _, err := w.cmdRunner.RunCommand("-Command", manualStartJobScript)
	if err != nil {
		return bosherr.WrapError(err, "Starting windows job process")
	}
	_, _, _, err = w.cmdRunner.RunCommand("-Command", startJobScript)
	if err != nil {
		return bosherr.WrapError(err, "Starting windows job process")
	}

	err = w.fs.RemoveAll(w.stoppedFilePath())
	if err != nil {
		return bosherr.WrapError(err, "Removing stopped file")
	}

	w.stateSet(stateEnabled)
	return nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:26,代码来源:windows_job_supervisor.go

示例13: SetupHostname

func (p linux) SetupHostname(hostname string) (err error) {
	_, _, _, err = p.cmdRunner.RunCommand("hostname", hostname)
	if err != nil {
		err = bosherr.WrapError(err, "Shelling out to hostname")
		return
	}

	err = p.fs.WriteFileString("/etc/hostname", hostname)
	if err != nil {
		err = bosherr.WrapError(err, "Writing /etc/hostname")
		return
	}

	buffer := bytes.NewBuffer([]byte{})
	t := template.Must(template.New("etc-hosts").Parse(etcHostsTemplate))

	err = t.Execute(buffer, hostname)
	if err != nil {
		err = bosherr.WrapError(err, "Generating config from template")
		return
	}

	err = p.fs.WriteFile("/etc/hosts", buffer.Bytes())
	if err != nil {
		err = bosherr.WrapError(err, "Writing to /etc/hosts")
	}
	return
}
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:28,代码来源:linux_platform.go

示例14: SetupTmpDir

func (p linux) SetupTmpDir() error {
	systemTmpDir := "/tmp"
	boshTmpDir := p.dirProvider.TmpDir()
	boshRootTmpPath := path.Join(p.dirProvider.DataDir(), "root_tmp")

	err := p.fs.MkdirAll(boshTmpDir, tmpDirPermissions)
	if err != nil {
		return bosherr.WrapError(err, "Creating temp dir")
	}

	err = os.Setenv("TMPDIR", boshTmpDir)
	if err != nil {
		return bosherr.WrapError(err, "Setting TMPDIR")
	}

	err = p.changeTmpDirPermissions(systemTmpDir)
	if err != nil {
		return err
	}

	// /var/tmp is used for preserving temporary files between system reboots
	varTmpDir := "/var/tmp"

	err = p.changeTmpDirPermissions(varTmpDir)
	if err != nil {
		return err
	}

	if p.options.UseDefaultTmpDir {
		return nil
	}

	err = p.fs.RemoveAll(boshRootTmpPath)
	if err != nil {
		return bosherr.WrapError(err, fmt.Sprintf("cleaning up %s", boshRootTmpPath))
	}

	_, _, _, err = p.cmdRunner.RunCommand("mkdir", "-p", boshRootTmpPath)
	if err != nil {
		return bosherr.WrapError(err, "Creating root tmp dir")
	}

	// change permissions
	err = p.changeTmpDirPermissions(boshRootTmpPath)
	if err != nil {
		return bosherr.WrapError(err, "Chmoding root tmp dir")
	}

	err = p.bindMountDir(boshRootTmpPath, systemTmpDir)
	if err != nil {
		return err
	}

	err = p.bindMountDir(boshRootTmpPath, varTmpDir)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:60,代码来源:linux_platform.go

示例15: Provision

func (p VCAPUserProvisioner) Provision() error {
	stage := p.eventLog.BeginStage("Setting up vcap user", 3)

	task := stage.BeginTask("Adding vcap user")

	err := task.End(p.setUpVcapUser())
	if err != nil {
		return bosherr.WrapError(err, "Setting up vcap user")
	}

	task = stage.BeginTask("Configuring locales")

	err = task.End(p.configureLocales())
	if err != nil {
		return bosherr.WrapError(err, "Configuring locales")
	}

	task = stage.BeginTask("Harden permissions")

	err = task.End(p.hardenPermissinons())
	if err != nil {
		return bosherr.WrapError(err, "Harden permissions")
	}

	return nil
}
开发者ID:pcfdev-forks,项目名称:bosh-provisioner,代码行数:26,代码来源:vcap_user_provisioner.go


注:本文中的github.com/cloudfoundry/bosh-utils/errors.WrapError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。