Search in sources :

Example 1 with ContrailManager

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

the class VirtualNetworkModel method setProperties.

/**
 * Initialize the object properties based on the DB object.
 * Common code between plugin calls and DBSync.
 */
public void setProperties(ModelController controller, Network network) {
    ContrailManager manager = controller.getManager();
    _name = manager.getCanonicalName(network);
    _prefix = network.getCidr();
    _gateway = network.getGateway();
    // For non-cloudstack managed network, find the uuid at this stage.
    if (!isDynamicNetwork()) {
        try {
            _uuid = manager.findVirtualNetworkId(network);
        } catch (IOException ex) {
            s_logger.warn("Unable to read virtual-network", ex);
        }
    }
    _id = network.getId();
    try {
        _projectId = manager.getProjectId(network.getDomainId(), network.getAccountId());
    } catch (IOException ex) {
        s_logger.warn("project read", ex);
        throw new CloudRuntimeException(ex);
    }
    _initialized = true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) IOException(java.io.IOException)

Example 2 with ContrailManager

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

the class VirtualMachineModel method buildServiceInstance.

/**
 * Link the virtual machine with the service instance when recovering state from database.
 *
 * @param controller
 * @param serviceUuid
 */
private void buildServiceInstance(ModelController controller, String serviceUuid) {
    ContrailManager manager = controller.getManager();
    ApiConnector api = controller.getApiAccessor();
    _serviceUuid = serviceUuid;
    ServiceInstance siObj;
    try {
        siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
    } catch (IOException ex) {
        s_logger.warn("service-instance read", ex);
        throw new CloudRuntimeException("Unable to read service-instance object", ex);
    }
    ServiceInstanceModel siModel;
    String fqn = StringUtils.join(siObj.getQualifiedName(), ':');
    siModel = manager.getDatabase().lookupServiceInstance(fqn);
    if (siModel == null) {
        siModel = new ServiceInstanceModel(serviceUuid);
        siModel.build(controller, siObj);
        manager.getDatabase().getServiceInstances().add(siModel);
    }
    /*
         * The code that was under the ELSE was never executed and due to that has been removed.
         * Also, in the case siObj was null, it was going pass it as parameter to the build() method in the
         * siModel object.
         */
    _serviceModel = siModel;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) IOException(java.io.IOException)

Example 3 with ContrailManager

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

the class VirtualMachineModel method destroy.

@Override
public void destroy(ModelController controller) throws IOException {
    delete(controller);
    for (ModelObject successor : successors()) {
        successor.destroy(controller);
    }
    clearSuccessors();
    if (_serviceModel != null) {
        _serviceModel.removeSuccessor(this);
        _serviceModel.destroy(controller);
        ContrailManager manager = controller.getManager();
        manager.getDatabase().getServiceInstances().remove(_serviceModel);
        _serviceModel = null;
    }
}
Also used : ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager)

Example 4 with ContrailManager

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

the class VirtualMachineModel method setServiceInstanceNics.

private void setServiceInstanceNics(ModelController controller, VMInstanceVO instance) throws IOException {
    NicDao nicDao = controller.getNicDao();
    ContrailManager manager = controller.getManager();
    NetworkDao networkDao = controller.getNetworkDao();
    List<NicVO> nics = nicDao.listByVmId(_instanceId);
    for (NicVO nic : nics) {
        String tag;
        switch(nic.getDeviceId()) {
            case 0:
                tag = "management";
                break;
            case 1:
                tag = "left";
                break;
            case 2:
                tag = "right";
                break;
            default:
                tag = null;
        }
        VMInterfaceModel vmiModel = getVMInterface(nic.getUuid());
        if (vmiModel == null) {
            vmiModel = new VMInterfaceModel(nic.getUuid());
            vmiModel.addToVirtualMachine(this);
            NetworkVO network = networkDao.findById(nic.getNetworkId());
            VirtualNetworkModel vnModel = manager.getDatabase().lookupVirtualNetwork(network.getUuid(), manager.getCanonicalName(network), network.getTrafficType());
            assert vnModel != null;
            vmiModel.addToVirtualNetwork(vnModel);
        }
        vmiModel.setProperties(controller, instance, nic);
        vmiModel.setServiceTag(tag);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) NetworkDao(com.cloud.network.dao.NetworkDao) NicDao(com.cloud.vm.dao.NicDao) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) NicVO(com.cloud.vm.NicVO)

Example 5 with ContrailManager

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

the class VirtualMachineModel method setProperties.

/**
 * Initialize the object properties based on the DB object.
 * Common code between plugin calls and DBSync.
 */
public void setProperties(ModelController controller, VMInstanceVO instance) {
    ContrailManager manager = controller.getManager();
    _instanceName = instance.getInstanceName();
    _active = isActiveInstance(instance);
    try {
        _projectId = manager.getProjectId(instance.getDomainId(), instance.getAccountId());
    } catch (IOException ex) {
        s_logger.warn("project read", ex);
        throw new CloudRuntimeException(ex);
    }
    _initialized = true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) 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