Skip to content

Commit 484d6c4

Browse files
author
Sheng Yang
committed
CLOUDSTACK-2792: Call savepassword.sh inside VR
Also only set password when password service is running, thus avoid setting for redundant router BACKUP router.
1 parent 85dc65c commit 484d6c4

7 files changed

Lines changed: 87 additions & 30 deletions

File tree

‎core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
@Local(value = {VirtualRoutingResource.class})
104104
public class VirtualRoutingResource implements Manager {
105105
private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class);
106-
private String _savepasswordPath; // This script saves a random password to the DomR file system
107106
private String _publicIpAddress;
108107
private String _firewallPath;
109108
private String _loadbPath;
@@ -548,13 +547,14 @@ protected Answer execute(final SavePasswordCommand cmd) {
548547
final String vmIpAddress = cmd.getVmIpAddress();
549548
final String local = vmName;
550549

551-
// Run save_password_to_domr.sh
552-
final String result = savePassword(routerPrivateIPAddress, vmIpAddress, password, local);
550+
String args = "-v " + vmIpAddress;
551+
args += " -p " + password;
552+
553+
String result = routerProxy("savepassword.sh", routerPrivateIPAddress, args);
553554
if (result != null) {
554555
return new Answer(cmd, false, "Unable to save password to DomR.");
555-
} else {
556-
return new Answer(cmd);
557556
}
557+
return new Answer(cmd);
558558
}
559559

560560
protected Answer execute(final DhcpEntryCommand cmd) {
@@ -813,16 +813,6 @@ private Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, fin
813813
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
814814
}
815815

816-
public String savePassword(final String privateIpAddress, final String vmIpAddress, final String password, final String localPath) {
817-
final Script command = new Script(_savepasswordPath, _startTimeout, s_logger);
818-
command.add("-r", privateIpAddress);
819-
command.add("-v", vmIpAddress);
820-
command.add("-p", password);
821-
command.add(localPath);
822-
823-
return command.execute();
824-
}
825-
826816
public String assignGuestNetwork(final String dev, final String routerIP,
827817
final String routerGIP, final String gateway, final String cidr,
828818
final String netmask, final String dns, final String domainName) {
@@ -1128,11 +1118,6 @@ public boolean configure(final String name, final Map<String, Object> params) th
11281118
throw new ConfigurationException("Unable to find the call_loadbalancer.sh");
11291119
}
11301120

