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


Golang Context.WithField方法代码示例

本文整理汇总了Golang中github.com/codedellemc/libstorage/api/types.Context.WithField方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.WithField方法的具体用法?Golang Context.WithField怎么用?Golang Context.WithField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/codedellemc/libstorage/api/types.Context的用法示例。


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

示例1: Start

// Start starts the daemon.
func Start(
	ctx apitypes.Context,
	config gofig.Config,
	host string,
	stop <-chan os.Signal) (<-chan error, error) {

	var (
		err           error
		errs          = make(chan error)
		daemonErrChan <-chan error
	)

	if daemonErrChan, err = start(ctx, config, host, stop); err != nil {
		ctx.WithError(err).Error("daemon failed to initialize")
		return nil, err
	}

	ctx.Info("service successfully initialized, waiting on stop signal")

	go func() {
		sig := <-stop
		ctx.WithField("signal", sig).Info("service received stop signal")
		util.WaitUntilLibStorageStopped(ctx, daemonErrChan)
		close(errs)
	}()

	return errs, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:29,代码来源:daemon.go

示例2: findMachineByNameOrID

func (d *driver) findMachineByNameOrID(
	ctx types.Context, nameOrID string) (*vboxc.Machine, error) {

	ctx.WithField("nameOrID", nameOrID).Debug("finding local machine")

	m, err := d.vbox.FindMachine(nameOrID)
	if err != nil {
		return nil, err
	}
	if m == nil {
		return nil, goof.New("could not find machine")
	}

	if id, err := m.GetID(); err == nil {
		m.ID = id
	} else {
		return nil, err
	}

	if name, err := m.GetName(); err == nil {
		m.Name = name
	} else {
		return nil, err
	}

	return m, nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:27,代码来源:vbox_storage.go

示例3: handleWithMiddleware

func (s *server) handleWithMiddleware(
	ctx types.Context,
	route types.Route) types.APIFunc {

	/*if route.GetMethod() == "HEAD" {
		return route.GetHandler()
	}*/

	handler := route.GetHandler()

	middlewaresForRouteName, ok := s.routeHandlers[route.GetName()]
	if !ok {
		ctx.Warn("no middlewares for route")
	} else {
		for h := range reverse(middlewaresForRouteName) {
			handler = h.Handler(handler)
			ctx.WithField(
				"middleware", h.Name()).Debug("added route middleware")
		}
	}

	// add the global handlers
	for h := range reverse(s.globalHandlers) {
		handler = h.Handler(handler)
		ctx.WithField(
			"middleware", h.Name()).Debug("added global middleware")
	}

	return handler
}
开发者ID:emccode,项目名称:libstorage,代码行数:30,代码来源:server_middleware.go

示例4: getExecutorChecksum

func (c *client) getExecutorChecksum(ctx types.Context) (string, error) {

	if c.isController() {
		return "", utils.NewUnsupportedForClientTypeError(
			c.clientType, "getExecutorChecksum")
	}

	ctx.Debug("getting executor checksum")

	f, err := os.Open(types.LSX.String())
	if err != nil {
		return "", err
	}
	defer f.Close()

	h := md5.New()
	buf := make([]byte, 1024)
	for {
		n, err := f.Read(buf)
		if err == io.EOF {
			break
		}
		if err != nil {
			return "", err
		}
		if _, err := h.Write(buf[:n]); err != nil {
			return "", err
		}
	}

	sum := fmt.Sprintf("%x", h.Sum(nil))
	ctx.WithField("localChecksum", sum).Debug("got local executor checksum")
	return sum, nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:34,代码来源:libstorage_client.go

示例5: downloadExecutor

func (c *client) downloadExecutor(ctx types.Context) error {

	if c.isController() {
		return utils.NewUnsupportedForClientTypeError(
			c.clientType, "downloadExecutor")
	}

	ctx.Debug("downloading executor")

	f, err := os.OpenFile(
		types.LSX.String(),
		os.O_CREATE|os.O_RDWR|os.O_TRUNC,
		0755)
	if err != nil {
		return err
	}

	defer f.Close()

	rdr, err := c.APIClient.ExecutorGet(ctx, types.LSX.Name())
	n, err := io.Copy(f, rdr)
	if err != nil {
		return err
	}

	if err := f.Sync(); err != nil {
		return err
	}

	ctx.WithField("bytes", n).Debug("downloaded executor")
	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:32,代码来源:libstorage_client.go

示例6: initDefaultLibStorageServices

// initDefaultLibStorageServices initializes the config object with a default
// libStorage service if one is not present.
//
// TODO Move this into libStorage in libStorage 0.1.2
func initDefaultLibStorageServices(
	ctx apitypes.Context, config gofig.Config) error {

	if config.IsSet(apitypes.ConfigServices) {
		ctx.Debug(
			"libStorage auto service mode disabled; services defined")
		return nil
	}

	serviceName := config.GetString(apitypes.ConfigService)
	if serviceName == "" {
		ctx.Debug(
			"libStorage auto service mode disabled; service name empty")
		return nil
	}

	ctx.WithField("driver", serviceName).Info(
		"libStorage auto service mode enabled")

	buf := &bytes.Buffer{}
	fmt.Fprintf(buf, defaultServiceConfigFormat, serviceName)

	if err := config.ReadConfig(buf); err != nil {
		return err
	}

	return nil
}
开发者ID:akutz,项目名称:rexray,代码行数:32,代码来源:util_libstorage.go

示例7: Init

func (d *driver) Init(ctx types.Context, config gofig.Config) error {
	d.ctx = ctx
	d.config = config

	d.volPath = vfs.VolumesDirPath(config)
	d.snapPath = vfs.SnapshotsDirPath(config)

	ctx.WithField("vfs.root.path", vfs.RootDir(config)).Info("vfs.root")

	os.MkdirAll(d.volPath, 0755)
	os.MkdirAll(d.snapPath, 0755)

	d.volJSONGlobPatt = fmt.Sprintf("%s/*.json", d.volPath)
	d.snapJSONGlobPatt = fmt.Sprintf("%s/*.json", d.snapPath)

	volJSONPaths, err := d.getVolJSONs()
	if err != nil {
		return nil
	}
	d.volCount = int64(len(volJSONPaths)) - 1

	snapJSONPaths, err := d.getSnapJSONs()
	if err != nil {
		return nil
	}
	d.snapCount = int64(len(snapJSONPaths)) - 1

	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:29,代码来源:vfs_storage.go

示例8: initStorageDriver

func (s *storageService) initStorageDriver(ctx types.Context) error {
	driverName := s.config.GetString("driver")
	if driverName == "" {
		driverName = s.config.GetString("libstorage.driver")
		if driverName == "" {
			driverName = s.config.GetString("libstorage.storage.driver")
			if driverName == "" {
				return goof.WithField(
					"service", s.name, "error getting driver name")
			}
		}
	}

	ctx.WithField("driverName", driverName).Debug("got driver name")
	driver, err := registry.NewStorageDriver(driverName)
	if err != nil {
		return err
	}

	ctx = ctx.WithValue(context.DriverKey, driver)

	if err := driver.Init(ctx, s.config); err != nil {
		return err
	}

	s.driver = driver
	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:28,代码来源:services_storage.go

示例9: setHost

func setHost(
	ctx apitypes.Context,
	config gofig.Config,
	host string) apitypes.Context {
	ctx = ctx.WithValue(context.HostKey, host)
	ctx.WithField("host", host).Debug("set host in context")
	config.Set(apitypes.ConfigHost, host)
	ctx.WithField("host", host).Debug("set host in config")
	return ctx
}
开发者ID:akutz,项目名称:rexray,代码行数:10,代码来源:util.go

示例10: createVolume

func (d *driver) createVolume(
	ctx types.Context, name string, size int64) (*vboxc.Medium, error) {

	if name == "" {
		return nil, goof.New("name is empty")
	}
	path := filepath.Join(d.volumePath(), name)
	ctx.WithField("path", path).Debug("creating vmdk")
	return d.vbox.CreateMedium("vmdk", path, size)
}
开发者ID:emccode,项目名称:libstorage,代码行数:10,代码来源:vbox_storage.go

示例11: VolumeAttach

// VolumeAttach attaches a volume and provides a token clients can use
// to validate that device has appeared locally.
func (d *driver) VolumeAttach(
	ctx types.Context,
	volumeID string,
	opts *types.VolumeAttachOpts) (*types.Volume, string, error) {

	svc := mustSession(ctx)

	vol, err := d.VolumeInspect(ctx, volumeID,
		&types.VolumeInspectOpts{Attachments: types.VolAttReqTrue})
	if err != nil {
		return nil, "", err
	}

	iid := context.MustInstanceID(ctx)

	var ma *types.VolumeAttachment
	for _, att := range vol.Attachments {
		if att.InstanceID.ID == iid.ID {
			ma = att
			break
		}
	}

	// No mount targets were found
	if ma == nil {

		secGrpIDs := d.secGroups
		if v, ok := iid.Fields[efs.InstanceIDFieldSecurityGroups]; ok {
			iSecGrpIDs := strings.Split(v, ";")
			ctx.WithField("secGrpIDs", iSecGrpIDs).Debug(
				"using instance security group IDs")
			secGrpIDs = iSecGrpIDs
		}

		if len(secGrpIDs) == 0 {
			return nil, "", errInvalidSecGroups
		}

		request := &awsefs.CreateMountTargetInput{
			FileSystemId:   aws.String(vol.ID),
			SubnetId:       aws.String(iid.ID),
			SecurityGroups: aws.StringSlice(secGrpIDs),
		}
		// TODO(mhrabovcin): Should we block here until MountTarget is in
		// "available" LifeCycleState? Otherwise mount could fail until creation
		//  is completed.
		_, err = svc.CreateMountTarget(request)
		// Failed to create mount target
		if err != nil {
			return nil, "", err
		}
	}

	return vol, "", err
}
开发者ID:emccode,项目名称:libstorage,代码行数:57,代码来源:efs_storage.go

示例12: dial

func (c *client) dial(ctx types.Context) error {

	ctx.WithField("path", lsxMutex).Info("lsx lock file path")

	svcInfos, err := c.Services(ctx)
	if err != nil {
		return err
	}

	// controller clients do not have any additional dialer logic
	if c.isController() {
		return nil
	}

	store := utils.NewStore()
	c.ctx = c.ctx.WithValue(context.ServerKey, c.ServerName())

	if !c.config.GetBool(types.ConfigExecutorNoDownload) {

		ctx.Info("initializing executors cache")
		if _, err := c.Executors(ctx); err != nil {
			return err
		}

		if err := c.updateExecutor(ctx); err != nil {
			return err
		}
	}

	for service, _ := range svcInfos {
		ctx := c.ctx.WithValue(context.ServiceKey, service)
		ctx.Info("initializing supported cache")
		supported, err := c.Supported(ctx, store)
		if err != nil {
			return goof.WithError("error initializing supported cache", err)
		}

		if !supported {
			ctx.Warn("executor not supported")
			continue
		}

		ctx.Info("initializing instance ID cache")
		if _, err := c.InstanceID(ctx, store); err != nil {
			if err == types.ErrNotImplemented {
				ctx.WithError(err).Warn("cannot get instance ID")
				continue
			}
			return goof.WithError("error initializing instance ID cache", err)
		}
	}

	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:54,代码来源:libstorage_client.go

示例13: Init

// Init initializes the service.
func (s *globalTaskService) Init(ctx types.Context, config gofig.Config) error {
	s.tasks = map[int]*task{}
	s.config = config

	s.resultSchemaValidationEnabled = config.GetBool(
		types.ConfigSchemaResponseValidationEnabled)
	ctx.WithField("enabled", s.resultSchemaValidationEnabled).Debug(
		"configured result schema validation")

	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:12,代码来源:services_task.go

示例14: InitializeDefaultModules

// InitializeDefaultModules initializes the default modules.
func InitializeDefaultModules(
	ctx apitypes.Context,
	config gofig.Config) (<-chan error, error) {

	modTypesRwl.RLock()
	defer modTypesRwl.RUnlock()

	var (
		err  error
		mod  *Instance
		errs <-chan error
	)

	// enable path caching for the modules
	config.Set(apitypes.ConfigIgVolOpsPathCacheEnabled, true)

	ctx, config, errs, err = util.ActivateLibStorage(ctx, config)
	if err != nil {
		return nil, err
	}

	modConfigs, err := getConfiguredModules(ctx, config)
	if err != nil {
		return nil, err
	}

	ctx.WithField("len(modConfigs)", len(modConfigs)).Debug(
		"got configured modules")

	for _, mc := range modConfigs {

		ctx.WithField("name", mc.Name).Debug(
			"creating libStorage client for module instance")

		if mc.Client, err = util.NewClient(ctx, mc.Config); err != nil {
			panic(err)
		}

		if mod, err = InitializeModule(ctx, mc); err != nil {
			return nil, err
		}

		modInstances[mod.Name] = mod
	}

	return errs, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:48,代码来源:module.go

示例15: unmarshalLocalDevices

func unmarshalLocalDevices(
	ctx types.Context, out []byte) (*types.LocalDevices, error) {

	ld := &types.LocalDevices{}
	if err := ld.UnmarshalText(out); err != nil {
		return nil, err
	}

	// remove any local devices that has no mapped volume information
	for k, v := range ld.DeviceMap {
		if len(v) == 0 {
			ctx.WithField("deviceID", k).Warn(
				"removing local device w/ invalid volume id")
			delete(ld.DeviceMap, k)
		}
	}

	return ld, nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:19,代码来源:libstorage_client_xcli.go


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