Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I879b19931afdd88c875af88bf75ab6df70b6b8ce Partial-Bug: #1772594
- Loading branch information
1 parent
4baf3cd
commit 9db7112
Showing
13 changed files
with
448 additions
and
18 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#maven.buildNumber.plugin properties file | ||
#Fri May 18 13:04:09 CEST 2018 | ||
buildNumber=1354 | ||
#Wed Jun 06 17:32:42 CEST 2018 | ||
buildNumber=1423 |
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
18 changes: 18 additions & 0 deletions
18
...onfig/src/main/kotlin/net/juniper/contrail/vro/config/constants/ModelSpecificConstants.kt
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,18 @@ | ||
/* | ||
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
package net.juniper.contrail.vro.config.constants | ||
|
||
enum class EndpointType(val value: String) { | ||
None("none"), | ||
Tag("tag"), | ||
AddressGroup("address group"), | ||
VirtualNetwork("virtual network"), | ||
AnyWorkload("any workload") | ||
} | ||
|
||
enum class ServiceType(val value: String) { | ||
Manual("manual"), | ||
Reference("reference") | ||
} |
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
82 changes: 82 additions & 0 deletions
82
...trail-core/src/main/kotlin/net/juniper/contrail/vro/model/FirewallRulePropertyExecutor.kt
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,82 @@ | ||
/* | ||
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
package net.juniper.contrail.vro.model | ||
|
||
import net.juniper.contrail.api.types.AddressGroup | ||
import net.juniper.contrail.api.types.FirewallRule | ||
import net.juniper.contrail.api.types.FirewallRuleEndpointType | ||
import net.juniper.contrail.api.types.Tag | ||
import net.juniper.contrail.api.types.VirtualNetwork | ||
import net.juniper.contrail.vro.config.constants.EndpointType | ||
import net.juniper.contrail.vro.config.constants.ServiceType | ||
|
||
interface FirewallRuleComplexProperties { | ||
fun FirewallRule.endpointType(endpointNumber: Int): String? | ||
fun FirewallRule.serviceType(): String? | ||
fun FirewallRule.endpointNetwork(endpointNumber: Int): VirtualNetwork? | ||
fun FirewallRule.endpointAddressGroup(endpointNumber: Int): AddressGroup? | ||
fun FirewallRule.endpointTags(endpointNumber: Int): List<Tag?>? | ||
fun FirewallRule.serviceSrcPorts(): String? | ||
fun FirewallRule.serviceDstPorts(): String? | ||
} | ||
|
||
open class FirewallRuleComplexPropertyExecutor(private val connection: Connection) : FirewallRuleComplexProperties { | ||
override fun FirewallRule.endpointType(endpointNumber: Int): String? = | ||
endpoint(endpointNumber)?.type() | ||
|
||
override fun FirewallRule.serviceType(): String? = when { | ||
serviceGroup[0] != null -> ServiceType.Reference.value | ||
else -> ServiceType.Manual.value | ||
} | ||
|
||
override fun FirewallRule.endpointNetwork(endpointNumber: Int): VirtualNetwork? { | ||
val networkFqn = endpoint(endpointNumber)?.virtualNetwork ?: return null | ||
return connection.findByFQN(networkFqn) | ||
} | ||
|
||
override fun FirewallRule.endpointAddressGroup(endpointNumber: Int): AddressGroup? { | ||
val addressGroupFqn = endpoint(endpointNumber)?.addressGroup ?: return null | ||
return connection.findByFQN(addressGroupFqn) | ||
} | ||
|
||
override fun FirewallRule.serviceSrcPorts(): String? = | ||
utils.formatPort(service.srcPorts) | ||
|
||
override fun FirewallRule.serviceDstPorts(): String? = | ||
utils.formatPort(service.dstPorts) | ||
|
||
override fun FirewallRule.endpointTags(endpointNumber: Int): List<Tag?>? { | ||
val rawTags = endpoint(endpointNumber)?.tags ?: return null | ||
return rawTags.map { | ||
tagFromString(qualifiedName, it) | ||
} | ||
} | ||
|
||
private fun tagFromString(ruleFqn: List<String>, tagString: String): Tag? { | ||
val projectFqn = ruleFqn.dropLast(1) | ||
val isGlobal = tagString.split(":")[0] == "global" | ||
val tagFqn = if (isGlobal) { | ||
tagString.split(":")[1] | ||
} else { | ||
val fqnList = projectFqn + tagString | ||
fqnList.joinToString(":") | ||
} | ||
return connection.findByFQN<Tag>(tagFqn) | ||
} | ||
|
||
private fun FirewallRuleEndpointType.type(): String? = when { | ||
any == true -> EndpointType.AnyWorkload.value | ||
addressGroup != null -> EndpointType.AddressGroup.value | ||
virtualNetwork != null -> EndpointType.VirtualNetwork.value | ||
tags.isNotEmpty() -> EndpointType.Tag.value | ||
else -> EndpointType.None.value | ||
} | ||
|
||
private fun FirewallRule.endpoint(endpointNumber: Int): FirewallRuleEndpointType? = when (endpointNumber) { | ||
1 -> endpoint1 | ||
2 -> endpoint2 | ||
else -> null | ||
} | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
o11nplugin-contrail-workflows/src/main/js/workflows/createFirewallRule.js
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,41 @@ | ||
var rule = new ContrailFirewallRule(); | ||
var ruleUuid = ContrailUtils.randomUUID(); | ||
rule.setUuid(ruleUuid); | ||
rule.setName(ruleUuid); | ||
if (typeof parentProject === 'undefined') { | ||
// if the parent project is undefined, we're using the policy management version | ||
var defaultPolicyManagement = parentConnection.findPolicyManagementByFQName("default-policy-management"); | ||
rule.setParentPolicyManagement(defaultPolicyManagement); | ||
} else { | ||
rule.setParentProject(parentProject); | ||
} | ||
rule.setDirection(direction); | ||
|
||
var actions = new ContrailActionListType() | ||
actions.setSimpleAction(action); | ||
rule.setActionList(actions); | ||
|
||
var endpoint1 = ContrailUtils.createEndpoint(endpoint1Type, endpoint1Tags, endpoint1VirtualNetwork, endpoint1AddressGroup); | ||
var endpoint2 = ContrailUtils.createEndpoint(endpoint2Type, endpoint2Tags, endpoint2VirtualNetwork, endpoint2AddressGroup); | ||
rule.setEndpoint1(endpoint1); | ||
rule.setEndpoint2(endpoint2); | ||
|
||
var mTags = new ContrailFirewallRuleMatchTagsType([]); | ||
if(matchTags != null) { | ||
mTags = new ContrailFirewallRuleMatchTagsType(matchTags); | ||
} | ||
rule.setMatchTags(mTags); | ||
|
||
if(serviceType == "manual") { | ||
var service = new ContrailFirewallServiceType(); | ||
service.setProtocol(serviceProtocol); | ||
service.setSrcPorts(ContrailUtils.parsePortsOfFirewallRule(serviceSrcPorts)); | ||
service.setDstPorts(ContrailUtils.parsePortsOfFirewallRule(serviceDstPorts)); | ||
rule.setService(service); | ||
} else { | ||
if(serviceReference != null) { | ||
rule.addServiceGroup(serviceReference); | ||
} | ||
} | ||
|
||
rule.create(); |
Oops, something went wrong.