@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True, retry_on_request=True)
@pick_context_manager_writer
def fixed_ip_associate(context, address, instance_uuid, network_id=None, reserved=False, virtual_interface_id=None):
 if (not uuidutils.is_uuid_like(instance_uuid)):
  raise exception.InvalidUUID(uuid=instance_uuid)
 network_or_none = or_((models.FixedIp.network_id == network_id), (models.FixedIp.network_id == null()))
 fixed_ip_ref = model_query(context, models.FixedIp, read_deleted='no').filter(network_or_none).filter_by(reserved=reserved).filter_by(address=address).first()
 if (fixed_ip_ref is None):
  raise exception.FixedIpNotFoundForNetwork(address=address, network_uuid=network_id)
 if fixed_ip_ref.instance_uuid:
  raise exception.FixedIpAlreadyInUse(address=address, instance_uuid=instance_uuid)
 params = {'instance_uuid': instance_uuid, 'allocated': (virtual_interface_id is not None)}
 if (not fixed_ip_ref.network_id):
  params['network_id'] = network_id
 if virtual_interface_id:
  params['virtual_interface_id'] = virtual_interface_id
 rows_updated = model_query(context, models.FixedIp, read_deleted='no').filter_by(id=fixed_ip_ref.id).filter(network_or_none).filter_by(reserved=reserved).filter_by(address=address).update(params, synchronize_session='evaluate')
 if (not rows_updated):
  LOG.debug('The row was updated in a concurrent transaction, we will fetch another row')
  raise db_exc.RetryRequest(exception.FixedIpAssociateFailed(net=network_id))
 return fixed_ip_ref

@ oslo_db_api . wrap_db_retry ( max_retries = 5 , retry_on_deadlock = True , retry_on_request = True ) @ pick_context_manager_writer def fixed_ip_associate ( context , address , instance_uuid , network_id = None , reserved = False , virtual_interface_id = None ) : if ( not uuidutils . is_uuid_like ( instance_uuid ) ) : raise exception . InvalidUUID ( uuid = instance_uuid ) network_or_none = or_ ( ( models . FixedIp . network_id == network_id ) , ( models . FixedIp . network_id == null ( ) ) ) fixed_ip_ref = model_query ( context , models . FixedIp , read_deleted = 'no' ) . filter ( network_or_none ) . filter_by ( reserved = reserved ) . filter_by ( address = address ) . first ( ) if ( fixed_ip_ref is None ) : raise exception . FixedIpNotFoundForNetwork ( address = address , network_uuid = network_id ) if fixed_ip_ref . instance_uuid : raise exception . FixedIpAlreadyInUse ( address = address , instance_uuid = instance_uuid ) params = { 'instance_uuid' : instance_uuid , 'allocated' : ( virtual_interface_id is not None ) } if ( not fixed_ip_ref . network_id ) : params [ 'network_id' ] = network_id if virtual_interface_id : params [ 'virtual_interface_id' ] = virtual_interface_id rows_updated = model_query ( context , models . FixedIp , read_deleted = 'no' ) . filter_by ( id = fixed_ip_ref . id ) . filter ( network_or_none ) . filter_by ( reserved = reserved ) . filter_by ( address = address ) . update ( params , synchronize_session = 'evaluate' ) if ( not rows_updated ) : LOG . debug ( 'The row was updated in a concurrent transaction, we will fetch another row' ) raise db_exc . RetryRequest ( exception . FixedIpAssociateFailed ( net = network_id ) ) return fixed_ip_ref
associate fixed ip to instance .