本文整理匯總了Golang中github.com/emccode/rexray/core/errors.WithFields函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithFields函數的具體用法?Golang WithFields怎麽用?Golang WithFields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithFields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getInstanceID
func getInstanceID(c *config.Config) (string, error) {
cmd := newCmd(c, "/usr/bin/xenstore-read", "name")
cmdOut, err := cmd.Output()
if err != nil {
return "",
errors.WithFields(eff(errors.Fields{
"cmd.Path": cmd.Path,
"cmd.Args": cmd.Args,
"cmd.Out": cmdOut,
}), "error getting instance id")
}
instanceID := strings.Replace(string(cmdOut), "\n", "", -1)
validInstanceID := regexp.MustCompile(`^instance-`)
valid := validInstanceID.MatchString(instanceID)
if !valid {
return "", errors.WithFields(eff(errors.Fields{
"instanceId": instanceID}), "error matching instance id")
}
instanceID = strings.Replace(instanceID, "instance-", "", 1)
return instanceID, nil
}
示例2: AttachVolume
func (d *driver) AttachVolume(
runAsync bool,
volumeID, instanceID string) ([]*core.VolumeAttachment, error) {
fields := eff(map[string]interface{}{
"runAsync": runAsync,
"volumeId": volumeID,
"instanceId": instanceID,
})
if volumeID == "" {
return nil, errors.WithFields(fields, "volumeId is required")
}
mapVolumeSdcParam := &types.MapVolumeSdcParam{
SdcID: d.sdc.Sdc.ID,
AllowMultipleMappings: "false",
AllSdcs: "",
}
volumes, err := d.getVolume(volumeID, "")
if err != nil {
return nil, errors.WithFieldsE(fields, "error getting volume", err)
}
if len(volumes) == 0 {
return nil, errors.WithFields(fields, "no volumes returned")
}
targetVolume := goscaleio.NewVolume(d.client)
targetVolume.Volume = volumes[0]
err = targetVolume.MapVolumeSdc(mapVolumeSdcParam)
if err != nil {
return nil, errors.WithFieldsE(fields, "error mapping volume sdc", err)
}
_, err = waitMount(volumes[0].ID)
if err != nil {
fields["volumeId"] = volumes[0].ID
return nil, errors.WithFieldsE(
fields, "error waiting on volume to mount", err)
}
volumeAttachment, err := d.GetVolumeAttach(volumeID, instanceID)
if err != nil {
return nil, errors.WithFieldsE(
fields, "error getting volume attachments", err)
}
log.WithFields(log.Fields{
"provider": providerName,
"volumeId": volumeID,
"instanceId": instanceID,
}).Debug("attached volume to instance")
return volumeAttachment, nil
}
示例3: createVolumeHandleSnapshotID
func (d *driver) createVolumeHandleSnapshotID(
size *int64, snapshotID string, fields map[string]interface{}) error {
if snapshotID == "" {
return nil
}
snapshots, err := d.GetSnapshot("", snapshotID, "")
if err != nil {
return errors.WithFieldsE(fields, "error getting snapshot", err)
}
if len(snapshots) == 0 {
return errors.WithFields(fields, "snapshot array is empty")
}
volSize := snapshots[0].VolumeSize
sizeInt, err := strconv.Atoi(volSize)
if err != nil {
f := errors.Fields{
"volumeSize": volSize,
}
for k, v := range fields {
f[k] = v
}
return errors.WithFieldsE(f, "error casting volume size", err)
}
*size = int64(sizeInt)
return nil
}
示例4: Init
func (d *driver) Init(r *core.RexRay) error {
d.r = r
var err error
d.instanceDocument, err = getInstanceIdentityDocument()
if err != nil {
return errors.WithFields(ef(), "error getting instance id doc")
}
auth := aws.Auth{
AccessKey: d.r.Config.AwsAccessKey,
SecretKey: d.r.Config.AwsSecretKey,
}
region := d.r.Config.AwsRegion
if region == "" {
region = d.instanceDocument.Region
}
d.ec2Instance = ec2.New(
auth,
aws.Regions[region],
)
log.WithField("provider", providerName).Info("storage driver initialized")
return nil
}
示例5: RemoveVolume
func (d *driver) RemoveVolume(volumeID string) error {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
var err error
var volumes []*types.Volume
if volumes, err = d.getVolume(volumeID, ""); err != nil {
return errors.WithFieldsE(fields, "error getting volume", err)
}
targetVolume := goscaleio.NewVolume(d.client)
targetVolume.Volume = volumes[0]
if err = targetVolume.RemoveVolume("ONLY_ME"); err != nil {
return errors.WithFieldsE(fields, "error removing volume", err)
}
log.WithFields(fields).Debug("removed volume")
return nil
}
示例6: GetVolumeAttach
func (d *driver) GetVolumeAttach(
volumeID, instanceID string) ([]*core.VolumeAttachment, error) {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
"instanceId": instanceID,
})
if volumeID == "" {
return []*core.VolumeAttachment{},
errors.WithFields(fields, "volumeId is required")
}
volume, err := d.GetVolume(volumeID, "")
if err != nil {
return []*core.VolumeAttachment{},
errors.WithFieldsE(fields, "error getting volume attach", err)
}
if instanceID != "" {
var attached bool
for _, volumeAttachment := range volume[0].Attachments {
if volumeAttachment.InstanceID == instanceID {
return volume[0].Attachments, nil
}
}
if !attached {
return []*core.VolumeAttachment{}, nil
}
}
return volume[0].Attachments, nil
}
示例7: waitMount
func waitMount(volumeID string) (*goscaleio.SdcMappedVolume, error) {
timeout := make(chan bool, 1)
go func() {
time.Sleep(10 * time.Second)
timeout <- true
}()
successCh := make(chan *goscaleio.SdcMappedVolume, 1)
errorCh := make(chan error, 1)
go func(volumeID string) {
log.WithField("provider", providerName).Debug("waiting for volume mount")
for {
sdcMappedVolumes, err := goscaleio.GetLocalVolumeMap()
if err != nil {
errorCh <- errors.WithFieldE(
"provider", providerName,
"problem getting local volume mappings", err)
return
}
sdcMappedVolume := &goscaleio.SdcMappedVolume{}
var foundVolume bool
for _, sdcMappedVolume = range sdcMappedVolumes {
if sdcMappedVolume.VolumeID ==
volumeID && sdcMappedVolume.SdcDevice != "" {
foundVolume = true
break
}
}
if foundVolume {
successCh <- sdcMappedVolume
return
}
time.Sleep(100 * time.Millisecond)
}
}(volumeID)
select {
case sdcMappedVolume := <-successCh:
log.WithFields(log.Fields{
"provider": providerName,
"volumeId": sdcMappedVolume.VolumeID,
"volume": sdcMappedVolume.SdcDevice,
}).Debug("got sdcMappedVolume")
return sdcMappedVolume, nil
case err := <-errorCh:
return &goscaleio.SdcMappedVolume{}, err
case <-timeout:
return &goscaleio.SdcMappedVolume{}, errors.WithFields(
ef(), "timed out waiting for mount")
}
}
示例8: DetachVolume
func (d *driver) DetachVolume(
runAsync bool, volumeID string, blank string) error {
fields := eff(map[string]interface{}{
"runAsync": runAsync,
"volumeId": volumeID,
"blank": blank,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
volumes, err := d.getVolume(volumeID, "")
if err != nil {
return errors.WithFieldsE(fields, "error getting volume", err)
}
if len(volumes) == 0 {
return errors.WithFields(fields, "no volumes returned")
}
targetVolume := goscaleio.NewVolume(d.client)
targetVolume.Volume = volumes[0]
unmapVolumeSdcParam := &types.UnmapVolumeSdcParam{
SdcID: d.sdc.Sdc.ID,
IgnoreScsiInitiators: "true",
AllSdcs: "",
}
// need to detect if unmounted first
err = targetVolume.UnmapVolumeSdc(unmapVolumeSdcParam)
if err != nil {
return errors.WithFieldsE(fields, "error unmapping volume sdc", err)
}
log.WithFields(log.Fields{
"provider": providerName,
"volumeId": volumeID}).Debug("detached volume")
return nil
}
示例9: createVolumeHandleVolumeID
func (d *driver) createVolumeHandleVolumeID(
availabilityZone, snapshotID, volumeID *string,
size *int64,
fields map[string]interface{}) ([]*core.Volume, error) {
if *volumeID == "" {
return nil, nil
}
var err error
var volume []*core.Volume
if volume, err = d.GetVolume(*volumeID, ""); err != nil {
return nil, errors.WithFieldsE(fields, "error getting volumes", err)
}
if len(volume) == 0 {
return nil, errors.WithFieldsE(fields, "", errors.ErrNoVolumesReturned)
}
volSize := volume[0].Size
sizeInt, err := strconv.Atoi(volSize)
if err != nil {
f := errors.Fields{
"volumeSize": volSize,
}
for k, v := range fields {
f[k] = v
}
return nil,
errors.WithFieldsE(f, "error casting volume size", err)
}
*size = int64(sizeInt)
*volumeID = volume[0].VolumeID
snapshot, err := d.CreateSnapshot(
false, fmt.Sprintf("temp-%s", *volumeID), *volumeID, "")
if err != nil {
return nil,
errors.WithFields(fields, "error creating snapshot")
}
*snapshotID = snapshot[0].SnapshotID
if *availabilityZone == "" {
*availabilityZone = volume[0].AvailabilityZone
}
return volume, nil
}
示例10: Init
func (d *xtremIODriver) Init(r *core.RexRay) error {
d.r = r
d.volumesByNaa = map[string]xtio.Volume{}
fields := eff(map[string]interface{}{
"endpoint": r.Config.XtremIOEndpoint,
"userName": r.Config.XtremIOUserName,
"deviceMapper": r.Config.XtremIODeviceMapper,
"multipath": r.Config.XtremIOMultipath,
"remoteManagement": r.Config.XtremIORemoteManagement,
"insecure": r.Config.XtremIOInsecure,
})
if r.Config.XtremIoPassword == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
if !isXtremIOAttached() && !d.r.Config.XtremIORemoteManagement {
return errors.WithFields(fields, "device not detected")
}
var err error
if d.client, err = xtio.NewClientWithArgs(
r.Config.XtremIOEndpoint,
r.Config.XtremIOInsecure,
r.Config.XtremIOUserName,
r.Config.XtremIoPassword); err != nil {
return errors.WithFieldsE(fields,
"error creating xtremio client", err)
}
if !d.r.Config.XtremIORemoteManagement {
var iqn string
if iqn, err = getIQN(); err != nil {
return err
}
if d.initiator, err = d.client.GetInitiator("", iqn); err != nil {
return err
}
}
log.WithField("provider", providerName).Debug("storage driver initialized")
return nil
}
示例11: Init
func (d *driver) Init(r *core.RexRay) error {
d.r = r
d.volumesByNaa = map[string]xtio.Volume{}
fields := eff(map[string]interface{}{
"endpoint": d.endpoint(),
"userName": d.userName(),
"deviceMapper": d.deviceMapper(),
"multipath": d.multipath(),
"remoteManagement": d.remoteManagement(),
"insecure": d.insecure(),
})
if d.password() == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
if !isXtremIOAttached() && !d.remoteManagement() {
return errors.WithFields(fields, "device not detected")
}
var err error
if d.client, err = xtio.NewClientWithArgs(
d.endpoint(),
d.insecure(),
d.userName(),
d.password()); err != nil {
return errors.WithFieldsE(fields,
"error creating xtremio client", err)
}
if !d.remoteManagement() {
var iqn string
if iqn, err = getIQN(); err != nil {
return err
}
if d.initiator, err = d.client.GetInitiator("", iqn); err != nil {
return err
}
}
log.WithField("provider", providerName).Info("storage driver initialized")
return nil
}
示例12: RemoveVolume
func (d *driver) RemoveVolume(volumeID string) error {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
res := volumes.Delete(d.clientBlockStorage, volumeID)
if res.Err != nil {
return errors.WithFieldsE(fields, "error removing volume", res.Err)
}
log.WithFields(fields).Debug("removed volume")
return nil
}
示例13: getInstanceID
func getInstanceID(c *config.Config) (string, error) {
cmd := newCmd(c, "/usr/sbin/dmidecode")
cmdOut, err := cmd.Output()
if err != nil {
return "",
errors.WithFields(eff(errors.Fields{
"cmd.Path": cmd.Path,
"cmd.Args": cmd.Args,
"cmd.Out": cmdOut,
}), "error getting instance id")
}
rp := regexp.MustCompile("UUID:(.*)")
uuid := strings.Replace(rp.FindString(string(cmdOut)), "UUID: ", "", -1)
return strings.ToLower(uuid), nil
}
示例14: getInstanceRegion
func getInstanceRegion(cfg *config.Config) (string, error) {
cmd := newCmd(
cfg, "/usr/bin/xenstore-read",
"vm-data/provider_data/region")
cmdOut, err := cmd.Output()
if err != nil {
return "",
errors.WithFields(eff(errors.Fields{
"cmd.Path": cmd.Path,
"cmd.Args": cmd.Args,
"cmd.Out": cmdOut,
}), "error getting instance region")
}
region := strings.Replace(string(cmdOut), "\n", "", -1)
return region, nil
}
示例15: InitializeModule
// InitializeModule initializes a module.
func InitializeModule(
modTypeID int32,
modConfig *Config) (*Instance, error) {
modInstancesRwl.Lock()
defer modInstancesRwl.Unlock()
lf := log.Fields{
"typeId": modTypeID,
"address": modConfig.Address,
}
mt, modTypeExists := modTypes[modTypeID]
if !modTypeExists {
return nil, errors.WithFields(lf, "unknown module type")
}
lf["typeName"] = mt.Name
lf["ignoreFailOnInit"] = mt.IgnoreFailOnInit
modInstID := atomic.AddInt32(&nextModInstanceID, 1)
mod, initErr := mt.InitFunc(modInstID, modConfig)
if initErr != nil {
atomic.AddInt32(&nextModInstanceID, -1)
return nil, initErr
}
modInst := &Instance{
ID: modInstID,
Type: mt,
TypeID: mt.ID,
Inst: mod,
Name: mod.Name(),
Config: modConfig,
Description: mod.Description(),
}
modInstances[modInstID] = modInst
lf["id"] = modInstID
log.WithFields(lf).Info("initialized module instance")
return modInst, nil
}