forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'shixin-9978-master@@3' into 'master'
port bug 9978 from 2.3.0 to master See merge request zstackio/zstack!2373
- Loading branch information
Showing
10 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<globalConfig xmlns="http://zstack.org/schema/zstack"> | ||
<config> | ||
<category>vyos</category> | ||
<name>private.l3.firewall.default.action</name> | ||
<description>default action for private l3 network</description> | ||
<type>java.lang.String</type> | ||
<defaultValue>reject</defaultValue> | ||
</config> | ||
</globalConfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...rk/service/virtualrouter/vyos/VyosChangePrivateL3FirewallDefaultActionExtensionPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.zstack.network.service.virtualrouter.vyos; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.zstack.core.cloudbus.CloudBus; | ||
import org.zstack.core.cloudbus.CloudBusCallBack; | ||
import org.zstack.core.timeout.ApiTimeoutManager; | ||
import org.zstack.header.core.Completion; | ||
import org.zstack.header.core.NoErrorCompletion; | ||
import org.zstack.header.errorcode.ErrorCode; | ||
import org.zstack.header.message.MessageReply; | ||
import org.zstack.header.network.service.VirtualRouterAfterAttachNicExtensionPoint; | ||
import org.zstack.header.vm.VmInstanceConstant; | ||
import org.zstack.header.vm.VmNicInventory; | ||
import org.zstack.network.service.virtualrouter.*; | ||
import org.zstack.utils.Utils; | ||
import org.zstack.utils.logging.CLogger; | ||
|
||
import java.util.Collections; | ||
import static org.zstack.core.Platform.operr; | ||
|
||
public class VyosChangePrivateL3FirewallDefaultActionExtensionPoint implements VirtualRouterAfterAttachNicExtensionPoint { | ||
@Autowired | ||
protected CloudBus bus; | ||
@Autowired | ||
protected ApiTimeoutManager apiTimeoutManager; | ||
private final static CLogger logger = Utils.getLogger(VyosChangePrivateL3FirewallDefaultActionExtensionPoint.class); | ||
|
||
@Override | ||
public void afterAttachNic(VmNicInventory nic, Completion completion) { | ||
if (!VirtualRouterNicMetaData.GUEST_NIC_MASK_STRING_LIST.contains(nic.getMetaData())) { | ||
completion.success(); | ||
return; | ||
} | ||
|
||
String action = VyosGlobalConfig.PRIVATE_L3_FIREWALL_DEFAULT_ACTION.value(String.class); | ||
VirtualRouterCommands.NicInfo info = new VirtualRouterCommands.NicInfo(); | ||
info.setIp(nic.getIp()); | ||
info.setDefaultRoute(false); | ||
info.setGateway(nic.getGateway()); | ||
info.setMac(nic.getMac()); | ||
info.setNetmask(nic.getNetmask()); | ||
info.setFirewallDefaultAction(action); | ||
|
||
VirtualRouterCommands.ConfigureNicFirewallDefaultActionCmd cmd = new VirtualRouterCommands.ConfigureNicFirewallDefaultActionCmd(); | ||
cmd.setNics(Collections.singletonList(info)); | ||
|
||
VirtualRouterAsyncHttpCallMsg cmsg = new VirtualRouterAsyncHttpCallMsg(); | ||
cmsg.setCommand(cmd); | ||
cmsg.setCommandTimeout(apiTimeoutManager.getTimeout(cmd.getClass(), "30m")); | ||
cmsg.setPath(VirtualRouterConstant.VR_CONFIGURE_NIC_FIREWALL_DEFAULT_ACTION_PATH); | ||
cmsg.setVmInstanceUuid(nic.getVmInstanceUuid()); | ||
bus.makeTargetServiceIdByResourceUuid(cmsg, VmInstanceConstant.SERVICE_ID, nic.getVmInstanceUuid()); | ||
bus.send(cmsg, new CloudBusCallBack(completion) { | ||
@Override | ||
public void run(MessageReply reply) { | ||
if (!reply.isSuccess()) { | ||
completion.fail(reply.getError()); | ||
return; | ||
} | ||
|
||
VirtualRouterAsyncHttpCallReply re = reply.castReply(); | ||
VirtualRouterCommands.ConfigureNicFirewallDefaultActionRsp rsp = re.toResponse(VirtualRouterCommands.ConfigureNicFirewallDefaultActionRsp.class); | ||
if (rsp.isSuccess()) { | ||
logger.debug(String.format("successfully change nic[ip:%s, mac:%s] firewall default action of virtual router vm[uuid:%s]", | ||
nic.getIp(), nic.getMac(), nic.getVmInstanceUuid())); | ||
completion.success(); | ||
} else { | ||
ErrorCode err = operr("failed to change nic[ip:%s, mac:%s] firewall default action of virtual router vm[uuid:%s], because %s", | ||
nic.getIp(), nic.getMac(), nic.getVmInstanceUuid(), rsp.getError()); | ||
completion.fail(err); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void afterAttachNicRollback(VmNicInventory nic, NoErrorCompletion completion) { | ||
/* rollback nic will delete all nic configure */ | ||
completion.done(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...tack/network/service/virtualrouter/vyos/VyosChangePrivateL3FirewallDefaultActionFlow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.zstack.network.service.virtualrouter.vyos; | ||
|
||
import org.springframework.beans.factory.annotation.Autowire; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Configurable; | ||
import org.zstack.core.cloudbus.CloudBus; | ||
import org.zstack.core.cloudbus.CloudBusCallBack; | ||
import org.zstack.core.timeout.ApiTimeoutManager; | ||
import org.zstack.header.core.workflow.FlowTrigger; | ||
import org.zstack.header.core.workflow.NoRollbackFlow; | ||
import org.zstack.header.errorcode.ErrorCode; | ||
import org.zstack.header.message.MessageReply; | ||
import org.zstack.header.vm.VmInstanceConstant; | ||
import org.zstack.header.vm.VmNicInventory; | ||
import org.zstack.network.service.virtualrouter.*; | ||
import org.zstack.utils.CollectionUtils; | ||
import org.zstack.utils.Utils; | ||
import org.zstack.utils.function.Function; | ||
import org.zstack.utils.logging.CLogger; | ||
|
||
import java.util.*; | ||
|
||
import static org.zstack.core.Platform.operr; | ||
|
||
/** | ||
* Created by shixin.ruan on 18-03-10. | ||
*/ | ||
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE) | ||
public class VyosChangePrivateL3FirewallDefaultActionFlow extends NoRollbackFlow { | ||
@Autowired | ||
protected CloudBus bus; | ||
@Autowired | ||
protected ApiTimeoutManager apiTimeoutManager; | ||
|
||
private final static CLogger logger = Utils.getLogger(VyosChangePrivateL3FirewallDefaultActionFlow.class); | ||
|
||
@Override | ||
public void run(FlowTrigger trigger, Map data) { | ||
String action = VyosGlobalConfig.PRIVATE_L3_FIREWALL_DEFAULT_ACTION.value(String.class); | ||
|
||
final VirtualRouterVmInventory servedVm = (VirtualRouterVmInventory) data.get(VirtualRouterConstant.Param.VR.toString()); | ||
List<VirtualRouterCommands.NicInfo> infos = CollectionUtils.transformToList(servedVm.getGuestNics(), new Function<VirtualRouterCommands.NicInfo, VmNicInventory>() { | ||
@Override | ||
public VirtualRouterCommands.NicInfo call(VmNicInventory arg) { | ||
VirtualRouterCommands.NicInfo info = new VirtualRouterCommands.NicInfo(); | ||
info.setIp(arg.getIp()); | ||
info.setDefaultRoute(false); | ||
info.setGateway(arg.getGateway()); | ||
info.setMac(arg.getMac()); | ||
info.setNetmask(arg.getNetmask()); | ||
info.setFirewallDefaultAction(action); | ||
|
||
return info; | ||
} | ||
}); | ||
|
||
if (infos == null || infos.isEmpty()) { | ||
trigger.next(); | ||
return; | ||
} | ||
|
||
VirtualRouterCommands.ConfigureNicFirewallDefaultActionCmd cmd = new VirtualRouterCommands.ConfigureNicFirewallDefaultActionCmd(); | ||
cmd.setNics(infos); | ||
|
||
VirtualRouterAsyncHttpCallMsg cmsg = new VirtualRouterAsyncHttpCallMsg(); | ||
cmsg.setCommand(cmd); | ||
cmsg.setCommandTimeout(apiTimeoutManager.getTimeout(cmd.getClass(), "30m")); | ||
cmsg.setPath(VirtualRouterConstant.VR_CONFIGURE_NIC_FIREWALL_DEFAULT_ACTION_PATH); | ||
cmsg.setVmInstanceUuid(servedVm.getUuid()); | ||
bus.makeTargetServiceIdByResourceUuid(cmsg, VmInstanceConstant.SERVICE_ID, servedVm.getUuid()); | ||
bus.send(cmsg, new CloudBusCallBack(trigger) { | ||
/* failure in this flow will not block normal process */ | ||
@Override | ||
public void run(MessageReply reply) { | ||
if (!reply.isSuccess()) { | ||
logger.debug(String.format("failed to change nic firewall default action of virtual router vm[uuid:%s ip:%s], because %s", | ||
servedVm.getUuid(), servedVm.getManagementNic().getIp(), reply.getError())); | ||
trigger.next(); | ||
return; | ||
} | ||
|
||
VirtualRouterAsyncHttpCallReply re = reply.castReply(); | ||
VirtualRouterCommands.ConfigureNicFirewallDefaultActionRsp rsp = re.toResponse(VirtualRouterCommands.ConfigureNicFirewallDefaultActionRsp.class); | ||
if (rsp.isSuccess()) { | ||
logger.debug(String.format("successfully change nic firewall default action of virtual router vm[uuid:%s, ip:%s]", | ||
servedVm.getUuid(), servedVm.getManagementNic().getIp())); | ||
trigger.next(); | ||
} else { | ||
logger.debug(String.format("failed to change nic firewall default action of virtual router vm[uuid:%s ip:%s], because %s", | ||
servedVm.getUuid(), servedVm.getManagementNic().getIp(), rsp.getError())); | ||
trigger.next(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...rovider/src/main/java/org/zstack/network/service/virtualrouter/vyos/VyosGlobalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.zstack.network.service.virtualrouter.vyos; | ||
|
||
import org.zstack.core.config.GlobalConfig; | ||
import org.zstack.core.config.GlobalConfigDefinition; | ||
import org.zstack.core.config.GlobalConfigValidation; | ||
|
||
/** | ||
* Created by shixin.ruan on 18/03/09. | ||
*/ | ||
@GlobalConfigDefinition | ||
public class VyosGlobalConfig { | ||
public static final String CATEGORY = "vyos"; | ||
|
||
@GlobalConfigValidation(validValues = {"accept", "reject"}) | ||
public static GlobalConfig PRIVATE_L3_FIREWALL_DEFAULT_ACTION = new GlobalConfig(CATEGORY, "private.l3.firewall.default.action"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters