You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/11 00:29:22 UTC

[2/7] more files changed

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/test/IPRangeConfig.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/test/IPRangeConfig.java b/server/src/com/cloud/test/IPRangeConfig.java
index 1f1f90f..4b884f8 100755
--- a/server/src/com/cloud/test/IPRangeConfig.java
+++ b/server/src/com/cloud/test/IPRangeConfig.java
@@ -26,482 +26,482 @@ import java.util.List;
 import java.util.UUID;
 import java.util.Vector;
 
-
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.net.NetUtils;
 
 
 public class IPRangeConfig {
-	
-	public static void main(String[] args) {
-		IPRangeConfig config = ComponentLocator.inject(IPRangeConfig.class);
-		config.run(args);
-		System.exit(0);
+
+    public static void main(String[] args) {
+        IPRangeConfig config = ComponentContext.inject(IPRangeConfig.class);
+        config.run(args);
+        System.exit(0);
+    }
+
+    private String usage() {
+        return "Usage: ./change_ip_range.sh [add|delete] [public zone | private pod zone] startIP endIP";
     }
-	
-	private String usage() {
-		return "Usage: ./change_ip_range.sh [add|delete] [public zone | private pod zone] startIP endIP";
-	}
-	
-	
-	public void run(String[] args) {
-		if (args.length < 2) {
+
+
+    public void run(String[] args) {
+        if (args.length < 2) {
             printError(usage());
         }
-		
-		String op = args[0];
-		String type = args[1];
-		
-		if (type.equals("public")) {
-			if (args.length != 4 && args.length != 5) {
+
+        String op = args[0];
+        String type = args[1];
+
+        if (type.equals("public")) {
+            if (args.length != 4 && args.length != 5) {
                 printError(usage());
             }
-			String zone = args[2];
-			String startIP = args[3];
-			String endIP = null;
-			if (args.length == 5) {
+            String zone = args[2];
+            String startIP = args[3];
+            String endIP = null;
+            if (args.length == 5) {
                 endIP = args[4];
             }
-			
-			String result = checkErrors(type, op, null, zone, startIP, endIP);
-			if (!result.equals("success")) {
+
+            String result = checkErrors(type, op, null, zone, startIP, endIP);
+            if (!result.equals("success")) {
                 printError(result);
             }
-			
-			long zoneId = PodZoneConfig.getZoneId(zone);
-			result = changeRange(op, "public", -1, zoneId, startIP, endIP, null, -1);
-			result.replaceAll("<br>", "/n");
-			System.out.println(result);
-		} else if (type.equals("private")) {
-			if (args.length != 5 && args.length != 6) {
+
+            long zoneId = PodZoneConfig.getZoneId(zone);
+            result = changeRange(op, "public", -1, zoneId, startIP, endIP, null, -1);
+            result.replaceAll("<br>", "/n");
+            System.out.println(result);
+        } else if (type.equals("private")) {
+            if (args.length != 5 && args.length != 6) {
                 printError(usage());
             }
-			String pod = args[2];
-			String zone = args[3];;
-			String startIP = args[4];
-			String endIP = null;
-			if (args.length == 6) {
+            String pod = args[2];
+            String zone = args[3];;
+            String startIP = args[4];
+            String endIP = null;
+            if (args.length == 6) {
                 endIP = args[5];
             }
-			
-			String result = checkErrors(type, op, pod, zone, startIP, endIP);
-			if (!result.equals("success")) {
+
+            String result = checkErrors(type, op, pod, zone, startIP, endIP);
+            if (!result.equals("success")) {
                 printError(result);
             }
-			
-			long podId = PodZoneConfig.getPodId(pod, zone);
-			long zoneId = PodZoneConfig.getZoneId(zone);
-			result = changeRange(op, "private", podId, zoneId, startIP, endIP, null, -1);
-			result.replaceAll("<br>", "/n");
-			System.out.println(result);
-		} else {
-			printError(usage());
-		}
-	}
-	
-	public List<String> changePublicIPRangeGUI(String op, String zone, String startIP, String endIP, long physicalNetworkId) {
-		String result = checkErrors("public", op, null, zone, startIP, endIP);
-		if (!result.equals("success")) {
+
+            long podId = PodZoneConfig.getPodId(pod, zone);
+            long zoneId = PodZoneConfig.getZoneId(zone);
+            result = changeRange(op, "private", podId, zoneId, startIP, endIP, null, -1);
+            result.replaceAll("<br>", "/n");
+            System.out.println(result);
+        } else {
+            printError(usage());
+        }
+    }
+
+    public List<String> changePublicIPRangeGUI(String op, String zone, String startIP, String endIP, long physicalNetworkId) {
+        String result = checkErrors("public", op, null, zone, startIP, endIP);
+        if (!result.equals("success")) {
             return DatabaseConfig.genReturnList("false", result);
         }
-		
-		long zoneId = PodZoneConfig.getZoneId(zone);
-		result = changeRange(op, "public", -1, zoneId, startIP, endIP, null, physicalNetworkId);
-		
-		return DatabaseConfig.genReturnList("true", result);
-	}
-	
-	public List<String> changePrivateIPRangeGUI(String op, String pod, String zone, String startIP, String endIP) {
-		String result = checkErrors("private", op, pod, zone, startIP, endIP);
-		if (!result.equals("success")) {
+
+        long zoneId = PodZoneConfig.getZoneId(zone);
+        result = changeRange(op, "public", -1, zoneId, startIP, endIP, null, physicalNetworkId);
+
+        return DatabaseConfig.genReturnList("true", result);
+    }
+
+    public List<String> changePrivateIPRangeGUI(String op, String pod, String zone, String startIP, String endIP) {
+        String result = checkErrors("private", op, pod, zone, startIP, endIP);
+        if (!result.equals("success")) {
             return DatabaseConfig.genReturnList("false", result);
         }
-		
-		long podId = PodZoneConfig.getPodId(pod, zone);
-		long zoneId = PodZoneConfig.getZoneId(zone);
-		result = changeRange(op, "private", podId, zoneId, startIP, endIP, null, -1);
-		
-		return DatabaseConfig.genReturnList("true", result);
-	}
 
-	private String checkErrors(String type, String op, String pod, String zone, String startIP, String endIP) {
-		if (!op.equals("add") && !op.equals("delete")) {
+        long podId = PodZoneConfig.getPodId(pod, zone);
+        long zoneId = PodZoneConfig.getZoneId(zone);
+        result = changeRange(op, "private", podId, zoneId, startIP, endIP, null, -1);
+
+        return DatabaseConfig.genReturnList("true", result);
+    }
+
+    private String checkErrors(String type, String op, String pod, String zone, String startIP, String endIP) {
+        if (!op.equals("add") && !op.equals("delete")) {
             return usage();
         }
-		
-		if (type.equals("public")) {
-			// Check that the zone is valid
-			if (!PodZoneConfig.validZone(zone)) {
+
+        if (type.equals("public")) {
+            // Check that the zone is valid
+            if (!PodZoneConfig.validZone(zone)) {
                 return "Please specify a valid zone.";
             }
-		} else if (type.equals("private")) {
-			// Check that the pod and zone are valid
-			if (!PodZoneConfig.validZone(zone)) {
+        } else if (type.equals("private")) {
+            // Check that the pod and zone are valid
+            if (!PodZoneConfig.validZone(zone)) {
                 return "Please specify a valid zone.";
             }
-			if (!PodZoneConfig.validPod(pod, zone)) {
+            if (!PodZoneConfig.validPod(pod, zone)) {
                 return "Please specify a valid pod.";
             }
-		}
-		
-		if (!validIP(startIP)) {
+        }
+
+        if (!validIP(startIP)) {
             return "Please specify a valid start IP";
         }
-		
-		if (!validOrBlankIP(endIP)) {
+
+        if (!validOrBlankIP(endIP)) {
             return "Please specify a valid end IP";
         }
-		
-		// Check that the IPs that are being added are compatible with either the zone's public netmask, or the pod's CIDR
-		if (type.equals("public")) {
-			// String publicNetmask = getPublicNetmask(zone);
-			// String publicGateway = getPublicGateway(zone);
-			
-			// if (publicNetmask == null) return "Please ensure that your zone's public net mask is specified";
-			// if (!sameSubnet(startIP, endIP, publicNetmask)) return "Please ensure that your start IP and end IP are in the same subnet, as per the zone's netmask.";
-			// if (!sameSubnet(startIP, publicGateway, publicNetmask)) return "Please ensure that your start IP is in the same subnet as your zone's gateway, as per the zone's netmask.";
-			// if (!sameSubnet(endIP, publicGateway, publicNetmask)) return "Please ensure that your end IP is in the same subnet as your zone's gateway, as per the zone's netmask.";
-		} else if (type.equals("private")) {
-			String cidrAddress = getCidrAddress(pod, zone);
-			long cidrSize = getCidrSize(pod, zone);
-
-			if (!sameSubnetCIDR(startIP, endIP, cidrSize)) {
+
+        // Check that the IPs that are being added are compatible with either the zone's public netmask, or the pod's CIDR
+        if (type.equals("public")) {
+            // String publicNetmask = getPublicNetmask(zone);
+            // String publicGateway = getPublicGateway(zone);
+
+            // if (publicNetmask == null) return "Please ensure that your zone's public net mask is specified";
+            // if (!sameSubnet(startIP, endIP, publicNetmask)) return "Please ensure that your start IP and end IP are in the same subnet, as per the zone's netmask.";
+            // if (!sameSubnet(startIP, publicGateway, publicNetmask)) return "Please ensure that your start IP is in the same subnet as your zone's gateway, as per the zone's netmask.";
+            // if (!sameSubnet(endIP, publicGateway, publicNetmask)) return "Please ensure that your end IP is in the same subnet as your zone's gateway, as per the zone's netmask.";
+        } else if (type.equals("private")) {
+            String cidrAddress = getCidrAddress(pod, zone);
+            long cidrSize = getCidrSize(pod, zone);
+
+            if (!sameSubnetCIDR(startIP, endIP, cidrSize)) {
                 return "Please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size.";
             }
-			if (!sameSubnetCIDR(startIP, cidrAddress, cidrSize)) {
+            if (!sameSubnetCIDR(startIP, cidrAddress, cidrSize)) {
                 return "Please ensure that your start IP is in the same subnet as the pod's CIDR address.";
             }
-			if (!sameSubnetCIDR(endIP, cidrAddress, cidrSize)) {
+            if (!sameSubnetCIDR(endIP, cidrAddress, cidrSize)) {
                 return "Please ensure that your end IP is in the same subnet as the pod's CIDR address.";
             }
-		}
-		
-		if (!validIPRange(startIP, endIP)) {
+        }
+
+        if (!validIPRange(startIP, endIP)) {
             return "Please specify a valid IP range.";
         }
-		
-		return "success";
-	}
-	
-	private String genChangeRangeSuccessString(List<String> problemIPs, String op) {
-		if (problemIPs == null) {
+
+        return "success";
+    }
+
+    private String genChangeRangeSuccessString(List<String> problemIPs, String op) {
+        if (problemIPs == null) {
             return "";
         }
-		
-		if (problemIPs.size() == 0) {
-			if (op.equals("add")) {
+
+        if (problemIPs.size() == 0) {
+            if (op.equals("add")) {
                 return "Successfully added all IPs in the specified range.";
             } else if (op.equals("delete")) {
                 return "Successfully deleted all IPs in the specified range.";
             } else {
                 return "";
             }
-		} else {
-			String successString = "";
-			if (op.equals("add")) {
+        } else {
+            String successString = "";
+            if (op.equals("add")) {
                 successString += "Failed to add the following IPs, because they are already in the database: <br><br>";
             } else if (op.equals("delete")) {
                 successString += "Failed to delete the following IPs, because they are in use: <br><br>";
             }
-			
-			for (int i = 0; i < problemIPs.size(); i++) {
-				successString += problemIPs.get(i);
-				if (i != (problemIPs.size() - 1)) {
+
+            for (int i = 0; i < problemIPs.size(); i++) {
+                successString += problemIPs.get(i);
+                if (i != (problemIPs.size() - 1)) {
                     successString += ", ";
                 }
-			}
-			
-			successString += "<br><br>";
-			
-			if (op.equals("add")) {
+            }
+
+            successString += "<br><br>";
+
+            if (op.equals("add")) {
                 successString += "Successfully added all other IPs in the specified range.";
             } else if (op.equals("delete")) {
                 successString += "Successfully deleted all other IPs in the specified range.";
             }
-			
-			return successString;
-		}
-	}
-	
-	private String changeRange(String op, String type, long podId, long zoneId, String startIP, String endIP, Long networkId, long physicalNetworkId) {
-		
-		// Go through all the IPs and add or delete them
-		List<String> problemIPs = null;
-		if (op.equals("add")) {
-			problemIPs = saveIPRange(type, podId, zoneId, 1, startIP, endIP, networkId, physicalNetworkId);
-		} else if (op.equals("delete")) {
-			problemIPs = deleteIPRange(type, podId, zoneId, 1, startIP, endIP);
-		}
-		
-		if (problemIPs == null) {
+
+            return successString;
+        }
+    }
+
+    private String changeRange(String op, String type, long podId, long zoneId, String startIP, String endIP, Long networkId, long physicalNetworkId) {
+
+        // Go through all the IPs and add or delete them
+        List<String> problemIPs = null;
+        if (op.equals("add")) {
+            problemIPs = saveIPRange(type, podId, zoneId, 1, startIP, endIP, networkId, physicalNetworkId);
+        } else if (op.equals("delete")) {
+            problemIPs = deleteIPRange(type, podId, zoneId, 1, startIP, endIP);
+        }
+
+        if (problemIPs == null) {
             return null;
         } else {
             return genChangeRangeSuccessString(problemIPs, op);
         }
-	}
-	
-	private String genSuccessString(Vector<String> problemIPs, String op) {
-		if (problemIPs == null) {
+    }
+
+    private String genSuccessString(Vector<String> problemIPs, String op) {
+        if (problemIPs == null) {
             return "";
         }
-		
-		if (problemIPs.size() == 0) {
-			if (op.equals("add")) {
+
+        if (problemIPs.size() == 0) {
+            if (op.equals("add")) {
                 return "Successfully added all IPs in the specified range.";
             } else if (op.equals("delete")) {
                 return "Successfully deleted all IPs in the specified range.";
             } else {
                 return "";
             }
-		} else {
-			String successString = "";
-			if (op.equals("add")) {
+        } else {
+            String successString = "";
+            if (op.equals("add")) {
                 successString += "Failed to add the following IPs, because they are already in the database: <br><br>";
             } else if (op.equals("delete")) {
                 successString += "Failed to delete the following IPs, because they are in use: <br><br>";
             }
-			
-			for (int i = 0; i < problemIPs.size(); i++) {
-				successString += problemIPs.elementAt(i);
-				if (i != (problemIPs.size() - 1)) {
+
+            for (int i = 0; i < problemIPs.size(); i++) {
+                successString += problemIPs.elementAt(i);
+                if (i != (problemIPs.size() - 1)) {
                     successString += ", ";
                 }
-			}
-			
-			successString += "<br><br>";
-			
-			if (op.equals("add")) {
+            }
+
+            successString += "<br><br>";
+
+            if (op.equals("add")) {
                 successString += "Successfully added all other IPs in the specified range.";
             } else if (op.equals("delete")) {
                 successString += "Successfully deleted all other IPs in the specified range.";
             }
-			
-			return successString;
-		}
-	}
-	
-	public static String getCidrAddress(String pod, String zone) {
-		long dcId = PodZoneConfig.getZoneId(zone);
-		String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
-		String errorMsg = "Could not read CIDR address for pod/zone: " + pod + "/" + zone + " from database. Please contact Cloud Support.";
-		return DatabaseConfig.getDatabaseValueString(selectSql, "cidr_address", errorMsg);
-	}
-	
-	public static long getCidrSize(String pod, String zone) {
-		long dcId = PodZoneConfig.getZoneId(zone);
-		String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
-		String errorMsg = "Could not read CIDR address for pod/zone: " + pod + "/" + zone + " from database. Please contact Cloud Support.";
-		return DatabaseConfig.getDatabaseValueLong(selectSql, "cidr_size", errorMsg);
-	}
-
-	@DB
-	protected Vector<String> deleteIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP) {
-    	long startIPLong = NetUtils.ip2Long(startIP);
-    	long endIPLong = startIPLong;
-    	if (endIP != null) {
+
+            return successString;
+        }
+    }
+
+    public static String getCidrAddress(String pod, String zone) {
+        long dcId = PodZoneConfig.getZoneId(zone);
+        String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
+        String errorMsg = "Could not read CIDR address for pod/zone: " + pod + "/" + zone + " from database. Please contact Cloud Support.";
+        return DatabaseConfig.getDatabaseValueString(selectSql, "cidr_address", errorMsg);
+    }
+
+    public static long getCidrSize(String pod, String zone) {
+        long dcId = PodZoneConfig.getZoneId(zone);
+        String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
+        String errorMsg = "Could not read CIDR address for pod/zone: " + pod + "/" + zone + " from database. Please contact Cloud Support.";
+        return DatabaseConfig.getDatabaseValueLong(selectSql, "cidr_size", errorMsg);
+    }
+
+    @DB
+    protected Vector<String> deleteIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP) {
+        long startIPLong = NetUtils.ip2Long(startIP);
+        long endIPLong = startIPLong;
+        if (endIP != null) {
             endIPLong = NetUtils.ip2Long(endIP);
         }
- 
-    	Transaction txn = Transaction.currentTxn();
-    	Vector<String> problemIPs = null;
-    	if (type.equals("public")) {
+
+        Transaction txn = Transaction.currentTxn();
+        Vector<String> problemIPs = null;
+        if (type.equals("public")) {
             problemIPs = deletePublicIPRange(txn, startIPLong, endIPLong, vlanDbId);
         } else if (type.equals("private")) {
             problemIPs = deletePrivateIPRange(txn, startIPLong, endIPLong, podId, zoneId);
         }
-    	
-    	return problemIPs;
+
+        return problemIPs;
     }
-	
-	private Vector<String> deletePublicIPRange(Transaction txn, long startIP, long endIP, long vlanDbId) {
-		String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
-		String isPublicIPAllocatedSelectSql = "SELECT * FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
-		
-		Vector<String> problemIPs = new Vector<String>();
-		PreparedStatement stmt = null;
-		PreparedStatement isAllocatedStmt = null;
-		
-		Connection conn = null;
-		try {
-			conn = txn.getConnection();
-			stmt = conn.prepareStatement(deleteSql);
-			isAllocatedStmt = conn.prepareStatement(isPublicIPAllocatedSelectSql);
-		} catch (SQLException e) {
-			return null;
-		}
-		
-		while (startIP <= endIP) {
-			if (!isPublicIPAllocated(startIP, vlanDbId, isAllocatedStmt)) {
-				try {
-					stmt.clearParameters();
-					stmt.setLong(1, startIP);
-					stmt.setLong(2, vlanDbId);
-					stmt.executeUpdate();
-				} catch (Exception ex) {
-				}
-			} else {
-				problemIPs.add(NetUtils.long2Ip(startIP));
-			}
-			startIP += 1;
-		}
-			
+
+    private Vector<String> deletePublicIPRange(Transaction txn, long startIP, long endIP, long vlanDbId) {
+        String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
+        String isPublicIPAllocatedSelectSql = "SELECT * FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
+
+        Vector<String> problemIPs = new Vector<String>();
+        PreparedStatement stmt = null;
+        PreparedStatement isAllocatedStmt = null;
+
+        Connection conn = null;
+        try {
+            conn = txn.getConnection();
+            stmt = conn.prepareStatement(deleteSql);
+            isAllocatedStmt = conn.prepareStatement(isPublicIPAllocatedSelectSql);
+        } catch (SQLException e) {
+            return null;
+        }
+
+        while (startIP <= endIP) {
+            if (!isPublicIPAllocated(startIP, vlanDbId, isAllocatedStmt)) {
+                try {
+                    stmt.clearParameters();
+                    stmt.setLong(1, startIP);
+                    stmt.setLong(2, vlanDbId);
+                    stmt.executeUpdate();
+                } catch (Exception ex) {
+                }
+            } else {
+                problemIPs.add(NetUtils.long2Ip(startIP));
+            }
+            startIP += 1;
+        }
+
         return problemIPs;
-	}
-	
-	private Vector<String> deletePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
-		String deleteSql = "DELETE FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND pod_id = ? AND data_center_id = ?";
-		String isPrivateIPAllocatedSelectSql = "SELECT * FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND data_center_id = ? AND pod_id = ?";
-		
-		Vector<String> problemIPs = new Vector<String>();
-		PreparedStatement stmt = null;
-		PreparedStatement isAllocatedStmt = null;
-				
-		Connection conn = null;
-		try {
-			conn = txn.getConnection();
-			stmt = conn.prepareStatement(deleteSql);
-			isAllocatedStmt = conn.prepareStatement(isPrivateIPAllocatedSelectSql);
-		} catch (SQLException e) {
-			System.out.println("Exception: " + e.getMessage());
-			printError("Unable to start DB connection to delete private IPs. Please contact Cloud Support.");
-		}
-		
-		while (startIP <= endIP) {
-			if (!isPrivateIPAllocated(NetUtils.long2Ip(startIP), podId, zoneId, isAllocatedStmt)) {
-				try {
-					stmt.clearParameters();
-					stmt.setString(1, NetUtils.long2Ip(startIP));
-					stmt.setLong(2, podId);
-					stmt.setLong(3, zoneId);
-					stmt.executeUpdate();
-				} catch (Exception ex) {
-				}
-			} else {
-				problemIPs.add(NetUtils.long2Ip(startIP));
-			}
-        	startIP += 1;
-		}
+    }
+
+    private Vector<String> deletePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
+        String deleteSql = "DELETE FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND pod_id = ? AND data_center_id = ?";
+        String isPrivateIPAllocatedSelectSql = "SELECT * FROM `cloud`.`op_dc_ip_address_alloc` WHERE ip_address = ? AND data_center_id = ? AND pod_id = ?";
+
+        Vector<String> problemIPs = new Vector<String>();
+        PreparedStatement stmt = null;
+        PreparedStatement isAllocatedStmt = null;
+
+        Connection conn = null;
+        try {
+            conn = txn.getConnection();
+            stmt = conn.prepareStatement(deleteSql);
+            isAllocatedStmt = conn.prepareStatement(isPrivateIPAllocatedSelectSql);
+        } catch (SQLException e) {
+            System.out.println("Exception: " + e.getMessage());
+            printError("Unable to start DB connection to delete private IPs. Please contact Cloud Support.");
+        }
+
+        while (startIP <= endIP) {
+            if (!isPrivateIPAllocated(NetUtils.long2Ip(startIP), podId, zoneId, isAllocatedStmt)) {
+                try {
+                    stmt.clearParameters();
+                    stmt.setString(1, NetUtils.long2Ip(startIP));
+                    stmt.setLong(2, podId);
+                    stmt.setLong(3, zoneId);
+                    stmt.executeUpdate();
+                } catch (Exception ex) {
+                }
+            } else {
+                problemIPs.add(NetUtils.long2Ip(startIP));
+            }
+            startIP += 1;
+        }
 
         return problemIPs;
-	}
-	
-	private boolean isPublicIPAllocated(long ip, long vlanDbId, PreparedStatement stmt) {
-		try {
-        	stmt.clearParameters();
-        	stmt.setLong(1, ip);
-        	stmt.setLong(2, vlanDbId);
-        	ResultSet rs = stmt.executeQuery();
-        	if (rs.next()) {
+    }
+
+    private boolean isPublicIPAllocated(long ip, long vlanDbId, PreparedStatement stmt) {
+        try {
+            stmt.clearParameters();
+            stmt.setLong(1, ip);
+            stmt.setLong(2, vlanDbId);
+            ResultSet rs = stmt.executeQuery();
+            if (rs.next()) {
                 return (rs.getString("allocated") != null);
             } else {
                 return false;
             }
         } catch (SQLException ex) {
-        	System.out.println(ex.getMessage());
+            System.out.println(ex.getMessage());
             return true;
         }
-	}
-	
-	private boolean isPrivateIPAllocated(String ip, long podId, long zoneId, PreparedStatement stmt) {
-		try {
-			stmt.clearParameters();
-        	stmt.setString(1, ip);
-        	stmt.setLong(2, zoneId);
-        	stmt.setLong(3, podId);
-        	ResultSet rs = stmt.executeQuery();
-        	if (rs.next()) {
+    }
+
+    private boolean isPrivateIPAllocated(String ip, long podId, long zoneId, PreparedStatement stmt) {
+        try {
+            stmt.clearParameters();
+            stmt.setString(1, ip);
+            stmt.setLong(2, zoneId);
+            stmt.setLong(3, podId);
+            ResultSet rs = stmt.executeQuery();
+            if (rs.next()) {
                 return (rs.getString("taken") != null);
             } else {
                 return false;
             }
         } catch (SQLException ex) {
-        	System.out.println(ex.getMessage());
+            System.out.println(ex.getMessage());
             return true;
         }
-	}
-	
-	@DB
-	public List<String> saveIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP, Long sourceNetworkId, long physicalNetworkId) {
-    	long startIPLong = NetUtils.ip2Long(startIP);
-    	long endIPLong = startIPLong;
-    	if (endIP != null) {
+    }
+
+    @DB
+    public List<String> saveIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP, Long sourceNetworkId, long physicalNetworkId) {
+        long startIPLong = NetUtils.ip2Long(startIP);
+        long endIPLong = startIPLong;
+        if (endIP != null) {
             endIPLong = NetUtils.ip2Long(endIP);
         }
-    	
-    	Transaction txn = Transaction.currentTxn();
-    	List<String> problemIPs = null;
-    	
-    	if (type.equals("public")) {
+
+        Transaction txn = Transaction.currentTxn();
+        List<String> problemIPs = null;
+
+        if (type.equals("public")) {
             problemIPs = savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkId, physicalNetworkId);
         } else if (type.equals("private")) {
             problemIPs = savePrivateIPRange(txn, startIPLong, endIPLong, podId, zoneId);
         }
-    	
-    	String[] linkLocalIps = NetUtils.getLinkLocalIPRange(10);
-    	long startLinkLocalIp = NetUtils.ip2Long(linkLocalIps[0]);
-    	long endLinkLocalIp = NetUtils.ip2Long(linkLocalIps[1]);
-    	
-    	saveLinkLocalPrivateIPRange(txn, startLinkLocalIp,  endLinkLocalIp, podId, zoneId);
-    	
-    	return problemIPs;
+
+        String[] linkLocalIps = NetUtils.getLinkLocalIPRange(10);
+        long startLinkLocalIp = NetUtils.ip2Long(linkLocalIps[0]);
+        long endLinkLocalIp = NetUtils.ip2Long(linkLocalIps[1]);
+
+        saveLinkLocalPrivateIPRange(txn, startLinkLocalIp,  endLinkLocalIp, podId, zoneId);
+
+        return problemIPs;
     }
-	
-	public Vector<String> savePublicIPRange(Transaction txn, long startIP, long endIP, long zoneId, long vlanDbId, Long sourceNetworkId, long physicalNetworkId) {
-		String insertSql = "INSERT INTO `cloud`.`user_ip_address` (public_ip_address, data_center_id, vlan_db_id, mac_address, source_network_id, physical_network_id, uuid) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?), ?, ?, ?)";
-		String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
-		Vector<String> problemIPs = new Vector<String>();
-		PreparedStatement stmt = null;
-		
-		Connection conn = null;
-		try {
-			conn = txn.getConnection();
-		} catch (SQLException e) {
-			return null;
-		}
-        
+
+    public Vector<String> savePublicIPRange(Transaction txn, long startIP, long endIP, long zoneId, long vlanDbId, Long sourceNetworkId, long physicalNetworkId) {
+        String insertSql = "INSERT INTO `cloud`.`user_ip_address` (public_ip_address, data_center_id, vlan_db_id, mac_address, source_network_id, physical_network_id, uuid) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?), ?, ?, ?)";
+        String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
+        Vector<String> problemIPs = new Vector<String>();
+        PreparedStatement stmt = null;
+
+        Connection conn = null;
+        try {
+            conn = txn.getConnection();
+        } catch (SQLException e) {
+            return null;
+        }
+
         while (startIP <= endIP) {
             try {
-    		stmt = conn.prepareStatement(insertSql);
-    		stmt.setString(1, NetUtils.long2Ip(startIP));
-    		stmt.setLong(2, zoneId);
-    		stmt.setLong(3, vlanDbId);
-    		stmt.setLong(4, zoneId);
-    		stmt.setLong(5, sourceNetworkId);
-    		stmt.setLong(6, physicalNetworkId);
-    		stmt.setString(7, UUID.randomUUID().toString());
-    		stmt.executeUpdate();
-    		stmt.close();
-    		stmt = conn.prepareStatement(updateSql);
-    		stmt.setLong(1, zoneId);
-            stmt.executeUpdate();
-            stmt.close();
+                stmt = conn.prepareStatement(insertSql);
+                stmt.setString(1, NetUtils.long2Ip(startIP));
+                stmt.setLong(2, zoneId);
+                stmt.setLong(3, vlanDbId);
+                stmt.setLong(4, zoneId);
+                stmt.setLong(5, sourceNetworkId);
+                stmt.setLong(6, physicalNetworkId);
+                stmt.setString(7, UUID.randomUUID().toString());
+                stmt.executeUpdate();
+                stmt.close();
+                stmt = conn.prepareStatement(updateSql);
+                stmt.setLong(1, zoneId);
+                stmt.executeUpdate();
+                stmt.close();
             } catch (Exception ex) {
                 problemIPs.add(NetUtils.long2Ip(startIP));
             }
             startIP++;
         }
-        
+
         return problemIPs;
-	}
-	
-	public List<String> savePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
-		String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
+    }
+
+    public List<String> savePrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
+        String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
         String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
-		Vector<String> problemIPs = new Vector<String>();
-		
+        Vector<String> problemIPs = new Vector<String>();
+
         try {
             Connection conn = null;
             conn = txn.getConnection();
             while (startIP <= endIP) {
                 try {
                     PreparedStatement stmt = conn.prepareStatement(insertSql);
-            		stmt.setString(1, NetUtils.long2Ip(startIP));
-            		stmt.setLong(2, zoneId);
-            		stmt.setLong(3, podId);
-            		stmt.setLong(4, zoneId);
-            		stmt.executeUpdate();
-            		stmt.close();
+                    stmt.setString(1, NetUtils.long2Ip(startIP));
+                    stmt.setLong(2, zoneId);
+                    stmt.setLong(3, podId);
+                    stmt.setLong(4, zoneId);
+                    stmt.executeUpdate();
+                    stmt.close();
                     stmt = conn.prepareStatement(updateSql);
                     stmt.setLong(1, zoneId);
                     stmt.executeUpdate();
@@ -515,30 +515,30 @@ public class IPRangeConfig {
             System.out.print(ex.getMessage());
             ex.printStackTrace();
         } 
-        
+
         return problemIPs;
-	}
-	
-	private Vector<String> saveLinkLocalPrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
-		String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
-		Vector<String> problemIPs = new Vector<String>();
-		
-		Connection conn = null;
-		try {
-			conn = txn.getConnection();
-		} catch (SQLException e) {
-			System.out.println("Exception: " + e.getMessage());
-			printError("Unable to start DB connection to save private IPs. Please contact Cloud Support.");
-		}
-		
+    }
+
+    private Vector<String> saveLinkLocalPrivateIPRange(Transaction txn, long startIP, long endIP, long podId, long zoneId) {
+        String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
+        Vector<String> problemIPs = new Vector<String>();
+
+        Connection conn = null;
+        try {
+            conn = txn.getConnection();
+        } catch (SQLException e) {
+            System.out.println("Exception: " + e.getMessage());
+            printError("Unable to start DB connection to save private IPs. Please contact Cloud Support.");
+        }
+
         try {
             long start = startIP;
             PreparedStatement stmt = conn.prepareStatement(insertSql);
             while (startIP <= endIP) {
-        		stmt.setString(1, NetUtils.long2Ip(startIP++));
-        		stmt.setLong(2, zoneId);
-        		stmt.setLong(3, podId);
-        		stmt.addBatch();
+                stmt.setString(1, NetUtils.long2Ip(startIP++));
+                stmt.setLong(2, zoneId);
+                stmt.setLong(3, podId);
+                stmt.addBatch();
             }
             int[] results = stmt.executeBatch();
             for (int i = 0; i < results.length; i += 2) {
@@ -547,28 +547,28 @@ public class IPRangeConfig {
                 }
             }
             stmt.close();
-	    } catch (Exception ex) {
+        } catch (Exception ex) {
         }
-        
+
         return problemIPs;
-	}
-	
-	public static String getPublicNetmask(String zone) {
-		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"", "netmask",
-								"Unable to start DB connection to read public netmask. Please contact Cloud Support.");
-	}
-		
-	public static String getPublicGateway(String zone) {
-		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"", "gateway",
-								"Unable to start DB connection to read public gateway. Please contact Cloud Support.");
-	}
-	
-	public static String getGuestNetworkCidr(Long zoneId)
-	{
-		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id = \"" + zoneId + "\"","guest_network_cidr",
-				"Unable to start DB connection to read guest cidr network. Please contact Cloud Support.");
-	}
-	
+    }
+
+    public static String getPublicNetmask(String zone) {
+        return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"", "netmask",
+                "Unable to start DB connection to read public netmask. Please contact Cloud Support.");
+    }
+
+    public static String getPublicGateway(String zone) {
+        return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"", "gateway",
+                "Unable to start DB connection to read public gateway. Please contact Cloud Support.");
+    }
+
+    public static String getGuestNetworkCidr(Long zoneId)
+    {
+        return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id = \"" + zoneId + "\"","guest_network_cidr",
+                "Unable to start DB connection to read guest cidr network. Please contact Cloud Support.");
+    }
+
 //	public static String getGuestIpNetwork() {
 //		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`configuration` WHERE name = \"guest.ip.network\"", "value",
 //		"Unable to start DB connection to read guest IP network. Please contact Cloud Support.");
@@ -578,7 +578,7 @@ public class IPRangeConfig {
 //		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`configuration` WHERE name = \"guest.netmask\"", "value",
 //		"Unable to start DB connection to read guest netmask. Please contact Cloud Support.");
 //	}
-	
+
 //	public static String getGuestSubnet() {
 //		String guestIpNetwork = getGuestIpNetwork();
 //		String guestNetmask = getGuestNetmask();
@@ -593,9 +593,9 @@ public class IPRangeConfig {
 //		String guestNetmask = getGuestNetmask();
 //		return NetUtils.getCidrSize(guestNetmask);
 //	}
-	
-	public static boolean validCIDR(final String cidr) {
-		if (cidr == null || cidr.isEmpty()) {
+
+    public static boolean validCIDR(final String cidr) {
+        if (cidr == null || cidr.isEmpty()) {
             return false;
         }
         String[] cidrPair = cidr.split("\\/");
@@ -608,92 +608,92 @@ public class IPRangeConfig {
             return false;
         }
         int cidrSizeNum = -1;
-        
+
         try {
-        	cidrSizeNum = Integer.parseInt(cidrSize);
+            cidrSizeNum = Integer.parseInt(cidrSize);
         } catch (Exception e) {
-        	return false;
+            return false;
         }
-        
+
         if (cidrSizeNum < 1 || cidrSizeNum > 32) {
             return false;
         }
-        
+
         return true;
-	}
-	
-	public static boolean validOrBlankIP(final String ip) {
-	    if (ip == null || ip.isEmpty()) {
+    }
+
+    public static boolean validOrBlankIP(final String ip) {
+        if (ip == null || ip.isEmpty()) {
             return true;
         }
-	    return validIP(ip);
-	}
-	    
-	public static boolean validIP(final String ip) {
-		final String[] ipAsList = ip.split("\\.");
-		
-	    // The IP address must have four octets
-	    if (Array.getLength(ipAsList) != 4) {
-	    	return false;
-	    }
-	    
-	    for (int i = 0; i < 4; i++) {
-	    	// Each octet must be an integer
-	    	final String octetString = ipAsList[i];
-	    	int octet;
-	    	try {
-	    		octet = Integer.parseInt(octetString);
-	    	} catch(final Exception e) {
-	    		return false;
-	   		}
-	    	// Each octet must be between 0 and 255, inclusive
-	    	if (octet < 0 || octet > 255) {
+        return validIP(ip);
+    }
+
+    public static boolean validIP(final String ip) {
+        final String[] ipAsList = ip.split("\\.");
+
+        // The IP address must have four octets
+        if (Array.getLength(ipAsList) != 4) {
+            return false;
+        }
+
+        for (int i = 0; i < 4; i++) {
+            // Each octet must be an integer
+            final String octetString = ipAsList[i];
+            int octet;
+            try {
+                octet = Integer.parseInt(octetString);
+            } catch(final Exception e) {
+                return false;
+            }
+            // Each octet must be between 0 and 255, inclusive
+            if (octet < 0 || octet > 255) {
                 return false;
             }
 
-	    	// Each octetString must have between 1 and 3 characters
-	    	if (octetString.length() < 1 || octetString.length() > 3) {
+            // Each octetString must have between 1 and 3 characters
+            if (octetString.length() < 1 || octetString.length() > 3) {
                 return false;
             }
-	   		
-	   	}
-	    
-	   	// IP is good, return true
-		return true;
-	}
-	   
+
+        }
+
+        // IP is good, return true
+        return true;
+    }
+
     public static boolean validIPRange(String startIP, String endIP) {
-    	if (endIP == null || endIP.isEmpty()) {
+        if (endIP == null || endIP.isEmpty()) {
             return true;
         }
-    	
-    	long startIPLong = NetUtils.ip2Long(startIP);
-    	long endIPLong =  NetUtils.ip2Long(endIP);
-	   	return (startIPLong < endIPLong);
+
+        long startIPLong = NetUtils.ip2Long(startIP);
+        long endIPLong =  NetUtils.ip2Long(endIP);
+        return (startIPLong < endIPLong);
     }
-    
+
     public static boolean sameSubnet(final String ip1, final String ip2, final String netmask) {
-    	if (ip1 == null || ip1.isEmpty() || ip2 == null || ip2.isEmpty()) {
+        if (ip1 == null || ip1.isEmpty() || ip2 == null || ip2.isEmpty()) {
             return true;
         }
-    	String subnet1 = NetUtils.getSubNet(ip1, netmask);
-    	String subnet2 = NetUtils.getSubNet(ip2, netmask);
-    	
-    	return (subnet1.equals(subnet2));
+        String subnet1 = NetUtils.getSubNet(ip1, netmask);
+        String subnet2 = NetUtils.getSubNet(ip2, netmask);
+
+        return (subnet1.equals(subnet2));
     }
-    
+
     public static boolean sameSubnetCIDR(final String ip1, final String ip2, final long cidrSize) {
-    	if (ip1 == null || ip1.isEmpty() || ip2 == null || ip2.isEmpty()) {
+        if (ip1 == null || ip1.isEmpty() || ip2 == null || ip2.isEmpty()) {
             return true;
         }
-    	String subnet1 = NetUtils.getCidrSubNet(ip1, cidrSize);
-    	String subnet2 = NetUtils.getCidrSubNet(ip2, cidrSize);
-    	
-    	return (subnet1.equals(subnet2));
+        String subnet1 = NetUtils.getCidrSubNet(ip1, cidrSize);
+        String subnet2 = NetUtils.getCidrSubNet(ip2, cidrSize);
+
+        return (subnet1.equals(subnet2));
     }
-    
-	private static void printError(String message) {
-		DatabaseConfig.printError(message);
-	}
-	
+
+    private static void printError(String message) {
+        DatabaseConfig.printError(message);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/test/PodZoneConfig.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/test/PodZoneConfig.java b/server/src/com/cloud/test/PodZoneConfig.java
index 70ee0ac..59f8b6c 100644
--- a/server/src/com/cloud/test/PodZoneConfig.java
+++ b/server/src/com/cloud/test/PodZoneConfig.java
@@ -25,194 +25,194 @@ import java.util.List;
 import java.util.Vector;
 
 import com.cloud.network.Networks.TrafficType;
-
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.net.NetUtils;
 
 public class PodZoneConfig {
-	
-	public static void main(String[] args) {
-		PodZoneConfig config = ComponentLocator.inject(PodZoneConfig.class);
-		//config.run(args);
-		System.exit(0);
+
+    public static void main(String[] args) {
+        PodZoneConfig config = ComponentContext.inject(PodZoneConfig.class);
+        //config.run(args);
+        System.exit(0);
     }
-	
-	public void savePod(boolean printOutput, long id, String name, long dcId, String gateway, String cidr, int vlanStart, int vlanEnd) {
-		// Check that the cidr was valid
-		if (!IPRangeConfig.validCIDR(cidr)) printError("Please enter a valid CIDR for pod: " + name);
-		
-		// Get the individual cidrAddress and cidrSize values
-		String[] cidrPair = cidr.split("\\/");
-		String cidrAddress = cidrPair[0];
-		String cidrSize = cidrPair[1];
-
-		String sql = null;
-		if (id != -1) sql = "INSERT INTO `cloud`.`host_pod_ref` (id, name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + id + "','" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
-		else sql = "INSERT INTO `cloud`.`host_pod_ref` (name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
-			
+
+    public void savePod(boolean printOutput, long id, String name, long dcId, String gateway, String cidr, int vlanStart, int vlanEnd) {
+        // Check that the cidr was valid
+        if (!IPRangeConfig.validCIDR(cidr)) printError("Please enter a valid CIDR for pod: " + name);
+
+        // Get the individual cidrAddress and cidrSize values
+        String[] cidrPair = cidr.split("\\/");
+        String cidrAddress = cidrPair[0];
+        String cidrSize = cidrPair[1];
+
+        String sql = null;
+        if (id != -1) sql = "INSERT INTO `cloud`.`host_pod_ref` (id, name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + id + "','" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
+        else sql = "INSERT INTO `cloud`.`host_pod_ref` (name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
+
         DatabaseConfig.saveSQL(sql, "Failed to save pod due to exception. Please contact Cloud Support.");
-        
+
         if (printOutput) System.out.println("Successfuly saved pod.");
-	}
-	
-	public void checkAllPodCidrSubnets() {
-		Vector<Long> allZoneIDs = getAllZoneIDs();
-		for (Long dcId : allZoneIDs) {
-			HashMap<Long, Vector<Object>> currentPodCidrSubnets = getCurrentPodCidrSubnets(dcId.longValue());
-			String result = checkPodCidrSubnets(dcId.longValue(), currentPodCidrSubnets);
-			if (!result.equals("success")) printError(result);
-		}
-	}
-	
-	private String checkPodCidrSubnets(long dcId, HashMap<Long, Vector<Object>> currentPodCidrSubnets) {
-		
+    }
+
+    public void checkAllPodCidrSubnets() {
+        Vector<Long> allZoneIDs = getAllZoneIDs();
+        for (Long dcId : allZoneIDs) {
+            HashMap<Long, Vector<Object>> currentPodCidrSubnets = getCurrentPodCidrSubnets(dcId.longValue());
+            String result = checkPodCidrSubnets(dcId.longValue(), currentPodCidrSubnets);
+            if (!result.equals("success")) printError(result);
+        }
+    }
+
+    private String checkPodCidrSubnets(long dcId, HashMap<Long, Vector<Object>> currentPodCidrSubnets) {
+
 //		DataCenterDao _dcDao = null;
 //        final ComponentLocator locator = ComponentLocator.getLocator("management-server");
-        
+
 //        _dcDao = locator.getDao(DataCenterDao.class);
-		// For each pod, return an error if any of the following is true:
-		// 1. The pod's CIDR subnet conflicts with the guest network subnet
-		// 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod
-		
-		String zoneName  = PodZoneConfig.getZoneName(dcId);
-		
-		//get the guest network cidr and guest netmask from the zone
+        // For each pod, return an error if any of the following is true:
+        // 1. The pod's CIDR subnet conflicts with the guest network subnet
+        // 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod
+
+        String zoneName  = PodZoneConfig.getZoneName(dcId);
+
+        //get the guest network cidr and guest netmask from the zone
 //		DataCenterVO dcVo = _dcDao.findById(dcId);
-		
-		String guestNetworkCidr = IPRangeConfig.getGuestNetworkCidr(dcId);
-		
-		if (guestNetworkCidr == null || guestNetworkCidr.isEmpty()) return "Please specify a valid guest cidr";
+
+        String guestNetworkCidr = IPRangeConfig.getGuestNetworkCidr(dcId);
+
+        if (guestNetworkCidr == null || guestNetworkCidr.isEmpty()) return "Please specify a valid guest cidr";
         String[] cidrTuple = guestNetworkCidr.split("\\/");
-        
-		String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
-		long guestCidrSize = Long.parseLong(cidrTuple[1]);
-        
+
+        String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
+        long guestCidrSize = Long.parseLong(cidrTuple[1]);
+
         // Iterate through all pods in this zone
-		for (Long podId : currentPodCidrSubnets.keySet()) {
-			String podName;
-			if (podId.longValue() == -1) podName = "newPod";
-			else podName = PodZoneConfig.getPodName(podId.longValue(), dcId);
-			
-			Vector<Object> cidrPair = currentPodCidrSubnets.get(podId);
-			String cidrAddress = (String) cidrPair.get(0);
-			long cidrSize = ((Long) cidrPair.get(1)).longValue();
-			
-			long cidrSizeToUse = -1;
-			if (cidrSize < guestCidrSize) cidrSizeToUse = cidrSize;
-			else cidrSizeToUse = guestCidrSize;
-			
-			String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
-			String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse);
-			
-			// Check that cidrSubnet does not equal guestSubnet
-			if (cidrSubnet.equals(guestSubnet)) {
-				if (podName.equals("newPod")) {
-					return "The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR.";
-				} else {
-					return "Warning: The subnet of pod " + podName + " in zone " + zoneName + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management.";
-				}
-			}
-			
-			// Iterate through the rest of the pods
-			for (Long otherPodId : currentPodCidrSubnets.keySet()) {
-				if (podId.equals(otherPodId)) continue;
-				
-				// Check that cidrSubnet does not equal otherCidrSubnet
-				Vector<Object> otherCidrPair = currentPodCidrSubnets.get(otherPodId);
-				String otherCidrAddress = (String) otherCidrPair.get(0);
-				long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue();
-				
-				if (cidrSize < otherCidrSize) cidrSizeToUse = cidrSize;
-				else cidrSizeToUse = otherCidrSize;
-				
-				cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
-				String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse);
-				
-				if (cidrSubnet.equals(otherCidrSubnet)) {
-					String otherPodName = PodZoneConfig.getPodName(otherPodId.longValue(), dcId);
-					if (podName.equals("newPod")) {
-						return "The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR.";
-					} else {
-						return "Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods.";
-					}
-				}
-			}
-		}
-		
-		return "success";
-	}
-	
-	@DB
-	protected HashMap<Long, Vector<Object>> getCurrentPodCidrSubnets(long dcId) {
-		HashMap<Long, Vector<Object>> currentPodCidrSubnets = new HashMap<Long, Vector<Object>>();
-		
-		String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + dcId;
-		Transaction txn = Transaction.currentTxn();
-		try {
-        	PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
-        	ResultSet rs = stmt.executeQuery();
-        	while (rs.next()) {
-        		Long podId = rs.getLong("id");
-        		String cidrAddress = rs.getString("cidr_address");
-        		long cidrSize = rs.getLong("cidr_size");
-        		Vector<Object> cidrPair = new Vector<Object>();
-        		cidrPair.add(0, cidrAddress);
-        		cidrPair.add(1, new Long(cidrSize));
-        		currentPodCidrSubnets.put(podId, cidrPair);
-        	}
+        for (Long podId : currentPodCidrSubnets.keySet()) {
+            String podName;
+            if (podId.longValue() == -1) podName = "newPod";
+            else podName = PodZoneConfig.getPodName(podId.longValue(), dcId);
+
+            Vector<Object> cidrPair = currentPodCidrSubnets.get(podId);
+            String cidrAddress = (String) cidrPair.get(0);
+            long cidrSize = ((Long) cidrPair.get(1)).longValue();
+
+            long cidrSizeToUse = -1;
+            if (cidrSize < guestCidrSize) cidrSizeToUse = cidrSize;
+            else cidrSizeToUse = guestCidrSize;
+
+            String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
+            String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse);
+
+            // Check that cidrSubnet does not equal guestSubnet
+            if (cidrSubnet.equals(guestSubnet)) {
+                if (podName.equals("newPod")) {
+                    return "The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR.";
+                } else {
+                    return "Warning: The subnet of pod " + podName + " in zone " + zoneName + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management.";
+                }
+            }
+
+            // Iterate through the rest of the pods
+            for (Long otherPodId : currentPodCidrSubnets.keySet()) {
+                if (podId.equals(otherPodId)) continue;
+
+                // Check that cidrSubnet does not equal otherCidrSubnet
+                Vector<Object> otherCidrPair = currentPodCidrSubnets.get(otherPodId);
+                String otherCidrAddress = (String) otherCidrPair.get(0);
+                long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue();
+
+                if (cidrSize < otherCidrSize) cidrSizeToUse = cidrSize;
+                else cidrSizeToUse = otherCidrSize;
+
+                cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
+                String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse);
+
+                if (cidrSubnet.equals(otherCidrSubnet)) {
+                    String otherPodName = PodZoneConfig.getPodName(otherPodId.longValue(), dcId);
+                    if (podName.equals("newPod")) {
+                        return "The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR.";
+                    } else {
+                        return "Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods.";
+                    }
+                }
+            }
+        }
+
+        return "success";
+    }
+
+    @DB
+    protected HashMap<Long, Vector<Object>> getCurrentPodCidrSubnets(long dcId) {
+        HashMap<Long, Vector<Object>> currentPodCidrSubnets = new HashMap<Long, Vector<Object>>();
+
+        String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + dcId;
+        Transaction txn = Transaction.currentTxn();
+        try {
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
+            ResultSet rs = stmt.executeQuery();
+            while (rs.next()) {
+                Long podId = rs.getLong("id");
+                String cidrAddress = rs.getString("cidr_address");
+                long cidrSize = rs.getLong("cidr_size");
+                Vector<Object> cidrPair = new Vector<Object>();
+                cidrPair.add(0, cidrAddress);
+                cidrPair.add(1, new Long(cidrSize));
+                currentPodCidrSubnets.put(podId, cidrPair);
+            }
         } catch (SQLException ex) {
-        	System.out.println(ex.getMessage());
-        	printError("There was an issue with reading currently saved pod CIDR subnets. Please contact Cloud Support.");
+            System.out.println(ex.getMessage());
+            printError("There was an issue with reading currently saved pod CIDR subnets. Please contact Cloud Support.");
             return null;
         }
-        
+
         return currentPodCidrSubnets;
-	}
-	
-	public void deletePod(String name, long dcId) {
-		String sql = "DELETE FROM `cloud`.`host_pod_ref` WHERE name=\"" + name + "\" AND data_center_id=\"" + dcId + "\"";
-		DatabaseConfig.saveSQL(sql, "Failed to delete pod due to exception. Please contact Cloud Support.");
-	}
-	
-	public long getVlanDbId(String zone, String vlanId) {
-		long zoneId = getZoneId(zone);
-		
-		return DatabaseConfig.getDatabaseValueLong("SELECT * FROM `cloud`.`vlan` WHERE data_center_id=\"" + zoneId + "\" AND vlan_id =\"" + vlanId + "\"", "id",
-		"Unable to start DB connection to read vlan DB id. Please contact Cloud Support.");
     }
-	
-	public List<String> modifyVlan(String zone, boolean add, String vlanId, String vlanGateway, String vlanNetmask, String pod, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
-    	// Check if the zone is valid
-    	long zoneId = getZoneId(zone);
-    	if (zoneId == -1)
-    		return genReturnList("false", "Please specify a valid zone.");
-    	
-    	//check if physical network is valid
+
+    public void deletePod(String name, long dcId) {
+        String sql = "DELETE FROM `cloud`.`host_pod_ref` WHERE name=\"" + name + "\" AND data_center_id=\"" + dcId + "\"";
+        DatabaseConfig.saveSQL(sql, "Failed to delete pod due to exception. Please contact Cloud Support.");
+    }
+
+    public long getVlanDbId(String zone, String vlanId) {
+        long zoneId = getZoneId(zone);
+
+        return DatabaseConfig.getDatabaseValueLong("SELECT * FROM `cloud`.`vlan` WHERE data_center_id=\"" + zoneId + "\" AND vlan_id =\"" + vlanId + "\"", "id",
+                "Unable to start DB connection to read vlan DB id. Please contact Cloud Support.");
+    }
+
+    public List<String> modifyVlan(String zone, boolean add, String vlanId, String vlanGateway, String vlanNetmask, String pod, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
+        // Check if the zone is valid
+        long zoneId = getZoneId(zone);
+        if (zoneId == -1)
+            return genReturnList("false", "Please specify a valid zone.");
+
+        //check if physical network is valid
         long physicalNetworkDbId = checkPhysicalNetwork(physicalNetworkId);
         if (physicalNetworkId == -1)
             return genReturnList("false", "Please specify a valid physical network.");
-    	
-    	
-    	Long podId = pod!=null?getPodId(pod, zone):null;
-    	if (podId != null && podId == -1)
-    		return genReturnList("false", "Please specify a valid pod.");
-    	
-    	if (add) {
-    		
-    		// Make sure the gateway is valid
-    		if (!NetUtils.isValidIp(vlanGateway))
-    			return genReturnList("false", "Please specify a valid gateway.");
-    		
-    		// Make sure the netmask is valid
-    		if (!NetUtils.isValidIp(vlanNetmask))
-    			return genReturnList("false", "Please specify a valid netmask.");
-    		
-    		// Check if a vlan with the same vlanId already exists in the specified zone
-    		if (getVlanDbId(zone, vlanId) != -1)
-    			return genReturnList("false", "A VLAN with the specified VLAN ID already exists in zone " + zone + ".");
-    		
-    		/*
+
+
+        Long podId = pod!=null?getPodId(pod, zone):null;
+        if (podId != null && podId == -1)
+            return genReturnList("false", "Please specify a valid pod.");
+
+        if (add) {
+
+            // Make sure the gateway is valid
+            if (!NetUtils.isValidIp(vlanGateway))
+                return genReturnList("false", "Please specify a valid gateway.");
+
+            // Make sure the netmask is valid
+            if (!NetUtils.isValidIp(vlanNetmask))
+                return genReturnList("false", "Please specify a valid netmask.");
+
+            // Check if a vlan with the same vlanId already exists in the specified zone
+            if (getVlanDbId(zone, vlanId) != -1)
+                return genReturnList("false", "A VLAN with the specified VLAN ID already exists in zone " + zone + ".");
+
+            /*
     		// Check if another vlan in the same zone has the same subnet
     		String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask);
     		List<VlanVO> vlans = _vlanDao.findByZone(zoneId);
@@ -221,146 +221,146 @@ public class PodZoneConfig {
     			if (newVlanSubnet.equals(currentVlanSubnet))
     				return genReturnList("false", "The VLAN with ID " + vlan.getVlanId() + " in zone " + zone + " has the same subnet. Please specify a different gateway/netmask.");
     		}
-    		*/
-    		
-    		// Everything was fine, so persist the VLAN
-    		saveVlan(zoneId, podId, vlanId, vlanGateway, vlanNetmask, vlanType, ipRange, networkId, physicalNetworkDbId);
+             */
+
+            // Everything was fine, so persist the VLAN
+            saveVlan(zoneId, podId, vlanId, vlanGateway, vlanNetmask, vlanType, ipRange, networkId, physicalNetworkDbId);
             if (podId != null) {
-            	long vlanDbId = getVlanDbId(zone, vlanId);
-            	String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES ('" + podId + "','" + vlanDbId  + "')";
+                long vlanDbId = getVlanDbId(zone, vlanId);
+                String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES ('" + podId + "','" + vlanDbId  + "')";
                 DatabaseConfig.saveSQL(sql, "Failed to save pod_vlan_map due to exception vlanDbId=" + vlanDbId + ", podId=" + podId + ". Please contact Cloud Support.");
             }
-    		
-    		return genReturnList("true", "Successfully added VLAN.");
-    		
-    	} else {
-    		return genReturnList("false", "That operation is not suppored.");
-    	}
-    	
-    	/*
+
+            return genReturnList("true", "Successfully added VLAN.");
+
+        } else {
+            return genReturnList("false", "That operation is not suppored.");
+        }
+
+        /*
     	else {
-    		
+
     		// Check if a VLAN actually exists in the specified zone
     		long vlanDbId = getVlanDbId(zone, vlanId);
     		if (vlanDbId == -1)
     			return genReturnList("false", "A VLAN with ID " + vlanId + " does not exist in zone " + zone);
-    		
+
     		// Check if there are any public IPs that are in the specified vlan.
     		List<IPAddressVO> ips = _publicIpAddressDao.listByVlanDbId(vlanDbId);
     		if (ips.size() != 0)
     			return genReturnList("false", "Please delete all IP addresses that are in VLAN " + vlanId + " before deleting the VLAN.");
-    		
+
     		// Delete the vlan
     		_vlanDao.delete(vlanDbId);
-    		
+
     		return genReturnList("true", "Successfully deleted VLAN.");
     	}
-    	*/
+         */
     }
-	
-	@DB
-	public void saveZone(boolean printOutput, long id, String name, String dns1, String dns2, String dns3, String dns4, String guestNetworkCidr, String networkType) {
-		
-		if (printOutput) System.out.println("Saving zone, please wait...");
-		
-		String columns = null;
-		String values = null;
-		
-		if (id != -1) {
-			columns = "(id, name";
-			values = "('" + id + "','" + name + "'";
-		} else {
-			columns = "(name";
-			values = "('" + name + "'";
-		}
-
-		if (dns1 != null) {
-			columns += ", dns1";
-			values += ",'" + dns1 + "'";
-		}
-		
-		if (dns2 != null) {
-			columns += ", dns2";
-			values += ",'" + dns2 + "'";
-		}
-		
-		if (dns3 != null) {
-			columns += ", internal_dns1";
-			values += ",'" + dns3 + "'";
-		}
-		
-		if (dns4 != null) {
-			columns += ", internal_dns2";
-			values += ",'" + dns4 + "'";
-		}
-		
-		if(guestNetworkCidr != null) {
-			columns += ", guest_network_cidr";
-			values += ",'" + guestNetworkCidr + "'";
-		}
-		
-		if(networkType != null) {
-			columns += ", networktype";
-			values += ",'" + networkType + "'";
-		}
-		
+
+    @DB
+    public void saveZone(boolean printOutput, long id, String name, String dns1, String dns2, String dns3, String dns4, String guestNetworkCidr, String networkType) {
+
+        if (printOutput) System.out.println("Saving zone, please wait...");
+
+        String columns = null;
+        String values = null;
+
+        if (id != -1) {
+            columns = "(id, name";
+            values = "('" + id + "','" + name + "'";
+        } else {
+            columns = "(name";
+            values = "('" + name + "'";
+        }
+
+        if (dns1 != null) {
+            columns += ", dns1";
+            values += ",'" + dns1 + "'";
+        }
+
+        if (dns2 != null) {
+            columns += ", dns2";
+            values += ",'" + dns2 + "'";
+        }
+
+        if (dns3 != null) {
+            columns += ", internal_dns1";
+            values += ",'" + dns3 + "'";
+        }
+
+        if (dns4 != null) {
+            columns += ", internal_dns2";
+            values += ",'" + dns4 + "'";
+        }
+
+        if(guestNetworkCidr != null) {
+            columns += ", guest_network_cidr";
+            values += ",'" + guestNetworkCidr + "'";
+        }
+
+        if(networkType != null) {
+            columns += ", networktype";
+            values += ",'" + networkType + "'";
+        }
+
         columns += ", uuid";
         values += ", UUID()";
-			
-		columns += ")";
-		values += ")";
-		
-		String sql = "INSERT INTO `cloud`.`data_center` " + columns +  " VALUES " + values;
-		
-		DatabaseConfig.saveSQL(sql, "Failed to save zone due to exception. Please contact Cloud Support.");
-		
-		if (printOutput) System.out.println("Successfully saved zone.");
-	}
-	
-	@DB
+
+        columns += ")";
+        values += ")";
+
+        String sql = "INSERT INTO `cloud`.`data_center` " + columns +  " VALUES " + values;
+
+        DatabaseConfig.saveSQL(sql, "Failed to save zone due to exception. Please contact Cloud Support.");
+
+        if (printOutput) System.out.println("Successfully saved zone.");
+    }
+
+    @DB
     public void savePhysicalNetwork(boolean printOutput, long id, long dcId, int vnetStart, int vnetEnd) {
-        
+
         if (printOutput) System.out.println("Saving physical network, please wait...");
-        
+
         String columns = null;
         String values = null;
-        
+
         columns = "(id ";
         values = "('" + id + "'";
-        
+
         columns += ", name ";
         values += ",'physical network'";
-        
+
         columns += ", data_center_id ";
         values += ",'" + dcId + "'";
-        
+
         //save vnet information
         columns += ", vnet";
         values += ",'" + vnetStart + "-" + vnetEnd + "'";
-            
+
         columns += ", state";
         values += ", 'Enabled'";
-        
+
         columns += ", uuid";
         values += ", UUID()";
-            
+
         columns += ")";
         values += ")";
-        
+
         String sql = "INSERT INTO `cloud`.`physical_network` " + columns +  " VALUES " + values;
-        
+
         DatabaseConfig.saveSQL(sql, "Failed to save physical network due to exception. Please contact Cloud Support.");
-        
+
         // Hardcode the vnet range to be the full range
         int begin = 0x64;
         int end = 64000;
-        
+
         // If vnet arguments were passed in, use them
         if (vnetStart != -1 && vnetEnd != -1) {
             begin = vnetStart;
             end = vnetEnd;
         }
-        
+
         String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id, physical_network_id) VALUES ( ?, ?, ?)";
 
         Transaction txn = Transaction.currentTxn();
@@ -376,17 +376,17 @@ public class PodZoneConfig {
         } catch (SQLException ex) {
             printError("Error creating vnet for the physical network. Please contact Cloud Support.");
         }
-        
+
         //add default traffic types
-        
+
         //get default Xen network labels
         String defaultXenPrivateNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Management);
         String defaultXenPublicNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Public);
         String defaultXenStorageNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Storage);
         String defaultXenGuestNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Guest);
-        
+
         String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` " +
-        		"(physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)";
+                "(physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)";
 
         try {
             PreparedStatement stmt = txn.prepareAutoCloseStatement(insertTraficType);
@@ -406,128 +406,128 @@ public class PodZoneConfig {
                 }else if(traffic.equals(TrafficType.Guest)){
                     stmt.setString(3, defaultXenGuestNetworkLabel);
                 }
-                
+
                 stmt.addBatch();
             }
             stmt.executeBatch();
         } catch (SQLException ex) {
             printError("Error adding default traffic types for the physical network. Please contact Cloud Support.");
         }
-        
+
         if (printOutput) System.out.println("Successfully saved physical network.");
     }
-	
+
     private String getDefaultXenNetworkLabel(TrafficType trafficType){
         String xenLabel = null;
         String configName = null;
         switch(trafficType){
-            case Public: configName = "xen.public.network.device";
-            break;
-            case Guest: configName = "xen.guest.network.device";
-            break;
-            case Storage: configName = "xen.storage.network.device1";
-            break;
-            case Management: configName = "xen.private.network.device";
-            break;
+        case Public: configName = "xen.public.network.device";
+        break;
+        case Guest: configName = "xen.guest.network.device";
+        break;
+        case Storage: configName = "xen.storage.network.device1";
+        break;
+        case Management: configName = "xen.private.network.device";
+        break;
         }
-        
+
         if(configName != null){
             xenLabel = getConfiguredValue(configName);
         }
         return xenLabel;
     }
-    
+
     public static String getConfiguredValue(String configName)
     {
         return DatabaseConfig.getDatabaseValueString("SELECT value FROM `cloud`.`configuration` where name = \"" + configName + "\"","value",
                 "Unable to start DB connection to read configuration. Please contact Cloud Support.");
     }
-	
-	public void deleteZone(String name) {
-		String sql = "DELETE FROM `cloud`.`data_center` WHERE name=\"" + name + "\"";
-		DatabaseConfig.saveSQL(sql, "Failed to delete zone due to exception. Please contact Cloud Support.");
-	}
-	
-	public void saveVlan(long zoneId, Long podId, String vlanId, String vlanGateway, String vlanNetmask, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
-		String sql = "INSERT INTO `cloud`.`vlan` (vlan_id, vlan_gateway, vlan_netmask, data_center_id, vlan_type, description, network_id, physical_network_id) " + "VALUES ('" + vlanId + "','" + vlanGateway + "','" + vlanNetmask + "','" + zoneId + "','" + vlanType + "','" + ipRange +  "','" + networkId +  "','" + physicalNetworkId + "')";
+
+    public void deleteZone(String name) {
+        String sql = "DELETE FROM `cloud`.`data_center` WHERE name=\"" + name + "\"";
+        DatabaseConfig.saveSQL(sql, "Failed to delete zone due to exception. Please contact Cloud Support.");
+    }
+
+    public void saveVlan(long zoneId, Long podId, String vlanId, String vlanGateway, String vlanNetmask, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
+        String sql = "INSERT INTO `cloud`.`vlan` (vlan_id, vlan_gateway, vlan_netmask, data_center_id, vlan_type, description, network_id, physical_network_id) " + "VALUES ('" + vlanId + "','" + vlanGateway + "','" + vlanNetmask + "','" + zoneId + "','" + vlanType + "','" + ipRange +  "','" + networkId +  "','" + physicalNetworkId + "')";
         DatabaseConfig.saveSQL(sql, "Failed to save vlan due to exception. Please contact Cloud Support.");
-	}
-	
-	public static long getPodId(String pod, String zone) {
-		long dcId = getZoneId(zone);
-		String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
-		String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
-		return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
-	}
-	
-	public static long getPodId(String pod, long dcId) {
+    }
+
+    public static long getPodId(String pod, String zone) {
+        long dcId = getZoneId(zone);
         String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
         String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
         return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
     }
-	
-	public static long getZoneId(String zone) {
-		String selectSql = "SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"";
-		String errorMsg = "Could not read zone ID from database. Please contact Cloud Support.";
-		return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
-	}
-	
+
+    public static long getPodId(String pod, long dcId) {
+        String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
+        String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
+        return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
+    }
+
+    public static long getZoneId(String zone) {
+        String selectSql = "SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"";
+        String errorMsg = "Could not read zone ID from database. Please contact Cloud Support.";
+        return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
+    }
+
     public static long checkPhysicalNetwork(long physicalNetworkId) {
         String selectSql = "SELECT * FROM `cloud`.`physical_network` WHERE id = \"" + physicalNetworkId + "\"";
         String errorMsg = "Could not read physicalNetwork ID from database. Please contact Cloud Support.";
         return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
     }	
-	
-	@DB
-	public Vector<Long> getAllZoneIDs() {
-		Vector<Long> allZoneIDs = new Vector<Long>();
-		
-		String selectSql = "SELECT id FROM data_center";
-		Transaction txn = Transaction.currentTxn();
-		try {
-        	PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
-        	ResultSet rs = stmt.executeQuery();
-        	while (rs.next()) {
-        		Long dcId = rs.getLong("id");
-        		allZoneIDs.add(dcId);
-        	}
+
+    @DB
+    public Vector<Long> getAllZoneIDs() {
+        Vector<Long> allZoneIDs = new Vector<Long>();
+
+        String selectSql = "SELECT id FROM data_center";
+        Transaction txn = Transaction.currentTxn();
+        try {
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
+            ResultSet rs = stmt.executeQuery();
+            while (rs.next()) {
+                Long dcId = rs.getLong("id");
+                allZoneIDs.add(dcId);
+            }
         } catch (SQLException ex) {
-        	System.out.println(ex.getMessage());
-        	printError("There was an issue with reading zone IDs. Please contact Cloud Support.");
+            System.out.println(ex.getMessage());
+            printError("There was an issue with reading zone IDs. Please contact Cloud Support.");
             return null;
         }
-        
+
         return allZoneIDs;
-	}
-	
-	
-	public static boolean validPod(String pod, String zone) {
-		return (getPodId(pod, zone) != -1);
-	}
-	
-	public static boolean validZone(String zone) {
-		return (getZoneId(zone) != -1);
-	}
-	
-	public static String getPodName(long podId, long dcId) {
-		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`host_pod_ref` WHERE id=" + podId + " AND data_center_id=" + dcId, "name",
-		"Unable to start DB connection to read pod name. Please contact Cloud Support.");
-	}
-	
-	public static String getZoneName(long dcId) {
-		return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id=" + dcId, "name",
-		"Unable to start DB connection to read zone name. Please contact Cloud Support.");
-	}
-	
-	private static void printError(String message) {
-		DatabaseConfig.printError(message);
-	}
-	
-	private List<String> genReturnList(String success, String message) {
-    	List<String> returnList = new ArrayList<String>();
-    	returnList.add(0, success);
-    	returnList.add(1, message);
-    	return returnList;
     }
-	
+
+
+    public static boolean validPod(String pod, String zone) {
+        return (getPodId(pod, zone) != -1);
+    }
+
+    public static boolean validZone(String zone) {
+        return (getZoneId(zone) != -1);
+    }
+
+    public static String getPodName(long podId, long dcId) {
+        return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`host_pod_ref` WHERE id=" + podId + " AND data_center_id=" + dcId, "name",
+                "Unable to start DB connection to read pod name. Please contact Cloud Support.");
+    }
+
+    public static String getZoneName(long dcId) {
+        return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id=" + dcId, "name",
+                "Unable to start DB connection to read zone name. Please contact Cloud Support.");
+    }
+
+    private static void printError(String message) {
+        DatabaseConfig.printError(message);
+    }
+
+    private List<String> genReturnList(String success, String message) {
+        List<String> returnList = new ArrayList<String>();
+        returnList.add(0, success);
+        returnList.add(1, message);
+        return returnList;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/vm/SystemVmLoadScanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/SystemVmLoadScanner.java b/server/src/com/cloud/vm/SystemVmLoadScanner.java
index 174d8c7..4251b40 100644
--- a/server/src/com/cloud/vm/SystemVmLoadScanner.java
+++ b/server/src/com/cloud/vm/SystemVmLoadScanner.java
@@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.log4j.Logger;
 
-import com.cloud.cluster.StackMaid;
 import com.cloud.utils.Pair;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.GlobalLock;
@@ -32,27 +31,27 @@ import com.cloud.utils.db.Transaction;
 // TODO: simple load scanner, to minimize code changes required in console proxy manager and SSVM, we still leave most of work at handler
 //
 public class SystemVmLoadScanner<T> {
-	public enum AfterScanAction { nop, expand, shrink }
-	
+    public enum AfterScanAction { nop, expand, shrink }
+
     private static final Logger s_logger = Logger.getLogger(SystemVmLoadScanner.class);
 
     private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3;   // 3 seconds
-    
-	private final SystemVmLoadScanHandler<T> _scanHandler;
+
+    private final SystemVmLoadScanHandler<T> _scanHandler;
     private final ScheduledExecutorService _capacityScanScheduler;
     private final GlobalLock _capacityScanLock;
-	
-	public SystemVmLoadScanner(SystemVmLoadScanHandler<T> scanHandler) {
-		_scanHandler = scanHandler;
-		_capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(scanHandler.getScanHandlerName()));
-		_capacityScanLock = GlobalLock.getInternLock(scanHandler.getScanHandlerName() + ".scan.lock");
-	}
-	
-	public void initScan(long startupDelayMs, long scanIntervalMs) {
+
+    public SystemVmLoadScanner(SystemVmLoadScanHandler<T> scanHandler) {
+        _scanHandler = scanHandler;
+        _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(scanHandler.getScanHandlerName()));
+        _capacityScanLock = GlobalLock.getInternLock(scanHandler.getScanHandlerName() + ".scan.lock");
+    }
+
+    public void initScan(long startupDelayMs, long scanIntervalMs) {
         _capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), startupDelayMs, scanIntervalMs, TimeUnit.MILLISECONDS);
-	}
-	
-	public void stop() {
+    }
+
+    public void stop() {
         _capacityScanScheduler.shutdownNow();
 
         try {
@@ -61,8 +60,8 @@ public class SystemVmLoadScanner<T> {
         }
 
         _capacityScanLock.releaseRef();
-	}
-	
+    }
+
     private Runnable getCapacityScanTask() {
         return new Runnable() {
 
@@ -74,56 +73,55 @@ public class SystemVmLoadScanner<T> {
                 } catch (Throwable e) {
                     s_logger.warn("Unexpected exception " + e.getMessage(), e);
                 } finally {
-                    StackMaid.current().exitCleanup();
                     txn.close();
                 }
             }
 
             private void reallyRun() {
-            	loadScan();
+                loadScan();
             }
         };
     }
-    
+
     private void loadScan() {
-    	if(!_scanHandler.canScan()) {
-    		return;
-    	}
-    	
+        if(!_scanHandler.canScan()) {
+            return;
+        }
+
         if (!_capacityScanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
             if (s_logger.isTraceEnabled()) {
                 s_logger.trace("Capacity scan lock is used by others, skip and wait for my turn");
             }
             return;
         }
-        
+
         try {
-	    	_scanHandler.onScanStart();
-	
-	    	T[] pools = _scanHandler.getScannablePools();
-	    	for(T p : pools) {
-	    		if(_scanHandler.isPoolReadyForScan(p)) {
-	    			Pair<AfterScanAction, Object> actionInfo = _scanHandler.scanPool(p);
-	    			
-	    			switch(actionInfo.first()) {
-	    			case nop:
-	    				break;
-	    				
-	    			case expand:
-	    				_scanHandler.expandPool(p, actionInfo.second());
-	    				break;
-	    				
-	    			case shrink:
-	    				_scanHandler.shrinkPool(p, actionInfo.second());
-	    				break;
-	    			}
-	    		}
-	    	}
-	    	
-	    	_scanHandler.onScanEnd();
-    	
+            _scanHandler.onScanStart();
+
+            T[] pools = _scanHandler.getScannablePools();
+            for(T p : pools) {
+                if(_scanHandler.isPoolReadyForScan(p)) {
+                    Pair<AfterScanAction, Object> actionInfo = _scanHandler.scanPool(p);
+
+                    switch(actionInfo.first()) {
+                    case nop:
+                        break;
+
+                    case expand:
+                        _scanHandler.expandPool(p, actionInfo.second());
+                        break;
+
+                    case shrink:
+                        _scanHandler.shrinkPool(p, actionInfo.second());
+                        break;
+                    }
+                }
+            }
+
+            _scanHandler.onScanEnd();
+
         } finally {
-        	_capacityScanLock.unlock();
+            _capacityScanLock.unlock();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 1972304..ac14e77 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -214,7 +214,6 @@ import com.cloud.uservm.UserVm;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.PasswordGenerator;
-
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.crypt.RSAHelper;
@@ -381,7 +380,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
     protected String _instance;
     protected String _zone;
 
-    private ConfigurationDao _configDao;
+    @Inject ConfigurationDao _configDao;
     private int _createprivatetemplatefromvolumewait;
     private int _createprivatetemplatefromsnapshotwait;
 
@@ -1333,8 +1332,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             throws ConfigurationException {
         _name = name;
 
-        ComponentLocator locator = ComponentLocator.getCurrentLocator();
-        _configDao = locator.getDao(ConfigurationDao.class);
         if (_configDao == null) {
             throw new ConfigurationException(
                     "Unable to get the configuration dao.");