#NEWLINE# def free( self , instance = None ) : #NEWLINE# #INDENT# ok_statuses = ( fields . PciDeviceStatus . ALLOCATED , fields . PciDeviceStatus . CLAIMED ) #NEWLINE# free_devs = [ ] #NEWLINE# if ( self . status not in ok_statuses ) : #NEWLINE# #INDENT# raise exception . PciDeviceInvalidStatus ( compute_node_id = self . compute_node_id , address = self . address , status = self . status , hopestatus = ok_statuses ) #NEWLINE# #UNINDENT# if ( parent and ( self . instance_uuid != instance [ 'uuid' ] ) ) : #NEWLINE# #INDENT# raise exception . PciDeviceInvalidOwner ( compute_node_id = self . compute_node_id , address = self . address , owner = self . instance_uuid , hopeowner = instance [ 'uuid' ] ) #NEWLINE# #UNINDENT# if ( self . dev_type == fields . PciDeviceType . SRIOV_PF ) : #NEWLINE# #INDENT# vfs_list = objects . PciDeviceList . get_by_parent_address ( self . _context , self . compute_node_id , self . address ) #NEWLINE# self . _bulk_update_status ( vfs_list , fields . PciDeviceStatus . AVAILABLE ) #NEWLINE# free_devs . extend ( vfs_list ) #NEWLINE# #UNINDENT# if ( self . dev_type == fields . PciDeviceType . SRIOV_VF ) : #NEWLINE# #INDENT# vfs_list = objects . PciDeviceList . get_by_parent_address ( self . _context , self . compute_node_id , self . parent_addr ) #NEWLINE# if all ( [ vf . is_available ( ) for vf in vfs_list if ( vf . id != self . id ) ] ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# parent = self . get_by_dev_addr ( self . _context , self . compute_node_id , self . parent_addr ) #NEWLINE# parent . status = fields . PciDeviceStatus . AVAILABLE #NEWLINE# free_devs . append ( parent ) #NEWLINE# #UNINDENT# except exception . PciDeviceNotFound : #NEWLINE# #INDENT# LOG . debug ( 'Physical function addr: %(pf_addr)s parent of VF addr: %(vf_addr)s was not found' , { #NEWLINE# #INDENT# 'pf_addr' : self . parent_addr , #NEWLINE# 'vf_addr' : self . address , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# old_status = self . status #NEWLINE# self . status = fields . PciDeviceStatus . AVAILABLE #NEWLINE# free_devs . append ( self ) #NEWLINE# self . instance_uuid = None #NEWLINE# self . request_id = None #NEWLINE# if ( ( old_status == fields . PciDeviceStatus . ALLOCATED ) and instance ) : #NEWLINE# #INDENT# existed = next ( ( dev for dev in instance [ 'pci_devices' ] if ( dev . id == self . id ) ) ) #NEWLINE# if isinstance ( instance , dict ) : #NEWLINE# #INDENT# instance [ 'pci_devices' ] . remove ( existed ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# instance . pci_devices . objects . remove ( existed ) #NEWLINE# #UNINDENT# #UNINDENT# return free_devs