def allocate_controller_key_and_unit_number(client_factory, devices, adapter_type):
 if (devices.__class__.__name__ == 'ArrayOfVirtualDevice'):
  devices = devices.VirtualDevice
 taken = _find_allocated_slots(devices)
 ret = None
 if (adapter_type == constants.ADAPTER_TYPE_IDE):
  ide_keys = [dev.key for dev in devices if _is_ide_controller(dev)]
  ret = _find_controller_slot(ide_keys, taken, 2)
 elif (adapter_type in constants.SCSI_ADAPTER_TYPES):
  scsi_keys = [dev.key for dev in devices if _is_scsi_controller(dev)]
  ret = _find_controller_slot(scsi_keys, taken, 16)
 if ret:
  return (ret[0], ret[1], None)
 controller_key = (-101)
 bus_number = 0
 if (adapter_type in constants.SCSI_ADAPTER_TYPES):
  bus_number = _get_bus_number_for_scsi_controller(devices)
 controller_spec = create_controller_spec(client_factory, controller_key, adapter_type, bus_number)
 return (controller_key, 0, controller_spec)

def allocate_controller_key_and_unit_number ( client_factory , devices , adapter_type ) : if ( devices . __class__ . __name__ == 'ArrayOfVirtualDevice' ) : devices = devices . VirtualDevice taken = _find_allocated_slots ( devices ) ret = None if ( adapter_type == constants . ADAPTER_TYPE_IDE ) : ide_keys = [ dev . key for dev in devices if _is_ide_controller ( dev ) ] ret = _find_controller_slot ( ide_keys , taken , 2 ) elif ( adapter_type in constants . SCSI_ADAPTER_TYPES ) : scsi_keys = [ dev . key for dev in devices if _is_scsi_controller ( dev ) ] ret = _find_controller_slot ( scsi_keys , taken , 16 ) if ret : return ( ret [ 0 ] , ret [ 1 ] , None ) controller_key = ( - 101 ) bus_number = 0 if ( adapter_type in constants . SCSI_ADAPTER_TYPES ) : bus_number = _get_bus_number_for_scsi_controller ( devices ) controller_spec = create_controller_spec ( client_factory , controller_key , adapter_type , bus_number ) return ( controller_key , 0 , controller_spec )
this function inspects the current set of hardware devices and returns controller_key and unit_number that can be used for attaching a new virtual disk to adapter with the given adapter_type .