cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [6/6] git commit: updated refs/heads/master to 6b5fab2
Date Fri, 01 Nov 2013 16:56:01 GMT
OpenContrail network plugin

Signed-off-by: Hugo Trippaers <htrippaers@schubergphilis.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6b5fab2f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6b5fab2f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6b5fab2f

Branch: refs/heads/master
Commit: 6b5fab2f5cd939f64b5c9c1ee8d87ca8b6f6514d
Parents: 1e41799
Author: Pedro Marques <roque@juniper.net>
Authored: Thu Oct 31 17:16:58 2013 -0700
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Fri Nov 1 17:46:52 2013 +0100

----------------------------------------------------------------------
 api/src/com/cloud/network/Network.java          |   1 +
 client/pom.xml                                  |   5 +
 client/tomcatconf/commands.properties.in        |   3 +
 .../xen/resource/CitrixResourceBase.java        |  13 +-
 .../network-elements/juniper-contrail/pom.xml   | 136 +++
 .../api/command/CreateServiceInstanceCmd.java   | 182 ++++
 .../api/response/ServiceInstanceResponse.java   |  83 ++
 .../contrail/management/ContrailElement.java    |  28 +
 .../management/ContrailElementImpl.java         | 349 +++++++
 .../contrail/management/ContrailGuru.java       | 333 +++++++
 .../contrail/management/ContrailManager.java    |  93 ++
 .../management/ContrailManagerImpl.java         | 769 +++++++++++++++
 .../contrail/management/DBSyncGeneric.java      | 322 +++++++
 .../network/contrail/management/EventUtils.java | 120 +++
 .../management/ManagementNetworkGuru.java       | 114 +++
 .../contrail/management/ModelDatabase.java      |  89 ++
 .../contrail/management/ServerDBSync.java       |  39 +
 .../contrail/management/ServerDBSyncImpl.java   | 965 +++++++++++++++++++
 .../contrail/management/ServerEventHandler.java |  22 +
 .../management/ServerEventHandlerImpl.java      | 251 +++++
 .../contrail/management/ServiceManager.java     |  40 +
 .../contrail/management/ServiceManagerImpl.java | 249 +++++
 .../management/ServiceVirtualMachine.java       |  30 +
 .../network/contrail/model/FloatingIpModel.java | 213 ++++
 .../contrail/model/FloatingIpPoolModel.java     | 170 ++++
 .../network/contrail/model/InstanceIpModel.java | 174 ++++
 .../network/contrail/model/ModelController.java |  85 ++
 .../network/contrail/model/ModelObject.java     | 118 +++
 .../network/contrail/model/ModelObjectBase.java | 111 +++
 .../contrail/model/ServiceInstanceModel.java    | 320 ++++++
 .../contrail/model/VMInterfaceModel.java        | 265 +++++
 .../contrail/model/VirtualMachineModel.java     | 349 +++++++
 .../contrail/model/VirtualNetworkModel.java     | 494 ++++++++++
 .../management/ApiConnectorMockito.java         | 149 +++
 .../IntegrationTestConfiguration.java           | 835 ++++++++++++++++
 .../management/ManagementServerMock.java        | 393 ++++++++
 .../contrail/management/MockAccountManager.java | 372 +++++++
 .../management/NetworkProviderTest.java         | 477 +++++++++
 .../management/ProviderTestConfiguration.java   |  12 +
 .../contrail/management/PublicNetworkTest.java  | 147 +++
 .../PublicNetworkTestConfiguration.java         |  13 +
 .../contrail/management/TestDbSetup.java        | 151 +++
 .../management/VirtualNetworkModelTest.java     |  62 ++
 .../test/resources/commonContext.xml            | 172 ++++
 .../test/resources/contrail.properties          |  19 +
 .../test/resources/db.properties                |  66 ++
 .../test/resources/log4j.properties             |  35 +
 .../test/resources/mysql_db_start.sh            |  51 +
 .../test/resources/mysql_db_stop.sh             |  31 +
 .../test/resources/providerContext.xml          |  16 +
 .../test/resources/publicNetworkContext.xml     |  16 +
 plugins/pom.xml                                 |   1 +
 52 files changed, 9549 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/api/src/com/cloud/network/Network.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java
index 49f380b..bda3326 100644
--- a/api/src/com/cloud/network/Network.java
+++ b/api/src/com/cloud/network/Network.java
@@ -114,6 +114,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
         private static List<Provider> supportedProviders = new ArrayList<Provider>();
 
         public static final Provider VirtualRouter = new Provider("VirtualRouter", false);
