Merge branch '3.0.x' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 3.0.x

This commit is contained in:
Vijayendra Bhamidipati 2012-06-18 13:01:11 -07:00
commit b9263b0c51
5 changed files with 25 additions and 25 deletions

View File

@ -1864,7 +1864,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (result == null || result.isEmpty()) {
throw new InternalErrorException("Xen plugin \"ipassoc\" failed.");
throw new InternalErrorException("Xen plugin \"vpc_ipassoc\" failed.");
}
} catch (Exception e) {
String msg = "Unable to assign public IP address due to " + e.toString();

View File

@ -16,7 +16,6 @@
# $Id: ipassoc.sh 9804 2010-06-22 18:36:49Z alex $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/network/domr/ipassoc.sh $
# ipassoc.sh -- associate/disassociate a public ip with an instance
# @VERSION@
@ -34,9 +33,6 @@ usage() {
printf " %s -D -l <public-ip-address> -c <dev> [-f] \n" $(basename $0) >&2
}
remove_routing() {
}
add_routing() {
logger -t cloud "$(basename $0):Add routing $pubIp on interface $ethDev"
@ -44,20 +40,26 @@ add_routing() {
sudo ip route add $subnet/$mask dev $ethDev table $tableName proto static
sudo ip route add default via $defaultGwIP table $tableName proto static
sudo ip route flush cache
return 0;
return 0
}
remove_routing() {
return 0
}
add_an_ip () {
logger -t cloud "$(basename $0):Adding ip $pubIp on interface $ethDev"
sudo ip link show $ethDev | grep "state DOWN" > /dev/null
local old_state=$?
sudo ip addr add dev $ethDev $pubIp/$mask
if [ $if_keep_state -ne 1 -o $old_state -ne 0 ]
if [ $old_state -eq 0 ]
then
sudo ip link set $ethDev up
sudo arping -c 3 -I $ethDev -A -U -s $ipNoMask $ipNoMask;
sudo arping -c 3 -I $ethDev -A -U -s $pubIp $pubIp
fi
add_routing $1
add_routing
return $?
}
@ -77,7 +79,7 @@ remove_an_ip () {
sudo ip addr add dev $ethDev $ipMask
done
remove_routing $1
remove_routing
return 0
}
@ -90,7 +92,7 @@ nflag=0
op=""
while getopts 'ADl:c:g:' OPTION
while getopts 'ADl:c:g:m:n:' OPTION
do
case $OPTION in
A) Aflag=1

View File

@ -2507,20 +2507,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return;
}
String currCidrAddress = getCidrAddress(cidr);
int currCidrSize = getCidrSize(cidr);
for (long networkId : networkToCidr.keySet()) {
String ntwkCidr = networkToCidr.get(networkId);
String ntwkCidrAddress = getCidrAddress(ntwkCidr);
int ntwkCidrSize = getCidrSize(ntwkCidr);
long cidrSizeToUse = currCidrSize < ntwkCidrSize ? currCidrSize : ntwkCidrSize;
String ntwkCidrSubnet = NetUtils.getCidrSubNet(ntwkCidrAddress, cidrSizeToUse);
String cidrSubnet = NetUtils.getCidrSubNet(currCidrAddress, cidrSizeToUse);
if (cidrSubnet.equals(ntwkCidrSubnet)) {
if (NetUtils.isNetworksOverlap(ntwkCidr, cidr)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!");
ex.addProxyObject("networks", networkId, "networkId");
throw ex;

View File

@ -795,8 +795,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
for (Network ntwk : ntwks) {
assert (cidr != null) : "Why the network cidr is null when it belongs to vpc?";
if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), vpc.getCidr())
|| NetUtils.isNetworkAWithinNetworkB(vpc.getCidr(), ntwk.getCidr())) {
if (NetUtils.isNetworksOverlap(ntwk.getCidr(), cidr)) {
throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk +
" belonging to the same vpc " + vpc);
}

View File

@ -780,6 +780,16 @@ public class NetUtils {
long shift = 32 - cidrBLong[1];
return ((cidrALong[0] >> shift) == (cidrBLong[0] >> shift));
}
public static boolean isNetworksOverlap(String cidrA, String cidrB) {
Long[] cidrALong = cidrToLong(cidrA);
Long[] cidrBLong = cidrToLong(cidrB);
if (cidrALong == null || cidrBLong == null) {
return false;
}
long shift = 32 - (cidrALong[1] > cidrBLong[1] ? cidrBLong[1] : cidrALong[1]);
return ((cidrALong[0] >> shift) == (cidrBLong[0] >> shift));
}
public static Long[] cidrToLong(String cidr) {
if (cidr == null || cidr.isEmpty()) {