<s> from __future__ import unicode_literals <EOL> from moto . core . responses import BaseResponse <EOL> from moto . ec2 . utils import filters_from_querystring <EOL> class ElasticBlockStore ( BaseResponse ) : <EOL> def attach_volume ( self ) : <EOL> volume_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> instance_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> device_path = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> attachment = self . ec2_backend . attach_volume ( volume_id , instance_id , device_path ) <EOL> template = self . response_template ( ATTACHED_VOLUME_RESPONSE ) <EOL> return template . render ( attachment = attachment ) <EOL> def copy_snapshot ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def create_snapshot ( self ) : <EOL> description = None <EOL> if '<STR_LIT>' in self . querystring : <EOL> description = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> volume_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> snapshot = self . ec2_backend . create_snapshot ( volume_id , description ) <EOL> template = self . response_template ( CREATE_SNAPSHOT_RESPONSE ) <EOL> return template . render ( snapshot = snapshot ) <EOL> def create_volume ( self ) : <EOL> size = self . _get_param ( '<STR_LIT>' ) <EOL> zone = self . _get_param ( '<STR_LIT>' ) <EOL> snapshot_id = self . _get_param ( '<STR_LIT>' ) <EOL> volume = self . ec2_backend . create_volume ( size , zone , snapshot_id ) <EOL> template = self . response_template ( CREATE_VOLUME_RESPONSE ) <EOL> return template . render ( volume = volume ) <EOL> def delete_snapshot ( self ) : <EOL> snapshot_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . ec2_backend . delete_snapshot ( snapshot_id ) <EOL> return DELETE_SNAPSHOT_RESPONSE <EOL> def delete_volume ( self ) : <EOL> volume_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . ec2_backend . delete_volume ( volume_id ) <EOL> return DELETE_VOLUME_RESPONSE <EOL> def describe_snapshots ( self ) : <EOL> filters = filters_from_querystring ( self . querystring ) <EOL> snapshot_ids = '<STR_LIT:U+002C>' . join ( [ '<STR_LIT:U+002C>' . join ( s [ <NUM_LIT:1> ] ) for s in self . querystring . items ( ) if '<STR_LIT>' in s [ <NUM_LIT:0> ] ] ) <EOL> snapshots = self . ec2_backend . describe_snapshots ( filters = filters ) <EOL> snapshots = [ s for s in snapshots if s . id in snapshot_ids ] if snapshot_ids else snapshots <EOL> template = self . response_template ( DESCRIBE_SNAPSHOTS_RESPONSE ) <EOL> return template . render ( snapshots = snapshots ) <EOL> def describe_volumes ( self ) : <EOL> filters = filters_from_querystring ( self . querystring ) <EOL> volume_ids = '<STR_LIT:U+002C>' . join ( [ '<STR_LIT:U+002C>' . join ( v [ <NUM_LIT:1> ] ) for v in self . querystring . items ( ) if '<STR_LIT>' in v [ <NUM_LIT:0> ] ] ) <EOL> volumes = self . ec2_backend . describe_volumes ( filters = filters ) <EOL> volumes = [ v for v in volumes if v . id in volume_ids ] if volume_ids else volumes <EOL> template = self . response_template ( DESCRIBE_VOLUMES_RESPONSE ) <EOL> return template . render ( volumes = volumes ) <EOL> def describe_volume_attribute ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def describe_volume_status ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def detach_volume ( self ) : <EOL> volume_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> instance_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> device_path = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> attachment = self . ec2_backend . detach_volume ( volume_id , instance_id , device_path ) <EOL> template = self . response_template ( DETATCH_VOLUME_RESPONSE ) <EOL> return template . render ( attachment = attachment ) <EOL> def enable_volume_io ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def import_volume ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def describe_snapshot_attribute ( self ) : <EOL> snapshot_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> groups = self . ec2_backend . get_create_volume_permission_groups ( snapshot_id ) <EOL> template = self . response_template ( DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE ) <EOL> return template . render ( snapshot_id = snapshot_id , groups = groups ) <EOL> def modify_snapshot_attribute ( self ) : <EOL> snapshot_id = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> operation_type = self . querystring . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> group = self . querystring . get ( '<STR_LIT>' , [ None ] ) [ <NUM_LIT:0> ] <EOL> user_id = self . querystring . get ( '<STR_LIT>' , [ None ] ) [ <NUM_LIT:0> ] <EOL> if ( operation_type == '<STR_LIT>' ) : <EOL> self . ec2_backend . add_create_volume_permission ( snapshot_id , user_id = user_id , group = group ) <EOL> elif ( operation_type == '<STR_LIT>' ) : <EOL> self . ec2_backend . remove_create_volume_permission ( snapshot_id , user_id = user_id , group = group ) <EOL> return MODIFY_SNAPSHOT_ATTRIBUTE_RESPONSE <EOL> def modify_volume_attribute ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def reset_snapshot_attribute ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> CREATE_VOLUME_RESPONSE = """<STR_LIT>""" <EOL> DESCRIBE_VOLUMES_RESPONSE = """<STR_LIT>""" <EOL> DELETE_VOLUME_RESPONSE = """<STR_LIT>""" <EOL> ATTACHED_VOLUME_RESPONSE = """<STR_LIT>""" <EOL> DETATCH_VOLUME_RESPONSE = """<STR_LIT>""" <EOL> CREATE_SNAPSHOT_RESPONSE = """<STR_LIT>""" <EOL> DESCRIBE_SNAPSHOTS_RESPONSE = """<STR_LIT>""" <EOL> DELETE_SNAPSHOT_RESPONSE = """<STR_LIT>""" <EOL> DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE = """<STR_LIT>""" <EOL> MODIFY_SNAPSHOT_ATTRIBUTE_RESPONSE = """<STR_LIT>""" </s>
