@sqlalchemy_api.require_admin_context
def bm_node_associate_and_update(context, node_uuid, values):
 if ('instance_uuid' not in values):
  raise exception.NovaException(_('instance_uuid must be supplied to bm_node_associate_and_update'))
 session = db_session.get_session()
 with session.begin():
  query = model_query(context, models.BareMetalNode, session=session, read_deleted='no').filter_by(uuid=node_uuid)
  count = query.filter_by(instance_uuid=None).update(values, synchronize_session=False)
  if (count != 1):
   raise exception.NovaException((_('Failed to associate instance %(i_uuid)s to baremetal node %(n_uuid)s.') % {'i_uuid': values['instance_uuid'], 'n_uuid': node_uuid}))
  ref = query.first()
 return ref

@ sqlalchemy_api . require_admin_context def bm_node_associate_and_update ( context , node_uuid , values ) : if ( 'instance_uuid' not in values ) : raise exception . NovaException ( _ ( 'instance_uuid must be supplied to bm_node_associate_and_update' ) ) session = db_session . get_session ( ) with session . begin ( ) : query = model_query ( context , models . BareMetalNode , session = session , read_deleted = 'no' ) . filter_by ( uuid = node_uuid ) count = query . filter_by ( instance_uuid = None ) . update ( values , synchronize_session = False ) if ( count != 1 ) : raise exception . NovaException ( ( _ ( 'Failed to associate instance %(i_uuid)s to baremetal node %(n_uuid)s.' ) % { 'i_uuid' : values [ 'instance_uuid' ] , 'n_uuid' : node_uuid } ) ) ref = query . first ( ) return ref
associate an instance to a node safely associate an instance to a node only if that node is not yet assocated .