bug 11130: Add GetDomRVersionCmd

This commit is contained in:
Sheng Yang 2011-09-23 16:37:30 -07:00
parent 33b1055c01
commit 89e45bd671
11 changed files with 220 additions and 1 deletions

View File

@ -0,0 +1,46 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
public class GetDomRVersionAnswer extends Answer {
public static final String ROUTER_NAME = "router.name";
public static final String ROUTER_IP = "router.ip";
String templateVersion;
String scriptsVersion;
protected GetDomRVersionAnswer() {
}
public GetDomRVersionAnswer(GetDomRVersionCmd cmd, String details, String templateVersion, String scriptsVersion) {
super(cmd, true, details);
this.templateVersion = templateVersion;
this.scriptsVersion = scriptsVersion;
}
public GetDomRVersionAnswer(GetDomRVersionCmd cmd, String details) {
super(cmd, false, details);
}
public String getTemplateVersion() {
return this.templateVersion;
}
public String getScriptsVersion() {
return this.scriptsVersion;
}
}

View File

@ -0,0 +1,31 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api;
import com.cloud.agent.api.routing.NetworkElementCommand;
public class GetDomRVersionCmd extends NetworkElementCommand {
@Override
public boolean executeInSequence() {
return false;
}
public GetDomRVersionCmd() {
super();
}
}

View File

@ -44,6 +44,8 @@ import com.cloud.agent.api.BumpUpPriorityCommand;
import com.cloud.agent.api.CheckRouterAnswer;
import com.cloud.agent.api.CheckRouterCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
@ -96,6 +98,7 @@ public class VirtualRoutingResource implements Manager {
private String _getRouterStatusPath;
private String _bumpUpPriorityPath;
private String _l2tpVpnPath;
private String _getDomRVersionPath;
private int _timeout;
@ -136,6 +139,8 @@ public class VirtualRoutingResource implements Manager {
return execute((RemoteAccessVpnCfgCommand)cmd);
} else if (cmd instanceof VpnUsersCfgCommand) {
return execute((VpnUsersCfgCommand)cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
return execute((GetDomRVersionCmd)cmd);
}
else {
return Answer.createUnsupportedCommandAnswer(cmd);
@ -495,6 +500,31 @@ public class VirtualRoutingResource implements Manager {
return new Answer(cmd, true, null);
}
protected String getDomRVersion(String routerIP) {
final Script command = new Script(_getDomRVersionPath, _timeout, s_logger);
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
command.add(routerIP);
String result = command.execute(parser);
if (result == null) {
return parser.getLine();
}
return null;
}
protected Answer execute(GetDomRVersionCmd cmd) {
final String routerPrivateIPAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
final String result = getDomRVersion(routerPrivateIPAddress);
if (result == null || result.isEmpty()) {
return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
}
String[] lines = result.split("&");
if (lines.length != 2) {
return new GetDomRVersionAnswer(cmd, result);
}
return new GetDomRVersionAnswer(cmd, result, lines[0], lines[1]);
}
protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
return executeProxyLoadScan(cmd, cmd.getProxyVmId(), cmd.getProxyVmName(), cmd.getProxyManagementIp(), cmd.getProxyCmdPort());
}
@ -826,6 +856,11 @@ public class VirtualRoutingResource implements Manager {
throw new ConfigurationException("Unable to find l2tp_vpn.sh");
}
_getDomRVersionPath = findScript("getDomRVersion.sh");
if(_getDomRVersionPath == null) {
throw new ConfigurationException("Unable to find getRouterStatus.sh");
}
return true;
}

View File

@ -54,6 +54,8 @@ import com.cloud.agent.api.DeleteSnapshotBackupAnswer;
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
import com.cloud.agent.api.DeleteSnapshotsDirCommand;
import com.cloud.agent.api.DeleteStoragePoolCommand;
import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.GetHostStatsAnswer;
import com.cloud.agent.api.GetHostStatsCommand;
import com.cloud.agent.api.GetStorageStatsAnswer;
@ -393,6 +395,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
answer = execute((SetFirewallRulesCommand)cmd);
} else if (cmd instanceof BumpUpPriorityCommand) {
answer = execute((BumpUpPriorityCommand)cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
answer = execute((GetDomRVersionCmd)cmd);
} else {
answer = Answer.createUnsupportedCommandAnswer(cmd);
}
@ -935,6 +939,39 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return new CheckRouterAnswer(cmd, result.second(), true);
}
protected Answer execute(GetDomRVersionCmd cmd) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Executing resource GetDomRVersionCmd: " + _gson.toJson(cmd));
s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /opt/cloud/bin/get_template_version.sh ");
}
Pair<Boolean, String> result;
try {
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
result = SshHelper.sshExecute(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
"/opt/cloud/bin/get_template_version.sh ");
if (!result.first()) {
s_logger.error("GetDomRVersionCmd on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second());
return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed due to " + result.second());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("GetDomRVersionCmd on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed");
}
} catch (Throwable e) {
String msg = "GetDomRVersionCmd failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg);
return new GetDomRVersionAnswer(cmd, msg);
}
String[] lines = result.second().split("&");
if (lines.length != 2) {
return new GetDomRVersionAnswer(cmd, result.second());
}
return new GetDomRVersionAnswer(cmd, result.second(), lines[0], lines[1]);
}
protected Answer execute(BumpUpPriorityCommand cmd) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Executing resource BumpUpPriorityCommand: " + _gson.toJson(cmd));

