mirror of https://github.com/apache/cloudstack.git
bug CS-15221: Support multiple public interfaces
This commit is contained in:
parent
9da438b24c
commit
23aa4bff69
|
|
@ -182,6 +182,8 @@ public class XenServer56Resource extends CitrixResourceBase {
|
|||
args += "-r";
|
||||
} else if (option.equals("vpn")) {
|
||||
args += "-n";
|
||||
} else if (option.equals("remove")) {
|
||||
args += "-d";
|
||||
} else {
|
||||
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ source /root/func.sh
|
|||
source /opt/cloud/bin/vpc_func.sh
|
||||
|
||||
vpnoutmark="0x525"
|
||||
vpninmark="0x524"
|
||||
lock="biglock"
|
||||
locked=$(getLockFile $lock)
|
||||
if [ "$locked" != "1" ]
|
||||
|
|
@ -24,48 +25,58 @@ then
|
|||
fi
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s -[c|g|r] [-[a|d] <public interface>]\n" $(basename $0) >&2
|
||||
printf "Usage: %s -[c|g|r|n|d] [-l <public gateway>] [-v <vpc cidr>] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
create_usage_rules () {
|
||||
iptables -N NETWORK_STATS_$ethDev > /dev/null
|
||||
iptables -I FORWARD -j NETWORK_STATS_$ethDev > /dev/null
|
||||
iptables-save|grep "NETWORK_STATS_$ethDev -i $ethDev" > /dev/null
|
||||
iptables-save|grep "NETWORK_STATS_$ethDev" > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
iptables -A NETWORK_STATS_$ethDev -i $ethDev -d $vcidr > /dev/null
|
||||
fi
|
||||
iptables-save|grep "NETWORK_STATS_$ethDev -o $ethDev" > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
iptables -A NETWORK_STATS_$ethDev -o $ethDev -s $vcidr > /dev/null
|
||||
fi
|
||||
iptables -N NETWORK_STATS_$ethDev > /dev/null;
|
||||
iptables -I FORWARD -j NETWORK_STATS_$ethDev > /dev/null;
|
||||
iptables -A NETWORK_STATS_$ethDev -i $ethDev -d $vcidr > /dev/null;
|
||||
iptables -A NETWORK_STATS_$ethDev -o $ethDev -s $vcidr > /dev/null;
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
create_vpn_usage_rules () {
|
||||
iptables -N VPN_STATS_$ethDev > /dev/null
|
||||
iptables -I FORWARD -j VPN_STATS_$ethDev > /dev/null
|
||||
iptables-save|grep "VPN_STATS_$ethDev -i $ethDev" > /dev/null
|
||||
iptables-save|grep "VPN_STATS_$ethDev" > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
iptables -A VPN_STATS_$ethDev -i $ethDev -m mark --mark $vpnoutmark > /dev/null
|
||||
fi
|
||||
iptables-save|grep "VPN_STATS_$ethDev -o $ethDev" > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
iptables -A VPN_STATS_$ethDev -o $ethDev -m mark --mark $vpnoutmark > /dev/null
|
||||
iptables -N VPN_STATS_$ethDev > /dev/null;
|
||||
iptables -I FORWARD -j VPN_STATS_$ethDev > /dev/null;
|
||||
iptables -A VPN_STATS_$ethDev -i $ethDev -m mark --mark $vpninmark > /dev/null;
|
||||
iptables -A VPN_STATS_$ethDev -o $ethDev -m mark --mark $vpnoutmark > /dev/null;
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
remove_usage_rules () {
|
||||
echo $ethDev >> /root/removedVifs
|
||||
return $?
|
||||
}
|
||||
|
||||
get_usage () {
|
||||
iptables -L NETWORK_STATS_$ethDev -n -v -x | awk '$1 ~ /^[0-9]+$/ { printf "%s:", $2}'; > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
if [ -f /root/removedVifs ]
|
||||
then
|
||||
printf $?
|
||||
return 1
|
||||
fi
|
||||
var=`cat /root/removedVifs`
|
||||
# loop through vifs to be cleared
|
||||
for i in $var; do
|
||||
# Make sure vif doesn't exist
|
||||
if [ ! -f /sys/class/net/$i ]
|
||||
then
|
||||
# flush rules and remove chain
|
||||
iptables -F NETWORK_STATS_$i > /dev/null;
|
||||
iptables -X NETWORK_STATS_$i > /dev/null;
|
||||
iptables -F VPN_STATS_$i > /dev/null;
|
||||
iptables -X VPN_STATS_$i > /dev/null;
|
||||
fi
|
||||
done
|
||||
rm /root/removedVifs
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
get_vpn_usage () {
|
||||
|
|
@ -78,6 +89,7 @@ get_vpn_usage () {
|
|||
}
|
||||
|
||||
|
||||
|
||||
reset_usage () {
|
||||
iptables -Z NETWORK_STATS_$ethDev > /dev/null
|
||||
if [ $? -gt 0 -a $? -ne 2 ]
|
||||
|
|
@ -94,8 +106,9 @@ rflag=
|
|||
lflag=
|
||||
vflag=
|
||||
nflag=
|
||||
dflag=
|
||||
|
||||
while getopts 'cgnrl:v:' OPTION
|
||||
while getopts 'cgndrl:v:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
c) cflag=1
|
||||
|
|
@ -111,7 +124,9 @@ do
|
|||
vcidr="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
;;
|
||||
;;
|
||||
d) dflag=1
|
||||
;;
|
||||
i) #Do nothing, since it's parameter for host script
|
||||
;;
|
||||
?) usage
|
||||
|
|
@ -123,9 +138,12 @@ done
|
|||
ethDev=$(getEthByIp $publicIp)
|
||||
if [ "$cflag" == "1" ]
|
||||
then
|
||||
create_usage_rules
|
||||
create_vpn_usage_rules
|
||||
unlock_exit 0 $lock $locked
|
||||
if [ "$ethDev" != "" ]
|
||||
then
|
||||
create_usage_rules
|
||||
create_vpn_usage_rules
|
||||
unlock_exit 0 $lock $locked
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$gflag" == "1" ]
|
||||
|
|
@ -140,6 +158,12 @@ then
|
|||
unlock_exit $? $lock $locked
|
||||
fi
|
||||
|
||||
if [ "$dflag" == "1" ]
|
||||
then
|
||||
remove_usage_rules
|
||||
unlock_exit 0 $lock $locked
|
||||
fi
|
||||
|
||||
if [ "$rflag" == "1" ]
|
||||
then
|
||||
reset_usage
|
||||
|
|
|
|||
|
|
@ -335,15 +335,13 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName());
|
||||
|
||||
Commands cmds = new Commands(OnError.Stop);
|
||||
cmds.addCommand("plugnic", plugNicCmd);
|
||||
cmds.addCommand("plugnic", plugNicCmd);
|
||||
_agentMgr.send(dest.getHost().getId(), cmds);
|
||||
|
||||
PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
|
||||
if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
|
||||
s_logger.warn("Unable to plug nic for vm " + vm.getHostName());
|
||||
result = false;
|
||||
}
|
||||
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network,
|
||||
dest.getHost().getId(), e);
|
||||
|
|
@ -367,8 +365,12 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
|
||||
if (router.getState() == State.Running) {
|
||||
try {
|
||||
Commands cmds = new Commands(OnError.Stop);
|
||||
if(network.getTrafficType() == TrafficType.Public){
|
||||
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), "remove", true, nic.getIp());
|
||||
cmds.addCommand(netUsageCmd);
|
||||
}
|
||||
UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
|
||||
Commands cmds = new Commands(OnError.Stop);
|
||||
cmds.addCommand("unplugnic", unplugNicCmd);
|
||||
_agentMgr.send(dest.getHost().getId(), cmds);
|
||||
|
||||
|
|
@ -376,8 +378,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
|
||||
s_logger.warn("Unable to unplug nic from router " + router);
|
||||
result = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
if(network.getTrafficType() == TrafficType.Public){
|
||||
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), "remove", true, nic.getIp());
|
||||
cmds = new Commands(OnError.Stop);
|
||||
cmds.addCommand(netUsageCmd);
|
||||
_agentMgr.send(dest.getHost().getId(), cmds);
|
||||
}
|
||||
}
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network,
|
||||
dest.getHost().getId(), e);
|
||||
|
|
@ -570,7 +578,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Commands netUsagecmds = new Commands(OnError.Continue);
|
||||
VpcVO vpc = _vpcDao.findById(router.getVpcId());
|
||||
|
||||
//2) Plug the nics
|
||||
for (String vlanTag : nicsToPlug.keySet()) {
|
||||
PublicIpAddress ip = nicsToPlug.get(vlanTag);
|
||||
|
|
@ -605,6 +616,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return false;
|
||||
}
|
||||
}
|
||||
//Create network usage commands. Send commands to router after IPAssoc
|
||||
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(router.getPrivateIpAddress(), router.getInstanceName(), true, defaultNic.getIp4Address(), vpc.getCidr());
|
||||
netUsagecmds.addCommand(netUsageCmd);
|
||||
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(),
|
||||
publicNtwk.getId(), publicNic.getIp4Address(), router.getId(), router.getType().toString());
|
||||
if (stats == null) {
|
||||
stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), publicNic.getIp4Address(), router.getId(),
|
||||
router.getType().toString(), publicNtwk.getId());
|
||||
_userStatsDao.persist(stats);
|
||||
}
|
||||
}
|
||||
|
||||
//3) apply the rules
|
||||
|
|
@ -636,7 +657,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return sendCommandsToRouter(router, cmds);
|
||||
}
|
||||
});
|
||||
|
||||
if(result && netUsagecmds.size() > 0){
|
||||
//After successful ipassoc, send commands to router
|
||||
sendCommandsToRouter(router, netUsagecmds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue