mirror of https://github.com/apache/cloudstack.git
VPC : handle Revoke rules for staticroute
This commit is contained in:
parent
c2250fecf7
commit
d8ab3e1c36
|
|
@ -37,25 +37,22 @@ 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>();
|
||||
for (StaticRouteProfile route: staticRoutes) {
|
||||
/* example : ip:gateway:cidr,
|
||||
*/
|
||||
if( route.getState() == StaticRoute.State.Active || route.getState() == StaticRoute.State.Add ) {
|
||||
String cidr = route.getCidr();
|
||||
String subnet = NetUtils.getCidrSubNet(cidr);
|
||||
String cidrSize = cidr.split("\\/")[1];
|
||||
String entry = route.getIp4Address()+ ":" + route.getGateway() + ":" + subnet + "/" + cidrSize;
|
||||
toAdd.add(entry);
|
||||
String cidr = route.getCidr();
|
||||
String subnet = NetUtils.getCidrSubNet(cidr);
|
||||
String cidrSize = cidr.split("\\/")[1];
|
||||
String entry;
|
||||
if (route.getState() == StaticRoute.State.Active || route.getState() == StaticRoute.State.Add) {
|
||||
entry = route.getIp4Address() + ":" + route.getGateway() + ":" + subnet + "/" + cidrSize;
|
||||
} else {
|
||||
entry = "Revoke:" + route.getGateway() + ":" + subnet + "/" + cidrSize;
|
||||
}
|
||||
toAdd.add(entry);
|
||||
}
|
||||
result[0] = toAdd.toArray(new String[toAdd.size()]);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -526,11 +526,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String[] results = new String[cmd.getStaticRoutes().length];
|
||||
int i = 0;
|
||||
|
||||
if ( cmd.isEmpty() ) {
|
||||
s_logger.error("SetStaticRoute failed since incoming command is empty");
|
||||
return new SetStaticRouteAnswer(cmd, false, null);
|
||||
}
|
||||
|
||||
// Extract and build the arguments for the command to be sent to the VR.
|
||||
String [][] rules = cmd.generateSRouteRules();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
|
|||
|
|
@ -7521,34 +7521,26 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
Connection conn = getConnection();
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
try {
|
||||
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(',');
|
||||
}
|
||||
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);
|
||||
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(',');
|
||||
}
|
||||
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);
|
||||
|
||||
} catch (Exception e) {
|
||||
String msg = "SetStaticRoute failed due to " + e.toString();
|
||||
|
|
|
|||
|
|
@ -60,11 +60,11 @@ restore_table() {
|
|||
|
||||
static_route() {
|
||||
local rule=$1
|
||||
if [ "$rule" == "none" ]
|
||||
local ip=$(echo $rule | cut -d: -f1)
|
||||
if [ $ip == "Revoke" ]
|
||||
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)
|
||||
logger -t cloud "$(basename $0): static route: public ip=$ip \
|
||||
|
|
|
|||
Loading…
Reference in New Issue