private String lookupVolume ( String volumeIdOrName ) { String ret = null ; if ( ! Utils . isEmptyOrWhitespaces ( volumeIdOrName ) ) { // Lookup by volume ID DescribeVolumesRequest dvs = new DescribeVolumesRequest ( Collections . singletonList ( volumeIdOrName ) ) ; DescribeVolumesResult dvsresult = null ; try { dvsresult = this . ec2Api . describeVolumes ( dvs ) ; } catch ( Exception e ) { dvsresult = null ; } // If not found, lookup by name if ( dvsresult == null || dvsresult . getVolumes ( ) == null || dvsresult . getVolumes ( ) . size ( ) < 1 ) { dvs = new DescribeVolumesRequest ( ) . withFilters ( new Filter ( ) . withName ( "tag:Name" ) . withValues ( volumeIdOrName ) ) ; try { dvsresult = this . ec2Api . describeVolumes ( dvs ) ; } catch ( Exception e ) { dvsresult = null ; } } if ( dvsresult != null && dvsresult . getVolumes ( ) != null && dvsresult . getVolumes ( ) . size ( ) > 0 ) ret = dvsresult . getVolumes ( ) . get ( 0 ) . getVolumeId ( ) ; } return ret ; }
Looks up volume by ID or Name tag .