Search in sources :

Example 16 with VirtualNetworkModel

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

the class ServerDBSyncImpl method equalVirtualNetwork.

public Boolean equalVirtualNetwork(NetworkVO dbn, VirtualNetwork vnet, StringBuffer syncLogMesg) {
    syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbn) + "; VNC: " + vnet.getName() + "; action: equal\n");
    VirtualNetworkModel current = _manager.getDatabase().lookupVirtualNetwork(vnet.getUuid(), _manager.getCanonicalName(dbn), dbn.getTrafficType());
    VirtualNetworkModel vnModel = new VirtualNetworkModel(dbn, vnet.getUuid(), _manager.getCanonicalName(dbn), dbn.getTrafficType());
    if (dbn.getTrafficType() == TrafficType.Guest && dbn.getNetworkACLId() != null) {
        NetworkACLVO acl = _networkACLDao.findById(dbn.getNetworkACLId());
        NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
        if (policyModel == null) {
            s_logger.error("Network(" + dbn.getName() + ") has ACL but policy model not created: " + acl.getUuid() + ", name: " + acl.getName());
        } else {
            vnModel.addToNetworkPolicy(policyModel);
        }
    }
    vnModel.build(_manager.getModelController(), dbn);
    if (_rwMode) {
        if (current != null) {
            FloatingIpPoolModel fipPoolModel = current.getFipPoolModel();
            if (fipPoolModel != null) {
                vnModel.setFipPoolModel(fipPoolModel);
                fipPoolModel.addToVirtualNetwork(vnModel);
            }
            _manager.getDatabase().getVirtualNetworks().remove(current);
        }
        s_logger.debug("add model " + vnModel.getName());
        _manager.getDatabase().getVirtualNetworks().add(vnModel);
        try {
            if (!vnModel.verify(_manager.getModelController())) {
                vnModel.update(_manager.getModelController());
            }
        } catch (Exception ex) {
            s_logger.warn("update virtual-network", ex);
        }
        if (current != null) {
            NetworkPolicyModel oldPolicyModel = current.getNetworkPolicyModel();
            if (oldPolicyModel != vnModel.getNetworkPolicyModel()) {
                /*
                     * if no other VNs are associated with the old policy,
                     * we could delete it from the Contrail VNC
                     */
                if (oldPolicyModel != null && !oldPolicyModel.hasDescendents()) {
                    try {
                        oldPolicyModel.delete(_manager.getModelController());
                        _manager.getDatabase().getNetworkPolicys().remove(oldPolicyModel);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } else {
        //compare
        if (current != null && current.compare(_manager.getModelController(), vnModel) == false) {
            syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbn) + "; VNC: " + vnet.getName() + "; attributes differ\n");
            return false;
        }
    }
    return true;
}
Also used : NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) FloatingIpPoolModel(org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel) NetworkPolicyModel(org.apache.cloudstack.network.contrail.model.NetworkPolicyModel) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Aggregations

VirtualNetworkModel (org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)16 IOException (java.io.IOException)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 FloatingIpPoolModel (org.apache.cloudstack.network.contrail.model.FloatingIpPoolModel)4 InternalErrorException (com.cloud.exception.InternalErrorException)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkACLVO (com.cloud.network.vpc.NetworkACLVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NicVO (com.cloud.vm.NicVO)3 ConfigurationException (javax.naming.ConfigurationException)3 FloatingIpModel (org.apache.cloudstack.network.contrail.model.FloatingIpModel)3 NetworkPolicyModel (org.apache.cloudstack.network.contrail.model.NetworkPolicyModel)3 VMInterfaceModel (org.apache.cloudstack.network.contrail.model.VMInterfaceModel)3 VirtualMachineModel (org.apache.cloudstack.network.contrail.model.VirtualMachineModel)3 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)2 TrafficType (com.cloud.network.Networks.TrafficType)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2