Search in sources :

Example 1 with FloatingIp

use of net.juniper.contrail.api.types.FloatingIp in project cloudstack by apache.

the class ContrailManagerImpl method getFloatingIps.

@SuppressWarnings("unchecked")
@Override
public List<FloatingIp> getFloatingIps() {
    String fipPoolName = getDefaultPublicNetworkFQN() + ":PublicIpPool";
    FloatingIpPool fipPool = null;
    try {
        fipPool = (FloatingIpPool) _api.findByFQN(FloatingIpPool.class, fipPoolName);
    } catch (Exception ex) {
        s_logger.debug(ex);
    }
    if (fipPool == null) {
        return null;
    }
    List<ObjectReference<ApiPropertyBase>> ips = fipPool.getFloatingIps();
    if (ips != null) {
        try {
            return (List<FloatingIp>) _api.getObjects(FloatingIp.class, ips);
        } catch (IOException ex) {
            s_logger.debug(ex);
            return null;
        }
    }
    return null;
}
Also used : FloatingIpPool(net.juniper.contrail.api.types.FloatingIpPool) ObjectReference(net.juniper.contrail.api.ObjectReference) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) FloatingIp(net.juniper.contrail.api.types.FloatingIp) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException)

Example 2 with FloatingIp

use of net.juniper.contrail.api.types.FloatingIp in project cloudstack by apache.

the class FloatingIpModel method update.

@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
    assert _initialized;
    ApiConnector api = controller.getApiAccessor();
    ContrailManager manager = controller.getManager();
    FloatingIp fip = _fip;
    if (_fip == null) {
        _fip = fip = (FloatingIp) controller.getApiAccessor().findById(FloatingIp.class, _uuid);
        if (fip == null) {
            fip = new FloatingIp();
            fip.setUuid(_uuid);
            fip.setAddress(_addr);
            fip.setName(_name);
            fip.setParent(_fipPoolModel.getFloatingIpPool());
        }
    }
    IPAddressVO ipAddrVO = controller.getIPAddressDao().findById(_id);
    assert ipAddrVO != null : "can not find address object in db";
    Long vmId = ipAddrVO.getAssociatedWithVmId();
    Long networkId = ipAddrVO.getAssociatedWithNetworkId();
    if (vmId == null || networkId == null) {
        s_logger.debug("Floating ip is not yet associated to either vm or network");
        return;
    }
    NicVO nic = controller.getNicDao().findByNtwkIdAndInstanceId(networkId, vmId);
    assert nic != null : "can not find nic for the given network and vm in db";
    VMInstanceVO vm = controller.getVmDao().findById(vmId);
    assert vm != null : "can not find vm in db";
    VirtualMachineModel vmModel = manager.getDatabase().lookupVirtualMachine(vm.getUuid());
    assert vmModel != null : "can not find vm model";
    VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
    assert vmiModel != null && vmiModel.getVMInterface() != null : "can not find virtual machine interface";
    fip.setVirtualMachineInterface(vmiModel.getVMInterface());
    if (_fip == null) {
        try {
            api.create(fip);
        } catch (Exception ex) {
            s_logger.debug("floating ip create", ex);
            throw new CloudRuntimeException("Failed to create floating ip", ex);
        }
        _fip = fip;
    } else {
        try {
            api.update(fip);
        } catch (IOException ex) {
            s_logger.warn("floating ip update", ex);
            throw new CloudRuntimeException("Unable to update floating ip object", ex);
        }
    }
    addToVMInterface(vmiModel);
    for (ModelObject successor : successors()) {
        successor.update(controller);
    }
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) VMInstanceVO(com.cloud.vm.VMInstanceVO) IOException(java.io.IOException) FloatingIp(net.juniper.contrail.api.types.FloatingIp) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicVO(com.cloud.vm.NicVO)

Aggregations

IOException (java.io.IOException)2 FloatingIp (net.juniper.contrail.api.types.FloatingIp)2 InternalErrorException (com.cloud.exception.InternalErrorException)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NicVO (com.cloud.vm.NicVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConfigurationException (javax.naming.ConfigurationException)1 ApiConnector (net.juniper.contrail.api.ApiConnector)1 ObjectReference (net.juniper.contrail.api.ObjectReference)1 FloatingIpPool (net.juniper.contrail.api.types.FloatingIpPool)1 ContrailManager (org.apache.cloudstack.network.contrail.management.ContrailManager)1