Exemplo n.º 1
0
// merge volume properties from aws into volume.
func (d *Driver) merge(v *api.Volume, aws *ec2.Volume) {
	v.AttachedOn = api.MachineID("")
	v.State = api.VolumeDetached
	v.DevicePath = ""

	switch *aws.State {
	case ec2.VolumeStateAvailable:
		v.Status = api.Up
	case ec2.VolumeStateCreating, ec2.VolumeStateDeleting:
		v.State = api.VolumePending
		v.Status = api.Down
	case ec2.VolumeStateDeleted:
		v.State = api.VolumeDeleted
		v.Status = api.Down
	case ec2.VolumeStateError:
		v.State = api.VolumeError
		v.Status = api.Down
	case ec2.VolumeStateInUse:
		v.Status = api.Up
		if aws.Attachments != nil && len(aws.Attachments) != 0 {
			if aws.Attachments[0].InstanceID != nil {
				v.AttachedOn = api.MachineID(*aws.Attachments[0].InstanceID)
			}
			if aws.Attachments[0].State != nil {
				v.State = d.volumeState(aws.Attachments[0].State)
			}
			if aws.Attachments[0].Device != nil {
				v.DevicePath = *aws.Attachments[0].Device
			}
		}
	}
}
Exemplo n.º 2
0
// merge volume properties from aws into volume.
func (d *Driver) merge(v *api.Volume, aws *ec2.Volume) {
	v.AttachedOn = ""
	v.State = api.VolumeState_VOLUME_STATE_DETACHED
	v.DevicePath = ""

	switch *aws.State {
	case ec2.VolumeStateAvailable:
		v.Status = api.VolumeStatus_VOLUME_STATUS_UP
	case ec2.VolumeStateCreating, ec2.VolumeStateDeleting:
		v.State = api.VolumeState_VOLUME_STATE_PENDING
		v.Status = api.VolumeStatus_VOLUME_STATUS_DOWN
	case ec2.VolumeStateDeleted:
		v.State = api.VolumeState_VOLUME_STATE_DELETED
		v.Status = api.VolumeStatus_VOLUME_STATUS_DOWN
	case ec2.VolumeStateError:
		v.State = api.VolumeState_VOLUME_STATE_ERROR
		v.Status = api.VolumeStatus_VOLUME_STATUS_DOWN
	case ec2.VolumeStateInUse:
		v.Status = api.VolumeStatus_VOLUME_STATUS_UP
		if aws.Attachments != nil && len(aws.Attachments) != 0 {
			if aws.Attachments[0].InstanceId != nil {
				v.AttachedOn = *aws.Attachments[0].InstanceId
			}
			if aws.Attachments[0].State != nil {
				v.State = d.volumeState(aws.Attachments[0].State)
			}
			if aws.Attachments[0].Device != nil {
				v.DevicePath = *aws.Attachments[0].Device
			}
		}
	}
}