You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2015/07/10 12:08:02 UTC

[07/50] git commit: updated refs/heads/CLOUDSTACK-8581 to 1a2e80b

CLOUDSTACK-8607 - Adding support to update host passwd on XenServer hypervisors

   - Adding update_host_passwd to VRScripts
   - Add accessor method to host password on CitrixResourceBase
   - Add implementation to CitrixUpdateHostPasswordCommandWrapper
   - Improve testUpdateHostPasswordCommand() unit test on CitrixRequestWrapperTest
   - Add line to patch files on xenserver directory

Concerning the LibVirt change:

   - I forgot to assing the return of the getDefaultHypervisorScriptsDir() method to the hypervisorScriptsDir variable


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

Branch: refs/heads/CLOUDSTACK-8581
Commit: 0dd02ce04341b8026f49fd84be01bfcb7f18bf3d
Parents: 47c7a10
Author: wilderrodrigues <wr...@schubergphilis.com>
Authored: Fri Jul 3 10:24:44 2015 +0200
Committer: wilderrodrigues <wr...@schubergphilis.com>
Committed: Fri Jul 3 10:24:44 2015 +0200

----------------------------------------------------------------------
 .../resource/virtualnetwork/VRScripts.java      |   1 +
 .../kvm/resource/LibvirtComputingResource.java  |   6 +-
 .../xenserver/resource/CitrixResourceBase.java  | 132 ++++++++++---------
 .../CitrixUpdateHostPasswordCommandWrapper.java |  30 ++++-
 .../xenbase/CitrixRequestWrapperTest.java       |  15 ++-
 scripts/vm/hypervisor/kvm/update_host_passwd.sh |  24 ++++
 scripts/vm/hypervisor/update_host_passwd.sh     |  25 ----
 .../hypervisor/xenserver/update_host_passwd.sh  |  24 ++++
 scripts/vm/hypervisor/xenserver/xcpserver/patch |   1 +
 .../vm/hypervisor/xenserver/xenserver56/patch   |   1 +
 .../hypervisor/xenserver/xenserver56fp1/patch   |   1 +
 .../vm/hypervisor/xenserver/xenserver60/patch   |   1 +
 .../vm/hypervisor/xenserver/xenserver62/patch   |   1 +
 .../vm/hypervisor/xenserver/xenserver65/patch   |   1 +
 14 files changed, 168 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
index b915ce6..109801c 100644
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java
@@ -74,6 +74,7 @@ public class VRScripts {
     public static final String VPC_STATIC_NAT = "vpc_staticnat.sh";
     public static final String VPC_STATIC_ROUTE = "vpc_staticroute.sh";
     public static final String VPN_L2TP = "vpn_l2tp.sh";
+    public static final String UPDATE_HOST_PASSWD = "update_host_passwd.sh";
 
     public static final String VR_CFG = "vr_cfg.sh";
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/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 bc28f82..782ea28 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -523,7 +523,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     }
 
     protected String getDefaultHypervisorScriptsDir() {
-        return "scripts/vm/hypervisor";
+        return "scripts/vm/hypervisor/kvm";
     }
 
     protected String getDefaultKvmScriptsDir() {
@@ -557,9 +557,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             domrScriptsDir = getDefaultDomrScriptsDir();
         }
 
-        final String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
+        String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
         if (hypervisorScriptsDir == null) {
-            getDefaultHypervisorScriptsDir();
+            hypervisorScriptsDir = getDefaultHypervisorScriptsDir();
         }
 
         String kvmScriptsDir = (String)params.get("kvm.scripts.dir");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
index 8ed4ffc..24970a6 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
@@ -20,9 +20,9 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -275,6 +275,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         _password.add(password);
     }
 
