Search in sources :

Example 6 with ContrailManager

use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.

the class VMInterfaceModel method update.

@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
    if (!_netActive || !_nicActive) {
        s_logger.debug("vm interface update, _netActive: " + _netActive + ", _nicActive: " + _nicActive);
        delete(controller);
        return;
    }
    if (_vmModel == null) {
        throw new InternalErrorException("virtual-machine not set on VMI: " + _uuid);
    }
    if (_vnModel == null) {
        throw new InternalErrorException("virtual-network not set on VMI: " + _uuid);
    }
    ContrailManager manager = controller.getManager();
    ApiConnector api = controller.getApiAccessor();
    VirtualMachineInterface vmi = (VirtualMachineInterface) api.findById(VirtualMachineInterface.class, _uuid);
    boolean create = false;
    if (vmi == null) {
        create = true;
        vmi = new VirtualMachineInterface();
        vmi.setParent(_vmModel.getVirtualMachine());
        vmi.setName(manager.getVifNameByVmName(_vmModel.getInstanceName(), _deviceId));
        vmi.setUuid(_uuid);
        vmi.setVirtualNetwork(_vnModel.getVirtualNetwork());
    } else {
        // Do not try to update VMI to routing-instance references. These are managed by schema-transformer.
        vmi.clearRoutingInstance();
    }
    _vmi = vmi;
    if (_macAddress != null) {
        MacAddressesType mac = new MacAddressesType();
        mac.addMacAddress(_macAddress);
        vmi.setMacAddresses(mac);
    }
    if (_serviceTag != null) {
        vmi.setProperties(new VirtualMachineInterfacePropertiesType(_serviceTag, null));
    }
    if (create) {
        if (!api.create(vmi)) {
            throw new InternalErrorException("Unable to create virtual-machine-interface " + _uuid);
        }
    } else {
        if (!api.update(vmi)) {
            throw new InternalErrorException("Unable to update virtual-machine-interface " + _uuid);
        }
    }
    api.read(vmi);
    int ipCount = 0;
    for (ModelObject successor : successors()) {
        if (successor.getClass() == InstanceIpModel.class) {
            ipCount++;
        }
        successor.update(controller);
    }
    // delete the object.
    if (ipCount == 0) {
        s_logger.warn("virtual-machine-interface " + _uuid + " has no instance-ip");
    }
}
Also used : VirtualMachineInterface(net.juniper.contrail.api.types.VirtualMachineInterface) ApiConnector(net.juniper.contrail.api.ApiConnector) MacAddressesType(net.juniper.contrail.api.types.MacAddressesType) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) InternalErrorException(com.cloud.exception.InternalErrorException) VirtualMachineInterfacePropertiesType(net.juniper.contrail.api.types.VirtualMachineInterfacePropertiesType)

Example 7 with ContrailManager

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

Example 8 with ContrailManager

use of org.apache.cloudstack.network.contrail.management.ContrailManager in project cloudstack by apache.

the class FloatingIpPoolModel method update.

@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
    assert _vnModel != null : "vn model is not set";
    ApiConnector api = controller.getApiAccessor();
    ContrailManager manager = controller.getManager();
    FloatingIpPool fipPool = _fipPool;
    if (fipPool == null) {
        String fipPoolName = manager.getDefaultPublicNetworkFQN() + ":PublicIpPool";
        _fipPool = fipPool = (FloatingIpPool) controller.getApiAccessor().findByFQN(FloatingIpPool.class, fipPoolName);
        if (fipPool == null) {
            fipPool = new FloatingIpPool();
            fipPool.setName(_name);
            fipPool.setParent(_vnModel.getVirtualNetwork());
        }
    }
    if (_fipPool == null) {
        try {
            api.create(fipPool);
        } catch (Exception ex) {
            s_logger.debug("floating ip pool create", ex);
            throw new CloudRuntimeException("Failed to create floating ip pool", ex);
        }
        _fipPool = fipPool;
    } else {
        try {
            api.update(fipPool);
        } catch (IOException ex) {
            s_logger.warn("floating ip pool update", ex);
            throw new CloudRuntimeException("Unable to update floating ip ppol object", ex);
        }
    }
    for (ModelObject successor : successors()) {
        successor.update(controller);
    }
}
Also used : FloatingIpPool(net.juniper.contrail.api.types.FloatingIpPool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Aggregations

ContrailManager (org.apache.cloudstack.network.contrail.management.ContrailManager)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 IOException (java.io.IOException)5 ApiConnector (net.juniper.contrail.api.ApiConnector)4 InternalErrorException (com.cloud.exception.InternalErrorException)3 NicVO (com.cloud.vm.NicVO)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 NetworkDao (com.cloud.network.dao.NetworkDao)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 NicDao (com.cloud.vm.dao.NicDao)1 FloatingIp (net.juniper.contrail.api.types.FloatingIp)1 FloatingIpPool (net.juniper.contrail.api.types.FloatingIpPool)1 MacAddressesType (net.juniper.contrail.api.types.MacAddressesType)1 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)1 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)1 VirtualMachineInterfacePropertiesType (net.juniper.contrail.api.types.VirtualMachineInterfacePropertiesType)1