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.ToscaNodeType;
24 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
25 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
26 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
27 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
28 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
29 import org.openecomp.sdc.tosca.services.DataModelUtil;
30 import org.openecomp.sdc.tosca.services.ToscaConstants;
31 import org.openecomp.sdc.translator.services.heattotosca.Constants;
33 import java.util.HashMap;
36 public class ContrailComputeGlobalType {
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_COMPUTE_TEMPLATE_NAME, "1.0.0", null));
48 serviceTemplate.setDescription("Contrail Compute TOSCA Global Types");
49 serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
50 serviceTemplate.setNode_types(createGlobalNodeTypes());
51 return serviceTemplate;
55 private static Map<String, NodeType> createGlobalNodeTypes() {
56 Map<String, NodeType> globalNodeTypes = new HashMap<>();
58 .put(ToscaNodeType.CONTRAIL_COMPUTE.getDisplayName(), createContrailComputeNodeType());
59 return globalNodeTypes;
62 private static NodeType createContrailComputeNodeType() {
63 NodeType nodeType = new NodeType();
64 nodeType.setDerived_from(ToscaNodeType.COMPUTE.getDisplayName());
65 nodeType.setProperties(createContrailComputeProperties());
66 nodeType.setAttributes(createContrailComputeAttributes());
71 private static Map<String, PropertyDefinition> createContrailComputeProperties() {
72 Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
73 propertyDefMap.put("service_instance_name", DataModelUtil
74 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service instance name",
75 true, null, null, null, null));
76 propertyDefMap.put("service_template_name", DataModelUtil
77 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service template name",
78 false, null, null, null, null));
79 propertyDefMap.put("image_name", DataModelUtil
80 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
82 propertyDefMap.put("service_mode", DataModelUtil
83 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service mode", true,
85 .createValidValuesConstraintsList("transparent", "in-network", "in-network-nat"),
87 propertyDefMap.put("service_type", DataModelUtil
88 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service type", true,
89 DataModelUtil.createValidValuesConstraintsList("firewall", "analyzer", "source-nat",
90 "loadbalancer"), null, null, null));
91 propertyDefMap.put("image_name", DataModelUtil
92 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
94 propertyDefMap.put("flavor", DataModelUtil
95 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "flavor", false, null, null,
97 propertyDefMap.put("availability_zone_enable", DataModelUtil
98 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
99 "Indicates availability zone is enabled", false, null, null, null, false));
100 propertyDefMap.put("availability_zone", DataModelUtil
101 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
102 "Availability zone to create servers in", false, null, null, null, null));
103 return propertyDefMap;
106 private static Map<String, AttributeDefinition> createContrailComputeAttributes() {
107 Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
108 attributesDefMap.put("fq_name", DataModelUtil
109 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
111 attributesDefMap.put("status", DataModelUtil
112 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "status of the compute",
114 attributesDefMap.put("virtual_machines", DataModelUtil
115 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "VMs of this compute",
117 attributesDefMap.put("active_vms", DataModelUtil
118 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Number of active VMs",
120 attributesDefMap.put("tenant_id", DataModelUtil
121 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Tenant id of the VM",
123 attributesDefMap.put("show", DataModelUtil
124 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes", null,
126 return attributesDefMap;