Skip to content

Commit

Permalink
Create global security objects as children of "default-policy-managem…
Browse files Browse the repository at this point in the history
…ent".

Change-Id: I223ba29cf0dfab4da7dc25b01b4052504d48d11f
Closes-Bug: #1772594
(cherry picked from commit d1711da)
  • Loading branch information
danieljasinski committed Jun 8, 2018
1 parent 264ddff commit 4baf3cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ val customCreateWorkflows = setOf(
the<ServiceTemplate>(),
the<ServiceInstance>(),
the<PortTuple>(),
the<PolicyManagement>(),
the<Tag>(),
the<TagType>()
)
Expand All @@ -84,12 +85,14 @@ val customEditWorkflows = setOf(
the<FloatingIp>(),
the<ServiceTemplate>(),
the<ServiceInstance>(),
the<PortTuple>()
the<PortTuple>(),
the<PolicyManagement>()
)

val customDeleteWorkflows = setOf(
the<VirtualMachineInterface>(),
the<PortTuple>(),
the<PolicyManagement>(),
the<TagType>()
)

Expand Down Expand Up @@ -129,10 +132,12 @@ val hiddenRelations = setOf(
pair<VirtualMachineInterface, PortTuple>(),
pair<VirtualMachineInterface, VirtualMachine>(),
pair<ServiceTemplate, ServiceApplianceSet>(),
pair<Project, PolicyManagement>(),
pair<Tag, TagType>()
)

val tagRelations = setOf(
the<ConfigRoot>(),
the<Project>(),
the<VirtualNetwork>(),
the<VirtualMachineInterface>(),
Expand Down Expand Up @@ -236,6 +241,9 @@ val Class<*>?.isConfigRoot get() =
val Class<*>?.isDomain get() =
isA<Domain>()

val Class<*>?.isPolicyManagement get() =
isA<PolicyManagement>()

val Class<*>?.isDefaultRoot get() =
isConfigRoot || isDomain

Expand Down Expand Up @@ -313,6 +321,7 @@ val Class<*>.setParentMethods get() =

val Class<*>.parents get() =
setParentMethods.map { it.parameters[0].type as ObjectClass }
.filter { this isDisplayableChildOf it }

val ObjectClass.isRootClass: Boolean get() {
if (isInternal || isHiddenRoot || isDefaultRoot) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import net.juniper.contrail.vro.config.isConfigRoot
import net.juniper.contrail.vro.config.isDefaultRoot
import net.juniper.contrail.vro.config.isHiddenRoot
import net.juniper.contrail.vro.config.isModelClass
import net.juniper.contrail.vro.config.isPolicyManagement
import net.juniper.contrail.vro.config.isStringListWrapper
import net.juniper.contrail.vro.config.numberOfParentsInModel
import net.juniper.contrail.vro.config.objectType
Expand Down Expand Up @@ -48,15 +49,19 @@ fun createWorkflows(clazz: ObjectClass, refs: List<ObjectClass>, schema: Schema)
.toList()
}

fun createWorkflow(clazz: ObjectClass, parentClazz: ObjectClass, parentsInModel: Int, rootParents: Boolean, refs: List<ObjectClass>, schema: Schema): WorkflowDefinition {
fun createWorkflow(clazz: ObjectClass, parentClazz: ObjectClass, parentsInModel: Int, hasRootParents: Boolean, refs: List<ObjectClass>, schema: Schema): WorkflowDefinition {

val nonRootParents = parentsInModel > 0
val addInParent = rootParents || parentsInModel > 1
val addInParent = (hasRootParents || parentsInModel > 1) && ! parentClazz.isPolicyManagement
val addGlobal = (parentClazz.isDefaultRoot && nonRootParents) || parentClazz.isPolicyManagement

val workflowBaseName = "Create " + if (parentClazz.isDefaultRoot && nonRootParents) "global " else ""
val workflowNameSuffix = if (parentClazz.isModelClass && addInParent) " in ${parentClazz.allLowerCase}" else ""
val workflowBaseName = "Create " + if (addGlobal) "global " else ""
val workflowNameSuffix = if (addInParent) " in ${parentClazz.allLowerCase}" else ""
val workflowName = workflowBaseName + clazz.allLowerCase + workflowNameSuffix
val parentName = if (parentClazz.isModelClass) parentClazz.pluginName else Connection
val parentName = if (parentClazz.isModelClass && ! parentClazz.isPolicyManagement)
parentClazz.pluginName
else
Connection

return workflow(workflowName).withScript(clazz.createScriptBody(parentClazz, refs, schema)) {
description = schema.createWorkflowDescription(clazz, parentClazz)
Expand Down Expand Up @@ -155,15 +160,23 @@ ${clazz.allCapitalized}
${relationDescription(parentClazz, clazz)}
""".trim()

private fun ObjectClass.setParentCall(parentClazz: ObjectClass) =
if (parentClazz.isModelClass)
setRegularParentCall(parentClazz)
else
setRootParentCall(parentClazz) + "\n" + setParentConnectionCall()
private fun ObjectClass.setParentCall(parentClazz: ObjectClass) = when {
parentClazz.isPolicyManagement -> setParentPolicyManagementCall()
parentClazz.isModelClass -> setRegularParentCall(parentClazz)
else -> setRootParentCall(parentClazz) + "\n" + setParentConnectionCall()
}

private fun setParentConnectionCall() =
"$item.setParent$Connection($parent);"

private fun setRegularParentCall(parentClazz: ObjectClass) =
"$item.setParent${parentClazz.pluginName}($parent);"

private fun setParentPolicyManagementCall() = """
var defaultPolicyManagement = parent.findPolicyManagementByFQName("default-policy-management");
$item.setParentPolicyManagement(defaultPolicyManagement);
""".trim()

private fun ObjectClass.setRootParentCall(parentClazz: ObjectClass) = when {
// create empty ConfigRoot object just to configure parent type
parentClazz.isConfigRoot -> "$item.setParent${parentClazz.pluginName}(new Contrail${parentClazz.pluginName}());"
Expand All @@ -172,9 +185,6 @@ private fun ObjectClass.setRootParentCall(parentClazz: ObjectClass) = when {
else -> throw IllegalArgumentException("Unable to create parent ${parentClazz.simpleName} for $simpleName.")
}

private fun setRegularParentCall(parentClazz: ObjectClass) =
"$item.setParent${parentClazz.pluginName}($parent);"

private fun ObjectClass.createScriptBody(parentClazz: ObjectClass, references: List<ObjectClass>, schema: Schema) = """
$item = new Contrail$pluginName();
$item.setName(name);
Expand Down

0 comments on commit 4baf3cd

Please sign in to comment.