View File

@ -89,6 +89,8 @@ import com.cloud.agent.api.GetVmStatsAnswer;
import com.cloud.agent.api.GetVmStatsCommand;
import com.cloud.agent.api.GetVncPortAnswer;
import com.cloud.agent.api.GetVncPortCommand;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.HostStatsEntry;
import com.cloud.agent.api.ClusterSyncAnswer;
import com.cloud.agent.api.ClusterSyncCommand;
@ -509,6 +511,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((BumpUpPriorityCommand)cmd);
} else if (cmd instanceof ClusterSyncCommand) {
return execute((ClusterSyncCommand)cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
return execute((GetDomRVersionCmd)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
@ -1228,6 +1232,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return new CheckRouterAnswer(cmd, result, true);
}
private GetDomRVersionAnswer execute(GetDomRVersionCmd cmd) {
Connection conn = getConnection();
String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String result = callHostPlugin(conn, "vmops", "getDomRVersion", "args", args);
if (result == null || result.isEmpty()) {
return new GetDomRVersionAnswer(cmd, "getDomRVersionCmd failed");
}
String[] lines = result.split("&");
if (lines.length != 2) {
return new GetDomRVersionAnswer(cmd, result);
}
return new GetDomRVersionAnswer(cmd, result, lines[0], lines[1]);
}
private Answer execute(BumpUpPriorityCommand cmd) {
Connection conn = getConnection();
String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);

View File

@ -0,0 +1,4 @@
#!/bin/bash
echo -n `cat /etc/cloudstack-release`'&'
cat /var/cache/cloud/cloud-scripts-signature

View File

@ -0,0 +1,32 @@
#!/bin/bash
usage() {
printf "Usage:\n %s <domR eth1 ip> \n" $(basename $0) >&2
printf " %s <domR eth1 ip> \n" $(basename $0) >&2
}
cert="/root/.ssh/id_rsa.cloud"
domRIp=$1
shift
# check if gateway domain is up and running
check_gw() {
ping -c 1 -n -q $1 > /dev/null
if [ $? -gt 0 ]
then
sleep 1
ping -c 1 -n -q $1 > /dev/null
fi
return $?;
}
# Check if DomR is up and running. If not, exit with error code 1.
check_gw "$domRIp"
if [ $? -gt 0 ]
then
exit 1
fi
ssh -p 3922 -q -o StrictHostKeyChecking=no -i $cert root@$domRIp "/opt/cloud/bin/get_template_version.sh"
exit $?

0
scripts/network/domr/getRouterStatus.sh Normal file → Executable file
View File

View File

@ -1140,6 +1140,20 @@ def bumpUpPriority(session, args):
return txt
@echo
def getDomRVersion(session, args):
sargs = args['args']
cmd = sargs.split(' ')
cmd.insert(0, "/opt/xensource/bin/getDomRVersion.sh")
cmd.insert(0, "/bin/bash")
try:
txt = util.pread2(cmd)
except:
util.SMlog(" get domR version fail! ")
txt = ''
return txt
if __name__ == "__main__":
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
"getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration,
@ -1154,4 +1168,4 @@ if __name__ == "__main__":
"get_rule_logs_for_vms":get_rule_logs_for_vms,
"setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn,
"cleanup_rules":cleanup_rules, "checkRouter":checkRouter,
"bumpUpPriority":bumpUpPriority })
"bumpUpPriority":bumpUpPriority, "getDomRVersion":getDomRVersion })

View File

@ -47,3 +47,4 @@ cloud-clean-vlan.sh=..,0755,/opt/xensource/bin
cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin
getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin
bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin
getDomRVersion.sh=../../../../network/domr/,0755,/opt/xensource/bin

View File

@ -47,3 +47,4 @@ cloud-clean-vlan.sh=..,0755,/opt/xensource/bin
cloud-prepare-upgrade.sh=..,0755,/opt/xensource/bin
getRouterStatus.sh=../../../../network/domr/,0755,/opt/xensource/bin
bumpUpPriority.sh=../../../../network/domr/,0755,/opt/xensource/bin
getDomRVersion.sh=../../../../network/domr/,0755,/opt/xensource/bin