2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
23 import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
24 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
25 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
26 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
27 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
28 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
29 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
30 import org.openecomp.sdc.tosca.services.DataModelUtil;
31 import org.openecomp.sdc.tosca.services.ToscaConstants;
32 import org.openecomp.sdc.translator.services.heattotosca.Constants;
34 import java.util.HashMap;
37 public class ContrailPortGlobalType {
39 * Create service template service template.
41 * @return the service template
43 public static ServiceTemplate createServiceTemplate() {
44 ServiceTemplate serviceTemplate = new ServiceTemplate();
45 serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
46 serviceTemplate.setMetadata(
47 DataModelUtil.createMetadata(Constants.CONTRAIL_PORT_TEMPLATE_NAME, "1.0.0", null));
48 serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
49 serviceTemplate.setDescription("Contrail Port TOSCA Global Types");
50 serviceTemplate.setNode_types(createGlobalNodeTypes());
51 return serviceTemplate;
54 private static Map<String, NodeType> createGlobalNodeTypes() {
55 Map<String, NodeType> globalNodeTypes = new HashMap<>();
56 globalNodeTypes.put(ToscaNodeType.CONTRAIL_PORT.getDisplayName(), createContrailPortNodeType());
57 return globalNodeTypes;
60 private static NodeType createContrailPortNodeType() {
61 NodeType nodeType = new NodeType();
62 nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
63 nodeType.setProperties(createContrailPortProperties());
64 nodeType.setAttributes(createContrailPortAttributes());
68 private static Map<String, PropertyDefinition> createContrailPortProperties() {
69 Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
70 propertyDefMap.put("interface_type", DataModelUtil
71 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Interface type", true,
72 DataModelUtil.createValidValuesConstraintsList("management", "left", "right", "other"),
74 propertyDefMap.put("shared_ip", DataModelUtil
75 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Shared ip enabled", false,
76 null, null, null, false));
77 propertyDefMap.put("static_route", DataModelUtil
78 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Static route enabled",
79 false, null, null, null, false));
80 propertyDefMap.put("virtual_network", DataModelUtil
81 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
82 "Virtual Network for this interface", true, null, null, null, null));
83 propertyDefMap.put("static_routes", DataModelUtil
84 .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
85 "An ordered list of static routes to be added to this interface", false, null, null,
87 .createEntrySchema(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(), null,
89 propertyDefMap.put("allowed_address_pairs", DataModelUtil
90 .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
91 "List of allowed address pair for this interface", false, null, null, DataModelUtil
92 .createEntrySchema(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(), null,
94 propertyDefMap.put("ip_address", DataModelUtil
95 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP for this interface",
96 false, null, null, null, null));
97 return propertyDefMap;
100 private static Map<String, AttributeDefinition> createContrailPortAttributes() {
101 Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
102 attributesDefMap.put("fq_name", DataModelUtil
103 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
105 return attributesDefMap;