Package org.apache.cloudstack.network.contrail.model

Examples of org.apache.cloudstack.network.contrail.model.NetworkPolicyModel


        }

        VirtualNetworkModel vnModel = new VirtualNetworkModel(dbNet, dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType());
        if (dbNet.getTrafficType() == TrafficType.Guest && dbNet.getNetworkACLId() != null) {
            NetworkACLVO acl = _networkACLDao.findById(dbNet.getNetworkACLId());
            NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
            if (policyModel == null) {
                s_logger.error("Network(" + dbNet.getName() + ") has ACL but policy model not created: " +
                                       acl.getUuid() + ", name: " + acl.getName());
            } else {
                vnModel.addToNetworkPolicy(policyModel);
View Full Code Here


        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();
                        }
                    }
View Full Code Here

        if (_manager.getDatabase().lookupNetworkPolicy(db.getUuid()) != null) {
             s_logger.warn("Policy model object is already present in DB: " +
                                   db.getUuid() + ", name: " + db.getName());
        }
        NetworkPolicyModel policyModel = new NetworkPolicyModel(db.getUuid(), db.getName());
        net.juniper.contrail.api.types.Project project = null;
        try {
            VpcVO vpc = _vpcDao.findById(db.getVpcId());
            if (vpc != null) {
                project = _manager.getVncProject(vpc.getDomainId(), vpc.getAccountId());
            } else {
                project = _manager.getDefaultVncProject();
            }
        } catch (IOException ex) {
            s_logger.warn("read project", ex);
            throw ex;
        }
        policyModel.setProject(project);
        List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(db.getId());
        try {
            policyModel.build(_manager.getModelController(), rules);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (_rwMode) {
            try {
                if (!policyModel.verify(_manager.getModelController())) {
                    policyModel.update(_manager.getModelController());
                }
            } catch (Exception ex) {
                s_logger.warn("create network-policy", ex);
                syncLogMesg.append("Error: Policy# VNC : Unable to create network policy " +
                    db.getName() + "\n");
                return;
            }
            s_logger.debug("add model " + policyModel.getName());
            _manager.getDatabase().getNetworkPolicys().add(policyModel);
            syncLogMesg.append("Policy# VNC: " + db.getUuid() + ", " + policyModel.getName() + " created\n");
        } else {
            syncLogMesg.append("Policy# VNC: " + policyModel.getName() + " created \n");
        }
    }
