Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add workflow to manage labels of address groups
Change-Id: Ic17fc6633c698a791f464662f5dcef4e425aa2c6
Closes-Bug: #1783126
  • Loading branch information
IridiumOxide committed Jul 24, 2018
1 parent ba80f1c commit cdf9586
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
Expand Up @@ -42,6 +42,7 @@ val ipamHasNotAllocationMode = "ipamHasNotAllocationMode"
val networkHasNotAllcationMode = "networkHasNotAllocationMode"
val listElementProperty = "listElementProperty"
val listTagTypes = "listTagTypes"
val listLabelTags = "listLabelTags"
val matchesSecurityScope = "matchesSecurityScope"
val defaultConnection = "defaultConnection"

Expand Down
Expand Up @@ -11,6 +11,7 @@ import net.juniper.contrail.api.types.ServiceGroup
import net.juniper.contrail.api.types.VirtualMachineInterface
import net.juniper.contrail.api.types.ServiceTemplate
import net.juniper.contrail.api.types.ServiceInstance
import net.juniper.contrail.api.types.Tag
import net.juniper.contrail.api.types.TagType

// To reduce complexity of one class, the functionality has been split between multiple simpler classes.
Expand Down Expand Up @@ -51,6 +52,14 @@ FirewallRuleComplexProperties by FirewallRuleComplexPropertyExecutor(connection)
fun Connection.listTagTypes(): List<String> =
list<TagType>()?.asSequence()?.map { it.name }?.sorted()?.toList() ?: emptyList()

fun Connection.listLabels(): List<Tag> =
list<Tag>()?.asSequence()?.filter { isLabel(it) }?.toList() ?: emptyList()

private fun Connection.isLabel(tag: Tag): Boolean {
tag.typeName ?: read(tag)
return tag.typeName == "label"
}

fun ServiceGroup.servicePropertyProtocol(ruleString: String): String? =
findService(ruleString)?.protocol

Expand Down
@@ -0,0 +1,2 @@
var connection = item.getConnection();
return connection.listLabels();
@@ -0,0 +1,2 @@
item.addTag(label);
item.update();
@@ -0,0 +1,2 @@
item.removeTag(label);
item.update();
Expand Up @@ -6,9 +6,12 @@ package net.juniper.contrail.vro.workflows.custom

import net.juniper.contrail.api.types.AddressGroup
import net.juniper.contrail.api.types.IpamSubnetType
import net.juniper.contrail.api.types.Tag
import net.juniper.contrail.vro.config.addressGroupSubnets
import net.juniper.contrail.vro.config.constants.item
import net.juniper.contrail.vro.config.constants.subnet
import net.juniper.contrail.vro.config.listLabelTags
import net.juniper.contrail.vro.config.propertyValue
import net.juniper.contrail.vro.schema.Schema
import net.juniper.contrail.vro.workflows.dsl.WhenNonNull
import net.juniper.contrail.vro.workflows.dsl.WorkflowDefinition
Expand Down Expand Up @@ -51,3 +54,39 @@ internal fun removeSubnetFromAddressGroup(schema: Schema): WorkflowDefinition {
}
}
}

internal fun addLabelToAddressGroup(): WorkflowDefinition {
val workflowName = "Add label to Address Group"

return customWorkflow<AddressGroup>(workflowName).withScriptFile("addLabelToAddressGroup") {
parameter(item, reference<AddressGroup>()) {
description = "Address Group to add label to"
mandatory = true
}
parameter("label", reference<Tag>()) {
description = "Label to add"
mandatory = true
visibility = WhenNonNull(item)
validWhen = matchesSecurityScope(item, false)
listedBy = actionCallTo(listLabelTags).parameter(item)
}
}
}

internal fun removeLabelFromAddressGroup(): WorkflowDefinition {
val workflowName = "Remove label from Address Group"

return customWorkflow<AddressGroup>(workflowName).withScriptFile("removeLabelFromAddressGroup") {
parameter(item, reference<AddressGroup>()) {
description = "Address Group to remove label from"
mandatory = true
}
parameter("label", reference<Tag>()) {
description = "Label to remove"
mandatory = true
visibility = WhenNonNull(item)
validWhen = matchesSecurityScope(item, false)
listedBy = actionCallTo(propertyValue).parameter(item).string("tag")
}
}
}
Expand Up @@ -4,17 +4,20 @@

package net.juniper.contrail.vro.workflows.custom

import net.juniper.contrail.api.types.Tag
import net.juniper.contrail.vro.config.constants.element
import net.juniper.contrail.vro.config.constants.item
import net.juniper.contrail.vro.config.listTagTypes
import net.juniper.contrail.vro.config.propertyNotNull
import net.juniper.contrail.vro.config.listLabelTags
import net.juniper.contrail.vro.config.listElementProperty
import net.juniper.contrail.vro.config.propertyValue
import net.juniper.contrail.vro.config.readSubnet
import net.juniper.contrail.vro.workflows.dsl.ofType
import net.juniper.contrail.vro.workflows.model.any
import net.juniper.contrail.vro.workflows.model.array
import net.juniper.contrail.vro.workflows.model.boolean
import net.juniper.contrail.vro.workflows.model.reference
import net.juniper.contrail.vro.workflows.model.string

private val parameterPath = "parameterPath"
Expand Down Expand Up @@ -63,4 +66,12 @@ val listTagTypesAction = ActionDefinition (
parameters = listOf(
item ofType any
)
)

val listLabelTags = ActionDefinition (
name = listLabelTags,
resultType = reference<Tag>().array,
parameters = listOf(
item ofType any
)
)

0 comments on commit cdf9586

Please sign in to comment.