Search in sources :

Example 1 with ServiceInstanceType

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

the class ServiceInstanceModel method createServiceInstance.

private ServiceInstance createServiceInstance(ModelController controller) {
    Project project = null;
    if (_projectId != null) {
        try {
            ApiConnector api = controller.getApiAccessor();
            project = (Project) api.findById(Project.class, _projectId);
        } catch (IOException ex) {
            s_logger.warn("project read", ex);
            throw new CloudRuntimeException("Unable to create service-instance object", ex);
        }
    }
    ServiceInstance si_obj = new ServiceInstance();
    if (project != null) {
        si_obj.setParent(project);
    }
    si_obj.setName(getName());
    si_obj.setServiceTemplate(_tmpl);
    si_obj.setProperties(new ServiceInstanceType(false, _mgmtName, _leftName, null, _rightName, null, new ServiceInstanceType.ServiceScaleOutType(1, false)));
    try {
        ApiConnector api = controller.getApiAccessor();
        api.create(si_obj);
    } catch (IOException ex) {
        s_logger.warn("service-instance create", ex);
        throw new CloudRuntimeException("Unable to create service-instance object", ex);
    }
    return si_obj;
}
Also used : Project(net.juniper.contrail.api.types.Project) ServiceInstanceType(net.juniper.contrail.api.types.ServiceInstanceType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ServiceInstance(net.juniper.contrail.api.types.ServiceInstance) IOException(java.io.IOException)

Example 2 with ServiceInstanceType

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

the class ServiceInstanceModel method build.

/**
 * Recreate the model object from the Contrail API which is main for this type of object.
 * @param siObj
 */
public void build(ModelController controller, ServiceInstance siObj) {
    ApiConnector api = controller.getApiAccessor();
    _serviceInstance = siObj;
    _fqName = StringUtils.join(siObj.getQualifiedName(), ':');
    ServiceInstanceType props = siObj.getProperties();
    // TODO: read management network names and cache network objects.
    ObjectReference ref = siObj.getServiceTemplate().get(0);
    if (ref != null) {
        try {
            ServiceTemplate tmpl = (ServiceTemplate) api.findById(ServiceTemplate.class, ref.getUuid());
            _templateId = tmpl.getUuid();
        } catch (IOException ex) {
            s_logger.warn("service-template read", ex);
        }
    }
}
Also used : ServiceInstanceType(net.juniper.contrail.api.types.ServiceInstanceType) ObjectReference(net.juniper.contrail.api.ObjectReference) ApiConnector(net.juniper.contrail.api.ApiConnector) ServiceTemplate(net.juniper.contrail.api.types.ServiceTemplate) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ApiConnector (net.juniper.contrail.api.ApiConnector)2 ServiceInstanceType (net.juniper.contrail.api.types.ServiceInstanceType)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ObjectReference (net.juniper.contrail.api.ObjectReference)1 Project (net.juniper.contrail.api.types.Project)1 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)1 ServiceTemplate (net.juniper.contrail.api.types.ServiceTemplate)1