+    public String getPwdFromQueue() {
+        return _password.peek();
+    }
+
     protected StorageSubsystemCommandHandler buildStorageHandler() {
         final XenServerStorageProcessor processor = new XenServerStorageProcessor(this);
         return new StorageSubsystemCommandHandlerBase(processor);
@@ -3163,9 +3167,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
     public long getVMSnapshotChainSize(final Connection conn, final VolumeObjectTO volumeTo, final String vmName) throws BadServerResponse, XenAPIException, XmlRpcException {
         if (volumeTo.getVolumeType() == Volume.Type.DATADISK) {
-            VDI dataDisk = VDI.getByUuid(conn, volumeTo.getPath());
+            final VDI dataDisk = VDI.getByUuid(conn, volumeTo.getPath());
             if (dataDisk != null) {
-                String dataDiskName = dataDisk.getNameLabel(conn);
+                final String dataDiskName = dataDisk.getNameLabel(conn);
                 if (dataDiskName != null && !dataDiskName.isEmpty()) {
                     volumeTo.setName(dataDiskName);
                 }
@@ -4958,12 +4962,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         }
     }
 
-    public boolean createAndAttachConfigDriveIsoForVM(Connection conn, VM vm, List<String[]> vmDataList, String configDriveLabel) throws XenAPIException, XmlRpcException {
+    public boolean createAndAttachConfigDriveIsoForVM(final Connection conn, final VM vm, final List<String[]> vmDataList, final String configDriveLabel) throws XenAPIException, XmlRpcException {
 
-        String vmName = vm.getNameLabel(conn);
+        final String vmName = vm.getNameLabel(conn);
 
         // create SR
-        SR sr =  createLocalIsoSR(conn, _configDriveSRName+_host.getIp());
+        final SR sr =  createLocalIsoSR(conn, _configDriveSRName+_host.getIp());
         if (sr == null) {
             s_logger.debug("Failed to create local SR for the config drive");
             return false;
@@ -4989,57 +4993,57 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return true;
     }
 
-    public boolean createVmdataFiles(String vmName, List<String[]> vmDataList, String configDriveLabel) {
+    public boolean createVmdataFiles(final String vmName, final List<String[]> vmDataList, final String configDriveLabel) {
 
         // add vm iso to the isolibrary
-        String isoPath = "/tmp/"+vmName+"/configDrive/";
-        String configDriveName = "cloudstack/";
+        final String isoPath = "/tmp/"+vmName+"/configDrive/";
+        final String configDriveName = "cloudstack/";
 
         //create folder for the VM
         //Remove the folder before creating it.
 
         try {
             deleteLocalFolder("/tmp/"+isoPath);
-        } catch (IOException e) {
+        } catch (final IOException e) {
             s_logger.debug("Failed to delete the exiting config drive for vm "+vmName+ " "+ e.getMessage());
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.debug("Failed to delete the exiting config drive for vm "+vmName+ " "+ e.getMessage());
         }
 
 
         if (vmDataList != null) {
-            for (String[] item : vmDataList) {
-                String dataType = item[0];
-                String fileName = item[1];
-                String content = item[2];
+            for (final String[] item : vmDataList) {
+                final String dataType = item[0];
+                final String fileName = item[1];
+                final String content = item[2];
 
                 // create file with content in folder
 
                 if (dataType != null && !dataType.isEmpty()) {
                     //create folder
-                    String  folder = isoPath+configDriveName+dataType;
+                    final String  folder = isoPath+configDriveName+dataType;
                     if (folder != null && !folder.isEmpty()) {
-                        File dir = new File(folder);
-                        boolean result = true;
+                        final File dir = new File(folder);
+                        final boolean result = true;
 
                         try {
                             if (!dir.exists()) {
                                 dir.mkdirs();
                             }
-                        }catch (SecurityException ex) {
+                        }catch (final SecurityException ex) {
                             s_logger.debug("Failed to create dir "+ ex.getMessage());
                             return false;
                         }
 
                         if (result && content != null && !content.isEmpty()) {
                             try {
-                                File file = new File(folder+"/"+fileName+".txt");
-                                OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file.getAbsoluteFile()),"UTF-8");
-                                BufferedWriter bw = new BufferedWriter(fw);
+                                final File file = new File(folder+"/"+fileName+".txt");
+                                final OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file.getAbsoluteFile()),"UTF-8");
+                                final BufferedWriter bw = new BufferedWriter(fw);
                                 bw.write(content);
                                 bw.close();
                                 s_logger.debug("created file: "+ file + " in folder:"+folder);
-                            } catch (IOException ex) {
+                            } catch (final IOException ex) {
                                 s_logger.debug("Failed to create file "+ ex.getMessage());
                                 return false;
                             }
@@ -5053,13 +5057,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         String s = null;
         try {
 
-            String cmd =  "mkisofs -iso-level 3 -V "+ configDriveLabel +" -o "+ isoPath+vmName +".iso " + isoPath;
-            Process p = Runtime.getRuntime().exec(cmd);
+            final String cmd =  "mkisofs -iso-level 3 -V "+ configDriveLabel +" -o "+ isoPath+vmName +".iso " + isoPath;
+            final Process p = Runtime.getRuntime().exec(cmd);
 
-            BufferedReader stdInput = new BufferedReader(new
+            final BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p.getInputStream(),Charset.defaultCharset()));
 
-            BufferedReader stdError = new BufferedReader(new
+            final BufferedReader stdError = new BufferedReader(new
                     InputStreamReader(p.getErrorStream(),Charset.defaultCharset()));
 
             // read the output from the command
@@ -5072,7 +5076,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
                 s_logger.debug(s);
             }
             s_logger.debug(" Created config drive ISO using the command " + cmd +" in the host "+ _host.getIp());
-        } catch (IOException e) {
+        } catch (final IOException e) {
             s_logger.debug(e.getMessage());
             return false;
         }
@@ -5080,11 +5084,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return true;
     }
 
-    public boolean copyConfigDriveIsoToHost(Connection conn, SR sr, String vmName) {
+    public boolean copyConfigDriveIsoToHost(final Connection conn, final SR sr, final String vmName) {
 
-        String vmIso = "/tmp/"+vmName+"/configDrive/"+vmName+".iso";
+        final String vmIso = "/tmp/"+vmName+"/configDrive/"+vmName+".iso";
         //scp file into the host
-        com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
+        final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
 
         try {
             sshConnection.connect(null, 60000, 60000);
@@ -5093,28 +5097,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             }
 
             s_logger.debug("scp config drive iso file "+vmIso +" to host " + _host.getIp() +" path "+_configDriveIsopath);
-            SCPClient scp = new SCPClient(sshConnection);
-            String p = "0755";
+            final SCPClient scp = new SCPClient(sshConnection);
+            final String p = "0755";
 
             scp.put(vmIso, _configDriveIsopath, p);
             sr.scan(conn);
             s_logger.debug("copied config drive iso to host " + _host);
-        } catch (IOException e) {
+        } catch (final IOException e) {
             s_logger.debug("failed to copy configdrive iso " + vmIso + " to host " + _host, e);
             return false;
-        } catch (XmlRpcException e) {
+        } catch (final XmlRpcException e) {
             s_logger.debug("Failed to scan config drive iso SR "+ _configDriveSRName+_host.getIp() + " in host "+ _host, e);
             return false;
         } finally {
             sshConnection.close();
             //clean up the config drive files
 
-            String configDir = "/tmp/"+vmName;
+            final String configDir = "/tmp/"+vmName;
             try {
                 deleteLocalFolder(configDir);
                 s_logger.debug("Successfully cleaned up config drive directory " + configDir
                         + " after copying it to host ");
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 s_logger.debug("Failed to delete config drive folder :" + configDir + " for VM " + vmName + " "
                         + e.getMessage());
             }
@@ -5123,10 +5127,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return true;
     }
 
-    public boolean attachConfigDriveIsoToVm(Connection conn, VM vm) throws XenAPIException, XmlRpcException {
+    public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) throws XenAPIException, XmlRpcException {
 
-        String vmName = vm.getNameLabel(conn);
-        String isoURL = _configDriveIsopath + vmName+".iso";
+        final String vmName = vm.getNameLabel(conn);
+        final String isoURL = _configDriveIsopath + vmName+".iso";
         VDI srVdi;
 
         //1. find the vdi of the iso
@@ -5134,16 +5138,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         //3. attach iso to vm
 
         try {
-            Set<VDI> vdis = VDI.getByNameLabel(conn, vmName+".iso");
+            final Set<VDI> vdis = VDI.getByNameLabel(conn, vmName+".iso");
             if (vdis.isEmpty()) {
                 throw new CloudRuntimeException("Could not find ISO with URL: " + isoURL);
             }
             srVdi =  vdis.iterator().next();
 
-        } catch (XenAPIException e) {
+        } catch (final XenAPIException e) {
             s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
             return false;
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
             return false;
         }
@@ -5151,11 +5155,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         VBD isoVBD = null;
 
         // Find the VM's CD-ROM VBD
-        Set<VBD> vbds = vm.getVBDs(conn);
-        for (VBD vbd : vbds) {
-            Types.VbdType type = vbd.getType(conn);
+        final Set<VBD> vbds = vm.getVBDs(conn);
+        for (final VBD vbd : vbds) {
+            final Types.VbdType type = vbd.getType(conn);
 
-            VBD.Record vbdr = vbd.getRecord(conn);
+            final VBD.Record vbdr = vbd.getRecord(conn);
 
             // if the device exists then attach it
             if (!vbdr.userdevice.equals(_attachIsoDeviceNum) && type == Types.VbdType.CD) {
@@ -5166,14 +5170,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
         if (isoVBD == null) {
             //create vbd
-            VBD.Record cfgDriveVbdr = new VBD.Record();
+            final VBD.Record cfgDriveVbdr = new VBD.Record();
             cfgDriveVbdr.VM = vm;
             cfgDriveVbdr.empty = true;
             cfgDriveVbdr.bootable = false;
             cfgDriveVbdr.userdevice = "autodetect";
             cfgDriveVbdr.mode = Types.VbdMode.RO;
             cfgDriveVbdr.type = Types.VbdType.CD;
-            VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
+            final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
             isoVBD = cfgDriveVBD;
 
             s_logger.debug("Created CD-ROM VBD for VM: " + vm);
@@ -5189,7 +5193,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
                 // Insert the new ISO
                 isoVBD.insert(conn, srVdi);
                 s_logger.debug("Attached config drive iso to vm " + vmName);
-            }catch (XmlRpcException ex) {
+            }catch (final XmlRpcException ex) {
                 s_logger.debug("Failed to attach config drive iso to vm " + vmName);
                 return false;
             }
@@ -5198,7 +5202,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         return true;
     }
 
-    public SR createLocalIsoSR(Connection conn, String srName) throws XenAPIException, XmlRpcException {
+    public SR createLocalIsoSR(final Connection conn, final String srName) throws XenAPIException, XmlRpcException {
 
         // if config drive sr already exists then return
         SR sr = getSRByNameLabelandHost(conn, _configDriveSRName+_host.getIp());
@@ -5209,20 +5213,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         }
 
         try{
-            Map<String, String> deviceConfig = new HashMap<String, String>();
+            final Map<String, String> deviceConfig = new HashMap<String, String>();
 
-            com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
+            final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
             try {
                 sshConnection.connect(null, 60000, 60000);
                 if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
                     throw new CloudRuntimeException("Unable to authenticate");
                 }
 
-                String cmd = "mkdir -p " + _configDriveIsopath;
+                final String cmd = "mkdir -p " + _configDriveIsopath;
                 if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
                     throw new CloudRuntimeException("Cannot create directory configdrive_iso on XenServer hosts");
                 }
-            } catch (IOException e) {
+            } catch (final IOException e) {
                 throw new CloudRuntimeException("Unable to create iso folder", e);
             } finally {
                 sshConnection.close();
@@ -5231,8 +5235,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
             deviceConfig.put("location",  _configDriveIsopath);
             deviceConfig.put("legacy_mode", "true");
-            Host host = Host.getByUuid(conn, _host.getUuid());
-            String type = SRType.ISO.toString();
+            final Host host = Host.getByUuid(conn, _host.getUuid());
+            final String type = SRType.ISO.toString();
             sr = SR.create(conn, host, deviceConfig, new Long(0),  _configDriveIsopath, "iso", type, "iso", false, new HashMap<String, String>());
 
             sr.setNameLabel(conn, srName);
@@ -5241,12 +5245,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             sr.scan(conn);
             s_logger.debug("Config drive ISO SR at the path " + _configDriveIsopath  +" got created in host " + _host);
             return sr;
-        } catch (XenAPIException e) {
-            String msg = "createLocalIsoSR failed! mountpoint " + e.toString();
+        } catch (final XenAPIException e) {
+            final String msg = "createLocalIsoSR failed! mountpoint " + e.toString();
             s_logger.warn(msg, e);
             throw new CloudRuntimeException(msg, e);
-        } catch (Exception e) {
-            String msg = "createLocalIsoSR failed! mountpoint:  due to " + e.getMessage();
+        } catch (final Exception e) {
+            final String msg = "createLocalIsoSR failed! mountpoint:  due to " + e.getMessage();
             s_logger.warn(msg, e);
             throw new CloudRuntimeException(msg, e);
         }
@@ -5254,16 +5258,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
     }
 
 
-    public void deleteLocalFolder(String directory) throws Exception {
+    public void deleteLocalFolder(final String directory) throws Exception {
         if (directory == null || directory.isEmpty()) {
-            String msg = "Invalid directory path (null/empty) detected. Cannot delete specified directory.";
+            final String msg = "Invalid directory path (null/empty) detected. Cannot delete specified directory.";
             s_logger.debug(msg);
             throw new Exception(msg);
         }
 
         try {
             FileUtils.deleteDirectory(new File(directory));
-        } catch (IOException e) {
+        } catch (final IOException e) {
             // IOException here means failure to delete. Not swallowing it here to
             // let the caller handle with appropriate contextual log message.
             throw e;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java
index d95ba7a..7d0c99a 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java
@@ -19,18 +19,46 @@
 
 package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.UpdateHostPasswordCommand;
+import com.cloud.agent.resource.virtualnetwork.VRScripts;
 import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
 import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.Pair;
+import com.cloud.utils.ssh.SshHelper;
 
 @ResourceWrapper(handles =  UpdateHostPasswordCommand.class)
 public final class CitrixUpdateHostPasswordCommandWrapper extends CommandWrapper<UpdateHostPasswordCommand, Answer, CitrixResourceBase> {
 
+    private static final Logger s_logger = Logger.getLogger(CitrixUpdateHostPasswordCommandWrapper.class);
+    private static final int TIMEOUT = 10000;
+
     @Override
     public Answer execute(final UpdateHostPasswordCommand command, final CitrixResourceBase citrixResourceBase) {
+        final String hostIp = command.getHostIp();
+        final String username = command.getUsername();
+        final String newPassword = command.getNewPassword();
+
+        final StringBuffer cmdLine = new StringBuffer();
+        cmdLine.append(VRScripts.UPDATE_HOST_PASSWD);
+        cmdLine.append(' ');
+        cmdLine.append(username);
+        cmdLine.append(' ');
+        cmdLine.append(newPassword);
+
+        Pair<Boolean, String> result;
+
+        try {
+            s_logger.debug("Executing command in Host: " + cmdLine);
+            result = SshHelper.sshExecute(hostIp, 22, username, null, citrixResourceBase.getPwdFromQueue(), cmdLine.toString(), 60000, 60000, TIMEOUT);
+        } catch (final Exception e) {
+            return new Answer(command, false, e.getMessage());
+        }
+        // Add new password to the stack.
         citrixResourceBase.addToPwdQueue(command.getNewPassword());
-        return new Answer(command, true, null);
+        return new Answer(command, result.first(), result.second());
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
index 5948303..91f59be 100644
--- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
+++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java
@@ -118,6 +118,7 @@ import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.agent.resource.virtualnetwork.VRScripts;
 import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
 import com.cloud.host.HostEnvironment;
 import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
@@ -129,6 +130,7 @@ import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
 import com.cloud.storage.resource.StorageSubsystemCommandHandler;
+import com.cloud.utils.ExecutionResult;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.VirtualMachine;
 import com.xensource.xenapi.Connection;
@@ -1320,14 +1322,23 @@ public class CitrixRequestWrapperTest {
 
     @Test
     public void testUpdateHostPasswordCommand() {
-        final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123");
+        final ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);
+
+        final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123", "127.0.0.1");
+
+        final StringBuffer buff = new StringBuffer();
+        buff.append(updatePwd.getUsername());
+        buff.append(' ');
+        buff.append(updatePwd.getNewPassword());
+
+        when(citrixResourceBase.executeInVR(updatePwd.getHostIp(), VRScripts.UPDATE_HOST_PASSWD, buff.toString())).thenReturn(executionResult);
 
         final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
         assertNotNull(wrapper);
 
         final Answer answer = wrapper.execute(updatePwd, citrixResourceBase);
 
-        assertTrue(answer.getResult());
+        assertFalse(answer.getResult());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/kvm/update_host_passwd.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/kvm/update_host_passwd.sh b/scripts/vm/hypervisor/kvm/update_host_passwd.sh
new file mode 100755
index 0000000..39e4a3b
--- /dev/null
+++ b/scripts/vm/hypervisor/kvm/update_host_passwd.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+username=$1
+new_passwd=$2
+
+echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username
+
+return $?;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/update_host_passwd.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/update_host_passwd.sh b/scripts/vm/hypervisor/update_host_passwd.sh
deleted file mode 100755
index 7d4eec5..0000000
--- a/scripts/vm/hypervisor/update_host_passwd.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-hostIp=$1
-username=$2
-new_passwd=$3
-
-ssh -o StrictHostKeyChecking=no -p 3922 -i /root/.ssh/id_rsa.cloud root@$hostIp "echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username"
-
-return $?;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/update_host_passwd.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/update_host_passwd.sh b/scripts/vm/hypervisor/xenserver/update_host_passwd.sh
new file mode 100755
index 0000000..39e4a3b
--- /dev/null
+++ b/scripts/vm/hypervisor/xenserver/update_host_passwd.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+username=$1
+new_passwd=$2
+
+echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username
+
+return $?;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xcpserver/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch
index 0f9d9a0..62e15e3 100644
--- a/scripts/vm/hypervisor/xenserver/xcpserver/patch
+++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch
@@ -59,3 +59,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
 cloudstack_plugins.conf=..,0644,/etc/xensource
 cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xenserver56/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch
index e24136d..2145b31 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver56/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch
@@ -63,3 +63,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
 cloudstack_plugins.conf=..,0644,/etc/xensource
 cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
index 5e15598..60404dc 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
@@ -62,3 +62,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
 cloudstack_plugins.conf=..,0644,/etc/xensource
 cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xenserver60/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch
index 84472a6..c22d469 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver60/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch
@@ -68,3 +68,4 @@ ovs-pvlan-cleanup.sh=../../../network,0755,/opt/cloud/bin
 ovs-get-dhcp-iface.sh=..,0755,/opt/cloud/bin
 ovs-get-bridge.sh=..,0755,/opt/cloud/bin
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xenserver62/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver62/patch b/scripts/vm/hypervisor/xenserver/xenserver62/patch
index 939e97c..0901924 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver62/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver62/patch
@@ -64,3 +64,4 @@ ovs-pvlan-cleanup.sh=../../../network,0755,/opt/cloud/bin
 ovs-get-dhcp-iface.sh=..,0755,/opt/cloud/bin
 ovs-get-bridge.sh=..,0755,/opt/cloud/bin
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0dd02ce0/scripts/vm/hypervisor/xenserver/xenserver65/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver65/patch b/scripts/vm/hypervisor/xenserver/xenserver65/patch
index 939e97c..0901924 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver65/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver65/patch
@@ -64,3 +64,4 @@ ovs-pvlan-cleanup.sh=../../../network,0755,/opt/cloud/bin
 ovs-get-dhcp-iface.sh=..,0755,/opt/cloud/bin
 ovs-get-bridge.sh=..,0755,/opt/cloud/bin
 cloudlog=..,0644,/etc/logrotate.d
+update_host_passwd.sh=..,0755,/opt/cloud/bin
\ No newline at end of file