Ejemplo n.º 1
0
  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;
    }
  }
Ejemplo n.º 2
0
  // we use context.reservationId for dedup of guru & element operations.
  public boolean createNicEnv(
      Network network, NicProfile nic, DeployDestination dest, ReservationContext context) {
    String tenantNetworkUuid = _sspUuidDao.findUuidByNetwork(network);
    if (tenantNetworkUuid == null) {
      s_logger.debug("Skipping #createNicEnv() for nic on " + network.toString());
      return true;
    }

    String reservationId = context.getReservationId();
    List<SspUuidVO> tenantPortUuidVos = _sspUuidDao.listUUidVoByNicProfile(nic);
    for (SspUuidVO tenantPortUuidVo : tenantPortUuidVos) {
      if (reservationId.equals(tenantPortUuidVo.getReservationId())) {
        s_logger.info("Skipping because reservation found " + reservationId);
        return true;
      }
    }

    String tenantPortUuid = null;
    for (SspClient client :
        fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
      SspClient.TenantPort sspPort = client.createTenantPort(tenantNetworkUuid);
      if (sspPort != null) {
        tenantPortUuid = sspPort.uuid;
        nic.setReservationId(reservationId);

        SspUuidVO uuid = new SspUuidVO();
        uuid.setUuid(tenantPortUuid);
        uuid.setObjClass(SspUuidVO.objClassNicProfile);
        uuid.setObjId(nic.getId());
        uuid.setReservationId(reservationId);
        _sspUuidDao.persist(uuid);
        break;
      }
    }
    if (tenantPortUuid == null) {
      s_logger.debug("#createNicEnv() failed for nic on " + network.toString());
      return false;
    }

    for (SspClient client :
        fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
      SspClient.TenantPort sspPort =
          client.updateTenantVifBinding(tenantPortUuid, dest.getHost().getPrivateIpAddress());
      if (sspPort != null) {
        if (sspPort.vlanId != null) {
          nic.setBroadcastType(BroadcastDomainType.Vlan);
          nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(String.valueOf(sspPort.vlanId)));
        }
        return true;
      }
    }
    s_logger.error("Updating vif failed " + nic.toString());
    return false;
  }
Ejemplo n.º 3
0
  public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext context) {
    if (context == null) {
      s_logger.error("ReservationContext was null for " + nic + " " + network);
      return false;
    }
    String reservationId = context.getReservationId();

    SspUuidVO deleteTarget = null;
    SspUuidVO remainingTarget = null;
    List<SspUuidVO> tenantPortUuidVos = _sspUuidDao.listUUidVoByNicProfile(nic);
    for (SspUuidVO tenantPortUuidVo : tenantPortUuidVos) {
      if (reservationId.equals(tenantPortUuidVo.getReservationId())) {
        deleteTarget = tenantPortUuidVo;
      } else {
        remainingTarget = tenantPortUuidVo;
      }
    }

    if (deleteTarget != null) { // delete the target ssp uuid (tenant-port)
      String tenantPortUuid = deleteTarget.getUuid();
      boolean processed = false;
      for (SspClient client :
          fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
        SspClient.TenantPort sspPort = client.updateTenantVifBinding(tenantPortUuid, null);
        if (sspPort != null) {
          processed = true;
          break;
        }
      }
      if (!processed) {
        s_logger.warn("Ssp api nic detach failed " + nic.toString());
      }
      processed = false;
      for (SspClient client :
          fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
        if (client.deleteTenantPort(tenantPortUuid)) {
          _sspUuidDao.removeUuid(tenantPortUuid);
          processed = true;
          break;
        }
      }
      if (!processed) {
        s_logger.warn("Ssp api tenant port deletion failed " + nic.toString());
      }
      _sspUuidDao.removeUuid(tenantPortUuid);
    }
    if (remainingTarget != null) {
      NicVO nicVo = _nicDao.findById(nic.getId());
      nicVo.setReservationId(remainingTarget.getReservationId());
      _nicDao.persist(nicVo); // persist the new reservationId
    }
    return true;
  }