<s> import copy <EOL> import logging <EOL> from cinderclient import exceptions as cinder_exceptions <EOL> from novaclient import exceptions as nova_exceptions <EOL> from oslo_config import cfg <EOL> from cloudferry . lib . base . action import action <EOL> from cloudferry . lib . utils import utils as utl <EOL> CONF = cfg . CONF <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class AttachVolumesCompute ( action . Action ) : <EOL> def run ( self , info , ** kwargs ) : <EOL> info = copy . deepcopy ( info ) <EOL> compute_res = self . cloud . resources [ utl . COMPUTE_RESOURCE ] <EOL> storage_res = self . cloud . resources [ utl . STORAGE_RESOURCE ] <EOL> for instance in info [ utl . INSTANCES_TYPE ] . itervalues ( ) : <EOL> if not instance [ utl . META_INFO ] . get ( utl . VOLUME_BODY ) : <EOL> continue <EOL> for vol in instance [ utl . META_INFO ] [ utl . VOLUME_BODY ] : <EOL> volume = vol [ '<STR_LIT>' ] <EOL> volume_id = volume [ '<STR_LIT:id>' ] <EOL> status = None <EOL> try : <EOL> status = storage_res . get_status ( volume_id ) <EOL> except cinder_exceptions . NotFound : <EOL> dst_volume = storage_res . get_migrated_volume ( volume_id ) <EOL> if dst_volume : <EOL> volume_id = dst_volume . id <EOL> status = dst_volume . status <EOL> if status == '<STR_LIT>' : <EOL> nova_client = compute_res . nova_client <EOL> inst = instance [ '<STR_LIT>' ] <EOL> try : <EOL> nova_client . volumes . create_server_volume ( <EOL> inst [ '<STR_LIT:id>' ] , volume_id , volume [ '<STR_LIT>' ] ) <EOL> timeout = CONF . migrate . storage_backend_timeout <EOL> storage_res . try_wait_for_status ( volume_id , <EOL> storage_res . get_status , <EOL> '<STR_LIT>' , <EOL> timeout = timeout ) <EOL> except ( cinder_exceptions . ClientException , <EOL> nova_exceptions . ClientException ) as e : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> LOG . warning ( msg , volume_id , inst [ '<STR_LIT:id>' ] , e . message ) <EOL> return { } </s>
