cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject [3/3] git commit: updated refs/heads/master to 052c24c
Date Mon, 13 May 2013 11:38:57 GMT
CLOUDSTACK-702: Multiple ip ranges in different subnets.

This feature enables adding of guest ip ranges (public ips)  form different subnets.

In order to provide the dhcp service to a different subnet we create an ipalias on the router. This allows the router to listen to the dhcp request from the guest vms and respond accordingly. Every time a vm is deployed in the new subnet we configure an ip alias on the router. Cloudstack uses dnsmasq to provide dhcp service. We need to configure the dnsmasq to issue ips on the new subnets. Added a new class dnsmasqconfigurator which generates the dnsmasq confg file, this file replaces the old config in the router.

The details of the alias ips are stored in db in the nic_ip_alias table. Every time a new subnet is added one of the ip from the subnet is used to configure the ip alias.

I have pushed the code to  https://github.com/bvbharatk/cloud-stack/tree/Cloudstack-702 , also rebased the code with master.
I need to test the code for advanced sg enabled network using kvm.

I have added the unit test
Marvin tests are at https://git-wip-us.apache.org/repos/asf?p=cloudstack.git;h=53e4965

Also accomodated some of the changes suggested by koushik.
corrected the import statements. renamed the IpAlias command to createIpAlias command.

This feature supports only ipv4


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

Branch: refs/heads/master
Commit: 052c24c4d1c881f791b804dbb9c2fc083af7da36
Parents: 756a417
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Mon May 13 17:02:27 2013 +0530
Committer: Koushik Das <koushik.das@citrix.com>
Committed: Mon May 13 17:06:44 2013 +0530

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/DnsmasqTO.java      |   53 +++
 .../exception/MissingParameterValueException.java  |   25 +
 .../cloud/network/element/DhcpServiceProvider.java |    2 +
 api/src/com/cloud/vm/NicIpAlias.java               |   45 ++
 client/tomcatconf/applicationContext.xml.in        |    1 +
 .../agent/api/routing/CreateIpAliasCommand.java    |   36 ++
 .../agent/api/routing/DeleteIpAliasCommand.java    |   50 +++
 .../agent/api/routing/DnsMasqConfigCommand.java    |   65 +++
 .../src/com/cloud/agent/api/routing/IpAliasTO.java |   42 ++
 .../virtualnetwork/VirtualRoutingResource.java     |  117 ++++-
 .../src/com/cloud/network/DnsMasqConfigurator.java |  118 +++++
 engine/schema/src/com/cloud/dc/dao/VlanDao.java    |    6 +-
 .../schema/src/com/cloud/dc/dao/VlanDaoImpl.java   |   38 +-
 .../src/com/cloud/network/dao/IPAddressDao.java    |    8 +-
 .../com/cloud/network/dao/IPAddressDaoImpl.java    |   39 +-
 engine/schema/src/com/cloud/vm/dao/NicDao.java     |    6 +-
 engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java |   19 +-
 .../systemvm/debian/config/root/createIpAlias.sh   |   35 ++
 .../systemvm/debian/config/root/deleteIpAlias.sh   |   43 ++
 patches/systemvm/debian/config/root/dnsmasq.sh     |   43 ++
 .../networkservice/BaremetalDhcpElement.java       |   41 +-
 .../hypervisor/vmware/resource/VmwareResource.java |  199 +++++++--
 .../xen/resource/CitrixResourceBase.java           |  166 +++++--
 .../com/cloud/network/element/MidoNetElement.java  |   59 ++-
 scripts/vm/hypervisor/xenserver/createipAlias.sh   |   26 ++
 scripts/vm/hypervisor/xenserver/deleteipAlias.sh   |   25 +
 scripts/vm/hypervisor/xenserver/vmops              |   45 ++-
 scripts/vm/hypervisor/xenserver/xcpserver/patch    |    2 +
 scripts/vm/hypervisor/xenserver/xenserver56/patch  |    2 +
 .../vm/hypervisor/xenserver/xenserver56fp1/patch   |    2 +
 scripts/vm/hypervisor/xenserver/xenserver60/patch  |    2 +
 .../cloud/configuration/ConfigurationManager.java  |    2 -
 .../configuration/ConfigurationManagerImpl.java    |  344 ++++++++++++---
 server/src/com/cloud/network/NetworkManager.java   |    4 +
 .../src/com/cloud/network/NetworkManagerImpl.java  |   30 ++-
 server/src/com/cloud/network/addr/PublicIp.java    |    4 +
 .../network/element/VirtualRouterElement.java      |   59 +++
 .../router/VirtualNetworkApplianceManager.java     |   13 +-
 .../router/VirtualNetworkApplianceManagerImpl.java |  273 ++++++++++--
 server/src/com/cloud/vm/dao/NicIpAliasDao.java     |   61 +++
 server/src/com/cloud/vm/dao/NicIpAliasDaoImpl.java |  186 ++++++++
 server/src/com/cloud/vm/dao/NicIpAliasVO.java      |  226 ++++++++++
 .../cloud/configuration/ValidateIpRangeTest.java   |   71 +++
 .../com/cloud/network/MockNetworkManagerImpl.java  |   11 +
 .../cloud/vpc/MockConfigurationManagerImpl.java    |   73 ++--
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |   25 +-
 .../vpc/MockVpcVirtualNetworkApplianceManager.java |   10 +
 .../networkoffering/CreateNetworkOfferingTest.java |   29 +-
 server/test/resources/createNetworkOffering.xml    |   21 +-
 setup/db/db/schema-410to420.sql                    |   19 +
 50 files changed, 2454 insertions(+), 367 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/api/src/com/cloud/agent/api/to/DnsmasqTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/DnsmasqTO.java b/api/src/com/cloud/agent/api/to/DnsmasqTO.java
