Search in sources :

Example 6 with VirtualNetworkModel

use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel 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 7 with VirtualNetworkModel

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

the class ServerDBSyncImpl method createVirtualNetwork.

public void createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) throws IOException {
    syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbNet) + "(" + dbNet.getUuid() + "); VNC: none;  action: create\n");
    if (_manager.getDatabase().lookupVirtualNetwork(dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()) != null) {
        s_logger.warn("VN model object is already present in DB: " + dbNet.getUuid() + ", name: " + dbNet.getName());
    }
    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);
        }
    }
    vnModel.build(_manager.getModelController(), dbNet);
    if (_rwMode) {
        try {
            if (!vnModel.verify(_manager.getModelController())) {
                vnModel.update(_manager.getModelController());
            }
        } catch (InternalErrorException ex) {
            s_logger.warn("create virtual-network", ex);
            syncLogMesg.append("Error: VN# VNC : Unable to create network " + dbNet.getName() + "\n");
            return;
        }
        s_logger.debug("add model " + vnModel.getName());
        _manager.getDatabase().getVirtualNetworks().add(vnModel);
        syncLogMesg.append("VN# VNC: " + dbNet.getUuid() + ", " + vnModel.getName() + " created\n");
    } else {
        syncLogMesg.append("VN# VNC: " + vnModel.getName() + " created \n");
    }
}
Also used : NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) NetworkPolicyModel(org.apache.cloudstack.network.contrail.model.NetworkPolicyModel) InternalErrorException(com.cloud.exception.InternalErrorException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 8 with VirtualNetworkModel

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

the class ContrailGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
        vnModel.setProperties(_manager.getModelController(), network);
    }
    try {
        if (!vnModel.verify(_manager.getModelController())) {
            vnModel.update(_manager.getModelController());
        }
    } catch (Exception ex) {
        s_logger.warn("virtual-network update: ", ex);
        return network;
    }
    _manager.getDatabase().getVirtualNetworks().add(vnModel);
    if (network.getVpcId() != null) {
        List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
        if (ips.isEmpty()) {
            s_logger.debug("Creating a source nat ip for network " + network);
            Account owner = _accountMgr.getAccount(network.getAccountId());
            try {
                PublicIp publicIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
                IPAddressVO ip = publicIp.ip();
                ip.setVpcId(network.getVpcId());
                _ipAddressDao.acquireInLockTable(ip.getId());
                _ipAddressDao.update(ip.getId(), ip);
                _ipAddressDao.releaseFromLockTable(ip.getId());
            } catch (Exception e) {
                s_logger.error("Unable to allocate source nat ip: " + e);
            }
        }
    }
    return network;
}
Also used : Account(com.cloud.user.Account) PublicIp(com.cloud.network.addr.PublicIp) IPAddressVO(com.cloud.network.dao.IPAddressVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 9 with VirtualNetworkModel

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

the class ContrailGuru method shutdown.

@Override
public void shutdown(NetworkProfile network, NetworkOffering offering) {
    s_logger.debug("NetworkGuru shutdown");
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        return;
    }
    try {
        _manager.getDatabase().getVirtualNetworks().remove(vnModel);
        vnModel.delete(_manager.getModelController());
    } catch (IOException e) {
        s_logger.warn("virtual-network delete", e);
    }
}
Also used : IOException(java.io.IOException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 10 with VirtualNetworkModel

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

the class ContrailElementImpl method implement.

/**
     * Network add/update.
     */
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType());
    if (network.getTrafficType() == TrafficType.Guest) {
        s_logger.debug("ignore network " + network.getName());
        return true;
    }
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
        vnModel.setProperties(_manager.getModelController(), network);
    }
    try {
        if (!vnModel.verify(_manager.getModelController())) {
            vnModel.update(_manager.getModelController());
        }
        _manager.getDatabase().getVirtualNetworks().add(vnModel);
    } catch (Exception ex) {
        s_logger.warn("virtual-network update: ", ex);
    }
    return true;
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IOException(java.io.IOException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) 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