本文整理汇总了Golang中github.com/akutz/goof.WithError函数的典型用法代码示例。如果您正苦于以下问题:Golang WithError函数的具体用法?Golang WithError怎么用?Golang WithError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DetachVolume
//Added if statement for vmh mode
func (d *driver) DetachVolume(runAsync bool, volumeID string, blank string, notused bool) error {
volumes, err := d.GetVolume(volumeID, "")
if err != nil {
return err
}
if len(volumes) == 0 {
return goof.New("volume not found")
}
if d.vmh != nil {
if err := d.deleteScsiDevice(volumes[0].NetworkName); err != nil {
return goof.WithError("error deleting scsi device from host", err)
}
if err := d.vmh.DetachRDM(d.vmh.Vm, volumes[0].NetworkName); err != nil {
return goof.WithError("error removing RDM from vm", err)
}
}
if err := d.detachVolumeFromSG(runAsync, volumeID); err != nil {
return goof.WithError("error detaching volume from storage group", err)
}
log.Println("Detached volume", volumeID)
return nil
}
示例2: InstanceID
// InstanceID returns the aws instance configuration
func (d *driver) InstanceID(
ctx types.Context,
opts types.Store) (*types.InstanceID, error) {
cmd := exec.Command("xenstore-read", "name")
cmd.Env = d.config.EnvVars()
cmdOut, err := cmd.Output()
if err != nil {
return nil,
goof.WithError("problem getting InstanceID", err)
}
instanceID := strings.Replace(string(cmdOut), "\n", "", -1)
validInstanceID := regexp.MustCompile(`^instance-`)
valid := validInstanceID.MatchString(instanceID)
if !valid {
return nil, goof.WithError("InstanceID not valid", err)
}
instanceID = strings.Replace(instanceID, "instance-", "", 1)
iid := &types.InstanceID{Driver: rackspace.Name}
if err := iid.MarshalMetadata(instanceID); err != nil {
return nil, err
}
return iid, nil
}
示例3: VolumeDetach
// VolumeDetach detaches a volume.
func (d *driver) VolumeDetach(
ctx types.Context,
volumeID string,
opts *types.VolumeDetachOpts) (*types.Volume, error) {
// review volume with attachments to any host
ec2vols, err := d.getVolume(ctx, volumeID, "")
if err != nil {
return nil, goof.WithError("error getting volume", err)
}
volumes, convErr := d.toTypesVolume(
ctx, ec2vols, types.VolAttReqTrue)
if convErr != nil {
return nil, goof.WithError("error converting to types.Volume", convErr)
}
// no volumes to detach
if len(volumes) == 0 {
return nil, errNoVolReturned
}
// volume has no attachments
if len(volumes[0].Attachments) == 0 {
return nil, errVolAlreadyDetached
}
dvInput := &awsec2.DetachVolumeInput{
VolumeId: &volumeID,
Force: &opts.Force,
}
// Detach volume using EC2 API call
if _, err = mustSession(ctx).DetachVolume(dvInput); err != nil {
return nil, goof.WithFieldsE(
log.Fields{
"provider": d.Name(),
"volumeID": volumeID}, "error detaching volume", err)
}
if err = d.waitVolumeComplete(ctx, volumeID, waitVolumeDetach); err != nil {
return nil, goof.WithError("error waiting for volume detach", err)
}
ctx.Info("detached volume", volumeID)
// check if successful detach
detachedVol, err := d.VolumeInspect(
ctx, volumeID, &types.VolumeInspectOpts{
Attachments: types.VolAttReqTrue,
Opts: opts.Opts,
})
if err != nil {
return nil, goof.WithError("error getting volume", err)
}
return detachedVol, nil
}
示例4: AttachVolume
func (d *driver) AttachVolume(
notused bool,
volumeID, instanceID string, force bool) ([]*core.VolumeAttachment, error) {
// sanity check the input
if volumeID == "" {
return nil, errors.ErrMissingVolumeID
}
if instanceID == "" {
return nil, goof.New("Missing Instance ID")
}
// ensure the volume exists and is exported
volumes, err := d.GetVolume(volumeID, "")
if err != nil {
return nil, err
}
if len(volumes) == 0 {
return nil, errors.ErrNoVolumesReturned
}
if err := d.client.ExportVolume(volumeID); err != nil {
return nil, goof.WithError("problem exporting volume", err)
}
// see if anyone is attached already
clients, err := d.client.GetExportClients(volumeID)
if err != nil {
return nil, goof.WithError("problem getting export client", err)
}
// clear out any existing clients if necessary. if force is false and
// we have existing clients, we need to exit.
if len(clients) > 0 {
if force == false {
return nil, goof.New("Volume already attached to another host")
}
// remove all clients
err = d.client.ClearExportClients(volumeID)
if err != nil {
return nil, err
}
}
err = d.client.SetExportClients(volumeID, parseInstanceId(instanceID))
if err != nil {
return nil, err
}
volumeAttachment, err := d.GetVolumeAttach(volumeID, instanceID)
if err != nil {
return nil, err
}
return volumeAttachment, nil
}
示例5: 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
}
示例6: NextDevice
// NextDevice returns the next available device.
func (d *driver) NextDevice(
ctx types.Context,
opts types.Store) (string, error) {
// All possible device paths on Linux EC2 instances are /dev/xvd[f-p]
letters := []string{
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"}
// Find which letters are used for local devices
localDeviceNames := make(map[string]bool)
localDevices, err := d.LocalDevices(
ctx, &types.LocalDevicesOpts{Opts: opts})
if err != nil {
return "", goof.WithError("error getting local devices", err)
}
localDeviceMapping := localDevices.DeviceMap
for localDevice := range localDeviceMapping {
re, _ := regexp.Compile(`^/dev/` +
ebsUtils.NextDeviceInfo.Prefix +
`(` + ebsUtils.NextDeviceInfo.Pattern + `)`)
res := re.FindStringSubmatch(localDevice)
if len(res) > 0 {
localDeviceNames[res[1]] = true
}
}
// Find which letters are used for ephemeral devices
ephemeralDevices, err := d.getEphemeralDevices(ctx)
if err != nil {
return "", goof.WithError("error getting ephemeral devices", err)
}
for _, ephemeralDevice := range ephemeralDevices {
re, _ := regexp.Compile(`^` +
ebsUtils.NextDeviceInfo.Prefix +
`(` + ebsUtils.NextDeviceInfo.Pattern + `)`)
res := re.FindStringSubmatch(ephemeralDevice)
if len(res) > 0 {
localDeviceNames[res[1]] = true
}
}
// Find next available letter for device path
for _, letter := range letters {
if localDeviceNames[letter] {
continue
}
return fmt.Sprintf(
"/dev/%s%s", ebsUtils.NextDeviceInfo.Prefix, letter), nil
}
return "", errNoAvaiDevice
}
示例7: VolumeAttach
func (d *driver) VolumeAttach(
ctx types.Context,
volumeID string,
opts *types.VolumeAttachOpts) (*types.Volume, string, error) {
iid := context.MustInstanceID(ctx)
mapVolumeSdcParam := &siotypes.MapVolumeSdcParam{
SdcID: iid.ID,
AllowMultipleMappings: "false",
AllSdcs: "",
}
vol, err := d.VolumeInspect(
ctx, volumeID, &types.VolumeInspectOpts{
Attachments: types.VolAttReqTrue,
})
if err != nil {
return nil, "", goof.WithError("error getting volume", err)
}
if len(vol.Attachments) > 0 && !opts.Force {
return nil, "", goof.New("volume already attached to a host")
}
if len(vol.Attachments) > 0 && opts.Force {
if _, err := d.VolumeDetach(ctx, volumeID,
&types.VolumeDetachOpts{Force: opts.Force}); err != nil {
return nil, "", err
}
}
targetVolume := sio.NewVolume(d.client)
targetVolume.Volume = &siotypes.Volume{ID: vol.ID}
err = targetVolume.MapVolumeSdc(mapVolumeSdcParam)
if err != nil {
return nil, "", goof.WithError("error mapping volume sdc", err)
}
attachedVol, err := d.VolumeInspect(
ctx, volumeID, &types.VolumeInspectOpts{
Attachments: types.VolAttReqTrue,
Opts: opts.Opts,
})
if err != nil {
return nil, "", goof.WithError("error getting volume", err)
}
return attachedVol, attachedVol.ID, nil
}
示例8: attachVolume
// Used in VolumeAttach
func (d *driver) attachVolume(
ctx types.Context,
volumeID, volumeName, deviceName string) error {
// sanity check # of volumes to attach
vol, err := d.getVolume(ctx, volumeID, volumeName)
if err != nil {
return goof.WithError("error getting volume", err)
}
if len(vol) == 0 {
return errNoVolReturned
}
if len(vol) > 1 {
return errTooManyVolsReturned
}
// Attach volume via EC2 API call
avInput := &awsec2.AttachVolumeInput{
Device: &deviceName,
InstanceId: mustInstanceIDID(ctx),
VolumeId: &volumeID,
}
if _, err := mustSession(ctx).AttachVolume(avInput); err != nil {
return err
}
return nil
}
示例9: LocalDevices
// Retrieve device paths currently attached and/or mounted
func (d *driver) LocalDevices(
ctx types.Context,
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
f, err := os.Open(procPartitions)
if err != nil {
return nil, goof.WithError("error reading "+procPartitions, err)
}
defer f.Close()
devMap := map[string]string{}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) != 4 {
continue
}
devName := fields[3]
if !xvdRX.MatchString(devName) {
continue
}
devPath := path.Join("/dev/", devName)
devMap[devPath] = devPath
}
ld := &types.LocalDevices{Driver: d.Name()}
if len(devMap) > 0 {
ld.DeviceMap = devMap
}
return ld, nil
}
示例10: getEphemeralDevices
// Find ephemeral devices from metadata
func (d *driver) getEphemeralDevices(
ctx types.Context) (deviceNames []string, err error) {
buf, err := ebsUtils.BlockDevices(ctx)
if err != nil {
return nil, err
}
// Filter list of all block devices for ephemeral devices
scanner := bufio.NewScanner(bytes.NewReader(buf))
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
word := scanner.Bytes()
if !ephemDevRX.Match(word) {
continue
}
name, err := ebsUtils.BlockDeviceName(ctx, string(word))
if err != nil {
return nil, goof.WithError(
"ec2 block device mapping lookup failed", err)
}
// compensate for kernel volume mapping i.e. change "/dev/sda" to
// "/dev/xvda"
deviceNameStr := strings.Replace(
string(name),
"sd",
ebsUtils.NextDeviceInfo.Prefix, 1)
deviceNames = append(deviceNames, deviceNameStr)
}
return deviceNames, nil
}
示例11: RemoveVolume
func (d *driver) RemoveVolume(volumeID string) error {
log.WithField("provider", providerName).Debugf("RemoveVolume :%s", volumeID)
if _, err := d.client.Disks.Delete(d.project, d.zone, volumeID).Do(); err != nil {
return goof.WithError("problem removing volume", err)
}
return nil
}
示例12: LocalDevices
func (d *driver) LocalDevices(
ctx types.Context,
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
// Read from /proc/partitions
localDevices := make(map[string]string)
file := "/proc/partitions"
contentBytes, err := ioutil.ReadFile(file)
if err != nil {
return nil, goof.WithError(
"Error reading /proc/partitions", err)
}
content := string(contentBytes)
// Parse device names
var deviceName string
lines := strings.Split(content, "\n")
for _, line := range lines[2:] {
fields := strings.Fields(line)
if len(fields) == 4 {
deviceName = "/dev/" + fields[3]
localDevices[deviceName] = deviceName
}
}
return &types.LocalDevices{
Driver: rackspace.Name,
DeviceMap: localDevices,
}, nil
}
示例13: AttachVolume
func (d *driver) AttachVolume(
notused bool,
volumeID, instanceID string, force bool) ([]*core.VolumeAttachment, error) {
if volumeID == "" {
return nil, errors.ErrMissingVolumeID
}
volumes, err := d.GetVolume(volumeID, "")
if err != nil {
return nil, err
}
if len(volumes) == 0 {
return nil, errors.ErrNoVolumesReturned
}
if err := d.client.ExportVolume(volumeID); err != nil {
return nil, goof.WithError("problem exporting volume", err)
}
volumeAttachment, err := d.GetVolumeAttach(volumeID, instanceID)
if err != nil {
return nil, err
}
return volumeAttachment, nil
}
示例14: RemoveSnapshot
func (d *driver) RemoveSnapshot(snapshotID string) error {
log.WithField("provider", providerName).Debug("RemoveSnapshot :%s", snapshotID)
if _, err := d.client.Snapshots.Delete(d.project, snapshotID).Do(); err != nil {
return goof.WithError("problem removing snapshot", err)
}
return nil
}
示例15: GetVolume
func (d *driver) GetVolume(volumeID, volumeName string) ([]*core.Volume, error) {
localDeviceMap, err := d.getLocalWWNDeviceByID()
if err != nil {
return nil, goof.WithError("error getting local devices", err)
}
var volumesResp *govmax.GetVolumesResp
if volumeID != "" {
volumesResp, err = d.client.GetVolumeByID(d.sid(), volumeID)
} else if volumeName != "" {
volumesResp, err = d.client.GetVolumeByName(d.sid(), d.prefixVolumeName(volumeName))
} else {
volumesResp, err = d.client.GetVolumes(d.sid())
}
if err != nil {
return nil, goof.WithError("problem getting volumes", err)
}
var volumesSD []*core.Volume
for _, entry := range volumesResp.Entries {
if d.isValidVolume(entry.Content.I_ElementName) {
deviceName, _ := localDeviceMap[entry.Content.I_EMCWWN]
volumeSD := &core.Volume{
Name: d.unprefixVolumeName(entry.Content.I_ElementName),
VolumeID: entry.Content.I_DeviceID,
NetworkName: entry.Content.I_EMCWWN,
Status: strings.Join(entry.Content.I_StatusDescriptions, ","),
VolumeType: entry.Content.I_Caption,
AvailabilityZone: d.arrayID,
Size: strconv.Itoa((entry.Content.I_BlockSize * entry.Content.I_NumberOfBlocks) / 1024 / 1024 / 1024),
}
if deviceName != "" {
volumeSD.Attachments = append(volumeSD.Attachments, &core.VolumeAttachment{
VolumeID: entry.Content.I_DeviceID,
InstanceID: d.instanceID,
DeviceName: deviceName,
Status: strings.Join(entry.Content.I_StatusDescriptions, ","),
})
}
volumesSD = append(volumesSD, volumeSD)
}
}
return volumesSD, nil
}