private List<SspClient> fetchSspClients(
      Long physicalNetworkId, Long dataCenterId, boolean enabled_only) {
    ArrayList<SspClient> clients = new ArrayList<SspClient>();

    boolean provider_found = false;
    PhysicalNetworkServiceProviderVO provider =
        _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetworkId, s_SSP_NAME);
    if (enabled_only) {
      if (provider != null && provider.getState() == State.Enabled) {
        provider_found = true;
      }
    } else {
      provider_found = true;
    }

    if (physicalNetworkId != null && provider_found) {
      SspCredentialVO credential = _sspCredentialDao.findByZone(dataCenterId);
      List<HostVO> hosts =
          _resourceMgr.listAllHostsInOneZoneByType(Host.Type.L2Networking, dataCenterId);
      for (HostVO host : hosts) {
        assert (credential != null);
        _hostDao.loadDetails(host);
        if ("v1Api".equals(host.getDetail("sspHost"))) {
          clients.add(
              new SspClient(
                  host.getDetail("url"), credential.getUsername(), credential.getPassword()));
        }
      }
    }
    if (clients.size() == 0) {
      String global_apiUrl = _configDao.getValueAndInitIfNotExist("ssp.url", "Network", null);
      String global_username =
          _configDao.getValueAndInitIfNotExist("ssp.username", "Network", null);
      String global_password =
          _configDao.getValueAndInitIfNotExist("ssp.password", "Network", null);
      if (global_apiUrl != null && global_username != null && global_password != null) {
        clients.add(new SspClient(global_apiUrl, global_username, global_password));
      }
    }
    return clients;
  }
  public boolean createNetwork(
      Network network,
      NetworkOffering offering,
      DeployDestination dest,
      ReservationContext context) {
    if (_sspUuidDao.findUuidByNetwork(network) != null) {
      s_logger.info("Network already has ssp TenantNetwork uuid :" + network.toString());
      return true;
    }
    if (!canHandle(network)) {
      return false;
    }

    String tenantUuid = _sspTenantDao.findUuidByZone(network.getDataCenterId());
    if (tenantUuid == null) {
      tenantUuid = _configDao.getValueAndInitIfNotExist("ssp.tenant", "Network", null);
    }

    boolean processed = false;
    for (SspClient client :
        fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
      SspClient.TenantNetwork sspNet = client.createTenantNetwork(tenantUuid, network.getName());
      if (sspNet != null) {
        SspUuidVO uuid = new SspUuidVO();
        uuid.setUuid(sspNet.uuid);
        uuid.setObjClass(SspUuidVO.objClassNetwork);
        uuid.setObjId(network.getId());
        _sspUuidDao.persist(uuid);
        return true;
      }
      processed = true;
    }
    if (processed) {
      s_logger.error("Could not allocate an uuid for network " + network.toString());
      return false;
    } else {
      s_logger.error("Skipping #createNetwork() for " + network.toString());
      return true;
    }
  }