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/12/12 22:01:19 UTC

[19/48] All Checkstyle problems corrected

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 3596f8d..7a02f3b 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -301,7 +301,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     private String _ovsPvlanDhcpHostPath;
     private String _ovsPvlanVmPath;
     private String _routerProxyPath;
-	private String _ovsTunnelPath;
+    private String _ovsTunnelPath;
     private String _host;
     private String _dcId;
     private String _pod;
@@ -311,9 +311,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     private long _hvVersion;
     private long _kernelVersion;
     private KVMHAMonitor _monitor;
-    private final String _SSHKEYSPATH = "/root/.ssh";
-    private final String _SSHPRVKEYPATH = _SSHKEYSPATH + File.separator + "id_rsa.cloud";
-    private final String _SSHPUBKEYPATH = _SSHKEYSPATH + File.separator + "id_rsa.pub.cloud";
+    private static final String SSHKEYSPATH = "/root/.ssh";
+    private static final String SSHPRVKEYPATH = SSHKEYSPATH + File.separator + "id_rsa.cloud";
+    private static final String SSHPUBKEYPATH = SSHKEYSPATH + File.separator + "id_rsa.pub.cloud";
     private String _mountPoint = "/mnt";
     StorageLayer _storage;
     private KVMStoragePoolManager _storagePoolMgr;
@@ -355,7 +355,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         return null;
     }
 
-    protected static MessageFormat SnapshotXML = new MessageFormat("   <domainsnapshot>" + "       <name>{0}</name>" + "          <domain>"
+    protected static final MessageFormat SnapshotXML = new MessageFormat("   <domainsnapshot>" + "       <name>{0}</name>" + "          <domain>"
         + "            <uuid>{1}</uuid>" + "        </domain>" + "    </domainsnapshot>");
 
     protected HypervisorType _hypervisorType;
@@ -374,13 +374,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     protected String _privateIp;
     protected String _pool;
     protected String _localGateway;
-    private boolean _can_bridge_firewall;
+    private boolean _canBridgeFirewall;
     protected String _localStoragePath;
     protected String _localStorageUUID;
     protected String _guestCpuMode;
     protected String _guestCpuModel;
     private final Map<String, String> _pifs = new HashMap<String, String>();
-    private final Map<String, vmStats> _vmStats = new ConcurrentHashMap<String, vmStats>();
+    private final Map<String, VmStats> _vmStats = new ConcurrentHashMap<String, VmStats>();
 
     protected boolean _disconnected = true;
     protected int _timeout;
@@ -607,10 +607,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             throw new ConfigurationException("Unable to find the security_group.py");
         }
 
-	_ovsTunnelPath = Script.findScript(networkScriptsDir, "ovstunnel.py");
-	if (_ovsTunnelPath == null) {
-		throw new ConfigurationException("Unable to find the ovstunnel.py");
-	}
+        _ovsTunnelPath = Script.findScript(networkScriptsDir, "ovstunnel.py");
+        if (_ovsTunnelPath == null) {
+            throw new ConfigurationException("Unable to find the ovstunnel.py");
+        }
 
         _routerProxyPath = Script.findScript("scripts/network/domr/", "router_proxy.sh");
         if (_routerProxyPath == null) {
@@ -816,7 +816,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         }
         s_logger.debug("Found pif: " + _pifs.get("private") + " on " + _privBridgeName + ", pif: " + _pifs.get("public") + " on " + _publicBridgeName);
 
-        _can_bridge_firewall = can_bridge_firewall(_pifs.get("public"));
+        _canBridgeFirewall = can_bridge_firewall(_pifs.get("public"));
 
         _localGateway = Script.runSimpleBashScript("ip route |grep default|awk '{print $3}'");
         if (_localGateway == null) {
@@ -1284,17 +1284,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 return execute((SetMonitorServiceCommand)cmd);
             } else if (cmd instanceof CheckOnHostCommand) {
                 return execute((CheckOnHostCommand)cmd);
-	    } else if (cmd instanceof OvsFetchInterfaceCommand) {
-		return execute((OvsFetchInterfaceCommand) cmd);
-		} else if (cmd instanceof OvsSetupBridgeCommand) {
-			return execute((OvsSetupBridgeCommand) cmd);
-		} else if (cmd instanceof OvsDestroyBridgeCommand) {
-			return execute((OvsDestroyBridgeCommand) cmd);
-		} else if (cmd instanceof OvsCreateTunnelCommand) {
-			return execute((OvsCreateTunnelCommand) cmd);
-		} else if (cmd instanceof OvsDestroyTunnelCommand) {
-			return execute((OvsDestroyTunnelCommand) cmd);
-		} else {
+            } else if (cmd instanceof OvsFetchInterfaceCommand) {
+                return execute((OvsFetchInterfaceCommand)cmd);
+            } else if (cmd instanceof OvsSetupBridgeCommand) {
+                return execute((OvsSetupBridgeCommand)cmd);
+            } else if (cmd instanceof OvsDestroyBridgeCommand) {
+                return execute((OvsDestroyBridgeCommand)cmd);
+            } else if (cmd instanceof OvsCreateTunnelCommand) {
+                return execute((OvsCreateTunnelCommand)cmd);
+            } else if (cmd instanceof OvsDestroyTunnelCommand) {
+                return execute((OvsDestroyTunnelCommand)cmd);
+            } else {
                 s_logger.warn("Unsupported command ");
                 return Answer.createUnsupportedCommandAnswer(cmd);
             }