+        public static final Provider JuniperContrail = new Provider("JuniperContrail", false);
         public static final Provider JuniperSRX = new Provider("JuniperSRX", true);
         public static final Provider F5BigIp = new Provider("F5BigIp", true);
         public static final Provider Netscaler = new Provider("Netscaler", true);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 3e08a9a..b1f7bd5 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -87,6 +87,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-network-contrail</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-network-ovs</artifactId>
       <version>${project.version}</version>
     </dependency>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index e92596c..8cbe972 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -681,3 +681,6 @@ deleteLdapConfiguration=3
 listLdapUsers=3
 ldapCreateAccount=3
 importLdapUsers=3
+
+#### juniper-contrail commands
+createServiceInstance=1

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 3df28ed..ccb27ea 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -1072,7 +1072,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri());
     }
 
-    protected VIF createVif(Connection conn, String vmName, VM vm, NicTO nic) throws XmlRpcException, XenAPIException {
+    protected VIF createVif(Connection conn, String vmName, VM vm, VirtualMachineTO vmSpec, NicTO nic) throws XmlRpcException, XenAPIException {
         assert(nic.getUuid() != null) : "Nic should have a uuid value";
 
         if (s_logger.isDebugEnabled()) {
@@ -1087,6 +1087,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         vifr.otherConfig = new HashMap<String, String>();
         vifr.otherConfig.put("nicira-iface-id", nic.getUuid());
         vifr.otherConfig.put("nicira-vm-id", vm.getUuid(conn));
+        // Provide XAPI with the cloudstack vm and nic uids.
+        vifr.otherConfig.put("cloudstack-nic-id", nic.getUuid());
+	if (vmSpec != null) {
+	    vifr.otherConfig.put("cloudstack-vm-id", vmSpec.getUuid()); 
+	}
 
         vifr.network = getNetwork(conn, nic);
 
@@ -1716,7 +1721,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             }
 
             for (NicTO nic : vmSpec.getNics()) {
-                createVif(conn, vmName, vm, nic);
+                createVif(conn, vmName, vm, vmSpec, nic);
             }
 
             startVM(conn, host, vm, vmName);
@@ -2422,7 +2427,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
                 nic.setDeviceId(Integer.parseInt(vifDeviceNum));
 
-                correctVif = createVif(conn, vmName, router, nic);
+                correctVif = createVif(conn, vmName, router, null, nic);
                 correctVif.plug(conn);
                 // Add iptables rule for network usage
                 networkUsage(conn, privateIpAddress, "addVif", "eth" + correctVif.getDevice(conn));
@@ -8391,7 +8396,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             }
             String deviceId = getLowestAvailableVIFDeviceNum(conn, vm);
             nic.setDeviceId(Integer.parseInt(deviceId));
-            vif = createVif(conn, vmName, vm, nic);
+            vif = createVif(conn, vmName, vm, null, nic);
             vif.plug(conn);
             return new PlugNicAnswer(cmd, true, "success");
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/pom.xml b/plugins/network-elements/juniper-contrail/pom.xml
new file mode 100644
index 0000000..22167fe
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/pom.xml
@@ -0,0 +1,136 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-plugin-network-contrail</artifactId>
+  <name>Apache CloudStack Plugin - Network Juniper Contrail</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-plugins</artifactId>
+    <version>4.3.0-SNAPSHOT</version>
+    <relativePath>../../pom.xml</relativePath>
+  </parent>
+  <repositories>
+    <repository>
+      <id>juniper-contrail</id>
+      <url>http://juniper.github.io/contrail-maven/snapshots</url>
+    </repository>
+  </repositories>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-server</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-hypervisor-xen</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-network-internallb</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-engine-orchestration</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-engine-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-engine-schema</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-framework-config</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-framework-events</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>${cs.guava.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>net.juniper.contrail</groupId>
+      <artifactId>juniper-contrail-api</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <version>${cs.mysql.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-exec</artifactId>
+        <version>1.1</version>
+    </dependency>
+    <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-all</artifactId>
+        <version>1.9.5</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <sourceDirectory>src</sourceDirectory>
+    <testSourceDirectory>test</testSourceDirectory>
+    <testResources>
+      <testResource>
+        <directory>test/resources</directory>
+      </testResource>
+    </testResources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkMode>always</forkMode>
+          <argLine>-Xmx1024m</argLine>
+	  <excludes>
+	    <exclude>**/NetworkProviderTest.java</exclude>
+	    <exclude>**/PublicNetworkTest.java</exclude>
+	    </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/command/CreateServiceInstanceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/command/CreateServiceInstanceCmd.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/command/CreateServiceInstanceCmd.java
new file mode 100644
index 0000000..62ab317
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/command/CreateServiceInstanceCmd.java
@@ -0,0 +1,182 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.api.command;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.network.contrail.api.response.ServiceInstanceResponse;
+import org.apache.cloudstack.network.contrail.management.ServiceManager;
+import org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.NetworkResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.cloudstack.api.response.ServiceOfferingResponse;
+import org.apache.cloudstack.api.response.TemplateResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+
+@APICommand(name = "createServiceInstance",
+    description="Creates a system virtual-machine that implements network services",
+    responseObject=ServiceInstanceResponse.class)
+public class CreateServiceInstanceCmd extends BaseAsyncCreateCmd {
+    private static final String s_name = "createserviceinstanceresponse";
+    
+    /// API parameters
+    @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class,
+            required = true, description = "Availability zone for the service instance")
+    private Long zoneId;
+
+    //Owner information
+    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING,
+            description="An optional account for the virtual machine. Must be used with domainId.")
+    private String accountName;
+
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class,
+            description="An optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.")
+    private Long domainId;
+
+    @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class,
+            description = "Project ID for the service instance")
+    private Long projectId;
+    
+    @Parameter(name = "leftnetworkid", type = CommandType.UUID, entityType = NetworkResponse.class,
+            required = true, description = "The left (inside) network for service instance")
+    private Long leftNetworkId;
+    
+    @Parameter(name = "rightnetworkid", type = CommandType.UUID, entityType = NetworkResponse.class,
+            required = true, description = "The right (outside) network ID for the service instance")
+    private Long rightNetworkId;
+    
+    @Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class,
+            required = true, description = "The template ID that specifies the image for the service appliance")
+    private Long templateId;
+    
+    @Parameter(name = ApiConstants.SERVICE_OFFERING_ID, type = CommandType.UUID,
+            entityType = ServiceOfferingResponse.class, required = true,
+            description = "The service offering ID that defines the resources consumed by the service appliance")
+    private Long serviceOfferingId;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING)
+    private String name;
+    
+    /// Implementation
+    @Inject ServiceManager _vrouterService;
+    @Override
+    public void create() throws ResourceAllocationException {
+        // Parameter validation
+        try {
+            DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
+            if (zone == null) {
+                throw new InvalidParameterValueException("Unable to find zone ID " + zoneId);
+            }
+            
+            Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
+
+            VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
+            if (template == null) {
+                throw new InvalidParameterValueException("Invalid template ID " + templateId);
+            }
+            
+            ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+            if (serviceOffering == null) {
+                throw new InvalidParameterValueException("Invalid service offering ID " + serviceOfferingId);
+            }
+            
+            Network left = _networkService.getNetwork(leftNetworkId);
+            if (left == null) {
+                throw new InvalidParameterValueException("Invalid ID for left network " + leftNetworkId);
+            }
+            
+            Network right = _networkService.getNetwork(rightNetworkId);
+            if (right == null) {
+                throw new InvalidParameterValueException("Invalid ID for right network " + rightNetworkId);
+            }
+
+            ServiceVirtualMachine svm = _vrouterService.createServiceInstance(zone, owner, template, serviceOffering,
+                                                                              name, left, right);
+            if (svm == null) {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to create service instance");
+            }
+            setEntityId(svm.getId());
+            setEntityUuid(svm.getUuid());
+        } catch (Exception ex) {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+        }
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_VM_CREATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Create service instance";
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException,
+            InsufficientCapacityException, ServerApiException,
+            ConcurrentOperationException, ResourceAllocationException,
+            NetworkRuleConflictException {
+        try {
+            _vrouterService.startServiceInstance(getEntityId());
+            ServiceInstanceResponse response = _vrouterService.createServiceInstanceResponse(getEntityId());
+            response.setObjectName("serviceinstance");
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } catch (Exception ex) {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
+        if (accountId == null) {
+            return CallContext.current().getCallingAccount().getId();
+        }
+
+        return accountId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/response/ServiceInstanceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/response/ServiceInstanceResponse.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/response/ServiceInstanceResponse.java
new file mode 100644
index 0000000..6b17351
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/api/response/ServiceInstanceResponse.java
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.response.ControlledEntityResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class ServiceInstanceResponse extends BaseResponse implements
+        ControlledEntityResponse {
+    
+    @SerializedName(ApiConstants.ID) @Param(description="the ID of the virtual machine")
+    private String id;
+
+    @SerializedName(ApiConstants.NAME) @Param(description="the name of the virtual machine")
+    private String name;
+
+    @SerializedName("displayname") @Param(description="user generated name. The name of the virtual machine is returned if no displayname exists.")
+    private String displayName;
+
+    @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account associated with the virtual machine")
+    private String accountName;
+
+    @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the vm")
+    private String projectId;
+
+    @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the vm")
+    private String projectName;
+
+    @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the domain in which the virtual machine exists")
+    private String domainId;
+
+    @SerializedName(ApiConstants.DOMAIN) @Param(description="the name of the domain in which the virtual machine exists")
+    private String domainName;
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    @Override
+    public void setAccountName(String accountName) {
+        this.accountName = accountName;
+    }
+
+    @Override
+    public void setProjectId(String projectId) {
+        this.projectId = projectId;
+    }
+
+    @Override
+    public void setProjectName(String projectName) {
+        this.projectName = projectName;
+    }
+
+    @Override
+    public void setDomainId(String domainId) {
+        this.domainId = domainId;
+    }
+
+    @Override
+    public void setDomainName(String domainName) {
+        this.domainName = domainName;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElement.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElement.java
new file mode 100644
index 0000000..28680df
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElement.java
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.management;
+
+import com.cloud.utils.component.PluggableService;
+
+// Network Provider plugin
+public interface ContrailElement extends PluggableService {
+    /**
+     * TODO:
+     * define APIs to configure the Network Virtualization service.
+     */
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java
new file mode 100644
index 0000000..dfbe7d3
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java
@@ -0,0 +1,349 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.management;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.network.contrail.api.command.CreateServiceInstanceCmd;
+import org.apache.cloudstack.network.contrail.model.InstanceIpModel;
+import org.apache.cloudstack.network.contrail.model.VMInterfaceModel;
+import org.apache.cloudstack.network.contrail.model.VirtualMachineModel;
+import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Capability;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.element.DhcpServiceProvider;
+import com.cloud.network.element.IpDeployer;
+import com.cloud.network.element.NetworkACLServiceProvider;
+import com.cloud.network.element.SourceNatServiceProvider;
+import com.cloud.network.element.StaticNatServiceProvider;
+import com.cloud.network.element.VpcProvider;
+import com.cloud.network.rules.StaticNat;
+import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.PrivateGateway;
+import com.cloud.network.vpc.StaticRouteProfile;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.NicDao;
+import com.cloud.network.IpAddress;
+
+@Component
+@Local(value = {ContrailElement.class, StaticNatServiceProvider.class})
+public class ContrailElementImpl extends AdapterBase
+    implements ContrailElement, IpDeployer, StaticNatServiceProvider {
+
+	private static final Map<Service, Map<Capability, String>> _capabilities = InitCapabilities();
+
+	@Inject ContrailManager _manager;
+	@Inject NicDao _nicDao;
+	@Inject ServerDBSync  _dbSync;
+	private static final Logger s_logger =
+			Logger.getLogger(ContrailElement.class);
+	
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+    	s_logger.debug("configure");
+    	return true;
+    }
+
+    // PluggableService
+    @Override
+    public List<Class<?>> getCommands() {
+    	List<Class<?>> cmdList = new ArrayList<Class<?>>();
+        cmdList.add(CreateServiceInstanceCmd.class);
+        return cmdList;
+    }
+
+    // NetworkElement API
+    @Override
+    public Provider getProvider() {
+        return Provider.JuniperContrail;
+    }
+
+    private static Map<Service, Map<Capability, String>> InitCapabilities() {
+    	Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+    	capabilities.put(Service.Connectivity, null);
+    	capabilities.put(Service.Dhcp, new HashMap<Capability, String>());
+        capabilities.put(Service.StaticNat, null);
+        capabilities.put(Service.SourceNat, null);
+
+    	return capabilities;
+    }
+
+	@Override
+	public Map<Service, Map<Capability, String>> getCapabilities() {
+		return _capabilities;
+	}
+
+	/**
+	 * Network add/update.
+	 */
+	@Override
+	public boolean implement(Network network, NetworkOffering offering,
+			DeployDestination dest, ReservationContext context)
+			throws ConcurrentOperationException, ResourceUnavailableException,
+			InsufficientCapacityException {
+	    s_logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType());
+	    if (network.getTrafficType() == TrafficType.Guest) {
+	        s_logger.debug("ignore network " + network.getName());
+	        return true;        
+	    }
+	    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), 
+	            _manager.getCanonicalName(network), network.getTrafficType());
+
+	    if (vnModel == null) {
+	        vnModel = new VirtualNetworkModel(network, network.getUuid(), 
+	                _manager.getCanonicalName(network), network.getTrafficType());
+	        vnModel.setProperties(_manager.getModelController(), network);
+	    }
+	    try {
+	        if (!vnModel.verify(_manager.getModelController())) {
+	            vnModel.update(_manager.getModelController());
+	        }
+	        _manager.getDatabase().getVirtualNetworks().add(vnModel);   
+	    } catch (Exception ex) {
+	        s_logger.warn("virtual-network update: ", ex);
+	    }
+	    return true;
+	}
+
+	@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) {
+	        // There is no notification after a physical network is associated with the VRouter NetworkOffering
+	        // 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.getIp4Address());
+
+	    try {
+	        vmModel.update(_manager.getModelController());
+	    } catch (Exception ex) {
+	        s_logger.warn("virtual-machine-update", ex);
+	        return false;
+	    }
+	    _manager.getDatabase().getVirtualMachines().add(vmModel);   
+
+	    return true;
+	}
+
+	@Override
+	public boolean release(Network network, NicProfile nicProfile,
+			VirtualMachineProfile vm,
+			ReservationContext context) throws ConcurrentOperationException,
+			ResourceUnavailableException {
+	    if (network.getTrafficType() == TrafficType.Guest) {
+	        return true;
+	    } else if (!_manager.isManagedPhysicalNetwork(network)) {
+	        s_logger.debug("release ignore network " + network.getId());
+	        return true;
+	    }
+
+	    NicVO nic = _nicDao.findById(nicProfile.getId());
+	    assert nic != null;
+
+	    VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
+	    if (vmModel == null) {
+	        s_logger.debug("vm " + vm.getInstanceName() + " not in local database");
+	        return true;
+	    }
+	    VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
+	    if (vmiModel != null) {
+	        try {
+	            vmiModel.destroy(_manager.getModelController());
+	        } catch (IOException ex) {
+	            s_logger.warn("virtual-machine-interface delete", ex);
+	        }
+	        vmModel.removeSuccessor(vmiModel);
+	    }
+
+	    if (!vmModel.hasDescendents()) {
+	        _manager.getDatabase().getVirtualMachines().remove(vmModel);
+	        try {
+	            vmModel.delete(_manager.getModelController());
+	        } catch (IOException e) {
+	            return false;
+	        }
+	    }
+
+	    return true;
+	}
+
+	/**
+	 * Network disable
+	 */
+	@Override
+	public boolean shutdown(Network network, ReservationContext context,
+			boolean cleanup) throws ConcurrentOperationException,
+			ResourceUnavailableException {
+		s_logger.debug("NetworkElement shutdown");
+		return true;
+	}
+
+	/**
+	 * Network delete
+	 */
+	@Override
+	public boolean destroy(Network network, ReservationContext context)
+			throws ConcurrentOperationException, ResourceUnavailableException {
+		s_logger.debug("NetworkElement destroy");
+		return true;
+	}
+
+	@Override
+	public boolean isReady(PhysicalNetworkServiceProvider provider) {
+		return true;
+	}
+
+	@Override
+	public boolean shutdownProviderInstances(
+			PhysicalNetworkServiceProvider provider, ReservationContext context)
+			throws ConcurrentOperationException, ResourceUnavailableException {
+		s_logger.debug("NetworkElement shutdown ProviderInstances");
+		return true;
+	}
+
+	@Override
+	public boolean canEnableIndividualServices() {
+		return true;
+	}
+
+	@Override
+	public boolean verifyServicesCombination(Set<Service> services) {
+		// TODO Auto-generated method stub
+		s_logger.debug("NetworkElement verifyServices");
+		s_logger.debug("Services: " + services);
+		return true;
+	}
+
+
+    @Override
+    public IpDeployer getIpDeployer(Network network) {
+	return this;
+    }
+
+    @Override
+    public boolean applyIps(Network network,
+            List<? extends PublicIpAddress> ipAddress, Set<Service> services)
+                    throws ResourceUnavailableException {
+
+        for (PublicIpAddress ip: ipAddress) {
+            if (ip.isSourceNat()) {
+                continue;
+            }
+            if (isFloatingIpCreate(ip)) {
+                if (_manager.createFloatingIp(ip)) {
+                    s_logger.debug("Successfully created floating ip: " + ip.getAddress().addr());
+                }
+            } else {
+                if (_manager.deleteFloatingIp(ip)) {
+                    s_logger.debug("Successfully deleted floating ip: " + ip.getAddress().addr());
+                }
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean applyStaticNats(Network config,
+            List<? extends StaticNat> rules)
+                    throws ResourceUnavailableException {
+        return true;
+    }
+    
+    private boolean isFloatingIpCreate(PublicIpAddress ip) {        
+        if (ip.getState() == IpAddress.State.Allocated && ip.getAssociatedWithVmId() != null && !ip.isSourceNat()) {
+            return true;
+        }
+        return false;        
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
new file mode 100644
index 0000000..ca53f41
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java
@@ -0,0 +1,333 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.management;
+
+
+import java.io.IOException;
+
+import javax.inject.Inject;
+
+import net.juniper.contrail.api.types.MacAddressesType;
+import net.juniper.contrail.api.types.VirtualMachineInterface;
+
+import org.apache.cloudstack.network.contrail.model.InstanceIpModel;
+import org.apache.cloudstack.network.contrail.model.VMInterfaceModel;
+import org.apache.cloudstack.network.contrail.model.VirtualMachineModel;
+import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.network.Network;
+import com.cloud.network.Network.State;
+import com.cloud.network.NetworkProfile;
+import com.cloud.network.Networks.AddressFormat;
+import com.cloud.network.Networks.BroadcastDomainType;
+import com.cloud.network.Networks.Mode;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.guru.NetworkGuru;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.user.Account;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.Nic.ReservationStrategy;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.NicDao;
+import com.cloud.vm.NicVO;
+
+@Component
+public class ContrailGuru extends AdapterBase implements NetworkGuru {
+    @Inject NetworkDao _networkDao;
+    @Inject ContrailManager _manager;
+    @Inject NicDao _nicDao;
+
+    private static final Logger s_logger = Logger.getLogger(ContrailGuru.class);
+    private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
+
+    private boolean canHandle(NetworkOffering offering) {
+        return (offering.getName().equals(ContrailManager.offeringName));
+    }
+
+    @Override
+    public String getName() {
+	return "ContrailGuru";
+    }
+
+    @Override
+    public Network design(NetworkOffering offering, DeploymentPlan plan,
+            Network userSpecified, Account owner) {
+        if (!canHandle(offering)) {
+            return null;
+        }
+        NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch,
+                offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
+        if (userSpecified.getCidr() != null) {
+            network.setCidr(userSpecified.getCidr());
+            network.setGateway(userSpecified.getGateway());
+        }
+        s_logger.debug("Allocated network " + userSpecified.getName() +
+                (network.getCidr() == null ? "" : " subnet: " + network.getCidr()));
+        return network;
+    }
+
+    @Override
+    public Network implement(Network network, NetworkOffering offering,
+            DeployDestination destination, ReservationContext context)
+                    throws InsufficientVirtualNetworkCapcityException {
+        s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
+
+        VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(
+                network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
+        if (vnModel == null) {
+            vnModel = new VirtualNetworkModel(network, network.getUuid(), 
+                    _manager.getCanonicalName(network), network.getTrafficType());
+            vnModel.setProperties(_manager.getModelController(), network);
+        }
+
+        try {
+            if (!vnModel.verify(_manager.getModelController())) {
+                vnModel.update(_manager.getModelController());
+            }
+        } catch (Exception ex) {
+            s_logger.warn("virtual-network update: ", ex);
+            return network;
+        }
+        _manager.getDatabase().getVirtualNetworks().add(vnModel);   
+        return network;
+    }
+
+    /**
+     * Allocate the NicProfile object.
+     * At this point the UUID of the nic is not yet known. We defer allocating the VMI and instance-ip objects
+     * until the reserve API is called because of this reason. 
+     */
+    @Override
+    public NicProfile allocate(Network network, NicProfile profile,
+            VirtualMachineProfile vm)
+                    throws InsufficientVirtualNetworkCapcityException,
+                    InsufficientAddressCapacityException, ConcurrentOperationException {
+        s_logger.debug("allocate NicProfile on " + network.getName());
+
+        if (profile != null && profile.getRequestedIpv4() != null) {
+            throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + profile);
+        }
+        if (profile == null) {
+            profile = new NicProfile(ReservationStrategy.Create, null, null, null, null);
+        }
+
+        profile.setStrategy(ReservationStrategy.Start);
+        
+        return profile;
+    }
+
+    /**
+     * Allocate the ip address (and mac) for the specified VM device.
+     */
+    @Override
+    public void reserve(NicProfile nic, Network network,
+            VirtualMachineProfile vm,
+            DeployDestination dest, ReservationContext context)
+                    throws InsufficientVirtualNetworkCapcityException,
+                    InsufficientAddressCapacityException, ConcurrentOperationException {
+        s_logger.debug("reserve NicProfile on network id: " + network.getId() +
+                " " + network.getName());
+        s_logger.debug("deviceId: " + nic.getDeviceId());
+
+        NicVO nicVO = _nicDao.findById(nic.getId());
+        assert nicVO != null;
+
+        VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(
+                network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
+        /* Network must have been implemented */
+        assert vnModel != null;
+        
+        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);
+        }
+
+        VMInterfaceModel vmiModel = vmModel.getVMInterface(nicVO.getUuid());
+        if (vmiModel == null) {
+            vmiModel = new VMInterfaceModel(nicVO.getUuid());
+            vmiModel.addToVirtualMachine(vmModel);
+            vmiModel.addToVirtualNetwork(vnModel);
+        }
+        try {
+            vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nicVO);
+            vmiModel.setActive();
+        } catch (IOException ex) {
+            s_logger.error("virtual-machine-interface set", ex);
+            return;
+        }
+
+        InstanceIpModel ipModel = vmiModel.getInstanceIp();
+        if (ipModel == null) {
+            ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
+            ipModel.addToVMInterface(vmiModel);
+        } else {
+            s_logger.debug("Reuse existing instance-ip object on " + ipModel.getName());
+        }
+        if (nic.getIp4Address() != null) {
+            s_logger.debug("Nic using existing IP address " +  nic.getIp4Address());
+            ipModel.setAddress(nic.getIp4Address());
+        }
+
+        try {
+            vmModel.update(_manager.getModelController());
+        } catch (Exception ex) {
+            s_logger.warn("virtual-machine update", ex);
+            return;
+        }
+
+        _manager.getDatabase().getVirtualMachines().add(vmModel);   
+
+        VirtualMachineInterface vmi = vmiModel.getVMInterface();
+        // allocate mac address
+        if (nic.getMacAddress() == null) {
+            MacAddressesType macs = vmi.getMacAddresses();
+            if (macs == null) {
+                s_logger.debug("no mac address is allocated for Nic " + nicVO.getUuid());
+            } else {
+                s_logger.info("VMI " + _manager.getVifNameByVmUuid(vm.getUuid(), nicVO.getDeviceId()) + " got mac address: " +
+                        macs.getMacAddress().get(0));
+                nic.setMacAddress(macs.getMacAddress().get(0));
+            }
+        }
+
+        if (nic.getIp4Address() == null) {
+            s_logger.debug("Allocated IP address " + ipModel.getAddress());
+            nic.setIp4Address(ipModel.getAddress());
+            nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
+            nic.setGateway(network.getGateway());
+            nic.setFormat(AddressFormat.Ip4);
+        }
+    }
+
+    /**
+     * When a VM is stopped this API is called to release transient resources.
+     */
+    @Override
+    public boolean release(NicProfile nic,
+            VirtualMachineProfile vm,
+            String reservationId) {
+
+        s_logger.debug("release NicProfile " + nic.getId());
+
+        return true;
+    }
+
+    /**
+     * Release permanent resources of a Nic (VMI and addresses).
+     */
+    @Override
+    public void deallocate(Network network, NicProfile nic,
+            VirtualMachineProfile vm) {
+        s_logger.debug("deallocate NicProfile " + nic.getId() + " on " + network.getName());
+        NicVO nicVO = _nicDao.findById(nic.getId());
+        assert nicVO != null;
+
+        VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
+        if (vmModel == null) {
+            return;
+        }
+        VMInterfaceModel vmiModel = vmModel.getVMInterface(nicVO.getUuid());
+        if (vmiModel == null) {
+            return;
+        }
+        try {
+            vmiModel.destroy(_manager.getModelController());
+        } catch (IOException ex) {
+            return;
+        }
+        vmModel.removeSuccessor(vmiModel);
+        
+        if (!vmModel.hasDescendents()) {
+            _manager.getDatabase().getVirtualMachines().remove(vmModel);
+            try {
+                vmModel.delete(_manager.getModelController());
+            } catch (IOException ex) {
+                s_logger.warn("virtual-machine delete", ex);
+                return;
+            }
+        }
+
+    }
+
+    @Override
+    public void updateNicProfile(NicProfile profile, Network network) {
+        // TODO Auto-generated method stub
+        s_logger.debug("update NicProfile " + profile.getId() + " on " + network.getName());
+    }
+
+    @Override
+    public void shutdown(NetworkProfile network, NetworkOffering offering)  {
+        s_logger.debug("NetworkGuru shutdown");
+        VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), 
+                _manager.getCanonicalName(network), network.getTrafficType());
+        if (vnModel == null) {
+            return;
+        }
+        try {
+            vnModel.delete(_manager.getModelController());
+        } catch (IOException e) {
+            s_logger.warn("virtual-network delete", e);
+        }
+    }
+
+    @Override
+    public boolean trash(Network network, NetworkOffering offering) {
+        // TODO Auto-generated method stub
+        s_logger.debug("NetworkGuru trash");
+        return true;
+    }
+
+    @Override
+    public void updateNetworkProfile(NetworkProfile networkProfile) {
+        // TODO Auto-generated method stub
+        s_logger.debug("NetworkGuru updateNetworkProfile");
+    }
+
+    @Override
+    public TrafficType[] getSupportedTrafficType() {
+        return _trafficTypes;
+    }
+
+    @Override
+    public boolean isMyTrafficType(TrafficType type) {
+        for (TrafficType t : _trafficTypes) {
+            if (t == type) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailManager.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailManager.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailManager.java
new file mode 100644
index 0000000..b96b00c
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailManager.java
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.network.contrail.management;
+
+import java.util.List;
+import java.io.IOException;
+
+import org.apache.cloudstack.network.contrail.model.ModelController;
+import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel;
+
+import net.juniper.contrail.api.ApiConnector;
+import net.juniper.contrail.api.types.FloatingIp;
+import net.juniper.contrail.api.types.VirtualNetwork;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.domain.DomainVO;
+import com.cloud.projects.ProjectVO;
+
+public interface ContrailManager {
+    public static final String offeringName = "Juniper Contrail offering";
+    public static final String offeringDisplayText = "Juniper Contrail network offering";
+    public static final int DB_SYNC_INTERVAL_DEFAULT = 600000;
+    public static final String VNC_ROOT_DOMAIN = "default-domain";
+    public static final String VNC_DEFAULT_PROJECT = "default-project";
+    public static final String managementNetworkName = "ip-fabric";
+
+    public NetworkOffering getOffering();
+    public void syncNetworkDB(short syncMode) throws IOException;
+
+    public boolean isManagedPhysicalNetwork(Network network);
+
+    /**
+     * Lookup the virtual network that implements the CloudStack network object.
+     * @param net_id internal identifier of the NetworkVO object.
+     * @return the uuid of the virtual network that corresponds to the
+     * specified CloudStack network.
+     */
+    public String findVirtualNetworkId(Network net) throws IOException;
+    public void findInfrastructureNetworks(PhysicalNetworkVO phys, List<NetworkVO> dbList);
+    public String getPhysicalNetworkName(PhysicalNetworkVO phys_net);
+    public String getCanonicalName(Network net);
+    public String getDomainCanonicalName(DomainVO domain);
+    public String getProjectCanonicalName(ProjectVO project);
+    public String getFQN(Network net);
+    public String getDomainName(long domainId);
+    public String getProjectName(long accountId);
+    public String getDefaultPublicNetworkFQN();
+    public String getProjectId(long domainId, long accountId) throws IOException;
+    public net.juniper.contrail.api.types.Project getVncProject(long domainId, long accountId) throws IOException;
+    public boolean isSystemRootDomain(net.juniper.contrail.api.types.Domain vnc);
+    public boolean isSystemRootDomain(DomainVO domain);
+    public boolean isSystemDefaultProject(net.juniper.contrail.api.types.Project project);
+    public boolean isSystemDefaultProject(ProjectVO project);
+    public boolean isSystemDefaultNetwork(VirtualNetwork vnet);
+    public boolean isSystemDefaultNetwork(NetworkVO dbNet);
+    public String getVifNameByVmName(String vm_name, Integer device_id);
+    public String getVifNameByVmUuid(String vm_uuid, Integer device_id);
+    
+    public ApiConnector getApiConnector();
+    public ModelDatabase getDatabase();
+    public ModelController getModelController(); 
+    public List<NetworkVO> findJuniperManagedNetworks(List<TrafficType> types);
+    public List<IPAddressVO> findJuniperManagedPublicIps();
+    public VirtualNetwork findDefaultVirtualNetwork(TrafficType trafficType)
+            throws IOException;
+    public List<FloatingIp> getFloatingIps();
+    public VirtualNetworkModel lookupPublicNetworkModel();
+    public void createPublicNetworks();
+    public boolean createFloatingIp(PublicIpAddress ip);
+    public boolean deleteFloatingIp(PublicIpAddress ip);
+}
+  


Mime
View raw message