private void createHost(Network network,List<ScaleIOSDC> allSDCs){
  List<URI> tenantOrgList=_dbClient.queryByType(TenantOrg.class,true);
  Iterator<TenantOrg> it=_dbClient.queryIterativeObjects(TenantOrg.class,tenantOrgList);
  List<String> initiatorsToAddToNetwork=new ArrayList<>();
  URI rootTenant=null;
  while (it.hasNext()) {
    TenantOrg tenantOrg=it.next();
    if (TenantOrg.isRootTenant(tenantOrg)) {
      rootTenant=tenantOrg.getId();
      break;
    }
  }
  for (  ScaleIOSDC sdc : allSDCs) {
    String ip=sdc.getSdcIp();
    String guid=sdc.getSdcGuid();
    Host host=findByNativeGuid(guid);
    if (host == null) {
      host=findOrCreateByIp(rootTenant,ip,guid);
    }
    Initiator initiator=createInitiator(host,ip,sdc.getId());
    if (!network.hasEndpoint(initiator.getInitiatorPort())) {
      initiatorsToAddToNetwork.add(initiator.getInitiatorPort());
    }
  }
  if (!initiatorsToAddToNetwork.isEmpty()) {
    network.addEndpoints(initiatorsToAddToNetwork,true);
    _dbClient.updateAndReindexObject(network);
  }
}

private void createHost ( Network network , List < ScaleIOSDC > allSDCs ) { List < URI > tenantOrgList = _dbClient . queryByType ( TenantOrg . class , true ) ; Iterator < TenantOrg > it = _dbClient . queryIterativeObjects ( TenantOrg . class , tenantOrgList ) ; List < String > initiatorsToAddToNetwork = new ArrayList < > ( ) ; URI rootTenant = null ; while ( it . hasNext ( ) ) { TenantOrg tenantOrg = it . next ( ) ; if ( TenantOrg . isRootTenant ( tenantOrg ) ) { rootTenant = tenantOrg . getId ( ) ; break ; } } for ( ScaleIOSDC sdc : allSDCs ) { String ip = sdc . getSdcIp ( ) ; String guid = sdc . getSdcGuid ( ) ; Host host = findByNativeGuid ( guid ) ; if ( host == null ) { host = findOrCreateByIp ( rootTenant , ip , guid ) ; } Initiator initiator = createInitiator ( host , ip , sdc . getId ( ) ) ; if ( ! network . hasEndpoint ( initiator . getInitiatorPort ( ) ) ) { initiatorsToAddToNetwork . add ( initiator . getInitiatorPort ( ) ) ; } } if ( ! initiatorsToAddToNetwork . isEmpty ( ) ) { network . addEndpoints ( initiatorsToAddToNetwork , true ) ; _dbClient . updateAndReindexObject ( network ) ; } }
create a host object for every sdc that is found on the system . create a single initiator for the host in the specified network .
