Search in sources :

Example 1 with FloatingIpModel

use of org.apache.cloudstack.network.contrail.model.FloatingIpModel in project cloudstack by apache.

the class ServerDBSyncImpl method equalFloatingIp.

public Boolean equalFloatingIp(IPAddressVO db, FloatingIp vnc, StringBuffer syncLogMsg) throws IOException {
    syncLogMsg.append("fip# DB: " + db.getAddress().addr() + "; VNC: " + vnc.getAddress() + "; action: equal" + "\n");
    VirtualNetworkModel vnModel = _manager.lookupPublicNetworkModel();
    assert vnModel != null : "public network vn model is null";
    FloatingIpPoolModel fipPoolModel = vnModel.getFipPoolModel();
    if (fipPoolModel == null) {
        fipPoolModel = new FloatingIpPoolModel();
        fipPoolModel.addToVirtualNetwork(vnModel);
        fipPoolModel.build(_manager.getModelController());
        try {
            fipPoolModel.update(_manager.getModelController());
            vnModel.setFipPoolModel(fipPoolModel);
        } catch (Exception ex) {
            s_logger.warn("floating-ip-pool create: ", ex);
            return false;
        }
    }
    FloatingIpModel current = fipPoolModel.getFloatingIpModel(db.getUuid());
    if (current == null) {
        s_logger.debug("add model " + db.getAddress().addr());
        FloatingIpModel fipModel = new FloatingIpModel(db.getUuid());
        fipModel.addToFloatingIpPool(fipPoolModel);
        fipModel.build(_manager.getModelController(), PublicIp.createFromAddrAndVlan(db, _vlanDao.findById(db.getVlanId())));
        try {
            fipModel.update(_manager.getModelController());
        } catch (Exception ex) {
            s_logger.warn("floating-ip create: ", ex);
            return false;
        }
    }
    return true;
}
Also used : FloatingIpPoolModel(org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel) FloatingIpModel(org.apache.cloudstack.network.contrail.model.FloatingIpModel) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 2 with FloatingIpModel

use of org.apache.cloudstack.network.contrail.model.FloatingIpModel in project cloudstack by apache.

the class ContrailManagerImpl method createFloatingIp.

@Override
public boolean createFloatingIp(PublicIpAddress ip) {
    VirtualNetworkModel vnModel = lookupPublicNetworkModel();
    assert vnModel != null : "public network vn model is null";
    FloatingIpPoolModel fipPoolModel = vnModel.getFipPoolModel();
    /* create only, no updates */
    if (fipPoolModel == null) {
        fipPoolModel = new FloatingIpPoolModel();
        fipPoolModel.addToVirtualNetwork(vnModel);
        fipPoolModel.build(getModelController());
        try {
            fipPoolModel.update(getModelController());
            vnModel.setFipPoolModel(fipPoolModel);
        } catch (Exception ex) {
            s_logger.warn("floating-ip-pool create: ", ex);
            return false;
        }
    }
    FloatingIpModel fipModel = fipPoolModel.getFloatingIpModel(ip.getUuid());
    /* create only, no updates*/
    if (fipModel == null) {
        fipModel = new FloatingIpModel(ip.getUuid());
        fipModel.addToFloatingIpPool(fipPoolModel);
        fipModel.build(getModelController(), ip);
        try {
            fipModel.update(getModelController());
        } catch (Exception ex) {
            s_logger.warn("floating-ip create: ", ex);
            return false;
        }
    }
    return true;
}
Also used : FloatingIpPoolModel(org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel) FloatingIpModel(org.apache.cloudstack.network.contrail.model.FloatingIpModel) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 3 with FloatingIpModel

use of org.apache.cloudstack.network.contrail.model.FloatingIpModel in project cloudstack by apache.

the class ContrailManagerImpl method deleteFloatingIp.

@Override
public boolean deleteFloatingIp(PublicIpAddress ip) {
    VirtualNetworkModel vnModel = lookupPublicNetworkModel();
    assert vnModel != null : "public network model is null";
    FloatingIpPoolModel fipPoolModel = vnModel.getFipPoolModel();
    FloatingIpModel fipModel = fipPoolModel.getFloatingIpModel(ip.getUuid());
    if (fipModel != null) {
        try {
            fipModel.destroy(getModelController());
        } catch (IOException ex) {
            s_logger.warn("floating ip delete", ex);
            return false;
        }
        fipPoolModel.removeSuccessor(fipModel);
        if (!fipPoolModel.hasDescendents()) {
            try {
                fipPoolModel.delete(getModelController());
                vnModel.setFipPoolModel(null);
            } catch (IOException e) {
                return false;
            }
        }
    }
    return true;
}
Also used : FloatingIpPoolModel(org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel) FloatingIpModel(org.apache.cloudstack.network.contrail.model.FloatingIpModel) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Aggregations

IOException (java.io.IOException)3 FloatingIpModel (org.apache.cloudstack.network.contrail.model.FloatingIpModel)3 FloatingIpPoolModel (org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel)3 VirtualNetworkModel (org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)3 InternalErrorException (com.cloud.exception.InternalErrorException)1 ConfigurationException (javax.naming.ConfigurationException)1