cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [25/50] [abbrv] git commit: updated refs/heads/reporter to 28300b5
Date Wed, 08 Jul 2015 19:20:00 GMT
CLOUDSTACK-8607 - Adding update_host_passwd.sh script

   - Modifying the LibvirtUpdateHostPasswordCommandWrapper in order to execute the script
on the host
   - Adding the script path to LibvirtComputingResource
   - Adding the host IP address as an instance variable on UpdateHostPasswordCommand
   - Improving the Unit Test (LibvirtComputingResourceTest) to get it covering the new code


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

Branch: refs/heads/reporter
Commit: 47c7a1083fc4be9e74cb3fd73fce069c5e85c1cc
Parents: a74971d
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Thu Jul 2 14:54:51 2015 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Thu Jul 2 14:54:51 2015 +0200

----------------------------------------------------------------------
 .../agent/api/UpdateHostPasswordCommand.java    | 17 +++++++++++--
 .../kvm/resource/LibvirtComputingResource.java  | 20 ++++++++++++++++
 ...LibvirtUpdateHostPasswordCommandWrapper.java | 19 ++++++++++++++-
 .../resource/LibvirtComputingResourceTest.java  |  7 ++++--
 scripts/vm/hypervisor/update_host_passwd.sh     | 25 ++++++++++++++++++++
 .../com/cloud/resource/ResourceManagerImpl.java |  7 +++++-
 6 files changed, 89 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/47c7a108/core/src/com/cloud/agent/api/UpdateHostPasswordCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/UpdateHostPasswordCommand.java b/core/src/com/cloud/agent/api/UpdateHostPasswordCommand.java
index e8dfa13..1a75168 100644
--- a/core/src/com/cloud/agent/api/UpdateHostPasswordCommand.java
+++ b/core/src/com/cloud/agent/api/UpdateHostPasswordCommand.java
@@ -22,17 +22,26 @@ package com.cloud.agent.api;
 import com.cloud.agent.api.LogLevel.Log4jLevel;
 
 public class UpdateHostPasswordCommand extends Command {
+
     @LogLevel(Log4jLevel.Off)
     protected String username;
     @LogLevel(Log4jLevel.Off)
     protected String newPassword;
+    @LogLevel(Log4jLevel.Off)
+    protected String hostIp;
+
 
     protected UpdateHostPasswordCommand() {
     }
 
-    public UpdateHostPasswordCommand(String username, String newPassword) {
+    public UpdateHostPasswordCommand(final String username, final String newPassword) {
+        this(username, newPassword, null);
+    }
+
+    public UpdateHostPasswordCommand(final String username, final String newPassword, final
String hostIp) {
         this.username = username;
         this.newPassword = newPassword;
+        this.hostIp = hostIp;
     }
 
     public String getNewPassword() {
@@ -43,8 +52,12 @@ public class UpdateHostPasswordCommand extends Command {
         return username;
     }
 
+    public String getHostIp() {
+        return hostIp;
+    }
+
     @Override
     public boolean executeInSequence() {
         return false;
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/47c7a108/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 7bd02d0..bc28f82 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
@@ -257,6 +257,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
     private String _pingTestPath;
 
+    private String _updateHostPasswdPath;
+
     private int _dom0MinMem;
 
     protected boolean _disconnected = true;
@@ -372,6 +374,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         return _pingTestPath;
     }
 
+    public String getUpdateHostPasswdPath() {
+        return _updateHostPasswdPath;
+    }
+
     public int getTimeout() {
         return _timeout;
     }
@@ -516,6 +522,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         return "scripts/storage/qcow2";
     }
 
+    protected String getDefaultHypervisorScriptsDir() {
+        return "scripts/vm/hypervisor";
+    }
+
     protected String getDefaultKvmScriptsDir() {
         return "scripts/vm/hypervisor/kvm";
     }
@@ -547,6 +557,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
             domrScriptsDir = getDefaultDomrScriptsDir();
         }
 
+        final String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
+        if (hypervisorScriptsDir == null) {
+            getDefaultHypervisorScriptsDir();
+        }
+
         String kvmScriptsDir = (String)params.get("kvm.scripts.dir");
         if (kvmScriptsDir == null) {
             kvmScriptsDir = getDefaultKvmScriptsDir();
@@ -595,6 +610,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
         _clusterId = (String)params.get("cluster");
 
+        _updateHostPasswdPath = Script.findScript(hypervisorScriptsDir, "update_host_passwd.sh");
+        if (_updateHostPasswdPath == null) {
+            throw new ConfigurationException("Unable to find update_host_passwd.sh");
+        }
+
         _modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh");
         if (_modifyVlanPath == null) {
             throw new ConfigurationException("Unable to find modifyvlan.sh");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/47c7a108/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
index 5b7c7da..7ed827d 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
@@ -19,17 +19,34 @@
 
 package com.cloud.hypervisor.kvm.resource.wrapper;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.UpdateHostPasswordCommand;
 import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
 import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.script.Script;
 
 @ResourceWrapper(handles =  UpdateHostPasswordCommand.class)
 public final class LibvirtUpdateHostPasswordCommandWrapper extends CommandWrapper<UpdateHostPasswordCommand,
Answer, LibvirtComputingResource> {
 
+    private static final Logger s_logger = Logger.getLogger(LibvirtUpdateHostPasswordCommandWrapper.class);
+    private static final int TIMEOUT = 10000;
+
     @Override
     public Answer execute(final UpdateHostPasswordCommand command, final LibvirtComputingResource
libvirtComputingResource) {
-        return new Answer(command, true, null);
+        final String hostIp = command.getHostIp();
+        final String username = command.getUsername();
+        final String newPassword = command.getNewPassword();
+
+        final Script script = new Script(libvirtComputingResource.getUpdateHostPasswdPath(),
TIMEOUT, s_logger);
+        script.add(hostIp, username, newPassword);
+        final String result = script.execute();
+
+        if (result != null) {
+            return new Answer(command, false, result);
+        }
+        return new Answer(command);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/47c7a108/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index d5ce9bf..8ccdce5 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -5076,15 +5076,18 @@ public class LibvirtComputingResourceTest {
 
     @Test
     public void testUpdateHostPasswordCommand() {
+        final String hostIp = "127.0.0.1";
         final String username = "root";
         final String newPassword = "password";
-        final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username,
newPassword);
+        final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username,
newPassword, hostIp);
+
+        when(libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
 
         final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
         assertNotNull(wrapper);
 
         final Answer answer = wrapper.execute(command, libvirtComputingResource);
 
-        assertTrue(answer.getResult());
+        assertFalse(answer.getResult());
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/47c7a108/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
new file mode 100755
index 0000000..7d4eec5
--- /dev/null
+++ b/scripts/vm/hypervisor/update_host_passwd.sh
@@ -0,0 +1,25 @@
+#!/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/47c7a108/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index b6f7f4e..c31d2a5 100644
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -2233,7 +2233,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         final String username = nv.getValue();
         nv = _hostDetailsDao.findDetail(hostId, ApiConstants.PASSWORD);
         final String password = nv.getValue();
-        final UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
+
+
+        final HostVO host = _hostDao.findById(hostId);
+        final String hostIpAddress = host.getPrivateIpAddress();
+
+        final UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password,
hostIpAddress);
         final Answer answer = _agentMgr.easySend(hostId, cmd);
         return answer.getResult();
     }


Mime
View raw message