VPC : in no route in setStaticRoute, just remove all routes

This commit is contained in:
anthony 2012-07-10 18:40:06 -07:00
parent f0fb52e346
commit 5d224ed592
3 changed files with 38 additions and 17 deletions

View File

@ -36,6 +36,12 @@ public class SetStaticRouteCommand extends NetworkElementCommand{
return staticRoutes;
}
public boolean isEmpty() {
if(staticRoutes == null || staticRoutes.length == 0 ) {
return true;
}
return false;
}
public String[][] generateSRouteRules() {
String [][] result = new String [2][];
Set<String> toAdd = new HashSet<String>();

View File

@ -7477,32 +7477,43 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
String[] results = new String[cmd.getStaticRoutes().length];
String callResult;
Connection conn = getConnection();
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
try {
String [][] rules = cmd.generateSRouteRules();
StringBuilder sb = new StringBuilder();
String[] srRules = rules[0];
for (int i = 0; i < srRules.length; i++) {
sb.append(srRules[i]).append(',');
}
String args = "vpc_staticroute.sh " + routerIp;
args += " -a " + sb.toString();
callResult = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (callResult == null || callResult.isEmpty()) {
//FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails
for (int i=0; i < results.length; i++) {
results[i] = "Failed";
if ( !cmd.isEmpty() ) {
String[] results = new String[cmd.getStaticRoutes().length];
String [][] rules = cmd.generateSRouteRules();
StringBuilder sb = new StringBuilder();
String[] srRules = rules[0];
for (int i = 0; i < srRules.length; i++) {
sb.append(srRules[i]).append(',');
}
return new SetStaticRouteAnswer(cmd, false, results);
String args = "vpc_staticroute.sh " + routerIp;
args += " -a " + sb.toString();
callResult = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (callResult == null || callResult.isEmpty()) {
//FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails
for (int i=0; i < results.length; i++) {
results[i] = "Failed";
}
return new SetStaticRouteAnswer(cmd, false, results);
}
return new SetStaticRouteAnswer(cmd, true, results);
} else {
String args = "vpc_staticroute.sh " + routerIp;
args += " -a none";
callResult = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (callResult == null || callResult.isEmpty()) {
return new SetStaticRouteAnswer(cmd, false, null);
}
return new SetStaticRouteAnswer(cmd, true, null);
}
return new SetStaticRouteAnswer(cmd, true, results);
} catch (Exception e) {
String msg = "SetStaticRoute failed due to " + e.toString();
s_logger.error(msg, e);
return new SetStaticRouteAnswer(cmd, false, results);
return new SetStaticRouteAnswer(cmd, false, null);
}
}
}

View File

@ -60,6 +60,10 @@ restore_table() {
static_route() {
local rule=$1
if [ "$rule" == "none" ]
then
return 0
fi
local ip=$(echo $rule | cut -d: -f1)
local gateway=$(echo $rule | cut -d: -f2)
local cidr=$(echo $rule | cut -d: -f3)