new file mode 100644
index 0000000..f99878c
--- /dev/null
+++ b/api/src/com/cloud/agent/api/to/DnsmasqTO.java
@@ -0,0 +1,53 @@
+// 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 com.cloud.agent.api.to;
+
+public class DnsmasqTO {
+    String routerIp;
+    String gateway;
+    String netmask;
+
+    public DnsmasqTO(String routerIp, String gateway, String netmask) {
+        this.routerIp = routerIp;
+        this.gateway = gateway;
+        this.netmask =netmask;
+    }
+
+    public void setRouterIp(String routerIp){
+        this.routerIp = routerIp;
+    }
+
+    public void setGateway(String gateway) {
+        this.gateway = gateway;
+    }
+
+    public void setNetmask(String netmask) {
+        this.netmask = netmask ;
+    }
+
+    public String getRouterIp() {
+        return routerIp;
+    }
+
+    public String getGateway() {
+        return gateway;
+    }
+
+    public String getNetmask() {
+        return netmask;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/api/src/com/cloud/exception/MissingParameterValueException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/MissingParameterValueException.java b/api/src/com/cloud/exception/MissingParameterValueException.java
new file mode 100644
index 0000000..231541d
--- /dev/null
+++ b/api/src/com/cloud/exception/MissingParameterValueException.java
@@ -0,0 +1,25 @@
+// 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 com.cloud.exception;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+public class MissingParameterValueException extends CloudRuntimeException {
+
+    public MissingParameterValueException(String message) {
+        super(message);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/api/src/com/cloud/network/element/DhcpServiceProvider.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/element/DhcpServiceProvider.java b/api/src/com/cloud/network/element/DhcpServiceProvider.java
index f73590c..83008ca 100644
--- a/api/src/com/cloud/network/element/DhcpServiceProvider.java
+++ b/api/src/com/cloud/network/element/DhcpServiceProvider.java
@@ -28,4 +28,6 @@ import com.cloud.vm.VirtualMachineProfile;
 
 public interface DhcpServiceProvider extends NetworkElement {
     boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
+    boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
+    boolean  removeDhcpSupportForSubnet(Network network);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/api/src/com/cloud/vm/NicIpAlias.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/NicIpAlias.java b/api/src/com/cloud/vm/NicIpAlias.java
new file mode 100644
index 0000000..11e127c
--- /dev/null
+++ b/api/src/com/cloud/vm/NicIpAlias.java
@@ -0,0 +1,45 @@
+// 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 com.cloud.vm;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+/** Each entry represents the alis ip of a perticular nic.
+ *
+ */
+public interface NicIpAlias extends ControlledEntity, Identity, InternalIdentity{
+    /**
+     * @return id in the CloudStack database
+     */
+     enum  state {
+        active,
+        revoked,
+    }
+    long getId();
+    long getNicId();
+    String getIp4Address();
+    String getIp6Address();
+    long getNetworkId();
+    long getVmId();
+    Long getAliasCount();
+    String getNetmask();
+    String getGateway();
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index a41797e..1bd2f82 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -259,6 +259,7 @@
   <bean id="networkServiceMapDaoImpl" class="com.cloud.network.dao.NetworkServiceMapDaoImpl" />
   <bean id="nicDaoImpl" class="com.cloud.vm.dao.NicDaoImpl" />
   <bean id="nicSecondaryIpDaoImpl" class="com.cloud.vm.dao.NicSecondaryIpDaoImpl" />
+  <bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
   <bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />
   <bean id="ovsTunnelInterfaceDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelInterfaceDaoImpl" />
   <bean id="ovsTunnelNetworkDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelNetworkDaoImpl" />

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/agent/api/routing/CreateIpAliasCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/routing/CreateIpAliasCommand.java b/core/src/com/cloud/agent/api/routing/CreateIpAliasCommand.java
new file mode 100644
index 0000000..92486fb
--- /dev/null
+++ b/core/src/com/cloud/agent/api/routing/CreateIpAliasCommand.java
@@ -0,0 +1,36 @@
+// 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 com.cloud.agent.api.routing;
+import java.util.List;
+public class CreateIpAliasCommand extends NetworkElementCommand {
+    String routerip;
+    List<IpAliasTO> ipAliasTOs;
+
+
+    public CreateIpAliasCommand(String routerip, List<IpAliasTO> ipAliasTOs){
+    this.routerip = routerip;
+    this.ipAliasTOs = ipAliasTOs;
+    }
+
+    public  String getRouterip (){
+         return  routerip;
+    }
+
+    public List<IpAliasTO> getIpAliasList() {
+         return ipAliasTOs;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/agent/api/routing/DeleteIpAliasCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/routing/DeleteIpAliasCommand.java b/core/src/com/cloud/agent/api/routing/DeleteIpAliasCommand.java
new file mode 100644
index 0000000..612084f
--- /dev/null
+++ b/core/src/com/cloud/agent/api/routing/DeleteIpAliasCommand.java
@@ -0,0 +1,50 @@
+// 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 com.cloud.agent.api.routing;
+
+
+
+
+
+import java.util.List;
+
+public class DeleteIpAliasCommand extends NetworkElementCommand {
+    String routerip;
+    List<IpAliasTO> deleteIpAliasTOs;
+    List<IpAliasTO> createIpAliasTos;
+
+
+    public DeleteIpAliasCommand( String routerip, List<IpAliasTO> deleteIpAliasTOs, List<IpAliasTO> createIpAliasTos){
+        this.routerip = routerip;
+        this.deleteIpAliasTOs = deleteIpAliasTOs;
+        this.createIpAliasTos = createIpAliasTos;
+
+    }
+
+    public  String getRouterip (){
+        return  routerip;
+    }
+
+    public List<IpAliasTO> getDeleteIpAliasTos() {
+        return deleteIpAliasTOs;
+    }
+
+    public List<IpAliasTO> getCreateIpAliasTos() {
+        return createIpAliasTos;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/agent/api/routing/DnsMasqConfigCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/routing/DnsMasqConfigCommand.java b/core/src/com/cloud/agent/api/routing/DnsMasqConfigCommand.java
new file mode 100644
index 0000000..a52af90
--- /dev/null
+++ b/core/src/com/cloud/agent/api/routing/DnsMasqConfigCommand.java
@@ -0,0 +1,65 @@
+// 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 com.cloud.agent.api.routing;
+
+import com.cloud.agent.api.to.DnsmasqTO;
+
+import java.util.List;
+
+public class DnsMasqConfigCommand extends NetworkElementCommand {
+    String domain;
+    String dns1;
+    String dns2;
+    String internal_dns1;
+    String internal_dns2;
+    List<DnsmasqTO> dnsmasqTOs;
+
+    public DnsMasqConfigCommand(String domain, List<DnsmasqTO> dnsmasqTOs, String dns1, String dns2, String internal_dns1, String internal_dns2) {
+        this.domain = domain;
+        this.dnsmasqTOs = dnsmasqTOs;
+        this.dns1= dns1;
+        this.dns2= dns2;
+        this.internal_dns1 = internal_dns1;
+        this.internal_dns2 = internal_dns2;
+
+    }
+
+    public List<DnsmasqTO> getIps() {
+        return  dnsmasqTOs;
+    }
+
+    public  String getDomain() {
+        return domain;
+    }
+
+    public String getDns1() {
+        return dns1;
+    }
+
+    public String getDns2() {
+        return dns2;
+    }
+
+    public String getInternal_dns1() {
+        return internal_dns1;
+    }
+
+    public String getInternal_dns2() {
+        return internal_dns2;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/agent/api/routing/IpAliasTO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/routing/IpAliasTO.java b/core/src/com/cloud/agent/api/routing/IpAliasTO.java
new file mode 100644
index 0000000..26a545d
--- /dev/null
+++ b/core/src/com/cloud/agent/api/routing/IpAliasTO.java
@@ -0,0 +1,42 @@
+// 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 com.cloud.agent.api.routing;
+
+
+public class IpAliasTO {
+    String routerip;
+    String netmask;
+    String alias_count;
+
+    public  IpAliasTO(String routerip, String netmask, String alias_count) {
+        this.routerip = routerip;
+        this.netmask = netmask;
+        this.alias_count = alias_count;
+    }
+
+    public String getRouterip() {
+        return routerip;
+    }
+
+    public  String getNetmask() {
+        return netmask;
+    }
+
+    public String getAlias_count() {
+        return alias_count;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
index b9bda4d..db50f3f 100755
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
@@ -16,28 +16,6 @@
 // under the License.
 package com.cloud.agent.resource.virtualnetwork;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.InetSocketAddress;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.channels.SocketChannel;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.BumpUpPriorityCommand;
 import com.cloud.agent.api.CheckRouterAnswer;
@@ -50,7 +28,11 @@ import com.cloud.agent.api.GetDomRVersionCmd;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
+import com.cloud.agent.api.routing.CreateIpAliasCommand;
+import com.cloud.agent.api.routing.DeleteIpAliasCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.DnsMasqConfigCommand;
+import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
@@ -74,6 +56,7 @@ import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
 import com.cloud.agent.api.to.StaticNatRuleTO;
 import com.cloud.exception.InternalErrorException;
+import com.cloud.network.DnsMasqConfigurator;
 import com.cloud.network.HAProxyConfigurator;
 import com.cloud.network.LoadBalancerConfigurator;
 import com.cloud.network.rules.FirewallRule;
@@ -84,6 +67,26 @@ import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
 import com.cloud.utils.ssh.SshHelper;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.channels.SocketChannel;
+import java.util.List;
+import java.util.Map;
 
 /**
  * VirtualNetworkResource controls and configures virtual networking
@@ -106,6 +109,9 @@ public class VirtualRoutingResource implements Manager {
     private String _privateEthIf;
     private String _bumpUpPriorityPath;
     private String _routerProxyPath;
+    private String _createIpAliasPath;
+    private String _deleteIpAliasPath;
+    private String _configDhcpPath;
 
     private int _timeout;
     private int _startTimeout;
@@ -137,6 +143,12 @@ public class VirtualRoutingResource implements Manager {
                 return execute((SavePasswordCommand)cmd);
             }  else if (cmd instanceof DhcpEntryCommand) {
                 return execute((DhcpEntryCommand)cmd);
+            } else if (cmd instanceof CreateIpAliasCommand) {
+                return execute((CreateIpAliasCommand) cmd);
+            } else if (cmd instanceof DnsMasqConfigCommand) {
+                return execute((DnsMasqConfigCommand) cmd);
+            } else if (cmd instanceof DeleteIpAliasCommand) {
+                return execute((DeleteIpAliasCommand) cmd);
             } else if (cmd instanceof VmDataCommand) {
                 return execute ((VmDataCommand)cmd);
             } else if (cmd instanceof CheckRouterCommand) {
@@ -609,6 +621,67 @@ public class VirtualRoutingResource implements Manager {
         return new Answer(cmd, result==null, result);
     }
 
+    protected Answer execute(final CreateIpAliasCommand cmd) {
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        final Script command  = new Script(_createIpAliasPath, _timeout, s_logger);
+        List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
+        String args=routerIp+" ";
+        for (IpAliasTO ipaliasto : ipAliasTOs) {
+            args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
+        }
+        command.add(args);
+        final String result = command.execute();
+        return new Answer(cmd, result==null, result);
+    }
+
+    protected Answer execute(final DeleteIpAliasCommand cmd) {
+        final Script command  = new Script(_deleteIpAliasPath, _timeout, s_logger);
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        String args = "";
+        List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
+        for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        args = args + " " ;
+        List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
+        for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        command.add(args);
+        final String result = command.execute();
+        return new Answer(cmd, result==null, result);
+    }
+
+    protected Answer execute(final DnsMasqConfigCommand cmd) {
+        final Script command  = new Script(_configDhcpPath, _timeout, s_logger);
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        DnsMasqConfigurator configurator = new DnsMasqConfigurator();
+        String [] config = configurator.generateConfiguration(cmd);
+        File tmpCfgFile = null;
+        try {
+            String cfgFilePath = "";
+            if (routerIp != null) {
+                tmpCfgFile = File.createTempFile(routerIp.replace('.', '_'), "cfg");
+                final PrintWriter out
+                        = new PrintWriter(new BufferedWriter(new FileWriter(tmpCfgFile)));
+                for (int i=0; i < config.length; i++) {
+                    out.println(config[i]);
+                }
+                out.close();
+                cfgFilePath = tmpCfgFile.getAbsolutePath();
+            }
+            command.add(cfgFilePath);
+            final String result = command.execute();
+            return new Answer(cmd, result == null, result);
+        } catch (final IOException e) {
+            return new Answer(cmd, false, e.getMessage());
+        } finally {
+            if (tmpCfgFile != null) {
+                tmpCfgFile.delete();
+            }
+        }
+    }
+
     public String getRouterStatus(String routerIP) {
         return routerProxyWithParser("checkrouter.sh", routerIP, null);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/core/src/com/cloud/network/DnsMasqConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/network/DnsMasqConfigurator.java b/core/src/com/cloud/network/DnsMasqConfigurator.java
new file mode 100644
index 0000000..bbf721d
--- /dev/null
+++ b/core/src/com/cloud/network/DnsMasqConfigurator.java
@@ -0,0 +1,118 @@
+// 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 com.cloud.network;
+
+import com.cloud.agent.api.routing.DnsMasqConfigCommand;
+import com.cloud.agent.api.to.DnsmasqTO;
+import org.apache.log4j.Logger;
+
+import java.util.Arrays;
+import java.util.List;
+
+
+
+ public class DnsMasqConfigurator  {
+
+         private static final Logger s_logger = Logger.getLogger(DnsMasqConfigurator.class);
+         private static String[] Dnsmasq_config = {"# Never forward plain names (without a dot or domain part) \ndomain-needed\n",
+                                           "# Never forward addresses in the non-routed address spaces. \nbogus-priv\n",
+                                           "# Uncomment this to filter useless windows-originated DNS requests # which can trigger dial-on-demand links needlessly. \n # Note that (amongst other things) this blocks all SRV requests, # so don't use it if you use eg Kerberos, SIP, XMMP or Google-talk.# This option only affects forwarding, SRV records originating for # dnsmasq (via srv-host= lines) are not suppressed by it. \nfilterwin2k\n",
+                                           "# Change this line if you want dns to get its upstream servers from# somewhere other that /etc/resolv.conf \nresolv-file=/etc/dnsmasq-resolv.conf\n",
+                                           "# Add local-only domains here, queries in these domains are answered\n # from /etc/hosts or DHCP only.\n local=/cs1cloud.internal/",
+                                           "# If you want dnsmasq to listen for DHCP and DNS requests only on\n #specified interfaces (and the loopback) give the name of the\n# interface (eg eth0) here.\n# Repeat the line for more than one interface.\ninterface=eth0\n",
+                                           "# Or you can specify which interface _not_ to listen on\nexcept-interface=eth1\nexcept-interface=eth2\nexcept-interface=lo\n",
+                                           "# Or which to listen on by address (remember to include 127.0.0.1 if\n# you use this.)\n#listen-address=?\n",
+                                           "# If you want dnsmasq to provide only DNS service on an interface,\n# configure it as shown above, and then use the following line to\n#disable DHCP and TFTP on it.\nno-dhcp-interface=eth1\nno-dhcp-interface=eth2\n",
+                                           "# On systems which support it, dnsmasq binds the wildcard address,\n" +
+                                                   "# even when it is listening on only some interfaces. It then discards\n" +
+                                                   "# requests that it shouldn't reply to. This has the advantage of\n" +
+                                                   "# working even when interfaces come and go and change address. If you\n" +
+                                                   "# want dnsmasq to really bind only the interfaces it is listening on,\n" +
+                                                   "# uncomment this option. About the only time you may need this is when\n" +
+                                                   "# running another nameserver on the same machine.\n" +
+                                                   "bind-interfaces\n",
+                                           "# Set this (and domain: see below) if you want to have a domain\n" +
+                                                   "# automatically added to simple names in a hosts-file.\n" +
+                                                   "expand-hosts\n",
+                                           "# Set the domain for dnsmasq. this is optional, but if it is set, it\n" +
+                                                   "# does the following things.\n" +
+                                                   "# 1) Allows DHCP hosts to have fully qualified domain names, as long\n" +
+                                                   "#     as the domain part matches this setting.\n" +
+                                                   "# 2) Sets the \"domain\" DHCP option thereby potentially setting the\n" +
+                                                   "#    domain of all systems configured by DHCP\n" +
+                                                   "# 3) Provides the domain part for \"expand-hosts\"\n",
+                                                   "domain=cs1cloud.internal\n",
+                                           "# Set a different domain for a particular subnet\n",
+                                                   "domain=cs1cloud.internal\n",
+                                           "# Same idea, but range rather then subnet\n",
+                                                   "domain=cs1cloud.internal\n",
+                                           "# Uncomment this to enable the integrated DHCP server, you need\n" +
+                                                   "# to supply the range of addresses available for lease and optionally\n" +
+                                                   "# a lease time. If you have more than one network, you will need to\n" +
+                                                   "# repeat this for each network on which you want to supply DHCP\n" +
+                                                   "# service.\n",
+                                                   "dhcp-range=set:net1,ipaddress,static\n",
+                                           "dhcp-hostsfile=/etc/dhcphosts.txt\n",
+                                           "log-facility=/var/log/dnsmasq.log\n",
+                                           "conf-dir=/etc/dnsmasq.d\n",
+                                           "dhcp-option=tag:net1,3,ipaddress\n",
+                                           "dhcp-option=tag:net1,1,netmask\n",
+                                           "dhcp-option=6,10.147.28.149,8.8.8.8\n",
+                                           "dhcp-optsfile=/etc/dhcpopts.txt\n",
+
+
+         };
+
+     public String[] generateConfiguration(DnsMasqConfigCommand dnsMasqconfigcmd) {
+         List<DnsmasqTO> dnsmasqTOs = dnsMasqconfigcmd.getIps();
+         List <String> dnsMasqconf = Arrays.asList(Dnsmasq_config);
+         String range="";
+         String gateway="";
+         String netmask="";
+         String domain= dnsMasqconfigcmd.getDomain();
+         String dnsServers="";
+         int i=0;
+         for (; i< dnsmasqTOs.size(); i++) {
+              range=range + "dhcp-range=set:range"+i+","+dnsmasqTOs.get(i).getRouterIp()+",static\n";
+              gateway=gateway +"dhcp-option=tag:range"+i+",3,"+dnsmasqTOs.get(i).getGateway()+"\n";
+              netmask=netmask +"dhcp-option=tag:range"+i+",1,"+dnsmasqTOs.get(i).getNetmask()+"\n";
+         }
+         dnsMasqconf.set(12, "domain="+domain+"\n");
+         dnsMasqconf.set(14, "domain="+domain+"\n");
+         dnsMasqconf.set(16,"domain="+domain+"\n");
+         dnsMasqconf.set(18, range);
+         dnsMasqconf.set(22, gateway);
+         dnsMasqconf.set(23, netmask);
+         if (dnsMasqconfigcmd.getInternal_dns1() != null) {
+             dnsServers = dnsServers+dnsMasqconfigcmd.getInternal_dns1()+",";
+         }
+         if (dnsMasqconfigcmd.getInternal_dns2() != null) {
+             dnsServers = dnsServers+dnsMasqconfigcmd.getInternal_dns2()+",";
+         }
+         if (dnsMasqconfigcmd.getDns1() != null) {
+             dnsServers = dnsServers+dnsMasqconfigcmd.getDns1()+",";
+         }
+         if (dnsMasqconfigcmd.getDns2() != null) {
+             dnsServers = dnsServers+dnsMasqconfigcmd.getDns2()+",";
+         }
+         dnsServers = dnsServers +"*";
+         dnsServers = dnsServers.replace(";*", "");
+         dnsMasqconf.set(24,"dhcp-option=6,"+dnsServers);
+         return dnsMasqconf.toArray( new  String[dnsMasqconf.size()]);
+     }
+
+ }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/dc/dao/VlanDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/VlanDao.java b/engine/schema/src/com/cloud/dc/dao/VlanDao.java
index cc82632..605fb20 100755
--- a/engine/schema/src/com/cloud/dc/dao/VlanDao.java
+++ b/engine/schema/src/com/cloud/dc/dao/VlanDao.java
@@ -16,13 +16,13 @@
 // under the License.
 package com.cloud.dc.dao;
 
-import java.util.List;
-
 import com.cloud.dc.Vlan;
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.VlanVO;
 import com.cloud.utils.db.GenericDao;
 
+import java.util.List;
+
 public interface VlanDao extends GenericDao<VlanVO, Long> {
 	
 	VlanVO findByZoneAndVlanId(long zoneId, String vlanId);
@@ -52,4 +52,6 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
 	List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId);
 
         List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId);
+
+    List<VlanVO> listVlansByNetworkIdAndGateway(long networkid, String gateway);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
index 100295b..e8c68b1 100755
--- a/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
@@ -16,19 +16,6 @@
 // under the License.
 package com.cloud.dc.dao;
 
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.springframework.stereotype.Component;
-
 import com.cloud.dc.AccountVlanMapVO;
 import com.cloud.dc.PodVlanMapVO;
 import com.cloud.dc.Vlan;
@@ -43,6 +30,17 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 @Component
 @Local(value={VlanDao.class})
@@ -59,6 +57,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
     protected SearchBuilder<VlanVO> NetworkVlanSearch;
     protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
     protected SearchBuilder<VlanVO> ZoneWideNonDedicatedVlanSearch;
+    protected SearchBuilder<VlanVO> VlanGatewaysearch;
 
     protected SearchBuilder<AccountVlanMapVO> AccountVlanMapSearch;
 
@@ -103,6 +102,11 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
         PhysicalNetworkVlanSearch = createSearchBuilder();
         PhysicalNetworkVlanSearch.and("physicalNetworkId", PhysicalNetworkVlanSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
         PhysicalNetworkVlanSearch.done();
+
+        VlanGatewaysearch = createSearchBuilder();
+        VlanGatewaysearch.and("gateway", VlanGatewaysearch.entity().getVlanGateway(), SearchCriteria.Op.EQ);
+        VlanGatewaysearch.and("networkid", VlanGatewaysearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        VlanGatewaysearch.done();
     }
 
     @Override
@@ -318,6 +322,14 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
     }
 
     @Override
+    public List<VlanVO> listVlansByNetworkIdAndGateway(long networkid, String gateway){
+        SearchCriteria<VlanVO> sc =  VlanGatewaysearch.create();
+        sc.setParameters("networkid", networkid);
+        sc.setParameters("gateway", gateway);
+        return listBy(sc);
+    }
+
+    @Override
     public List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId) {
         SearchCriteria<VlanVO> sc = PhysicalNetworkVlanSearch.create();
         sc.setParameters("physicalNetworkId", physicalNetworkId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
index 3d588fa..fecd44a 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
@@ -16,12 +16,12 @@
 // under the License.
 package com.cloud.network.dao;
 
-import java.util.List;
-
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.utils.db.GenericDao;
 import com.cloud.utils.net.Ip;
 
+import java.util.List;
+
 public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
 	
     IPAddressVO markAsUnavailable(long ipAddressId);
@@ -68,4 +68,8 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
     IPAddressVO findByAssociatedVmIdAndVmIp(long vmId, String vmIp);
 
     IPAddressVO findByIpAndNetworkId(long networkId, String ipAddress);
+
+    IPAddressVO findByIpAndVlanId(String ipAddress, long vlanid);
+
+    long countFreeIpsInVlan(long vlanDbId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
index 73f310f..1839ca4 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
@@ -16,26 +16,12 @@
 // under the License.
 package com.cloud.network.dao;
 
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.PostConstruct;
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.VlanVO;
 import com.cloud.dc.dao.VlanDao;
-import com.cloud.dc.dao.VlanDaoImpl;
 import com.cloud.network.IpAddress.State;
 import com.cloud.server.ResourceTag.TaggedResourceType;
 import com.cloud.tags.dao.ResourceTagDao;
-import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
@@ -46,6 +32,16 @@ import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.net.Ip;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Date;
+import java.util.List;
 
 @Component
 @Local(value = { IPAddressDao.class })
@@ -193,6 +189,14 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
     }
 
     @Override
+    public IPAddressVO findByIpAndVlanId(String ipAddress, long vlanid) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("ipAddress", ipAddress);
+        sc.setParameters("vlan", vlanid);
+        return findOneBy(sc);
+    }
+
+    @Override
     public IPAddressVO findByIpAndDcId(long dcId, String ipAddress) {
         SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
         sc.setParameters("dataCenterId", dcId);
@@ -333,6 +337,13 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
     }
 
     @Override
+    public long countFreeIpsInVlan(long vlanDbId) {
+          SearchCriteria<IPAddressVO> sc =  VlanDbIdSearchUnallocated.create();
+          sc.setParameters("vlanDbId", vlanDbId);
+          return listBy(sc).size();
+    }
+
+    @Override
     public List<IPAddressVO> listByAssociatedVpc(long vpcId, Boolean isSourceNat) {
         SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
         sc.setParameters("vpcId", vpcId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/vm/dao/NicDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicDao.java b/engine/schema/src/com/cloud/vm/dao/NicDao.java
index 12efe08..83f280e 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java
@@ -16,12 +16,12 @@
 // under the License.
 package com.cloud.vm.dao;
 
-import java.util.List;
-
 import com.cloud.utils.db.GenericDao;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.VirtualMachine;
 
+import java.util.List;
+
 public interface NicDao extends GenericDao<NicVO, Long> {
     List<NicVO> listByVmId(long instanceId);
     
@@ -66,4 +66,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
     List<NicVO> listPlaceholderNicsByNetworkId(long networkId);
     
     List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType);
+
+    NicVO findByInstanceIdAndIpAddressAndVmtype(long instanceId, String ipaddress, VirtualMachine.Type type);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
index fa30168..420643f 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -16,12 +16,6 @@
 // under the License.
 package com.cloud.vm.dao;
 
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.springframework.stereotype.Component;
-
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
 import com.cloud.utils.db.SearchBuilder;
@@ -32,6 +26,10 @@ import com.cloud.vm.Nic;
 import com.cloud.vm.Nic.State;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.VirtualMachine;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
 
 @Component
 @Local(value=NicDao.class)
@@ -119,6 +117,15 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
         sc.setParameters("instance", instanceId);
         return findOneBy(sc);
     }
+
+    @Override
+    public NicVO findByInstanceIdAndIpAddressAndVmtype(long instanceId, String ipaddress, VirtualMachine.Type type) {
+        SearchCriteria<NicVO> sc = AllFieldsSearch.create();
+        sc.setParameters("instance", instanceId);
+        sc.setParameters("address", ipaddress);
+        sc.setParameters("vmType", type);
+        return findOneBy(sc);
+    }
     
     @Override
     public NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/patches/systemvm/debian/config/root/createIpAlias.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/createIpAlias.sh b/patches/systemvm/debian/config/root/createIpAlias.sh
new file mode 100755
index 0000000..2c79813
--- /dev/null
+++ b/patches/systemvm/debian/config/root/createIpAlias.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+# 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.
+
+usage() {
+  printf " %s   <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
+}
+
+set -x
+var="$1"
+cert="/root/.ssh/id_rsa.cloud"
+
+while [ -n "$var" ]
+do
+ var1=$(echo $var | cut -f1 -d "-")
+ alias_count=$( echo $var1 | cut -f1 -d ":" )
+ routerip=$(echo $var1 | cut -f2 -d ":")
+ netmask=$(echo $var1 | cut -f3 -d ":")
+ ifconfig eth0:$alias_count $routerip netmask $netmask up
+ var=$( echo $var | sed "s/${var1}-//" )
+done
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/patches/systemvm/debian/config/root/deleteIpAlias.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/deleteIpAlias.sh b/patches/systemvm/debian/config/root/deleteIpAlias.sh
new file mode 100755
index 0000000..865ff3b
--- /dev/null
+++ b/patches/systemvm/debian/config/root/deleteIpAlias.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# 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.
+
+usage() {
+  printf " %s   <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
+}
+
+set -x
+var="$1"
+cert="/root/.ssh/id_rsa.cloud"
+
+while [ -n "$var" ]
+do
+ var1=$(echo $var | cut -f1 -d "-")
+ alias_count=$( echo $var1 | cut -f1 -d ":" )
+ ifconfig eth0:$alias_count  down
+ var=$( echo $var | sed "s/${var1}-//" )
+done
+
+#recreating the active ip aliases
+sh /root/createIpAlias.sh $2
+result=$?
+if [  "$result" -ne "0" ]
+then
+ exit $result
+fi
+
+exit 0

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/patches/systemvm/debian/config/root/dnsmasq.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/dnsmasq.sh b/patches/systemvm/debian/config/root/dnsmasq.sh
new file mode 100755
index 0000000..656fd3c
--- /dev/null
+++ b/patches/systemvm/debian/config/root/dnsmasq.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# 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.
+
+usage() {
+  printf "Usage: %s:  <path to new dnsmasq config file>\n" $(basename $0) >&2
+}
+
+set -x
+#backup the old config file
+cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
+
+#apply the new confg
+echo $1
+cp $1 /etc/dnsmasq.conf
+
+#restart the dnsmasq
+service dnsmasq restart
+result=$?
+if [ "$result" -ne "0" ]
+then
+   echo "could not configure dnsmasq"
+   echo "reverting to the old config"
+   cp /etc/dnsmasq.config.bak /etc/dnsmasq.conf
+   service dnsmasq restart
+   exit 2
+fi
+rm $1
+echo "success"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java
index b72d1c8..fdf8b63 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java
@@ -18,21 +18,9 @@
 // Automatically generated by addcopyright.py at 01/29/2013
 package com.cloud.baremetal.networkservice;
 
-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.log4j.Logger;
-
 import com.cloud.baremetal.database.BaremetalDhcpVO;
-import com.cloud.baremetal.database.BaremetalPxeVO;
-import com.cloud.dc.Pod;
 import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.Pod;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -40,14 +28,13 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.host.Host;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Network;
-import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.GuestType;
 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.element.DhcpServiceProvider;
-import com.cloud.network.element.IpDeployer;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.utils.component.AdapterBase;
@@ -56,13 +43,16 @@ import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.SearchCriteria2;
 import com.cloud.utils.db.SearchCriteriaService;
 import com.cloud.utils.db.Transaction;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.*;
 import com.cloud.vm.VirtualMachine.Type;
 import com.cloud.vm.dao.NicDao;
-import com.cloud.vm.VirtualMachineProfile;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 @Local(value = NetworkElement.class)
 public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProvider {
@@ -175,4 +165,15 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
         }
         return _dhcpMgr.addVirtualMachineIntoNetwork(network, nic, vm, dest, context);
     }
+
+    @Override
+    public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public boolean removeDhcpSupportForSubnet(Network network) {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 6d7e0e7..7ce3b93 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -16,32 +16,6 @@
 // under the License.
 package com.cloud.hypervisor.vmware.resource;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.nio.channels.SocketChannel;
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.TimeZone;
-import java.util.UUID;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.NDC;
-
 import com.cloud.agent.IAgentControl;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.AttachIsoCommand;
@@ -133,7 +107,11 @@ import com.cloud.agent.api.ValidateSnapshotCommand;
 import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
+import com.cloud.agent.api.routing.CreateIpAliasCommand;
+import com.cloud.agent.api.routing.DeleteIpAliasCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.DnsMasqConfigCommand;
+import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.IpAssocVpcCommand;
@@ -200,10 +178,10 @@ import com.cloud.hypervisor.vmware.mo.VirtualSwitchType;
 import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
 import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
 import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary;
-import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.hypervisor.vmware.util.VmwareGuestOsMapper;
 import com.cloud.hypervisor.vmware.util.VmwareHelper;
+import com.cloud.network.DnsMasqConfigurator;
 import com.cloud.network.HAProxyConfigurator;
 import com.cloud.network.LoadBalancerConfigurator;
 import com.cloud.network.Networks;
@@ -256,9 +234,7 @@ import com.vmware.vim25.PerfMetricIntSeries;
 import com.vmware.vim25.PerfMetricSeries;
 import com.vmware.vim25.PerfQuerySpec;
 import com.vmware.vim25.PerfSampleInfo;
-import com.vmware.vim25.RuntimeFault;
 import com.vmware.vim25.RuntimeFaultFaultMsg;
-import com.vmware.vim25.ToolsUnavailable;
 import com.vmware.vim25.ToolsUnavailableFaultMsg;
 import com.vmware.vim25.VimPortType;
 import com.vmware.vim25.VirtualDevice;
@@ -274,6 +250,30 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
 import com.vmware.vim25.VirtualMachinePowerState;
 import com.vmware.vim25.VirtualMachineRuntimeInfo;
 import com.vmware.vim25.VirtualSCSISharing;
+import org.apache.log4j.Logger;
+import org.apache.log4j.NDC;
+
+import javax.naming.ConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.nio.channels.SocketChannel;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.TimeZone;
+import java.util.UUID;
 
 
 public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService {
@@ -367,6 +367,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                 answer = execute((SavePasswordCommand) cmd);
             } else if (clz == DhcpEntryCommand.class) {
                 answer = execute((DhcpEntryCommand) cmd);
+            } else if (clz == CreateIpAliasCommand.class) {
+                return execute((CreateIpAliasCommand) cmd);
+            } else if (clz == DnsMasqConfigCommand.class) {
+                return execute((DnsMasqConfigCommand) cmd);
+            } else if (clz == DeleteIpAliasCommand.class) {
+                return execute((DeleteIpAliasCommand) cmd);
             } else if (clz == VmDataCommand.class) {
                 answer = execute((VmDataCommand) cmd);
             } else if (clz == ReadyCommand.class) {
@@ -1837,6 +1843,141 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         return new Answer(cmd);
     }
 
+    protected Answer execute(final CreateIpAliasCommand cmd) {
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Executing createipAlias command: " + _gson.toJson(cmd));
+        }
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
+        String args=routerIp+" ";
+        for (IpAliasTO ipaliasto : ipAliasTOs) {
+            args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
+        }
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createipAlias " + args);
+        }
+
+        try {
+            VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+            String controlIp = getRouterSshControlIp(cmd);
+            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
+                    "/root/createipAlias.sh " + args);
+
+            if (!result.first()) {
+                s_logger.error("ipAlias command on domr " + controlIp + " failed, message: " + result.second());
+
+                return new Answer(cmd, false, "createipAlias failed due to " + result.second());
+            }
+
+            if (s_logger.isInfoEnabled()) {
+                s_logger.info("createipAlias command on domain router " + controlIp + " completed");
+            }
+
+        } catch (Throwable e) {
+            String msg = "createipAlias failed due to " + VmwareHelper.getExceptionMessage(e);
+            s_logger.error(msg, e);
+            return new Answer(cmd, false, msg);
+        }
+
+        return new Answer(cmd);
+    }
+
+    protected Answer execute(final DeleteIpAliasCommand cmd) {
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
+        List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Executing deleteipAlias command: " + _gson.toJson(cmd));
+        }
+        String args=routerIp+" ";
+        for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        args = args + " " ;
+        for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteipAlias " + args);
+        }
+
+        try {
+            VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+            String controlIp = getRouterSshControlIp(cmd);
+            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
+                    "/root/deleteipAlias.sh " + args);
+
+            if (!result.first()) {
+                s_logger.error("ipAlias command on domr " + controlIp + " failed, message: " + result.second());
+
+                return new Answer(cmd, false, "deleteipAlias failed due to " + result.second());
+            }
+
+            if (s_logger.isInfoEnabled()) {
+                s_logger.info("deleteipAlias command on domain router " + controlIp + " completed");
+            }
+
+        } catch (Throwable e) {
+            String msg = "deleteipAlias failed due to " + VmwareHelper.getExceptionMessage(e);
+            s_logger.error(msg, e);
+            return new Answer(cmd, false, msg);
+        }
+
+        return new Answer(cmd);
+    }
+
+    protected Answer execute(final DnsMasqConfigCommand cmd) {
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Executing deleteipAlias command: " + _gson.toJson(cmd));
+        }
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        String controlIp = getRouterSshControlIp(cmd);
+
+        assert(controlIp != null);
+
+        DnsMasqConfigurator configurator = new DnsMasqConfigurator();
+        String [] config = configurator.generateConfiguration(cmd);
+        String tmpConfigFilePath = "/tmp/"+ routerIp.replace(".","-")+".cfg";
+        String tmpConfigFileContents = "";
+        for (int i = 0; i < config.length; i++) {
+            tmpConfigFileContents += config[i];
+            tmpConfigFileContents += "\n";
+        }
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/dnsmasq.sh " +"config file at" + tmpConfigFilePath);
+        }
+        VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+        File keyFile = mgr.getSystemVMKeyFile();
+
+        try {
+            SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpConfigFileContents.getBytes(), routerIp.replace('.', '_') + ".cfg", null);
+
+            try {
+
+                Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "scp" + tmpConfigFilePath + "/root/dnsmasq.sh");
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Run command on domain router " + routerIp + ",  /root/dnsmasq.sh");
+                }
+
+                if (!result.first()) {
+                    s_logger.error("Unable to copy dnsmasq configuration file");
+                    return new Answer(cmd, false, "dnsmasq config failed due to uanble to copy dnsmasq configuration file");
+                }
+
+                if (s_logger.isInfoEnabled()) {
+                    s_logger.info("dnsmasq config command on domain router " + routerIp + " completed");
+                }
+            } finally {
+                SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "rm " + tmpConfigFilePath);
+            }
+
+            return new Answer(cmd);
+        } catch (Throwable e) {
+            s_logger.error("Unexpected exception: " + e.toString(), e);
+            return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to " + VmwareHelper.getExceptionMessage(e));
+        }
+    }
+
     protected CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + _gson.toJson(cmd));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/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 bac361d..9f6a9f0 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
@@ -17,53 +17,6 @@
 package com.cloud.hypervisor.xen.resource;
 
 
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Queue;
-import java.util.Random;
-import java.util.Set;
-import java.util.UUID;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import com.cloud.agent.api.*;
-import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
-import com.cloud.agent.api.to.*;
-import com.cloud.network.rules.FirewallRule;
-import org.apache.log4j.Logger;
-import org.apache.xmlrpc.XmlRpcException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
 import com.cloud.agent.IAgentControl;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.AttachIsoCommand;
@@ -137,6 +90,8 @@ import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.RevertToVMSnapshotAnswer;
 import com.cloud.agent.api.RevertToVMSnapshotCommand;
+import com.cloud.agent.api.ScaleVmAnswer;
+import com.cloud.agent.api.ScaleVmCommand;
 import com.cloud.agent.api.SecurityGroupRuleAnswer;
 import com.cloud.agent.api.SecurityGroupRulesCmd;
 import com.cloud.agent.api.SetupAnswer;
@@ -161,7 +116,11 @@ import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
+import com.cloud.agent.api.routing.CreateIpAliasCommand;
+import com.cloud.agent.api.routing.DeleteIpAliasCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.DnsMasqConfigCommand;
+import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.IpAssocVpcCommand;
@@ -195,6 +154,7 @@ import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.agent.api.storage.ResizeVolumeAnswer;
 import com.cloud.agent.api.storage.ResizeVolumeCommand;
+import com.cloud.agent.api.to.FirewallRuleTO;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
@@ -207,6 +167,7 @@ import com.cloud.agent.api.to.VolumeTO;
 import com.cloud.exception.InternalErrorException;
 import com.cloud.host.Host.Type;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.DnsMasqConfigurator;
 import com.cloud.network.HAProxyConfigurator;
 import com.cloud.network.LoadBalancerConfigurator;
 import com.cloud.network.Networks;
@@ -226,6 +187,7 @@ import com.cloud.network.ovs.OvsFetchInterfaceCommand;
 import com.cloud.network.ovs.OvsSetTagAndFlowAnswer;
 import com.cloud.network.ovs.OvsSetTagAndFlowCommand;
 import com.cloud.network.ovs.OvsSetupBridgeCommand;
+import com.cloud.network.rules.FirewallRule;
 import com.cloud.resource.ServerResource;
 import com.cloud.resource.hypervisor.HypervisorResource;
 import com.cloud.storage.Storage;
@@ -279,6 +241,48 @@ import com.xensource.xenapi.VLAN;
 import com.xensource.xenapi.VM;
 import com.xensource.xenapi.VMGuestMetrics;
 import com.xensource.xenapi.XenAPIObject;
+import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Queue;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
 
 /**
  * CitrixResourceBase encapsulates the calls to the XenServer Xapi process
@@ -460,6 +464,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             return execute((SavePasswordCommand) cmd);
         } else if (clazz == DhcpEntryCommand.class) {
             return execute((DhcpEntryCommand) cmd);
+        } else if (clazz == CreateIpAliasCommand.class) {
+            return execute((CreateIpAliasCommand) cmd);
+        } else if (clazz == DnsMasqConfigCommand.class) {
+            return execute((DnsMasqConfigCommand) cmd);
+        } else if (clazz == DeleteIpAliasCommand.class) {
+            return execute((DeleteIpAliasCommand) cmd);
         } else if (clazz == VmDataCommand.class) {
             return execute((VmDataCommand) cmd);
         } else if (clazz == ReadyCommand.class) {
@@ -1889,6 +1899,68 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return new Answer(cmd);
     }
 
+    protected Answer execute(final CreateIpAliasCommand cmd) {
+        Connection conn = getConnection();
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
+        String args=routerIp+" ";
+        for (IpAliasTO ipaliasto : ipAliasTOs) {
+            args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
+        }
+        String result = callHostPlugin(conn, "vmops", "createipAlias", "args", args);
+        if (result == null || result.isEmpty()) {
+            return new Answer(cmd, false, "CreateIPAliasCommand failed\n");
+        }
+
+        return  new Answer(cmd);
+    }
+
+    protected Answer execute(final DeleteIpAliasCommand cmd) {
+        Connection conn = getConnection();
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
+        String args=routerIp+" ";
+        for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        args = args + " " ;
+        List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
+        for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
+            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
+        }
+        String result = callHostPlugin(conn, "vmops", "deleteipAlias", "args", args);
+        if (result == null || result.isEmpty()) {
+            return new Answer(cmd, false, "DeleteipAliasCommand failed\n");
+        }
+
+        return  new Answer(cmd);
+    }
+
+    protected Answer execute(final DnsMasqConfigCommand cmd) {
+        Connection conn = getConnection();
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        DnsMasqConfigurator configurator = new DnsMasqConfigurator();
+        String [] config = configurator.generateConfiguration(cmd);
+        String tmpConfigFilePath = "/tmp/"+ routerIp.replace(".","-")+".cfg";
+        String tmpConfigFileContents = "";
+        for (int i = 0; i < config.length; i++) {
+            tmpConfigFileContents += config[i];
+            tmpConfigFileContents += "\n";
+        }
+
+        String result = callHostPlugin(conn, "vmops", "createFileInDomr", "filepath", tmpConfigFilePath, "filecontents", tmpConfigFileContents, "domrip" ,routerIp);
+        if (result == null || result.isEmpty()) {
+            return new Answer(cmd, false, "DnsMasqConfigCommand failed to create DnsMasq cfg file.");
+        }
+        result = callHostPlugin(conn, "vmops", "configdnsmasq", "routerip", routerIp, "filepath", tmpConfigFilePath);
+
+        if (result == null || result.isEmpty()) {
+            return new Answer(cmd, false, "DnsMasqconfigCommand failed");
+        }
+
+        return new Answer(cmd);
+
+    }
     protected Answer execute(final LoadBalancerConfigCommand cmd) {
         if ( cmd.getVpcId() != null ) {
             return VPCLoadBalancerConfig(cmd);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
index 804e4a6..d07fa56 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java
@@ -19,54 +19,67 @@
 
 package com.cloud.network.element;
 
-import com.cloud.network.*;
-import com.cloud.network.element.SimpleFirewallRule;
 import com.cloud.agent.api.to.FirewallRuleTO;
-import com.cloud.agent.api.to.NetworkACLTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+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.NetworkModel;
+import com.cloud.network.Networks;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.rules.StaticNat;
 import com.cloud.network.rules.PortForwardingRule;
-import com.cloud.network.addr.PublicIp;
+import com.cloud.network.rules.StaticNat;
+import com.cloud.network.vpc.VpcManager;
 import com.cloud.offering.NetworkOffering;
+import com.cloud.user.AccountManager;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.PluggableService;
 import com.cloud.utils.net.NetUtils;
-import com.cloud.vm.*;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
-import com.google.common.collect.*;
-import com.cloud.user.AccountManager;
 import com.midokura.midonet.client.MidonetApi;
 import com.midokura.midonet.client.dto.DtoRule;
-import com.midokura.midonet.client.resource.*;
+import com.midokura.midonet.client.resource.Bridge;
+import com.midokura.midonet.client.resource.BridgePort;
+import com.midokura.midonet.client.resource.DhcpHost;
+import com.midokura.midonet.client.resource.DhcpSubnet;
+import com.midokura.midonet.client.resource.Port;
+import com.midokura.midonet.client.resource.ResourceCollection;
+import com.midokura.midonet.client.resource.Route;
+import com.midokura.midonet.client.resource.Router;
+import com.midokura.midonet.client.resource.RouterPort;
+import com.midokura.midonet.client.resource.Rule;
+import com.midokura.midonet.client.resource.RuleChain;
 import com.sun.jersey.core.util.MultivaluedMapImpl;
 import org.apache.log4j.Logger;
-import com.cloud.network.vpc.PrivateGateway;
-import com.cloud.network.vpc.StaticRouteProfile;
-import com.cloud.network.vpc.Vpc;
-import com.cloud.network.vpc.VpcGateway;
-import com.cloud.network.vpc.VpcManager;
 import org.springframework.stereotype.Component;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.inject.Inject;
-import java.util.*;
-import java.lang.Class;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 
 @Component
@@ -432,6 +445,16 @@ public class MidoNetElement extends AdapterBase implements
         return true;
     }
 
+    @Override
+    public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public boolean removeDhcpSupportForSubnet(Network network) {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
     private void removeMidonetStaticNAT(RuleChain preFilter, RuleChain preNat, RuleChain postNat,
                                         String floatingIp, String fixedIp,
                                         Router providerRouter) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/scripts/vm/hypervisor/xenserver/createipAlias.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/createipAlias.sh b/scripts/vm/hypervisor/xenserver/createipAlias.sh
new file mode 100755
index 0000000..c35658e
--- /dev/null
+++ b/scripts/vm/hypervisor/xenserver/createipAlias.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# 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.
+
+
+usage() {
+  printf " %s  routerip  <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
+}
+
+set -x
+cert="/root/.ssh/id_rsa.cloud"
+ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/createIpAlias.sh $2"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/052c24c4/scripts/vm/hypervisor/xenserver/deleteipAlias.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/deleteipAlias.sh b/scripts/vm/hypervisor/xenserver/deleteipAlias.sh
new file mode 100644
index 0000000..6816edd
--- /dev/null
+++ b/scripts/vm/hypervisor/xenserver/deleteipAlias.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+# 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.
+
+usage() {
+  printf " %s  routerip  <alias_count:ip:netmask;alias_count2:ip2:netmask2;....> \n" $(basename $0) >&2
+}
+
+set -x
+cert="/root/.ssh/id_rsa.cloud"
+ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$1 "/root/deleteIpAlias.sh $2 $3"


Mime
View raw message