@@ -1304,173 +1304,173 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     private OvsFetchInterfaceAnswer execute(OvsFetchInterfaceCommand cmd) {
-    	String label = cmd.getLabel();
-    	s_logger.debug("Will look for network with name-label:" + label);
-    	try {
-    		String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'");
-    		String mask = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f4");
-    		String mac = Script.runSimpleBashScript("ifconfig " + label + " | grep HWaddr | awk -F \" \" '{print $5}'");
-			return new OvsFetchInterfaceAnswer(cmd, true, "Interface " + label
-					+ " retrieved successfully", ipadd, mask, mac);
-
-		} catch (Exception e) {
-			s_logger.warn("Caught execption when fetching interface", e);
-			return new OvsFetchInterfaceAnswer(cmd, false, "EXCEPTION:"
-					+ e.getMessage());
-    	}
-
-    }
-
-	private Answer execute(OvsSetupBridgeCommand cmd) {
-		findOrCreateTunnelNetwork(cmd.getKey());
-		configureTunnelNetwork(cmd.getNetworkId(), cmd.getHostId(),
-				cmd.getKey());
-		s_logger.debug("OVS Bridge configured");
-		return new Answer(cmd, true, null);
-	}
-
-	private Answer execute(OvsDestroyBridgeCommand cmd) {
-		destroyTunnelNetwork(cmd.getKey());
-		s_logger.debug("OVS Bridge destroyed");
-		return new Answer(cmd, true, null);
-	}
-
-	private synchronized void destroyTunnelNetwork(int key) {
-		try {
-			findOrCreateTunnelNetwork(key);
-			String bridge = "OVSTunnel" + key;
-			Script cmd = new Script(_ovsTunnelPath, _timeout, s_logger);
-			cmd.add("destroy_ovs_bridge");
-			cmd.add("--bridge", bridge);
-			String result = cmd.execute();
-			if (result != null) {
-				// TODO: Should make this error not fatal?
-				// Can Concurrent VM shutdown/migration/reboot events can cause
-				// this method
-				// to be executed on a bridge which has already been removed?
-				throw new CloudRuntimeException("Unable to remove OVS bridge " + bridge);
-			}
-			return;
-		} catch (Exception e) {
-			s_logger.warn("destroyTunnelNetwork failed:", e);
-			return;
-		}
-	}
-
-	private synchronized boolean findOrCreateTunnelNetwork(long key) {
-		try {
-			String nwName = "OVSTunnel" + key;
-			if (checkNetwork(nwName)) {
-				return true;
-			}
-			// if not found, create a new one
-			Map<String, String> otherConfig = new HashMap<String, String>();
-			otherConfig.put("ovs-host-setup", "");
-			Script.runSimpleBashScript("ovs-vsctl -- --may-exist add-br "
-					+ nwName + " -- set bridge " + nwName
-					+ " other_config:ovs_host_setup='-1'");
-			s_logger.debug("### KVM network for tunnels created:" + nwName);
-		} catch (Exception e) {
-			s_logger.warn("createTunnelNetwork failed", e);
-		}
-		return true;
-	}
-
-	private synchronized boolean configureTunnelNetwork(long networkId,
-			long hostId, int key) {
-		try {
-			findOrCreateTunnelNetwork(key);
-			String nwName = "OVSTunnel" + key;
-			String configuredHosts = Script
-					.runSimpleBashScript("ovs-vsctl get bridge " + nwName
-							+ " other_config:ovs_host_setup");
-			boolean configured = false;
-			if (configuredHosts != null) {
-				String hostIdsStr[] = configuredHosts.split(",");
-				for (String hostIdStr : hostIdsStr) {
-					if (hostIdStr.equals(((Long) hostId).toString())) {
-						configured = true;
-						break;
-					}
-				}
-			}
-			if (!configured) {
-				Script cmd = new Script(_ovsTunnelPath, _timeout, s_logger);
-				cmd.add("setup_ovs_bridge");
-				cmd.add("--key", String.valueOf(key));
-				cmd.add("--cs_host_id", ((Long) hostId).toString());
-				cmd.add("--bridge", nwName);
-				String result = cmd.execute();
-				if (result != null) {
-					throw new CloudRuntimeException(
-							"Unable to pre-configure OVS bridge " + nwName
-									+ " for network ID:" + networkId);
-				}
-			}
-		} catch (Exception e) {
-			s_logger.warn("createandConfigureTunnelNetwork failed", e);
-			return false;
-		}
-		return true;
-	}
-
-	private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
-		String bridge = "OVSTunnel" + cmd.getKey();
-		try {
-			if (!findOrCreateTunnelNetwork(cmd.getKey())) {
-				s_logger.debug("Error during bridge setup");
-				return new OvsCreateTunnelAnswer(cmd, false,
-						"Cannot create network", bridge);
-			}
-
-			configureTunnelNetwork(cmd.getNetworkId(), cmd.getFrom(),
-					cmd.getKey());
-			Script command = new Script(_ovsTunnelPath, _timeout, s_logger);
-			command.add("create_tunnel");
-			command.add("--bridge", bridge);
-			command.add("--remote_ip", cmd.getRemoteIp());
-			command.add("--key", cmd.getKey().toString());
-			command.add("--src_host", cmd.getFrom().toString());
-			command.add("--dst_host", cmd.getTo().toString());
-
-			String result = command.execute();
-			if (result != null) {
-				return new OvsCreateTunnelAnswer(cmd, true, result, null,
-						bridge);
-			} else {
-				return new OvsCreateTunnelAnswer(cmd, false, result, bridge);
-			}
-		} catch (Exception e) {
-			s_logger.debug("Error during tunnel setup");
-			s_logger.warn("Caught execption when creating ovs tunnel", e);
-			return new OvsCreateTunnelAnswer(cmd, false, e.getMessage(), bridge);
-		}
-	}
-
-	private Answer execute(OvsDestroyTunnelCommand cmd) {
-		try {
-			if (!findOrCreateTunnelNetwork(cmd.getKey())) {
-				s_logger.warn("Unable to find tunnel network for GRE key:"
-						+ cmd.getKey());
-				return new Answer(cmd, false, "No network found");
-			}
-
-			String bridge = "OVSTunnel" + cmd.getKey();
-			Script command = new Script(_ovsTunnelPath, _timeout, s_logger);
-			command.add("destroy_tunnel");
-			command.add("--bridge", bridge);
-			command.add("--iface_name", cmd.getInPortName());
-			String result = command.execute();
-			if (result == null) {
-				return new Answer(cmd, true, result);
-			} else {
-				return new Answer(cmd, false, result);
-			}
-		} catch (Exception e) {
-			s_logger.warn("caught execption when destroy ovs tunnel", e);
-			return new Answer(cmd, false, e.getMessage());
-		}
-	}
+        String label = cmd.getLabel();
+        s_logger.debug("Will look for network with name-label:" + label);
+        try {
+            String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'");
+            String mask = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f4");
+            String mac = Script.runSimpleBashScript("ifconfig " + label + " | grep HWaddr | awk -F \" \" '{print $5}'");
+            return new OvsFetchInterfaceAnswer(cmd, true, "Interface " + label
+                + " retrieved successfully", ipadd, mask, mac);
+
+        } catch (Exception e) {
+            s_logger.warn("Caught execption when fetching interface", e);
+            return new OvsFetchInterfaceAnswer(cmd, false, "EXCEPTION:"
+                + e.getMessage());
+        }
+
+    }
+
+    private Answer execute(OvsSetupBridgeCommand cmd) {
+        findOrCreateTunnelNetwork(cmd.getKey());
+        configureTunnelNetwork(cmd.getNetworkId(), cmd.getHostId(),
+            cmd.getKey());
+        s_logger.debug("OVS Bridge configured");
+        return new Answer(cmd, true, null);
+    }
+
+    private Answer execute(OvsDestroyBridgeCommand cmd) {
+        destroyTunnelNetwork(cmd.getKey());
+        s_logger.debug("OVS Bridge destroyed");
+        return new Answer(cmd, true, null);
+    }
+
+    private synchronized void destroyTunnelNetwork(int key) {
+        try {
+            findOrCreateTunnelNetwork(key);
+            String bridge = "OVSTunnel" + key;
+            Script cmd = new Script(_ovsTunnelPath, _timeout, s_logger);
+            cmd.add("destroy_ovs_bridge");
+            cmd.add("--bridge", bridge);
+            String result = cmd.execute();
+            if (result != null) {
+                // TODO: Should make this error not fatal?
+                // Can Concurrent VM shutdown/migration/reboot events can cause
+                // this method
+                // to be executed on a bridge which has already been removed?
+                throw new CloudRuntimeException("Unable to remove OVS bridge " + bridge);
+            }
+            return;
+        } catch (Exception e) {
+            s_logger.warn("destroyTunnelNetwork failed:", e);
+            return;
+        }
+    }
+
+    private synchronized boolean findOrCreateTunnelNetwork(long key) {
+        try {
+            String nwName = "OVSTunnel" + key;
+            if (checkNetwork(nwName)) {
+                return true;
+            }
+            // if not found, create a new one
+            Map<String, String> otherConfig = new HashMap<String, String>();
+            otherConfig.put("ovs-host-setup", "");
+            Script.runSimpleBashScript("ovs-vsctl -- --may-exist add-br "
+                + nwName + " -- set bridge " + nwName
+                + " other_config:ovs_host_setup='-1'");
+            s_logger.debug("### KVM network for tunnels created:" + nwName);
+        } catch (Exception e) {
+            s_logger.warn("createTunnelNetwork failed", e);
+        }
+        return true;
+    }
+
+    private synchronized boolean configureTunnelNetwork(long networkId,
+        long hostId, int key) {
+        try {
+            findOrCreateTunnelNetwork(key);
+            String nwName = "OVSTunnel" + key;
+            String configuredHosts = Script
+                .runSimpleBashScript("ovs-vsctl get bridge " + nwName
+                    + " other_config:ovs_host_setup");
+            boolean configured = false;
+            if (configuredHosts != null) {
+                String hostIdsStr[] = configuredHosts.split(",");
+                for (String hostIdStr : hostIdsStr) {
+                    if (hostIdStr.equals(((Long)hostId).toString())) {
+                        configured = true;
+                        break;
+                    }
+                }
+            }
+            if (!configured) {
+                Script cmd = new Script(_ovsTunnelPath, _timeout, s_logger);
+                cmd.add("setup_ovs_bridge");
+                cmd.add("--key", String.valueOf(key));
+                cmd.add("--cs_host_id", ((Long)hostId).toString());
+                cmd.add("--bridge", nwName);
+                String result = cmd.execute();
+                if (result != null) {
+                    throw new CloudRuntimeException(
+                        "Unable to pre-configure OVS bridge " + nwName
+                            + " for network ID:" + networkId);
+                }
+            }
+        } catch (Exception e) {
+            s_logger.warn("createandConfigureTunnelNetwork failed", e);
+            return false;
+        }
+        return true;
+    }
+
+    private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
+        String bridge = "OVSTunnel" + cmd.getKey();
+        try {
+            if (!findOrCreateTunnelNetwork(cmd.getKey())) {
+                s_logger.debug("Error during bridge setup");
+                return new OvsCreateTunnelAnswer(cmd, false,
+                    "Cannot create network", bridge);
+            }
+
+            configureTunnelNetwork(cmd.getNetworkId(), cmd.getFrom(),
+                cmd.getKey());
+            Script command = new Script(_ovsTunnelPath, _timeout, s_logger);
+            command.add("create_tunnel");
+            command.add("--bridge", bridge);
+            command.add("--remote_ip", cmd.getRemoteIp());
+            command.add("--key", cmd.getKey().toString());
+            command.add("--src_host", cmd.getFrom().toString());
+            command.add("--dst_host", cmd.getTo().toString());
+
+            String result = command.execute();
+            if (result != null) {
+                return new OvsCreateTunnelAnswer(cmd, true, result, null,
+                    bridge);
+            } else {
+                return new OvsCreateTunnelAnswer(cmd, false, result, bridge);
+            }
+        } catch (Exception e) {
+            s_logger.debug("Error during tunnel setup");
+            s_logger.warn("Caught execption when creating ovs tunnel", e);
+            return new OvsCreateTunnelAnswer(cmd, false, e.getMessage(), bridge);
+        }
+    }
+
+    private Answer execute(OvsDestroyTunnelCommand cmd) {
+        try {
+            if (!findOrCreateTunnelNetwork(cmd.getKey())) {
+                s_logger.warn("Unable to find tunnel network for GRE key:"
+                    + cmd.getKey());
+                return new Answer(cmd, false, "No network found");
+            }
+
+            String bridge = "OVSTunnel" + cmd.getKey();
+            Script command = new Script(_ovsTunnelPath, _timeout, s_logger);
+            command.add("destroy_tunnel");
+            command.add("--bridge", bridge);
+            command.add("--iface_name", cmd.getInPortName());
+            String result = command.execute();
+            if (result == null) {
+                return new Answer(cmd, true, result);
+            } else {
+                return new Answer(cmd, false, result);
+            }
+        } catch (Exception e) {
+            s_logger.warn("caught execption when destroy ovs tunnel", e);
+            return new Answer(cmd, false, e.getMessage());
+        }
+    }
 
     private CheckNetworkAnswer execute(CheckNetworkCommand cmd) {
         List<PhysicalNetworkSetupInfo> phyNics = cmd.getPhysicalNetworkInfoList();
@@ -2342,7 +2342,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
              *
              * These bindings will read the snapshot and write the contents to
              * the secondary storage directly
-             * 
+             *
              * It will stop doing so if the amount of time spend is longer then
              * cmds.timeout
              */
@@ -3217,8 +3217,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         }
     }
 
