Search in sources :

Example 11 with VirtualNetworkModel

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

the class ContrailElementImpl method prepare.

@Override
public boolean prepare(Network network, NicProfile nicProfile, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("NetworkElement prepare: " + network.getName() + ", traffic type: " + network.getTrafficType());
    if (network.getTrafficType() == TrafficType.Guest) {
        s_logger.debug("ignore network " + network.getName());
        return true;
    }
    s_logger.debug("network: " + network.getId());
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        // this may be the first time we see this network.
        return false;
    }
    VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
    if (vmModel == null) {
        VMInstanceVO vmVo = (VMInstanceVO) vm.getVirtualMachine();
        vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
        vmModel.setProperties(_manager.getModelController(), vmVo);
    }
    NicVO nic = _nicDao.findById(nicProfile.getId());
    assert nic != null;
    VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
    if (vmiModel == null) {
        vmiModel = new VMInterfaceModel(nic.getUuid());
        vmiModel.addToVirtualMachine(vmModel);
        vmiModel.addToVirtualNetwork(vnModel);
    }
    try {
        vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nic);
    } catch (IOException ex) {
        s_logger.warn("vm interface set", ex);
        return false;
    }
    InstanceIpModel ipModel = vmiModel.getInstanceIp();
    if (ipModel == null) {
        ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
        ipModel.addToVMInterface(vmiModel);
    }
    ipModel.setAddress(nicProfile.getIPv4Address());
    try {
        vmModel.update(_manager.getModelController());
    } catch (Exception ex) {
        s_logger.warn("virtual-machine-update", ex);
        return false;
    }
    _manager.getDatabase().getVirtualMachines().add(vmModel);
    return true;
}
Also used : VMInterfaceModel(org.apache.cloudstack.network.contrail.model.VMInterfaceModel) VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) VMInstanceVO(com.cloud.vm.VMInstanceVO) IOException(java.io.IOException) NicVO(com.cloud.vm.NicVO) InstanceIpModel(org.apache.cloudstack.network.contrail.model.InstanceIpModel) 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)

Example 12 with VirtualNetworkModel

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

the class ContrailManagerImpl method lookupPublicNetworkModel.

@Override
public VirtualNetworkModel lookupPublicNetworkModel() {
    List<TrafficType> types = new ArrayList<TrafficType>();
    types.add(TrafficType.Public);
    List<NetworkVO> dbNets = findManagedNetworks(types);
    if (dbNets == null) {
        return null;
    }
    NetworkVO net = dbNets.get(0);
    VirtualNetworkModel vnModel = getDatabase().lookupVirtualNetwork(net.getUuid(), getCanonicalName(net), TrafficType.Public);
    if (vnModel == null) {
        vnModel = new VirtualNetworkModel(net, net.getUuid(), getCanonicalName(net), net.getTrafficType());
        vnModel.setProperties(getModelController(), net);
    }
    try {
        if (!vnModel.verify(getModelController())) {
            vnModel.update(getModelController());
        }
        getDatabase().getVirtualNetworks().add(vnModel);
    } catch (Exception ex) {
        s_logger.warn("virtual-network update: ", ex);
    }
    return vnModel;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) TrafficType(com.cloud.network.Networks.TrafficType) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 13 with VirtualNetworkModel

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

Example 14 with VirtualNetworkModel

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

the class ModelDatabase method lookupVirtualNetwork.

public VirtualNetworkModel lookupVirtualNetwork(String uuid, String name, TrafficType ttype) {
    VirtualNetworkModel vnKey = new VirtualNetworkModel(null, uuid, name, ttype);
    VirtualNetworkModel current = _vnTable.ceiling(vnKey);
    if (current != null) {
        if (ttype == TrafficType.Management || ttype == TrafficType.Storage || ttype == TrafficType.Control) {
            if (current.getName().equals(name)) {
                return current;
            }
        } else if (current.getUuid().equals(uuid)) {
            return current;
        }
    }
    return null;
}
Also used : VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 15 with VirtualNetworkModel

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

the class ServerDBSyncImpl method buildNicResources.

private void buildNicResources(VirtualMachineModel vmModel, VMInstanceVO dbVm, StringBuffer syncLogMsg) throws IOException {
    List<NicVO> nics = _nicDao.listByVmId(dbVm.getId());
    for (NicVO nic : nics) {
        VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
        if (vmiModel == null) {
            vmiModel = new VMInterfaceModel(nic.getUuid());
            NetworkVO network = _networksDao.findById(nic.getNetworkId());
            VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
            if (vnModel == null) {
                s_logger.warn("Unable to locate virtual-network for network id " + network.getId());
                continue;
            }
            vmiModel.addToVirtualMachine(vmModel);
            vmiModel.addToVirtualNetwork(vnModel);
        }
        vmiModel.build(_manager.getModelController(), dbVm, nic);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInterfaceModel(org.apache.cloudstack.network.contrail.model.VMInterfaceModel) NicVO(com.cloud.vm.NicVO) 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