View Full Code Here

    }

    public Boolean equalNetworkPolicy(NetworkACLVO db, NetworkPolicy policy, StringBuffer syncLogMesg) {
        syncLogMesg.append("Policy# DB: " + db.getName() +
                "; VNC: " + policy.getName() + "; action: equal\n");
        NetworkPolicyModel current = _manager.getDatabase().lookupNetworkPolicy(policy.getUuid());
        NetworkPolicyModel policyModel = new NetworkPolicyModel(db.getUuid(), db.getName());
        net.juniper.contrail.api.types.Project project = null;
        try {
            VpcVO vpc = _vpcDao.findById(db.getVpcId());
            if (vpc != null) {
                project = _manager.getVncProject(vpc.getDomainId(), vpc.getAccountId());
            } else {
                project = _manager.getDefaultVncProject();
            }
        } catch (IOException ex) {
            s_logger.warn("read project", ex);
        }
        policyModel.setProject(project);
        List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(db.getId());
        try {
            policyModel.build(_manager.getModelController(), rules);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (_rwMode) {
            if (current != null) {
                _manager.getDatabase().getNetworkPolicys().remove(current);
            }
            s_logger.debug("add policy model " + policyModel.getName());
            _manager.getDatabase().getNetworkPolicys().add(policyModel);
            try {
                if (!policyModel.verify(_manager.getModelController())) {
                    policyModel.update(_manager.getModelController());
                }
            } catch (Exception ex) {
                s_logger.warn("update network-policy", ex);
            }
        } else {
View Full Code Here

            return true;
        }

        Long aclId = rules.get(0).getAclId();
        NetworkACLVO acl = _networkACLDao.findById(aclId);
        NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
        if (policyModel == null) {
            /*
             * For the first time, when a CS ACL applied to a network, create a network-policy in VNC
             * and when there are no networks associated to CS ACL, delete it from VNC.
             */
            policyModel = new NetworkPolicyModel(acl.getUuid(), acl.getName());
            net.juniper.contrail.api.types.Project project;
            try {
                project = _manager.getVncProject(net.getDomainId(), net.getAccountId());
                if (project == null) {
                    project = _manager.getDefaultVncProject();
                }
            } catch (IOException ex) {
                s_logger.warn("read project", ex);
                return false;
            }
            policyModel.setProject(project);
        }

        VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(net.getUuid(),
                _manager.getCanonicalName(net), net.getTrafficType());
        NetworkPolicyModel oldPolicyModel = null;
        /* this method is called when network is destroyed too, hence vn model might have been deleted already */
        if (vnModel != null) {
            oldPolicyModel = vnModel.getNetworkPolicyModel();
            vnModel.addToNetworkPolicy(policyModel);
        }

        try {
            policyModel.build(_manager.getModelController(), rules);
        } catch (Exception e) {
            s_logger.error(e);
            e.printStackTrace();
            return false;
        }

        try {
            if (!policyModel.verify(_manager.getModelController())) {
                policyModel.update(_manager.getModelController());
            }
            _manager.getDatabase().getNetworkPolicys().add(policyModel);
        } catch (Exception ex) {
            s_logger.error("network-policy update: ", ex);
            ex.printStackTrace();
            return false;
        }

        if (!policyModel.hasPolicyRules()) {
            try {
                policyModel.delete(_manager.getModelController());
                _manager.getDatabase().getNetworkPolicys().remove(policyModel);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
        /*
         * if no other VNs are associated with the old policy,
         * we could delete it from the Contrail VNC
         */
        if (policyModel != oldPolicyModel && oldPolicyModel != null && !oldPolicyModel.hasDescendents()) {
            try {
                oldPolicyModel.delete(_manager.getModelController());
                _manager.getDatabase().getNetworkPolicys().remove(oldPolicyModel);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
View Full Code Here

    public TreeSet<NetworkPolicyModel> getNetworkPolicys() {
        return _policyTable;
    }

    public NetworkPolicyModel lookupNetworkPolicy(String uuid) {
        NetworkPolicyModel vmKey = new NetworkPolicyModel(uuid, null);
        NetworkPolicyModel current = _policyTable.ceiling(vmKey);
        if (current != null && current.getUuid().equals(uuid)) {
            return current;
        }
        return null;
    }
View Full Code Here

    public TreeSet<NetworkPolicyModel> getNetworkPolicys() {
        return _policyTable;
    }

    public NetworkPolicyModel lookupNetworkPolicy(String uuid) {
        NetworkPolicyModel vmKey = new NetworkPolicyModel(uuid, null);
        NetworkPolicyModel current = _policyTable.ceiling(vmKey);
        if (current != null && current.getUuid().equals(uuid)) {
            return current;
        }
        return null;
    }
View Full Code Here

       
        VirtualNetworkModel vnModel = new VirtualNetworkModel(dbNet,
                dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType());
        if (dbNet.getTrafficType() == TrafficType.Guest && dbNet.getNetworkACLId() != null) {
            NetworkACLVO acl = _networkACLDao.findById(dbNet.getNetworkACLId());
            NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
            if (policyModel == null) {
                s_logger.error("Network(" + dbNet.getName() + ") has ACL but policy model not created: " +
                                       acl.getUuid() + ", name: " + acl.getName());     
            } else {
                vnModel.addToNetworkPolicy(policyModel);
View Full Code Here

        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 (_rw_mode) {
            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();
                        }
                    }
View Full Code Here

        if (_manager.getDatabase().lookupNetworkPolicy(db.getUuid()) != null) {
             s_logger.warn("Policy model object is already present in DB: " +
                                   db.getUuid() + ", name: " + db.getName());     
        }
        NetworkPolicyModel policyModel = new NetworkPolicyModel(db.getUuid(), db.getName());
        net.juniper.contrail.api.types.Project project = null;
        try {
            project = _manager.getDefaultVncProject();
        } catch (IOException ex) {
            s_logger.warn("read project", ex);
            throw ex;
        }
        policyModel.setProject(project);
        List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(db.getId());
        try {
            policyModel.build(_manager.getModelController(), rules);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (_rw_mode) {
            try {
                if (!policyModel.verify(_manager.getModelController())) {
                    policyModel.update(_manager.getModelController());
                }
            } catch (Exception ex) {
                s_logger.warn("create network-policy", ex);
                syncLogMesg.append("Error: Policy# VNC : Unable to create network policy " +
                    db.getName() + "\n");
                return;
            }
            s_logger.debug("add model " + policyModel.getName());
            _manager.getDatabase().getNetworkPolicys().add(policyModel);
            syncLogMesg.append("Policy# VNC: " + db.getUuid() + ", " + policyModel.getName() + " created\n");
        } else {
            syncLogMesg.append("Policy# VNC: " + policyModel.getName() + " created \n");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.network.contrail.model.NetworkPolicyModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.