當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。