Skip to content

Commit

Permalink
Add action for retrieving Contrail port of vCenter virtual machine.
Browse files Browse the repository at this point in the history
Change-Id: Ib7c25900050819f170cb34d9b2240982dc0d11e3
Depends-On: I8ea9a0a398fe9dc4357a8018456e61f7e79d7b41
Depends-On: I600cae79b9c2a388c4d666957aa8539338b49651
Partial-Bug: #1767046
  • Loading branch information
danieljasinski committed May 11, 2018
1 parent de88ec1 commit b5b0bf0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 8 deletions.
4 changes: 2 additions & 2 deletions o11nplugin-contrail-config/buildNumber.properties
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Thu Apr 26 13:03:36 CEST 2018
buildNumber=1309
#Fri Apr 27 08:34:41 CEST 2018
buildNumber=1313
Expand Up @@ -6,6 +6,9 @@ package net.juniper.contrail.vro.config

val actionPackage = globalProjectInfo.workflowPackage

val String.vCenterRelatedPackage get() =
"$this.vc"

val areValidCommunityAttributes = "areValidCommunityAttributes"
val listPropertyValue = "listPropertyValue"
val isValidAllocactionPool = "isValidAllocationPool"
Expand Down Expand Up @@ -33,4 +36,6 @@ val templateHasInterfaceWithName = "templateHasInterfaceWithName"
val serviceInstanceInterfaceNames = "serviceInstanceInterfaceNames"
val ipamHasAllocationMode = "ipamHasAllocationMode"
val ipamHasNotAllocationMode = "ipamHasNotAllocationMode"
val networkHasNotAllcationMode = "networkHasNotAllocationMode"
val networkHasNotAllcationMode = "networkHasNotAllocationMode"

val portOfVCVirtualMachine = "portOfVCVirtualMachine"
Expand Up @@ -9,6 +9,9 @@ val basePackageName = "net.juniper.contrail"
val apiPackageName = "$basePackageName.api"
val apiTypesPackageName = "$basePackageName.api.types"

val VC = "VC"
val VirtualMachine = "VirtualMachine"

val Configuration = "Configuration"
val Connection = "Connection"
val parent = "parent"
Expand Down
Expand Up @@ -143,9 +143,8 @@ private fun WorkflowDefinition.createWorkflow(info: ProjectInfo) =
createWorkflow(info.workflowPackage, info.workflowVersion)

private fun Action.save(info: ProjectInfo) {
val categoryPackage = info.workflowPackage
generateDefinition(info, categoryPackage)
generateElementInfo(info, categoryPackage)
generateDefinition(info, packageName)
generateElementInfo(info, packageName)
}

private class DefaultCharacterEscapeHandler : CharacterEscapeHandler {
Expand Down
Expand Up @@ -5,6 +5,7 @@
package net.juniper.contrail.vro.workflows.model

import net.juniper.contrail.vro.config.CDATA
import net.juniper.contrail.vro.config.constants.Contrail
import net.juniper.contrail.vro.config.pluginName
import java.util.Date
import javax.xml.bind.annotation.XmlAccessType
Expand Down Expand Up @@ -110,11 +111,11 @@ data class array<out Type : Any>(val type: ParameterType<Type>) : ParameterType<
name
}

data class Reference(val simpleName: String) : ParameterType<Reference>() {
data class Reference(val simpleName: String, val plugin: String = Contrail) : ParameterType<Reference>() {
constructor(clazz: Class<*>): this(clazz.pluginName)

override val name: String get() =
"Contrail:$simpleName"
"$plugin:$simpleName"

//just to avoid the auto-generated data class version of toString()
override fun toString() =
Expand Down
@@ -0,0 +1,23 @@
var id = vcvm.instanceId;

// default to 15 second timeout
if(!timeout) timeout = 15;
var start = new Date();
var timeoutDate = new Date(start.getTime() + (timeout * 1000));

var vm = null;
var ports = null;

while(true) {
vm = connection.findVirtualMachine(id);
if(vm) {
ports = vm.portBackRefs;
if(ports.length > 0)
break;
}
if(new Date().getTime() > timeoutDate.getTime())
throw "Failed to retrieve port of virtual machine due to timeout.";
System.sleep(500);
}

return ports[0];
Expand Up @@ -4,6 +4,7 @@

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

import net.juniper.contrail.vro.config.vCenterRelatedPackage
import net.juniper.contrail.vro.workflows.model.Action

fun loadCustomActions(version: String, packageName: String): List<Action> = mutableListOf<Action>().apply {
Expand Down Expand Up @@ -35,4 +36,6 @@ fun loadCustomActions(version: String, packageName: String): List<Action> = muta
this += ipamHasAllocationModeAction(version, packageName)
this += ipamHasNotAllocationModeAction(version, packageName)
this += networkHasNotAllcationModeAction(version, packageName)

this += portOfVCVirtualMachineAction(version, packageName.vCenterRelatedPackage)
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*/

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

import net.juniper.contrail.api.types.VirtualMachineInterface
import net.juniper.contrail.vro.config.constants.Connection
import net.juniper.contrail.vro.config.constants.VC
import net.juniper.contrail.vro.config.constants.VirtualMachine
import net.juniper.contrail.vro.config.portOfVCVirtualMachine
import net.juniper.contrail.vro.workflows.dsl.ofType
import net.juniper.contrail.vro.workflows.model.Reference
import net.juniper.contrail.vro.workflows.model.number
import net.juniper.contrail.vro.workflows.model.reference

val portOfVCVirtualMachineAction = ActionDefinition(
name = portOfVCVirtualMachine,
resultType = reference<VirtualMachineInterface>(),
parameters = listOf("connection" ofType Reference(Connection),
"vcvm" ofType Reference(VirtualMachine, VC),
"timeout" ofType number)
)

0 comments on commit b5b0bf0

Please sign in to comment.