<s> """<STR_LIT>""" <EOL> import uuid <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from oslo_utils import timeutils <EOL> from nova import exception <EOL> LOG = logging . getLogger ( __name__ ) <EOL> CONF = cfg . CONF <EOL> CONF . import_opt ( '<STR_LIT>' , <EOL> '<STR_LIT>' , group = '<STR_LIT>' ) <EOL> class fake_volume ( object ) : <EOL> user_uuid = '<STR_LIT>' <EOL> instance_uuid = '<STR_LIT>' <EOL> def __init__ ( self , size , name , <EOL> description , volume_id , snapshot , <EOL> volume_type , metadata , <EOL> availability_zone ) : <EOL> snapshot_id = None <EOL> if snapshot is not None : <EOL> snapshot_id = snapshot [ '<STR_LIT:id>' ] <EOL> if volume_id is None : <EOL> volume_id = str ( uuid . uuid4 ( ) ) <EOL> self . vol = { <EOL> '<STR_LIT>' : timeutils . utcnow ( ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : timeutils . utcnow ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:id>' : volume_id , <EOL> '<STR_LIT>' : self . user_uuid , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : snapshot_id , <EOL> '<STR_LIT:host>' : None , <EOL> '<STR_LIT:size>' : size , <EOL> '<STR_LIT>' : availability_zone , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : timeutils . utcnow ( ) , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : name , <EOL> '<STR_LIT>' : description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def get ( self , key , default = None ) : <EOL> return self . vol [ key ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . vol [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> return self . vol [ key ] <EOL> class fake_snapshot ( object ) : <EOL> user_uuid = '<STR_LIT>' <EOL> instance_uuid = '<STR_LIT>' <EOL> def __init__ ( self , volume_id , size , name , desc , id = None ) : <EOL> if id is None : <EOL> id = str ( uuid . uuid4 ( ) ) <EOL> self . snap = { <EOL> '<STR_LIT>' : timeutils . utcnow ( ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : timeutils . utcnow ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:id>' : str ( id ) , <EOL> '<STR_LIT>' : volume_id , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : name , <EOL> '<STR_LIT>' : desc , <EOL> '<STR_LIT>' : self . user_uuid , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def get ( self , key , default = None ) : <EOL> return self . snap [ key ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . snap [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> return self . snap [ key ] <EOL> class API ( object ) : <EOL> volume_list = [ ] <EOL> snapshot_list = [ ] <EOL> _instance = None <EOL> class Singleton ( object ) : <EOL> def __init__ ( self ) : <EOL> self . API = None <EOL> def __init__ ( self ) : <EOL> if API . _instance is None : <EOL> API . _instance = API . Singleton ( ) <EOL> self . _EventHandler_instance = API . _instance <EOL> def create ( self , context , size , name , description , snapshot = None , <EOL> volume_type = None , metadata = None , availability_zone = None ) : <EOL> v = fake_volume ( size , name , <EOL> description , None , <EOL> snapshot , volume_type , <EOL> metadata , availability_zone ) <EOL> self . volume_list . append ( v . vol ) <EOL> LOG . info ( '<STR_LIT>' , v . vol [ '<STR_LIT:id>' ] ) <EOL> return v . vol <EOL> def create_with_kwargs ( self , context , ** kwargs ) : <EOL> volume_id = kwargs . get ( '<STR_LIT>' , None ) <EOL> v = fake_volume ( kwargs [ '<STR_LIT:size>' ] , <EOL> kwargs [ '<STR_LIT:name>' ] , <EOL> kwargs [ '<STR_LIT:description>' ] , <EOL> str ( volume_id ) , <EOL> None , <EOL> None , <EOL> None , <EOL> None ) <EOL> if kwargs . get ( '<STR_LIT:status>' , None ) is not None : <EOL> v . vol [ '<STR_LIT:status>' ] = kwargs [ '<STR_LIT:status>' ] <EOL> if kwargs [ '<STR_LIT:host>' ] is not None : <EOL> v . vol [ '<STR_LIT:host>' ] = kwargs [ '<STR_LIT:host>' ] <EOL> if kwargs [ '<STR_LIT>' ] is not None : <EOL> v . vol [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> if kwargs . get ( '<STR_LIT>' , None ) is not None : <EOL> v . vol [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> self . volume_list . append ( v . vol ) <EOL> return v . vol <EOL> def get ( self , context , volume_id ) : <EOL> if str ( volume_id ) == '<STR_LIT>' : <EOL> return { '<STR_LIT:id>' : volume_id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' } <EOL> for v in self . volume_list : <EOL> if v [ '<STR_LIT:id>' ] == str ( volume_id ) : <EOL> return v <EOL> raise exception . VolumeNotFound ( volume_id = volume_id ) <EOL> def get_all ( self , context ) : <EOL> return self . volume_list <EOL> def delete ( self , context , volume_id ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> self . volume_list = [ v for v in self . volume_list <EOL> if v [ '<STR_LIT:id>' ] != volume_id ] <EOL> def check_attach ( self , context , volume , instance = None ) : <EOL> if volume [ '<STR_LIT:status>' ] != '<STR_LIT>' : <EOL> msg = "<STR_LIT>" % volume <EOL> raise exception . InvalidVolume ( reason = msg ) <EOL> if volume [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> msg = "<STR_LIT>" <EOL> raise exception . InvalidVolume ( reason = msg ) <EOL> if instance and not CONF . cinder . cross_az_attach : <EOL> if instance [ '<STR_LIT>' ] != volume [ '<STR_LIT>' ] : <EOL> msg = "<STR_LIT>" <EOL> raise exception . InvalidVolume ( reason = msg ) <EOL> def check_detach ( self , context , volume , instance = None ) : <EOL> if volume [ '<STR_LIT:status>' ] == "<STR_LIT>" : <EOL> msg = "<STR_LIT>" <EOL> raise exception . InvalidVolume ( reason = msg ) <EOL> if volume [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> msg = "<STR_LIT>" <EOL> raise exception . InvalidVolume ( reason = msg ) <EOL> if instance and not volume . get ( '<STR_LIT>' , { } ) . get ( instance . uuid ) : <EOL> raise exception . VolumeUnattached ( volume_id = volume [ '<STR_LIT:id>' ] ) <EOL> def attach ( self , context , volume_id , instance_uuid , mountpoint , mode = '<STR_LIT>' ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> volume [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> volume [ '<STR_LIT>' ] = timeutils . utcnow ( ) <EOL> volume [ '<STR_LIT>' ] = True <EOL> volume [ '<STR_LIT>' ] = { instance_uuid : <EOL> { '<STR_LIT>' : str ( uuid . uuid4 ( ) ) , <EOL> '<STR_LIT>' : mountpoint } } <EOL> def reset_fake_api ( self , context ) : <EOL> del self . volume_list [ : ] <EOL> del self . snapshot_list [ : ] <EOL> def detach ( self , context , volume_id , instance_uuid , attachment_id = None ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> volume [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def initialize_connection ( self , context , volume_id , connector ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:data>' : { } } <EOL> def terminate_connection ( self , context , volume_id , connector ) : <EOL> return None <EOL> def get_snapshot ( self , context , snapshot_id ) : <EOL> for snap in self . snapshot_list : <EOL> if snap [ '<STR_LIT:id>' ] == str ( snapshot_id ) : <EOL> return snap <EOL> def get_all_snapshots ( self , context ) : <EOL> return self . snapshot_list <EOL> def create_snapshot ( self , context , volume_id , name , description , id = None ) : <EOL> volume = self . get ( context , volume_id ) <EOL> snapshot = fake_snapshot ( volume [ '<STR_LIT:id>' ] , volume [ '<STR_LIT:size>' ] , <EOL> name , description , id ) <EOL> self . snapshot_list . append ( snapshot . snap ) <EOL> return snapshot . snap <EOL> def create_snapshot_with_kwargs ( self , context , ** kwargs ) : <EOL> snapshot = fake_snapshot ( kwargs . get ( '<STR_LIT>' ) , <EOL> kwargs . get ( '<STR_LIT>' ) , <EOL> kwargs . get ( '<STR_LIT:name>' ) , <EOL> kwargs . get ( '<STR_LIT:description>' ) , <EOL> kwargs . get ( '<STR_LIT>' ) ) <EOL> status = kwargs . get ( '<STR_LIT:status>' , None ) <EOL> snapshot . snap [ '<STR_LIT:status>' ] = status <EOL> self . snapshot_list . append ( snapshot . snap ) <EOL> return snapshot . snap <EOL> def create_snapshot_force ( self , context , volume_id , <EOL> name , description , id = None ) : <EOL> volume = self . get ( context , volume_id ) <EOL> snapshot = fake_snapshot ( volume [ '<STR_LIT:id>' ] , volume [ '<STR_LIT:size>' ] , <EOL> name , description , id ) <EOL> self . snapshot_list . append ( snapshot . snap ) <EOL> return snapshot . snap <EOL> def delete_snapshot ( self , context , snapshot_id ) : <EOL> self . snapshot_list = [ s for s in self . snapshot_list <EOL> if s [ '<STR_LIT:id>' ] != snapshot_id ] <EOL> def reserve_volume ( self , context , volume_id ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> def unreserve_volume ( self , context , volume_id ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> def begin_detaching ( self , context , volume_id ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> def roll_detaching ( self , context , volume_id ) : <EOL> LOG . info ( '<STR_LIT>' , volume_id ) <EOL> volume = self . get ( context , volume_id ) <EOL> volume [ '<STR_LIT:status>' ] = '<STR_LIT>' </s>