-
-	private Answer execute(RebootCommand cmd) {
+    private Answer execute(RebootCommand cmd) {
 
         synchronized (_vms) {
             _vms.put(cmd.getVmName(), State.Starting);
@@ -3299,8 +3298,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         }
     }
 
-
-	protected Answer execute(StopCommand cmd) {
+    protected Answer execute(StopCommand cmd) {
         final String vmName = cmd.getVmName();
 
         State state = null;
@@ -3345,21 +3343,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected Answer execute(ModifySshKeysCommand cmd) {
-        File sshKeysDir = new File(_SSHKEYSPATH);
+        File sshKeysDir = new File(SSHKEYSPATH);
         String result = null;
         if (!sshKeysDir.exists()) {
             // Change permissions for the 700
             Script script = new Script("mkdir", _timeout, s_logger);
             script.add("-m", "700");
-            script.add(_SSHKEYSPATH);
+            script.add(SSHKEYSPATH);
             script.execute();
 
             if (!sshKeysDir.exists()) {
-                s_logger.debug("failed to create directory " + _SSHKEYSPATH);
+                s_logger.debug("failed to create directory " + SSHKEYSPATH);
             }
         }
 
-        File pubKeyFile = new File(_SSHPUBKEYPATH);
+        File pubKeyFile = new File(SSHPUBKEYPATH);
         if (!pubKeyFile.exists()) {
             try {
                 pubKeyFile.createNewFile();
@@ -3376,15 +3374,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 pubkStream.write(pubKey.getBytes());
                 pubkStream.close();
             } catch (FileNotFoundException e) {
-                result = "File" + _SSHPUBKEYPATH + "is not found:" + e.toString();
+                result = "File" + SSHPUBKEYPATH + "is not found:" + e.toString();
                 s_logger.debug(result);
             } catch (IOException e) {
-                result = "Write file " + _SSHPUBKEYPATH + ":" + e.toString();
+                result = "Write file " + SSHPUBKEYPATH + ":" + e.toString();
                 s_logger.debug(result);
             }
         }
 
-        File prvKeyFile = new File(_SSHPRVKEYPATH);
+        File prvKeyFile = new File(SSHPRVKEYPATH);
         if (!prvKeyFile.exists()) {
             try {
                 prvKeyFile.createNewFile();
@@ -3401,15 +3399,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 prvKStream.write(prvKey.getBytes());
                 prvKStream.close();
             } catch (FileNotFoundException e) {
-                result = "File" + _SSHPRVKEYPATH + "is not found:" + e.toString();
+                result = "File" + SSHPRVKEYPATH + "is not found:" + e.toString();
                 s_logger.debug(result);
             } catch (IOException e) {
-                result = "Write file " + _SSHPRVKEYPATH + ":" + e.toString();
+                result = "Write file " + SSHPRVKEYPATH + ":" + e.toString();
                 s_logger.debug(result);
             }
 
             Script script = new Script("chmod", _timeout, s_logger);
-            script.add("600", _SSHPRVKEYPATH);
+            script.add("600", SSHPRVKEYPATH);
             script.execute();
         }
 
@@ -3616,7 +3614,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             }
 
             // pass cmdline info to system vms
-			if (vmSpec.getType() != VirtualMachine.Type.User) {
+            if (vmSpec.getType() != VirtualMachine.Type.User) {
                 if ((conn.getVersion() < 1001000)) { // CLOUDSTACK-2823: try passCmdLine some times if kernel < 2.6.34 and qemu < 1.1.0 on hypervisor (for instance, CentOS 6.4)
                     //wait for 5 minutes at most
                     String controlIp = null;
@@ -3962,7 +3960,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     public PingCommand getCurrentStatus(long id) {
         final HashMap<String, State> newStates = sync();
 
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, newStates, this.getHostVmStateReport());
         } else {
             HashMap<String, Pair<Long, Long>> nwGrpStates = syncNetworkGroups(id);
@@ -4821,14 +4819,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         }
     }
 
-    private class vmStats {
+    private class VmStats {
         long _usedTime;
         long _tx;
         long _rx;
-        long _io_rd;
-        long _io_wr;
-        long _bytes_rd;
-        long _bytes_wr;
+        long _ioRead;
+        long _ioWrote;
+        long _bytesRead;
+        long _bytesWrote;
         Calendar _timestamp;
     }
 
@@ -4843,7 +4841,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             stats.setEntityType("vm");
 
             /* get cpu utilization */
-            vmStats oldStats = null;
+            VmStats oldStats = null;
 
             Calendar now = Calendar.getInstance();
 
@@ -4896,29 +4894,29 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             }
 
             if (oldStats != null) {
-                long deltaiord = io_rd - oldStats._io_rd;
+                long deltaiord = io_rd - oldStats._ioRead;
                 if (deltaiord > 0)
                     stats.setDiskReadIOs(deltaiord);
-                long deltaiowr = io_wr - oldStats._io_wr;
+                long deltaiowr = io_wr - oldStats._ioWrote;
                 if (deltaiowr > 0)
                     stats.setDiskWriteIOs(deltaiowr);
-                double deltabytesrd = bytes_rd - oldStats._bytes_rd;
+                double deltabytesrd = bytes_rd - oldStats._bytesRead;
                 if (deltabytesrd > 0)
                     stats.setDiskReadKBs(deltabytesrd / 1024);
-                double deltabyteswr = bytes_wr - oldStats._bytes_wr;
+                double deltabyteswr = bytes_wr - oldStats._bytesWrote;
                 if (deltabyteswr > 0)
                     stats.setDiskWriteKBs(deltabyteswr / 1024);
             }
 
             /* save to Hashmap */
-            vmStats newStat = new vmStats();
+            VmStats newStat = new VmStats();
             newStat._usedTime = info.cpuTime;
             newStat._rx = rx;
             newStat._tx = tx;
-            newStat._io_rd = io_rd;
-            newStat._io_wr = io_wr;
-            newStat._bytes_rd = bytes_rd;
-            newStat._bytes_wr = bytes_wr;
+            newStat._ioRead = io_rd;
+            newStat._ioWrote = io_wr;
+            newStat._bytesRead = bytes_rd;
+            newStat._bytesWrote = bytes_wr;
             newStat._timestamp = now;
             _vmStats.put(vmName, newStat);
             return stats;
@@ -4941,7 +4939,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected boolean destroy_network_rules_for_vm(Connect conn, String vmName) {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
         String vif = null;
@@ -4964,7 +4962,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected boolean default_network_rules(Connect conn, String vmName, NicTO nic, Long vmId, String secIpStr) {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
 
@@ -4996,7 +4994,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected boolean post_default_network_rules(Connect conn, String vmName, NicTO nic, Long vmId, InetAddress dhcpServerIp, String hostIp, String hostMacAddr) {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
 
@@ -5030,7 +5028,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected boolean default_network_rules_for_systemvm(Connect conn, String vmName) {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
 
@@ -5047,7 +5045,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
 
     private boolean add_network_rules(String vmName, String vmId, String guestIP, String sig, String seq, String mac, String rules, String vif, String brname,
         String secIps) {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
 
@@ -5075,7 +5073,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
 
     private boolean network_rules_vmSecondaryIp(Connect conn, String vmName, String secIp, String action) {
 
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
 
@@ -5093,7 +5091,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     private boolean cleanup_rules() {
-        if (!_can_bridge_firewall) {
+        if (!_canBridgeFirewall) {
             return false;
         }
         Script cmd = new Script(_securityGroupPath, _timeout, s_logger);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java
index 6c8da8a..1ebf936 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java
@@ -28,28 +28,28 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
 
 public class LibvirtConnection {
     private static final Logger s_logger = Logger.getLogger(LibvirtConnection.class);
-    static private Map<String, Connect> _connections = new HashMap<String, Connect>();
+    static private Map<String, Connect> s_connections = new HashMap<String, Connect>();
 
-    static private Connect _connection;
-    static private String _hypervisorURI;
+    static private Connect s_connection;
+    static private String s_hypervisorURI;
 
     static public Connect getConnection() throws LibvirtException {
-        return getConnection(_hypervisorURI);
+        return getConnection(s_hypervisorURI);
     }
 
     static public Connect getConnection(String hypervisorURI) throws LibvirtException {
-        Connect conn = _connections.get(hypervisorURI);
+        Connect conn = s_connections.get(hypervisorURI);
 
         if (conn == null) {
             conn = new Connect(hypervisorURI, false);
-            _connections.put(hypervisorURI, conn);
+            s_connections.put(hypervisorURI, conn);
         } else {
             try {
                 conn.getVersion();
             } catch (LibvirtException e) {
                 s_logger.debug("Connection with libvirtd is broken, due to " + e.getMessage());
                 conn = new Connect(hypervisorURI, false);
-                _connections.put(hypervisorURI, conn);
+                s_connections.put(hypervisorURI, conn);
             }
         }
 
@@ -80,7 +80,7 @@ public class LibvirtConnection {
     }
 
     static void initialize(String hypervisorURI) {
-        _hypervisorURI = hypervisorURI;
+        s_hypervisorURI = hypervisorURI;
     }
 
     static String getHypervisorURI(String hypervisorType) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtNetworkDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtNetworkDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtNetworkDef.java
index a069e08..f20bec4 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtNetworkDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtNetworkDef.java
@@ -35,14 +35,14 @@ public class LibvirtNetworkDef {
     private String _brIPAddr;
     private String _brNetMask;
     private final List<IPRange> ipranges = new ArrayList<IPRange>();
-    private final List<dhcpMapping> dhcpMaps = new ArrayList<dhcpMapping>();
+    private final List<DhcpMapping> dhcpMaps = new ArrayList<DhcpMapping>();
 
-    public static class dhcpMapping {
+    public static class DhcpMapping {
         String _mac;
         String _name;
         String _ip;
 
-        public dhcpMapping(String mac, String name, String ip) {
+        public DhcpMapping(String mac, String name, String ip) {
             _mac = mac;
             _name = name;
             _ip = ip;
@@ -100,7 +100,7 @@ public class LibvirtNetworkDef {
     }
 
     public void adddhcpMapping(String mac, String host, String ip) {
-        dhcpMapping map = new dhcpMapping(mac, host, ip);
+        DhcpMapping map = new DhcpMapping(mac, host, ip);
         dhcpMaps.add(map);
     }
 
@@ -153,7 +153,7 @@ public class LibvirtNetworkDef {
                 for (IPRange ip : ipranges) {
                     netBuilder.append("<range start='" + ip._start + "'" + " end='" + ip._end + "'/>\n");
                 }
-                for (dhcpMapping map : dhcpMaps) {
+                for (DhcpMapping map : dhcpMaps) {
                     netBuilder.append("<host mac='" + map._mac + "' name='" + map._name + "' ip='" + map._ip + "'/>\n");
                 }
                 netBuilder.append("</dhcp>\n");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index 9910877..3e44e94 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -23,8 +23,8 @@ import java.util.Map;
 
 public class LibvirtVMDef {
     private String _hvsType;
-    private static long _libvirtVersion;
-    private static long _qemuVersion;
+    private static long s_libvirtVersion;
+    private static long s_qemuVersion;
     private String _domName;
     private String _domUUID;
     private String _desc;
@@ -665,8 +665,8 @@ public class LibvirtVMDef {
             diskBuilder.append("/>\n");
 
             if ((_deviceType != deviceType.CDROM) &&
-                (_libvirtVersion >= 9008) &&
-                (_qemuVersion >= 1001000) &&
+                (s_libvirtVersion >= 9008) &&
+                (s_qemuVersion >= 1001000) &&
                 (((_bytesReadRate != null) && (_bytesReadRate > 0)) || ((_bytesWriteRate != null) && (_bytesWriteRate > 0)) ||
                     ((_iopsReadRate != null) && (_iopsReadRate > 0)) || ((_iopsWriteRate != null) && (_iopsWriteRate > 0)))) { // not CDROM, from libvirt 0.9.8 and QEMU 1.1.0
                 diskBuilder.append("<iotune>\n");
@@ -866,7 +866,7 @@ public class LibvirtVMDef {
             if (_model != null) {
                 netBuilder.append("<model type='" + _model + "'/>\n");
             }
-            if ((_libvirtVersion >= 9004) && (_networkRateKBps > 0)) { // supported from libvirt 0.9.4
+            if ((s_libvirtVersion >= 9004) && (_networkRateKBps > 0)) { // supported from libvirt 0.9.4
                 netBuilder.append("<bandwidth>\n");
                 netBuilder.append("<inbound average='" + _networkRateKBps + "' peak='" + _networkRateKBps + "'/>\n");
                 netBuilder.append("<outbound average='" + _networkRateKBps + "' peak='" + _networkRateKBps + "'/>\n");
@@ -1113,11 +1113,11 @@ public class LibvirtVMDef {
     }
 
     public void setLibvirtVersion(long libvirtVersion) {
-        _libvirtVersion = libvirtVersion;
+        s_libvirtVersion = libvirtVersion;
     }
 
     public void setQemuVersion(long qemuVersion) {
-        _qemuVersion = qemuVersion;
+        s_qemuVersion = qemuVersion;
     }
 
     public void setDomainName(String domainName) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java
new file mode 100644
index 0000000..761bb37
--- /dev/null
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java
@@ -0,0 +1,367 @@
+// 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.hypervisor.kvm.storage;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
+
+import com.cloud.agent.api.to.DiskTO;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.utils.StringUtils;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.Script;
+
+public class IscsiAdmStorageAdaptor implements StorageAdaptor {
+    private static final Logger s_logger = Logger.getLogger(IscsiAdmStorageAdaptor.class);
+
+    private static final Map<String, KVMStoragePool> MapStorageUuidToStoragePool = new HashMap<String, KVMStoragePool>();
+
+    @Override
+    public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType) {
+        IscsiAdmStoragePool storagePool = new IscsiAdmStoragePool(uuid, host, port, storagePoolType, this);
+
+        MapStorageUuidToStoragePool.put(uuid, storagePool);
+
+        return storagePool;
+    }
+
+    @Override
+    public KVMStoragePool getStoragePool(String uuid) {
+        return MapStorageUuidToStoragePool.get(uuid);
+    }
+
+    @Override
+    public boolean deleteStoragePool(String uuid) {
+        return MapStorageUuidToStoragePool.remove(uuid) != null;
+    }
+
+    @Override
+    public boolean deleteStoragePool(KVMStoragePool pool) {
+        return deleteStoragePool(pool.getUuid());
+    }
+
+    // called from LibvirtComputingResource.execute(CreateCommand)
+    // does not apply for iScsiAdmStorageAdaptor
+    @Override
+    public KVMPhysicalDisk createPhysicalDisk(String volumeUuid, KVMStoragePool pool, PhysicalDiskFormat format, long size) {
+        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
+    }
+
+    @Override
+    public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map<String, String> details) {
+        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o new
+        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
+
+        iScsiAdmCmd.add("-m", "node");
+        iScsiAdmCmd.add("-T", getIqn(volumeUuid));
+        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
+        iScsiAdmCmd.add("-o", "new");
+
+        String result = iScsiAdmCmd.execute();
+
+        if (result != null) {
+            s_logger.debug("Failed to add iSCSI target " + volumeUuid);
+            System.out.println("Failed to add iSCSI target " + volumeUuid);
+
+            return false;
+        } else {
+            s_logger.debug("Successfully added iSCSI target " + volumeUuid);
+            System.out.println("Successfully added to iSCSI target " + volumeUuid);
+        }
+
+        String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME);
+        String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET);
+
+        if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorSecret)) {
+            try {
+                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.authmethod -v CHAP
+                executeChapCommand(volumeUuid, pool, "node.session.auth.authmethod", "CHAP", null);
+
+                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.username -v username
+                executeChapCommand(volumeUuid, pool, "node.session.auth.username", chapInitiatorUsername, "username");
+
+                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.password -v password
+                executeChapCommand(volumeUuid, pool, "node.session.auth.password", chapInitiatorSecret, "password");
+            } catch (Exception ex) {
+                return false;
+            }
+        }
+
+        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10 --login
+        iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
+
+        iScsiAdmCmd.add("-m", "node");
+        iScsiAdmCmd.add("-T", getIqn(volumeUuid));
+        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
+        iScsiAdmCmd.add("--login");
+
+        result = iScsiAdmCmd.execute();
+
+        if (result != null) {
+            s_logger.debug("Failed to log in to iSCSI target " + volumeUuid);
+            System.out.println("Failed to log in to iSCSI target " + volumeUuid);
+
+            return false;
+        } else {
+            s_logger.debug("Successfully logged in to iSCSI target " + volumeUuid);
+            System.out.println("Successfully logged in to iSCSI target " + volumeUuid);
+        }
+
+        // There appears to be a race condition where logging in to the iSCSI volume via iscsiadm
+        // returns success before the device has been added to the OS.
+        // What happens is you get logged in and the device shows up, but the device may not
+        // show up before we invoke Libvirt to attach the device to a VM.
+        // waitForDiskToBecomeAvailable(String, KVMStoragePool) invokes blockdev
+        // via getPhysicalDisk(String, KVMStoragePool) and checks if the size came back greater
+        // than 0.
+        // After a certain number of tries and a certain waiting period in between tries,
+        // this method could still return (it should not block indefinitely) (the race condition
+        // isn't solved here, but made highly unlikely to be a problem).
+        waitForDiskToBecomeAvailable(volumeUuid, pool);
+
+        return true;
+    }
+
+    private void waitForDiskToBecomeAvailable(String volumeUuid, KVMStoragePool pool) {
+        int numberOfTries = 10;
+        int timeBetweenTries = 1000;
+
+        while (getPhysicalDisk(volumeUuid, pool).getSize() == 0 && numberOfTries > 0) {
+            numberOfTries--;
+
+            try {
+                Thread.sleep(timeBetweenTries);
+            } catch (Exception ex) {
+                // don't do anything
+            }
+        }
+    }
+
+    private void executeChapCommand(String path, KVMStoragePool pool, String nParameter, String vParameter, String detail) throws Exception {
+        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
+
+        iScsiAdmCmd.add("-m", "node");
+        iScsiAdmCmd.add("-T", getIqn(path));
+        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
+        iScsiAdmCmd.add("--op", "update");
+        iScsiAdmCmd.add("-n", nParameter);
+        iScsiAdmCmd.add("-v", vParameter);
+
+        String result = iScsiAdmCmd.execute();
+
+        boolean useDetail = detail != null && detail.trim().length() > 0;
+
+        detail = useDetail ? detail.trim() + " " : detail;
+
+        if (result != null) {
+            s_logger.debug("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
+            System.out.println("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
+
+            throw new Exception("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
+        } else {
+            s_logger.debug("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path);
+            System.out.println("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path);
+        }
+    }
+
+    // example by-path: /dev/disk/by-path/ip-192.168.233.10:3260-iscsi-iqn.2012-03.com.solidfire:storagepool2-lun-0
+    private String getByPath(String host, String path) {
+        return "/dev/disk/by-path/ip-" + host + "-iscsi-" + getIqn(path) + "-lun-" + getLun(path);
+    }
+
+    @Override
+    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
+        String deviceByPath = getByPath(pool.getSourceHost() + ":" + pool.getSourcePort(), volumeUuid);
+        KVMPhysicalDisk physicalDisk = new KVMPhysicalDisk(deviceByPath, volumeUuid, pool);
+
+        physicalDisk.setFormat(PhysicalDiskFormat.RAW);
+
+        long deviceSize = getDeviceSize(deviceByPath);
+
+        physicalDisk.setSize(deviceSize);
+        physicalDisk.setVirtualSize(deviceSize);
+
+        return physicalDisk;
+    }
+
+    private long getDeviceSize(String deviceByPath) {
+        Script iScsiAdmCmd = new Script(true, "blockdev", 0, s_logger);
+
+        iScsiAdmCmd.add("--getsize64", deviceByPath);
+
+        OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
+
+        String result = iScsiAdmCmd.execute(parser);
+
+        if (result != null) {
+            s_logger.warn("Unable to retrieve the size of device " + deviceByPath);
+
+            return 0;
+        }
+
+        return Long.parseLong(parser.getLine());
+    }
+
+    private static String getIqn(String path) {
+        return getComponent(path, 1);
+    }
+
+    private static String getLun(String path) {
+        return getComponent(path, 2);
+    }
+
+    private static String getComponent(String path, int index) {
+        String[] tmp = path.split("/");
+
+        if (tmp.length != 3) {
+            String msg = "Wrong format for iScsi path: " + path + ". It should be formatted as '/targetIQN/LUN'.";
+
+            s_logger.warn(msg);
+
+            throw new CloudRuntimeException(msg);
+        }
+
+        return tmp[index].trim();
+    }
+
+    public boolean disconnectPhysicalDisk(String host, int port, String iqn, String lun) {
+        // use iscsiadm to log out of the iSCSI target and un-discover it
+
+        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10 --logout
+        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
+
+        iScsiAdmCmd.add("-m", "node");
+        iScsiAdmCmd.add("-T", iqn);
+        iScsiAdmCmd.add("-p", host + ":" + port);
+        iScsiAdmCmd.add("--logout");
+
+        String result = iScsiAdmCmd.execute();
+
+        if (result != null) {
+            s_logger.debug("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result);
+            System.out.println("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result);
+
+            return false;
+        } else {
+            s_logger.debug("Successfully logged out of iSCSI target /" + iqn + "/" + lun);
+            System.out.println("Successfully logged out of iSCSI target /" + iqn + "/" + lun);
+        }
+
+        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o delete
+        iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
+
+        iScsiAdmCmd.add("-m", "node");
+        iScsiAdmCmd.add("-T", iqn);
+        iScsiAdmCmd.add("-p", host + ":" + port);
+        iScsiAdmCmd.add("-o", "delete");
+
+        result = iScsiAdmCmd.execute();
+
+        if (result != null) {
+            s_logger.debug("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result);
+            System.out.println("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result);
+
+            return false;
+        } else {
+            s_logger.debug("Removed iSCSI target /" + iqn + "/" + lun);
+            System.out.println("Removed iSCSI target /" + iqn + "/" + lun);
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean disconnectPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
+        return disconnectPhysicalDisk(pool.getSourceHost(), pool.getSourcePort(), getIqn(volumeUuid), getLun(volumeUuid));
+    }
+
+    @Override
+    public boolean disconnectPhysicalDiskByPath(String localPath) {
+        String search1 = "/dev/disk/by-path/ip-";
+        String search2 = ":";
+        String search3 = "-iscsi-";
+        String search4 = "-lun-";
+
+        if (localPath.indexOf(search3) == -1) {
+            // this volume doesn't below to this adaptor, so just return true
+            return true;
+        }
+
+        int index = localPath.indexOf(search2);
+
+        String host = localPath.substring(search1.length(), index);
+
+        int index2 = localPath.indexOf(search3);
+
+        String port = localPath.substring(index + search2.length(), index2);
+
+        index = localPath.indexOf(search4);
+
+        String iqn = localPath.substring(index2 + search3.length(), index);
+
+        String lun = localPath.substring(index + search4.length());
+
+        return disconnectPhysicalDisk(host, Integer.parseInt(port), iqn, lun);
+    }
+
+    @Override
+    public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool) {
+        throw new UnsupportedOperationException("Deleting a physical disk is not supported.");
+    }
+
+    // does not apply for iScsiAdmStorageAdaptor
+    @Override
+    public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
+        throw new UnsupportedOperationException("Listing disks is not supported for this configuration.");
+    }
+
+    @Override
+    public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout) {
+        throw new UnsupportedOperationException("Creating a disk from a template is not yet supported for this configuration.");
+    }
+
+    @Override
+    public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool) {
+        throw new UnsupportedOperationException("Creating a template from a disk is not yet supported for this configuration.");
+    }
+
+    @Override
+    public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPool, int timeout) {
+        throw new UnsupportedOperationException("Copying a disk is not supported in this configuration.");
+    }
+
+    @Override
+    public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot, String snapshotName, String name, KVMStoragePool destPool) {
+        throw new UnsupportedOperationException("Creating a disk from a snapshot is not supported in this configuration.");
+    }
+
+    @Override
+    public boolean refresh(KVMStoragePool pool) {
+        return true;
+    }
+
+    @Override
+    public boolean createFolder(String uuid, String path) {
+        throw new UnsupportedOperationException("A folder cannot be created in this configuration.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStoragePool.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStoragePool.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStoragePool.java
new file mode 100644
index 0000000..2cecfa3
--- /dev/null
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/IscsiAdmStoragePool.java
@@ -0,0 +1,167 @@
+// 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.hypervisor.kvm.storage;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
+
+import com.cloud.storage.Storage.StoragePoolType;
+
+public class IscsiAdmStoragePool implements KVMStoragePool {
+    private String _uuid;
+    private String _sourceHost;
+    private int _sourcePort;
+    private StoragePoolType _storagePoolType;
+    private StorageAdaptor _storageAdaptor;
+    private String _authUsername;
+    private String _authSecret;
+    private String _sourceDir;
+    private String _localPath;
+
+    public IscsiAdmStoragePool(String uuid, String host, int port, StoragePoolType storagePoolType, StorageAdaptor storageAdaptor) {
+        _uuid = uuid;
+        _sourceHost = host;
+        _sourcePort = port;
+        _storagePoolType = storagePoolType;
+        _storageAdaptor = storageAdaptor;
+    }
+
+    @Override
+    public String getUuid() {
+        return _uuid;
+    }
+
+    @Override
+    public String getSourceHost() {
+        return _sourceHost;
+    }
+
+    @Override
+    public int getSourcePort() {
+        return _sourcePort;
+    }
+
+    @Override
+    public long getCapacity() {
+        return 0;
+    }
+
+    @Override
+    public long getUsed() {
+        return 0;
+    }
+
+    @Override
+    public long getAvailable() {
+        return 0;
+    }
+
+    @Override
+    public StoragePoolType getType() {
+        return _storagePoolType;
+    }
+
+    @Override
+    public PhysicalDiskFormat getDefaultFormat() {
+        return PhysicalDiskFormat.RAW;
+    }
+
+    // called from LibvirtComputingResource.copyPhysicalDisk(KVMPhysicalDisk, String, KVMStoragePool) and
+    // from LibvirtComputingResource.createDiskFromTemplate(KVMPhysicalDisk, String, PhysicalDiskFormat, long, KVMStoragePool)
+    // does not apply for iScsiAdmStoragePool
+    @Override
+    public KVMPhysicalDisk createPhysicalDisk(String name, PhysicalDiskFormat format, long size) {
+        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
+    }
+
+    // called from LibvirtComputingResource.execute(CreateCommand) and
+    // from KVMStorageProcessor.createVolume(CreateObjectCommand)
+    // does not apply for iScsiAdmStoragePool
+    @Override
+    public KVMPhysicalDisk createPhysicalDisk(String name, long size) {
+        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
+    }
+
+    @Override
+    public boolean connectPhysicalDisk(String name, Map<String, String> details) {
+        return this._storageAdaptor.connectPhysicalDisk(name, this, details);
+    }
+
+    @Override
+    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid) {
+        return this._storageAdaptor.getPhysicalDisk(volumeUuid, this);
+    }
+
+    @Override
+    public boolean disconnectPhysicalDisk(String volumeUuid) {
+        return this._storageAdaptor.disconnectPhysicalDisk(volumeUuid, this);
+    }
+
+    @Override
+    public boolean deletePhysicalDisk(String volumeUuid) {
+        return this._storageAdaptor.deletePhysicalDisk(volumeUuid, this);
+    }
+
+    // does not apply for iScsiAdmStoragePool
+    @Override
+    public List<KVMPhysicalDisk> listPhysicalDisks() {
+        return this._storageAdaptor.listPhysicalDisks(_uuid, this);
+    }
+
+    // does not apply for iScsiAdmStoragePool
+    @Override
+    public boolean refresh() {
+        return this._storageAdaptor.refresh(this);
+    }
+
+    @Override
+    public boolean delete() {
+        return this._storageAdaptor.deleteStoragePool(this);
+    }
+
+    @Override
+    public boolean createFolder(String path) {
+        return this._storageAdaptor.createFolder(_uuid, path);
+    }
+
+    @Override
+    public boolean isExternalSnapshot() {
+        return false;
+    }
+
+    @Override
+    public String getAuthUserName() {
+        return _authUsername;
+    }
+
+    @Override
+    public String getAuthSecret() {
+        return _authSecret;
+    }
+
+    @Override
+    public String getSourceDir() {
+        return _sourceDir;
+    }
+
+    @Override
+    public String getLocalPath() {
+        return _localPath;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
index 08286e4..fefb29c 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
@@ -94,7 +94,7 @@ public class KVMStoragePoolManager {
         this._storageMapper.put("libvirt", new LibvirtStorageAdaptor(storagelayer));
         // add other storage adaptors here
         // this._storageMapper.put("newadaptor", new NewStorageAdaptor(storagelayer));
-        this._storageMapper.put(StoragePoolType.Iscsi.toString(), new iScsiAdmStorageAdaptor());
+        this._storageMapper.put(StoragePoolType.Iscsi.toString(), new IscsiAdmStorageAdaptor());
     }
 
     public boolean connectPhysicalDisk(StoragePoolType type, String poolUuid, String volPath, Map<String, String> details) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index db7706c..fda4d1b 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -102,8 +102,8 @@ import com.cloud.utils.script.Script;
 
 public class KVMStorageProcessor implements StorageProcessor {
     private static final Logger s_logger = Logger.getLogger(KVMStorageProcessor.class);
-    private KVMStoragePoolManager storagePoolMgr;
-    private LibvirtComputingResource resource;
+    private final KVMStoragePoolManager storagePoolMgr;
+    private final LibvirtComputingResource resource;
     private StorageLayer storageLayer;
     private String _createTmplPath;
     private String _manageSnapshotPath;
@@ -460,7 +460,7 @@ public class KVMStorageProcessor implements StorageProcessor {
 
             KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath());
             String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateFolder;
-            this.storageLayer.mkdirs(tmpltPath);
+            storageLayer.mkdirs(tmpltPath);
             String templateName = UUID.randomUUID().toString();
 
             if (primary.getType() != StoragePoolType.RBD) {
@@ -512,14 +512,14 @@ public class KVMStorageProcessor implements StorageProcessor {
             }
 
             Map<String, Object> params = new HashMap<String, Object>();
-            params.put(StorageLayer.InstanceConfigKey, this.storageLayer);
+            params.put(StorageLayer.InstanceConfigKey, storageLayer);
             Processor qcow2Processor = new QCOW2Processor();
 
             qcow2Processor.configure("QCOW2 Processor", params);
 
             FormatInfo info = qcow2Processor.process(tmpltPath, null, templateName);
 
-            TemplateLocation loc = new TemplateLocation(this.storageLayer, tmpltPath);
+            TemplateLocation loc = new TemplateLocation(storageLayer, tmpltPath);
             loc.create(1, true, templateName);
             loc.addFormat(info);
             loc.save();
@@ -738,7 +738,7 @@ public class KVMStorageProcessor implements StorageProcessor {
             Domain vm = null;
             if (vmName != null) {
                 try {
-                    vm = this.resource.getDomain(conn, vmName);
+                    vm = resource.getDomain(conn, vmName);
                     state = vm.getInfo().state;
                 } catch (LibvirtException e) {
                     s_logger.trace("Ignoring libvirt error.", e);
@@ -754,7 +754,7 @@ public class KVMStorageProcessor implements StorageProcessor {
                  * libvirt on RHEL6 doesn't handle resume event emitted from
                  * qemu
                  */
-                vm = this.resource.getDomain(conn, vmName);
+                vm = resource.getDomain(conn, vmName);
                 state = vm.getInfo().state;
                 if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                     vm.resume();
@@ -808,12 +808,12 @@ public class KVMStorageProcessor implements StorageProcessor {
             isoXml = iso.toString();
         }
 
-        List<DiskDef> disks = this.resource.getDisks(conn, vmName);
+        List<DiskDef> disks = resource.getDisks(conn, vmName);
         String result = attachOrDetachDevice(conn, true, vmName, isoXml);
         if (result == null && !isAttach) {
             for (DiskDef disk : disks) {
                 if (disk.getDeviceType() == DiskDef.deviceType.CDROM) {
-                    this.resource.cleanupDisk(disk);
+                    resource.cleanupDisk(disk);
                 }
             }
 
@@ -1027,7 +1027,7 @@ public class KVMStorageProcessor implements StorageProcessor {
         }
     }
 
-    protected static MessageFormat SnapshotXML = new MessageFormat("   <domainsnapshot>" + "       <name>{0}</name>" + "          <domain>"
+    protected static final MessageFormat SnapshotXML = new MessageFormat("   <domainsnapshot>" + "       <name>{0}</name>" + "          <domain>"
         + "            <uuid>{1}</uuid>" + "        </domain>" + "    </domainsnapshot>");
 
     @Override
@@ -1043,7 +1043,7 @@ public class KVMStorageProcessor implements StorageProcessor {
             Domain vm = null;
             if (vmName != null) {
                 try {
-                    vm = this.resource.getDomain(conn, vmName);
+                    vm = resource.getDomain(conn, vmName);
                     state = vm.getInfo().state;
                 } catch (LibvirtException e) {
                     s_logger.trace("Ignoring libvirt error.", e);
@@ -1064,7 +1064,7 @@ public class KVMStorageProcessor implements StorageProcessor {
                  * libvirt on RHEL6 doesn't handle resume event emitted from
                  * qemu
                  */
-                vm = this.resource.getDomain(conn, vmName);
+                vm = resource.getDomain(conn, vmName);
                 state = vm.getInfo().state;
                 if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                     vm.resume();
@@ -1105,7 +1105,7 @@ public class KVMStorageProcessor implements StorageProcessor {
                     }
                 } else {
                     /* VM is not running, create a snapshot by ourself */
-                    final Script command = new Script(_manageSnapshotPath, this._cmdsTimeout, s_logger);
+                    final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
                     command.add("-c", disk.getPath());
                     command.add("-n", snapshotName);
                     String result = command.execute();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStorageAdaptor.java
deleted file mode 100644
index 3c50034..0000000
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStorageAdaptor.java
+++ /dev/null
@@ -1,367 +0,0 @@
-// 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.hypervisor.kvm.storage;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
-
-import com.cloud.agent.api.to.DiskTO;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.utils.StringUtils;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.OutputInterpreter;
-import com.cloud.utils.script.Script;
-
-public class iScsiAdmStorageAdaptor implements StorageAdaptor {
-    private static final Logger s_logger = Logger.getLogger(iScsiAdmStorageAdaptor.class);
-
-    private static final Map<String, KVMStoragePool> _mapStorageUuidToStoragePool = new HashMap<String, KVMStoragePool>();
-
-    @Override
-    public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType) {
-        iScsiAdmStoragePool storagePool = new iScsiAdmStoragePool(uuid, host, port, storagePoolType, this);
-
-        _mapStorageUuidToStoragePool.put(uuid, storagePool);
-
-        return storagePool;
-    }
-
-    @Override
-    public KVMStoragePool getStoragePool(String uuid) {
-        return _mapStorageUuidToStoragePool.get(uuid);
-    }
-
-    @Override
-    public boolean deleteStoragePool(String uuid) {
-        return _mapStorageUuidToStoragePool.remove(uuid) != null;
-    }
-
-    @Override
-    public boolean deleteStoragePool(KVMStoragePool pool) {
-        return deleteStoragePool(pool.getUuid());
-    }
-
-    // called from LibvirtComputingResource.execute(CreateCommand)
-    // does not apply for iScsiAdmStorageAdaptor
-    @Override
-    public KVMPhysicalDisk createPhysicalDisk(String volumeUuid, KVMStoragePool pool, PhysicalDiskFormat format, long size) {
-        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
-    }
-
-    @Override
-    public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map<String, String> details) {
-        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o new
-        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
-
-        iScsiAdmCmd.add("-m", "node");
-        iScsiAdmCmd.add("-T", getIqn(volumeUuid));
-        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
-        iScsiAdmCmd.add("-o", "new");
-
-        String result = iScsiAdmCmd.execute();
-
-        if (result != null) {
-            s_logger.debug("Failed to add iSCSI target " + volumeUuid);
-            System.out.println("Failed to add iSCSI target " + volumeUuid);
-
-            return false;
-        } else {
-            s_logger.debug("Successfully added iSCSI target " + volumeUuid);
-            System.out.println("Successfully added to iSCSI target " + volumeUuid);
-        }
-
-        String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME);
-        String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET);
-
-        if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorSecret)) {
-            try {
-                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.authmethod -v CHAP
-                executeChapCommand(volumeUuid, pool, "node.session.auth.authmethod", "CHAP", null);
-
-                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.username -v username
-                executeChapCommand(volumeUuid, pool, "node.session.auth.username", chapInitiatorUsername, "username");
-
-                // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --op update -n node.session.auth.password -v password
-                executeChapCommand(volumeUuid, pool, "node.session.auth.password", chapInitiatorSecret, "password");
-            } catch (Exception ex) {
-                return false;
-            }
-        }
-
-        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10 --login
-        iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
-
-        iScsiAdmCmd.add("-m", "node");
-        iScsiAdmCmd.add("-T", getIqn(volumeUuid));
-        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
-        iScsiAdmCmd.add("--login");
-
-        result = iScsiAdmCmd.execute();
-
-        if (result != null) {
-            s_logger.debug("Failed to log in to iSCSI target " + volumeUuid);
-            System.out.println("Failed to log in to iSCSI target " + volumeUuid);
-
-            return false;
-        } else {
-            s_logger.debug("Successfully logged in to iSCSI target " + volumeUuid);
-            System.out.println("Successfully logged in to iSCSI target " + volumeUuid);
-        }
-
-        // There appears to be a race condition where logging in to the iSCSI volume via iscsiadm
-        // returns success before the device has been added to the OS.
-        // What happens is you get logged in and the device shows up, but the device may not
-        // show up before we invoke Libvirt to attach the device to a VM.
-        // waitForDiskToBecomeAvailable(String, KVMStoragePool) invokes blockdev
-        // via getPhysicalDisk(String, KVMStoragePool) and checks if the size came back greater
-        // than 0.
-        // After a certain number of tries and a certain waiting period in between tries,
-        // this method could still return (it should not block indefinitely) (the race condition
-        // isn't solved here, but made highly unlikely to be a problem).
-        waitForDiskToBecomeAvailable(volumeUuid, pool);
-
-        return true;
-    }
-
-    private void waitForDiskToBecomeAvailable(String volumeUuid, KVMStoragePool pool) {
-        int numberOfTries = 10;
-        int timeBetweenTries = 1000;
-
-        while (getPhysicalDisk(volumeUuid, pool).getSize() == 0 && numberOfTries > 0) {
-            numberOfTries--;
-
-            try {
-                Thread.sleep(timeBetweenTries);
-            } catch (Exception ex) {
-                // don't do anything
-            }
-        }
-    }
-
-    private void executeChapCommand(String path, KVMStoragePool pool, String nParameter, String vParameter, String detail) throws Exception {
-        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
-
-        iScsiAdmCmd.add("-m", "node");
-        iScsiAdmCmd.add("-T", getIqn(path));
-        iScsiAdmCmd.add("-p", pool.getSourceHost() + ":" + pool.getSourcePort());
-        iScsiAdmCmd.add("--op", "update");
-        iScsiAdmCmd.add("-n", nParameter);
-        iScsiAdmCmd.add("-v", vParameter);
-
-        String result = iScsiAdmCmd.execute();
-
-        boolean useDetail = detail != null && detail.trim().length() > 0;
-
-        detail = useDetail ? detail.trim() + " " : detail;
-
-        if (result != null) {
-            s_logger.debug("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
-            System.out.println("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
-
-            throw new Exception("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result);
-        } else {
-            s_logger.debug("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path);
-            System.out.println("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path);
-        }
-    }
-
-    // example by-path: /dev/disk/by-path/ip-192.168.233.10:3260-iscsi-iqn.2012-03.com.solidfire:storagepool2-lun-0
-    private String getByPath(String host, String path) {
-        return "/dev/disk/by-path/ip-" + host + "-iscsi-" + getIqn(path) + "-lun-" + getLun(path);
-    }
-
-    @Override
-    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
-        String deviceByPath = getByPath(pool.getSourceHost() + ":" + pool.getSourcePort(), volumeUuid);
-        KVMPhysicalDisk physicalDisk = new KVMPhysicalDisk(deviceByPath, volumeUuid, pool);
-
-        physicalDisk.setFormat(PhysicalDiskFormat.RAW);
-
-        long deviceSize = getDeviceSize(deviceByPath);
-
-        physicalDisk.setSize(deviceSize);
-        physicalDisk.setVirtualSize(deviceSize);
-
-        return physicalDisk;
-    }
-
-    private long getDeviceSize(String deviceByPath) {
-        Script iScsiAdmCmd = new Script(true, "blockdev", 0, s_logger);
-
-        iScsiAdmCmd.add("--getsize64", deviceByPath);
-
-        OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
-
-        String result = iScsiAdmCmd.execute(parser);
-
-        if (result != null) {
-            s_logger.warn("Unable to retrieve the size of device " + deviceByPath);
-
-            return 0;
-        }
-
-        return Long.parseLong(parser.getLine());
-    }
-
-    private static String getIqn(String path) {
-        return getComponent(path, 1);
-    }
-
-    private static String getLun(String path) {
-        return getComponent(path, 2);
-    }
-
-    private static String getComponent(String path, int index) {
-        String[] tmp = path.split("/");
-
-        if (tmp.length != 3) {
-            String msg = "Wrong format for iScsi path: " + path + ". It should be formatted as '/targetIQN/LUN'.";
-
-            s_logger.warn(msg);
-
-            throw new CloudRuntimeException(msg);
-        }
-
-        return tmp[index].trim();
-    }
-
-    public boolean disconnectPhysicalDisk(String host, int port, String iqn, String lun) {
-        // use iscsiadm to log out of the iSCSI target and un-discover it
-
-        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10 --logout
-        Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
-
-        iScsiAdmCmd.add("-m", "node");
-        iScsiAdmCmd.add("-T", iqn);
-        iScsiAdmCmd.add("-p", host + ":" + port);
-        iScsiAdmCmd.add("--logout");
-
-        String result = iScsiAdmCmd.execute();
-
-        if (result != null) {
-            s_logger.debug("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result);
-            System.out.println("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result);
-
-            return false;
-        } else {
-            s_logger.debug("Successfully logged out of iSCSI target /" + iqn + "/" + lun);
-            System.out.println("Successfully logged out of iSCSI target /" + iqn + "/" + lun);
-        }
-
-        // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o delete
-        iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger);
-
-        iScsiAdmCmd.add("-m", "node");
-        iScsiAdmCmd.add("-T", iqn);
-        iScsiAdmCmd.add("-p", host + ":" + port);
-        iScsiAdmCmd.add("-o", "delete");
-
-        result = iScsiAdmCmd.execute();
-
-        if (result != null) {
-            s_logger.debug("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result);
-            System.out.println("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result);
-
-            return false;
-        } else {
-            s_logger.debug("Removed iSCSI target /" + iqn + "/" + lun);
-            System.out.println("Removed iSCSI target /" + iqn + "/" + lun);
-        }
-
-        return true;
-    }
-
-    @Override
-    public boolean disconnectPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
-        return disconnectPhysicalDisk(pool.getSourceHost(), pool.getSourcePort(), getIqn(volumeUuid), getLun(volumeUuid));
-    }
-
-    @Override
-    public boolean disconnectPhysicalDiskByPath(String localPath) {
-        String search1 = "/dev/disk/by-path/ip-";
-        String search2 = ":";
-        String search3 = "-iscsi-";
-        String search4 = "-lun-";
-
-        if (localPath.indexOf(search3) == -1) {
-            // this volume doesn't below to this adaptor, so just return true
-            return true;
-        }
-
-        int index = localPath.indexOf(search2);
-
-        String host = localPath.substring(search1.length(), index);
-
-        int index2 = localPath.indexOf(search3);
-
-        String port = localPath.substring(index + search2.length(), index2);
-
-        index = localPath.indexOf(search4);
-
-        String iqn = localPath.substring(index2 + search3.length(), index);
-
-        String lun = localPath.substring(index + search4.length());
-
-        return disconnectPhysicalDisk(host, Integer.parseInt(port), iqn, lun);
-    }
-
-    @Override
-    public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool) {
-        throw new UnsupportedOperationException("Deleting a physical disk is not supported.");
-    }
-
-    // does not apply for iScsiAdmStorageAdaptor
-    @Override
-    public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
-        throw new UnsupportedOperationException("Listing disks is not supported for this configuration.");
-    }
-
-    @Override
-    public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout) {
-        throw new UnsupportedOperationException("Creating a disk from a template is not yet supported for this configuration.");
-    }
-
-    @Override
-    public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool) {
-        throw new UnsupportedOperationException("Creating a template from a disk is not yet supported for this configuration.");
-    }
-
-    @Override
-    public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPool, int timeout) {
-        throw new UnsupportedOperationException("Copying a disk is not supported in this configuration.");
-    }
-
-    @Override
-    public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot, String snapshotName, String name, KVMStoragePool destPool) {
-        throw new UnsupportedOperationException("Creating a disk from a snapshot is not supported in this configuration.");
-    }
-
-    @Override
-    public boolean refresh(KVMStoragePool pool) {
-        return true;
-    }
-
-    @Override
-    public boolean createFolder(String uuid, String path) {
-        throw new UnsupportedOperationException("A folder cannot be created in this configuration.");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStoragePool.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStoragePool.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStoragePool.java
deleted file mode 100644
index 3808815..0000000
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/iScsiAdmStoragePool.java
+++ /dev/null
@@ -1,167 +0,0 @@
-// 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.hypervisor.kvm.storage;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
-
-import com.cloud.storage.Storage.StoragePoolType;
-
-public class iScsiAdmStoragePool implements KVMStoragePool {
-    private String _uuid;
-    private String _sourceHost;
-    private int _sourcePort;
-    private StoragePoolType _storagePoolType;
-    private StorageAdaptor _storageAdaptor;
-    private String _authUsername;
-    private String _authSecret;
-    private String _sourceDir;
-    private String _localPath;
-
-    public iScsiAdmStoragePool(String uuid, String host, int port, StoragePoolType storagePoolType, StorageAdaptor storageAdaptor) {
-        _uuid = uuid;
-        _sourceHost = host;
-        _sourcePort = port;
-        _storagePoolType = storagePoolType;
-        _storageAdaptor = storageAdaptor;
-    }
-
-    @Override
-    public String getUuid() {
-        return _uuid;
-    }
-
-    @Override
-    public String getSourceHost() {
-        return _sourceHost;
-    }
-
-    @Override
-    public int getSourcePort() {
-        return _sourcePort;
-    }
-
-    @Override
-    public long getCapacity() {
-        return 0;
-    }
-
-    @Override
-    public long getUsed() {
-        return 0;
-    }
-
-    @Override
-    public long getAvailable() {
-        return 0;
-    }
-
-    @Override
-    public StoragePoolType getType() {
-        return _storagePoolType;
-    }
-
-    @Override
-    public PhysicalDiskFormat getDefaultFormat() {
-        return PhysicalDiskFormat.RAW;
-    }
-
-    // called from LibvirtComputingResource.copyPhysicalDisk(KVMPhysicalDisk, String, KVMStoragePool) and
-    // from LibvirtComputingResource.createDiskFromTemplate(KVMPhysicalDisk, String, PhysicalDiskFormat, long, KVMStoragePool)
-    // does not apply for iScsiAdmStoragePool
-    @Override
-    public KVMPhysicalDisk createPhysicalDisk(String name, PhysicalDiskFormat format, long size) {
-        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
-    }
-
-    // called from LibvirtComputingResource.execute(CreateCommand) and
-    // from KVMStorageProcessor.createVolume(CreateObjectCommand)
-    // does not apply for iScsiAdmStoragePool
-    @Override
-    public KVMPhysicalDisk createPhysicalDisk(String name, long size) {
-        throw new UnsupportedOperationException("Creating a physical disk is not supported.");
-    }
-
-    @Override
-    public boolean connectPhysicalDisk(String name, Map<String, String> details) {
-        return this._storageAdaptor.connectPhysicalDisk(name, this, details);
-    }
-
-    @Override
-    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid) {
-        return this._storageAdaptor.getPhysicalDisk(volumeUuid, this);
-    }
-
-    @Override
-    public boolean disconnectPhysicalDisk(String volumeUuid) {
-        return this._storageAdaptor.disconnectPhysicalDisk(volumeUuid, this);
-    }
-
-    @Override
-    public boolean deletePhysicalDisk(String volumeUuid) {
-        return this._storageAdaptor.deletePhysicalDisk(volumeUuid, this);
-    }
-
-    // does not apply for iScsiAdmStoragePool
-    @Override
-    public List<KVMPhysicalDisk> listPhysicalDisks() {
-        return this._storageAdaptor.listPhysicalDisks(_uuid, this);
-    }
-
-    // does not apply for iScsiAdmStoragePool
-    @Override
-    public boolean refresh() {
-        return this._storageAdaptor.refresh(this);
-    }
-
-    @Override
-    public boolean delete() {
-        return this._storageAdaptor.deleteStoragePool(this);
-    }
-
-    @Override
-    public boolean createFolder(String path) {
-        return this._storageAdaptor.createFolder(_uuid, path);
-    }
-
-    @Override
-    public boolean isExternalSnapshot() {
-        return false;
-    }
-
-    @Override
-    public String getAuthUserName() {
-        return _authUsername;
-    }
-
-    @Override
-    public String getAuthSecret() {
-        return _authSecret;
-    }
-
-    @Override
-    public String getSourceDir() {
-        return _sourceDir;
-    }
-
-    @Override
-    public String getLocalPath() {
-        return _localPath;
-    }
-}