本文整理匯總了Golang中github.com/emccode/rexray/errors.WithFieldsE函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithFieldsE函數的具體用法?Golang WithFieldsE怎麽用?Golang WithFieldsE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithFieldsE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RemoveVolume
func (driver *Driver) RemoveVolume(volumeID string) error {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
volumes, err := driver.getVolume(volumeID, "")
if err != nil {
return errors.WithFieldsE(fields, "error getting volume", err)
}
targetVolume := goscaleio.NewVolume(driver.Client)
targetVolume.Volume = volumes[0]
err = targetVolume.RemoveVolume("ONLY_ME")
if err != nil {
return errors.WithFieldsE(fields, "error removing volume", err)
}
log.WithFields(fields).Debug("removed volume")
return nil
}
示例2: DetachVolume
func (driver *Driver) DetachVolume(runAsync bool, volumeID, instanceID string) error {
fields := eff(map[string]interface{}{
"runAsync": runAsync,
"volumeId": volumeID,
"instanceId": instanceID,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
volume, err := driver.GetVolume(volumeID, "")
if err != nil {
return errors.WithFieldsE(fields, "error getting volume", err)
}
fields["instanceId"] = volume[0].Attachments[0].InstanceID
resp := volumeattach.Delete(
driver.Client, volume[0].Attachments[0].InstanceID, volumeID)
if resp.Err != nil {
return errors.WithFieldsE(fields, "error deleting volume", err)
}
if !runAsync {
log.WithFields(fields).Debug("waiting for volume to detach")
err = driver.waitVolumeDetach(volumeID)
if err != nil {
return errors.WithFieldsE(
fields, "error waiting for volume to detach", err)
}
}
log.WithFields(fields).Debug("volume detached")
return nil
}
示例3: AttachVolume
func (driver *Driver) AttachVolume(runAsync bool, volumeID, instanceID string) ([]*storage.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: driver.Sdc.Sdc.ID,
AllowMultipleMappings: "false",
AllSdcs: "",
}
volumes, err := driver.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(driver.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 := driver.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 (driver *Driver) getVolume(volumeID, volumeName string) (volumesRet []volumes.Volume, err error) {
if volumeID != "" {
volume, err := volumes.Get(driver.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(driver.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: GetSnapshot
func (driver *Driver) GetSnapshot(volumeID, snapshotID, snapshotName string) ([]*storage.Snapshot, error) {
snapshots, err := driver.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 []*storage.Snapshot
for _, snapshot := range snapshots {
snapshotSD := &storage.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
}
示例6: GetVolumeAttach
func (driver *Driver) GetVolumeAttach(volumeID, instanceID string) ([]*storage.VolumeAttachment, error) {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
"instanceId": instanceID,
})
if volumeID == "" {
return []*storage.VolumeAttachment{},
errors.WithFields(fields, "volumeId is required")
}
volume, err := driver.GetVolume(volumeID, "")
if err != nil {
return []*storage.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 []*storage.VolumeAttachment{}, nil
}
}
return volume[0].Attachments, nil
}
示例7: GetVolumeMapping
func (driver *Driver) GetVolumeMapping() ([]*storage.BlockDevice, error) {
blockDevices, err := driver.getBlockDevices(driver.InstanceID)
if err != nil {
return nil,
errors.WithFieldsE(eff(errors.Fields{
"instanceId": driver.InstanceID,
}), "error getting block devices", err)
}
var BlockDevices []*storage.BlockDevice
for _, blockDevice := range blockDevices {
sdBlockDevice := &storage.BlockDevice{
ProviderName: ProviderName,
InstanceID: driver.InstanceID,
VolumeID: blockDevice.VolumeID,
DeviceName: blockDevice.Device,
Region: driver.Region,
Status: "",
}
BlockDevices = append(BlockDevices, sdBlockDevice)
}
return BlockDevices, nil
}
示例8: CreateSnapshot
func (driver *Driver) CreateSnapshot(runAsync bool, snapshotName, volumeID, description string) ([]*storage.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(driver.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(driver.ClientBlockStorage, resp.ID, "available", 120)
if err != nil {
return nil,
errors.WithFieldsE(fields,
"error waiting for snapshot creation to complete", err)
}
}
snapshot, err := driver.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
}
示例9: getBlockDevices
func (driver *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
}
示例10: getInstance
func (driver *Driver) getInstance() (*servers.Server, error) {
server, err := servers.Get(driver.Client, driver.InstanceID).Extract()
if err != nil {
return nil,
errors.WithFieldsE(ef(), "error getting server instance", err)
}
return server, nil
}
示例11: getSnapshot
func (driver *Driver) getSnapshot(volumeID, snapshotID, snapshotName string) (allSnapshots []snapshots.Snapshot, err error) {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
"snapshotId": snapshotID,
"snapshotName": snapshotName,
})
if snapshotID != "" {
snapshot, err := snapshots.Get(driver.ClientBlockStorage, snapshotID).Extract()
if err != nil {
return []snapshots.Snapshot{},
errors.WithFieldsE(fields, "error getting snapshot", err)
}
allSnapshots = append(allSnapshots, *snapshot)
} else {
opts := snapshots.ListOpts{
VolumeID: volumeID,
Name: snapshotName,
}
allPages, err := snapshots.List(driver.ClientBlockStorage, opts).AllPages()
if err != nil {
return []snapshots.Snapshot{},
errors.WithFieldsE(fields, "error listing snapshot", err)
}
allSnapshots, err = snapshots.ExtractSnapshots(allPages)
if err != nil {
return []snapshots.Snapshot{},
errors.WithFieldsE(fields, "error extracting snapshot", err)
}
}
return allSnapshots, nil
}
示例12: GetInstance
func (driver *Driver) GetInstance() (*storage.Instance, error) {
server, err := driver.getInstance()
if err != nil {
return nil,
errors.WithFieldsE(ef(), "error getting driver instance", err)
}
instance := &storage.Instance{
ProviderName: ProviderName,
InstanceID: driver.InstanceID,
Region: driver.Region,
Name: server.Name,
}
return instance, nil
}
示例13: getLocalDevices
func getLocalDevices() (deviceNames []string, err error) {
file := "/proc/partitions"
contentBytes, err := ioutil.ReadFile(file)
if err != nil {
return []string{},
errors.WithFieldsE(
eff(errors.Fields{"file": file}), "error reading file", err)
}
content := string(contentBytes)
lines := strings.Split(content, "\n")
for _, line := range lines[2:] {
fields := strings.Fields(line)
if len(fields) == 4 {
deviceNames = append(deviceNames, fields[3])
}
}
return deviceNames, nil
}
示例14: GetVolume
func (driver *Driver) GetVolume(volumeID, volumeName string) ([]*storage.Volume, error) {
volumesRet, err := driver.getVolume(volumeID, volumeName)
if err != nil {
return []*storage.Volume{},
errors.WithFieldsE(eff(errors.Fields{
"volumeId": volumeID,
"volumeName": volumeName}),
"error getting volume", err)
}
var volumesSD []*storage.Volume
for _, volume := range volumesRet {
var attachmentsSD []*storage.VolumeAttachment
for _, attachment := range volume.Attachments {
attachmentSD := &storage.VolumeAttachment{
VolumeID: attachment["volume_id"].(string),
InstanceID: attachment["server_id"].(string),
DeviceName: attachment["device"].(string),
Status: "",
}
attachmentsSD = append(attachmentsSD, attachmentSD)
}
volumeSD := &storage.Volume{
Name: volume.Name,
VolumeID: volume.ID,
AvailabilityZone: volume.AvailabilityZone,
Status: volume.Status,
VolumeType: volume.VolumeType,
IOPS: 0,
Size: strconv.Itoa(volume.Size),
Attachments: attachmentsSD,
}
volumesSD = append(volumesSD, volumeSD)
}
return volumesSD, nil
}
示例15: waitVolumeAttach
func (driver *Driver) waitVolumeAttach(volumeID string) error {
fields := eff(map[string]interface{}{
"volumeId": volumeID,
})
if volumeID == "" {
return errors.WithFields(fields, "volumeId is required")
}
for {
volume, err := driver.GetVolume(volumeID, "")
if err != nil {
return errors.WithFieldsE(fields, "error getting volume", err)
}
if volume[0].Status == "in-use" {
break
}
time.Sleep(1 * time.Second)
}
return nil
}