def get_volume_id(connection, volume):
<EOL>volume_id_pattern = re.compile('<STR_LIT>')<EOL>if volume_id_pattern.match(volume):<EOL><INDENT>try:<EOL><INDENT>connection.get_all_volumes(volume_ids=[volume])<EOL>volume_id = volume<EOL><DEDENT>except EC2ResponseError:<EOL><INDENT>logger.warning('<STR_LIT>'.format(volume))<EOL>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>name_filter = {'<STR_LIT>': '<STR_LIT:Name>', '<STR_LIT>': volume}<EOL>volumes = connection.get_all_volumes(filters=name_filter)<EOL>if not volumes:<EOL><INDENT>logger.warning('<STR_LIT>'.format(volume))<EOL>return None<EOL><DEDENT>if len(volumes) > <NUM_LIT:1>:<EOL><INDENT>logger.warning('<STR_LIT>'.format(volume))<EOL><DEDENT>volume_id = volumes[<NUM_LIT:0>].id<EOL><DEDENT>return volume_id<EOL>
Get Volume ID from the given volume. Input can be volume id
or its Name tag.

:type connection: boto.ec2.connection.EC2Connection
:param connection: EC2 connection object
:type volume: str
:param volume: Volume ID or Volume Name
:returns: Volume ID or None if the given volume does not exist