1131-
_savepasswordPath = findScript("save_password_to_domr.sh");
1132-
if (_savepasswordPath == null) {
1133-
throw new ConfigurationException("Unable to find save_password_to_domr.sh");
1134-
}
1135-
11361121
_dhcpEntryPath = findScript("dhcp_entry.sh");
11371122
if (_dhcpEntryPath == null) {
11381123
throw new ConfigurationException("Unable to find dhcp_entry.sh");
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Copyright 2012 Citrix Systems, Inc. Licensed under the
3+
# Apache License, Version 2.0 (the "License"); you may not use this
4+
# file except in compliance with the License. Citrix Systems, Inc.
5+
# reserves all rights not expressly granted by the License.
6+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
# Automatically generated by addcopyright.py at 04/03/2012
14+
15+
16+
17+
18+
19+
# Usage
20+
# save_password -v <user VM IP> -p <password>
21+
22+
source /root/func.sh
23+
24+
lock="passwdlock"
25+
#default timeout value is 30 mins as password reset command is not synchronized on agent side any more,
26+
#and multiple commands can be sent to the same VR at a time
27+
locked=$(getLockFile $lock 1800)
28+
if [ "$locked" != "1" ]
29+
then
30+
exit 1
31+
fi
32+
33+
PASSWD_FILE=/var/cache/cloud/passwords
34+
35+
while getopts 'v:p:' OPTION
36+
do
37+
case $OPTION in
38+
v) VM_IP="$OPTARG"
39+
;;
40+
p)
41+
ENCODEDPASSWORD="$OPTARG"
42+
PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]')
43+
;;
44+
?) echo "Incorrect usage"
45+
unlock_exit 1 $lock $locked
46+
;;
47+
esac
48+
done
49+
50+
[ -f $PASSWD_FILE ] || touch $PASSWD_FILE
51+
52+
sed -i /$VM_IP/d $PASSWD_FILE
53+
54+
ps aux | grep serve_password.sh |grep -v grep 2>&1 > /dev/null
55+
if [ $? -eq 0 ]
56+
then
57+
echo "$VM_IP=$PASSWORD" >> $PASSWD_FILE
58+
else
59+
echo "$VM_IP=saved_password" >> $PASSWD_FILE
60+
fi
61+
62+
unlock_exit $? $lock $locked

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,15 +2052,15 @@ protected Answer execute(SavePasswordCommand cmd) {
20522052
String args = " -v " + vmIpAddress;
20532053

20542054
if (s_logger.isDebugEnabled()) {
2055-
s_logger.debug("Run command on domain router " + controlIp + ", /root/savepassword.sh " + args + " -p " + StringUtils.getMaskedPasswordForDisplay(cmd.getPassword()));
2055+
s_logger.debug("Run command on domain router " + controlIp + ", /opt/cloud/bin/savepassword.sh " + args + " -p " + StringUtils.getMaskedPasswordForDisplay(cmd.getPassword()));
20562056
}
20572057

20582058
args += " -p " + password;
20592059

20602060

20612061
try {
20622062
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
2063-
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/root/savepassword.sh " + args);
2063+
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/opt/cloud/bin/savepassword.sh " + args);
20642064

20652065
if (!result.first()) {
20662066
s_logger.error("savepassword command on domain router " + controlIp + " failed, message: " + result.second());

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,16 +2228,12 @@ protected Answer execute(final SavePasswordCommand cmd) {
22282228
Connection conn = getConnection();
22292229
final String password = cmd.getPassword();
22302230
final String routerPrivateIPAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
2231-
final String vmName = cmd.getVmName();
22322231
final String vmIpAddress = cmd.getVmIpAddress();
2233-
final String local = vmName;
22342232

2235-
// Run save_password_to_domr.sh
2236-
String args = "-r " + routerPrivateIPAddress;
2233+
String args = "savepassword.sh " + routerPrivateIPAddress;
22372234
args += " -v " + vmIpAddress;
22382235
args += " -p " + password;
2239-
args += " " + local;
2240-
String result = callHostPlugin(conn, "vmops", "savePassword", "args", args);
2236+
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
22412237

22422238
if (result == null || result.isEmpty()) {
22432239
return new Answer(cmd, false, "savePassword failed");

systemvm/patches/debian/config/root/savepassword.sh renamed to systemvm/patches/debian/config/opt/cloud/bin/savepassword.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ done
5353
[ -f $PASSWD_FILE ] || touch $PASSWD_FILE
5454

5555
sed -i /$VM_IP/d $PASSWD_FILE
56-
echo "$VM_IP=$PASSWORD" >> $PASSWD_FILE
56+
57+
ps aux | grep serve_password.sh |grep -v grep 2>&1 > /dev/null
58+
if [ $? -eq 0 ]
59+
then
60+
echo "$VM_IP=$PASSWORD" >> $PASSWD_FILE
61+
else
62+
echo "$VM_IP=saved_password" >> $PASSWD_FILE
63+
fi
5764

5865
unlock_exit $? $lock $locked

‎systemvm/patches/debian/config/root/redundant_router/check_heartbeat.sh.templ‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ then
2525
if [ $diff -lt 30 ]
2626
then
2727
echo Keepalived process is dead! >> [RROUTER_LOG]
28+
[RROUTER_BIN_PATH]/services.sh stop >> [RROUTER_LOG] 2>&1
29+
[RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1
30+
[RROUTER_BIN_PATH]/primary-backup.sh fault >> [RROUTER_LOG] 2>&1
2831
service keepalived stop >> [RROUTER_LOG] 2>&1
2932
service conntrackd stop >> [RROUTER_LOG] 2>&1
3033
pkill -9 keepalived >> [RROUTER_LOG] 2>&1
31-
[RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1
34+
pkill -9 conntrackd >> [RROUTER_LOG] 2>&1
3235
echo Status: FAULT \(keepalived process is dead\) >> [RROUTER_LOG]
3336
exit
3437
fi

‎systemvm/patches/debian/config/root/redundant_router/fault.sh.templ‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ fi
2727

2828
echo To fault called >> [RROUTER_LOG]
2929
[RROUTER_BIN_PATH]/disable_pubip.sh >> [RROUTER_LOG] 2>&1
30+
echo Disable public ip >> [RROUTER_LOG]
31+
[RROUTER_BIN_PATH]/services.sh stop >> [RROUTER_LOG] 2>&1
32+
echo Stop services $? >> [RROUTER_LOG]
3033
[RROUTER_BIN_PATH]/primary-backup.sh fault >> [RROUTER_LOG] 2>&1
34+
echo Switch conntrackd mode fault $? >> [RROUTER_LOG]
3135
echo Status: FAULT >> [RROUTER_LOG]
3236

3337
releaseLockFile $lock $locked

0 commit comments

Comments
 (0)