本文整理匯總了Golang中github.com/emccode/rexray/core/errors.WithFieldsE函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithFieldsE函數的具體用法?Golang WithFieldsE怎麽用?Golang WithFieldsE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithFieldsE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: getVolume
func (d *driver) getVolume(
volumeID, volumeName string) (volumesRet []volumes.Volume, err error) {
if volumeID != "" {
volume, err := volumes.Get(d.clientBlockStorage, volumeID).Extract()
if err != nil {
return []volumes.Volume{},
errors.WithFieldsE(eff(errors.Fields{
"volumeId": volumeID,
"volumeName": volumeName}),
"error getting volumes", err)
}
volumesRet = append(volumesRet, *volume)
} else {
listOpts := &volumes.ListOpts{
//Name: volumeName,
}
allPages, err := volumes.List(d.clientBlockStorage, listOpts).AllPages()
if err != nil {
return []volumes.Volume{},
errors.WithFieldsE(eff(errors.Fields{
"volumeId": volumeID,
"volumeName": volumeName}),
"error listing volumes", err)
}
volumesRet, err = volumes.ExtractVolumes(allPages)
if err != nil {
return []volumes.Volume{},
errors.WithFieldsE(eff(errors.Fields{
"volumeId": volumeID,
"volumeName": volumeName}),
"error extracting volumes", err)
}
var volumesRetFiltered []volumes.Volume
if volumeName != "" {
var found bool
for _, volume := range volumesRet {
if volume.Name == volumeName {
volumesRetFiltered = append(volumesRetFiltered, volume)
found = true
break
}
}
if !found {
return []volumes.Volume{}, nil
}
volumesRet = volumesRetFiltered
}
}
return volumesRet, nil
}
示例5: Init
func (d *driver) Init(r *core.RexRay) error {
d.r = r
fields := ef()
var err error
if d.instanceID, err = getInstanceID(d.r.Config); err != nil {
return err
}
fields["instanceId"] = d.instanceID
if d.region, err = getInstanceRegion(d.r.Config); err != nil {
return err
}
fields["region"] = d.region
d.region = strings.ToUpper(d.region)
authOpts := getAuthOptions(d.r.Config)
fields["identityEndpoint"] = d.r.Config.RackspaceAuthURL
fields["userId"] = d.r.Config.RackspaceUserID
fields["userName"] = d.r.Config.RackspaceUserName
if d.r.Config.RackspacePassword == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
fields["tenantId"] = d.r.Config.RackspaceTenantID
fields["tenantName"] = d.r.Config.RackspaceTenantName
fields["domainId"] = d.r.Config.RackspaceDomainID
fields["domainName"] = d.r.Config.RackspaceDomainName
if d.provider, err = openstack.AuthenticatedClient(authOpts); err != nil {
return errors.WithFieldsE(fields,
"error getting authenticated client", err)
}
if d.client, err = openstack.NewComputeV2(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
errors.WithFieldsE(fields, "error getting newComputeV2", err)
}
if d.clientBlockStorage, err = openstack.NewBlockStorageV1(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
return errors.WithFieldsE(fields,
"error getting newBlockStorageV1", err)
}
log.WithField("provider", providerName).Info("storage driver initialized")
return nil
}
示例6: 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
}
示例7: CreateSnapshot
func (d *driver) CreateSnapshot(
runAsync bool,
snapshotName, volumeID, description string) ([]*core.Snapshot, error) {
fields := eff(map[string]interface{}{
"runAsync": runAsync,
"snapshotName": snapshotName,
"volumeId": volumeID,
"description": description,
})
opts := snapshots.CreateOpts{
Name: snapshotName,
VolumeID: volumeID,
Description: description,
Force: true,
}
resp, err := snapshots.Create(d.clientBlockStorage, opts).Extract()
if err != nil {
return nil,
errors.WithFieldsE(fields, "error creating snapshot", err)
}
if !runAsync {
log.Debug("waiting for snapshot creation to complete")
err = snapshots.WaitForStatus(d.clientBlockStorage, resp.ID, "available", 120)
if err != nil {
return nil,
errors.WithFieldsE(fields,
"error waiting for snapshot creation to complete", err)
}
}
snapshot, err := d.GetSnapshot("", resp.ID, "")
if err != nil {
return nil, err
}
log.WithFields(log.Fields{
"runAsync": runAsync,
"snapshotName": snapshotName,
"volumeId": volumeID,
"description": description}).Debug("created snapshot")
return snapshot, nil
}
示例8: GetVolumeMapping
func (d *driver) GetVolumeMapping() ([]*core.BlockDevice, error) {
blockDevices, err := d.getBlockDevices()
if err != nil {
return nil,
errors.WithFieldsE(ef(), "error getting block devices", err)
}
var BlockDevices []*core.BlockDevice
for _, blockDevice := range blockDevices {
sdBlockDevice := &core.BlockDevice{
ProviderName: providerName,
InstanceID: d.sdc.Sdc.ID,
Region: blockDevice.MdmID,
DeviceName: blockDevice.SdcDevice,
VolumeID: blockDevice.VolumeID,
Status: "",
}
BlockDevices = append(BlockDevices, sdBlockDevice)
}
log.WithFields(log.Fields{
"provider": providerName,
"blockDevices": BlockDevices,
}).Debug("got block device mappings")
return BlockDevices, nil
}
示例9: GetSnapshot
func (d *driver) GetSnapshot(
volumeID, snapshotID, snapshotName string) ([]*core.Snapshot, error) {
snapshots, err := d.getSnapshot(volumeID, snapshotID, snapshotName)
if err != nil {
return nil,
errors.WithFieldsE(eff(errors.Fields{
"volumeId": volumeID,
"snapshotId": snapshotID,
"snapshotName": snapshotName}),
"error getting snapshot", err)
}
var snapshotsInt []*core.Snapshot
for _, snapshot := range snapshots {
snapshotSD := &core.Snapshot{
Name: snapshot.Name,
VolumeID: snapshot.VolumeID,
SnapshotID: snapshot.ID,
VolumeSize: strconv.Itoa(snapshot.Size),
StartTime: snapshot.CreatedAt,
Description: snapshot.Description,
Status: snapshot.Status,
}
snapshotsInt = append(snapshotsInt, snapshotSD)
}
return snapshotsInt, nil
}
示例10: 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
}
示例11: GetVolumeMapping
func (d *driver) GetVolumeMapping() ([]*core.BlockDevice, error) {
blockDevices, err := d.getBlockDevices(d.instanceID)
if err != nil {
return nil,
errors.WithFieldsE(eff(errors.Fields{
"instanceId": d.instanceID,
}), "error getting block devices", err)
}
var BlockDevices []*core.BlockDevice
for _, blockDevice := range blockDevices {
sdBlockDevice := &core.BlockDevice{
ProviderName: providerName,
InstanceID: d.instanceID,
VolumeID: blockDevice.VolumeID,
DeviceName: blockDevice.Device,
Region: d.region,
Status: "",
}
BlockDevices = append(BlockDevices, sdBlockDevice)
}
return BlockDevices, nil
}
示例12: getBlockDevices
func (d *driver) getBlockDevices() ([]*goscaleio.SdcMappedVolume, error) {
volumeMaps, err := goscaleio.GetLocalVolumeMap()
if err != nil {
return []*goscaleio.SdcMappedVolume{},
errors.WithFieldsE(ef(), "error getting local volume map", err)
}
return volumeMaps, nil
}
示例13: getInstance
func (d *driver) getInstance() (*servers.Server, error) {
server, err := servers.Get(d.client, d.instanceID).Extract()
if err != nil {
return nil,
errors.WithFieldsE(ef(), "error getting server instance", err)
}
return server, nil
}
示例14: AttachVolume
func (d *driver) AttachVolume(
runAsync bool, volumeID, instanceID string) ([]*core.VolumeAttachment, error) {
fields := eff(map[string]interface{}{
"runAsync": runAsync,
"volumeId": volumeID,
"instanceId": instanceID,
})
nextDeviceName, err := d.GetDeviceNextAvailable()
if err != nil {
return nil, errors.WithFieldsE(
fields, "error getting next available device", err)
}
options := &volumeattach.CreateOpts{
Device: nextDeviceName,
VolumeID: volumeID,
}
_, err = volumeattach.Create(d.client, instanceID, options).Extract()
if err != nil {
return nil, errors.WithFieldsE(
fields, "error attaching volume", err)
}
if !runAsync {
log.WithFields(fields).Debug("waiting for volume to attach")
err = d.waitVolumeAttach(volumeID)
if err != nil {
return nil, errors.WithFieldsE(
fields, "error waiting for volume to detach", err)
}
}
volumeAttachment, err := d.GetVolumeAttach(volumeID, instanceID)
if err != nil {
return nil, err
}
log.WithFields(fields).Debug("volume attached")
return volumeAttachment, nil
}
示例15: 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
}