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.DataType;
27 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
28 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
29 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
30 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
31 import org.openecomp.sdc.tosca.services.DataModelUtil;
32 import org.openecomp.sdc.tosca.services.ToscaConstants;
33 import org.openecomp.sdc.translator.services.heattotosca.Constants;
35 import java.util.HashMap;
38 class ContrailV2VirtualMachineInterfaceGlobalType {
39 private ContrailV2VirtualMachineInterfaceGlobalType() {
42 public static ServiceTemplate createServiceTemplate() {
43 ServiceTemplate contrailVirtualMachineInterface = new ServiceTemplate();
44 contrailVirtualMachineInterface
45 .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
46 contrailVirtualMachineInterface.setMetadata(DataModelUtil
47 .createMetadata(Constants.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME, "1.0.0",
49 contrailVirtualMachineInterface.setImports(GlobalTypesUtil.createCommonImportList());
50 contrailVirtualMachineInterface
51 .setDescription("Contrail Virtual Machine Interface TOSCA Global Types");
52 contrailVirtualMachineInterface.setNode_types(createGlobalNodeTypes());
53 contrailVirtualMachineInterface.setData_types(createGlobalDataTypes());
54 return contrailVirtualMachineInterface;
57 private static Map<String, DataType> createGlobalDataTypes() {
58 Map<String, DataType> globalDataTypes = new HashMap<>();
60 .put(ToscaDataType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_PROPERTIES.getDisplayName(),
61 createVmiPropertiesDataType());
62 return globalDataTypes;
65 private static DataType createVmiPropertiesDataType() {
66 DataType dataType = new DataType();
67 dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
68 dataType.setDescription("Virtual Machine Interface Properties.");
69 Map<String, PropertyDefinition> properties = new HashMap<>();
71 properties.put("virtual_machine_interface_properties_service_interface_type", DataModelUtil
72 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service Interface Type.",
73 false, null, null, null, null));
74 dataType.setProperties(properties);
78 private static Map<String, NodeType> createGlobalNodeTypes() {
79 Map<String, NodeType> globalNodeTypes = new HashMap<>();
80 globalNodeTypes.put(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE.getDisplayName(),
82 return globalNodeTypes;
85 private static NodeType createVmiNodeType() {
86 NodeType nodeType = new NodeType();
87 nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
88 nodeType.setProperties(createVmiProperties());
89 nodeType.setAttributes(createVmiAttributes());
93 private static Map<String, AttributeDefinition> createVmiAttributes() {
94 Map<String, AttributeDefinition> vmiAttributesDefMap = new HashMap<>();
95 vmiAttributesDefMap.put("fq_name", DataModelUtil
96 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
97 "The FQ name of the Virtual Network.", null, null, null));
98 vmiAttributesDefMap.put("show", DataModelUtil
99 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes.", null,
101 return vmiAttributesDefMap;
104 private static Map<String, PropertyDefinition> createVmiProperties() {
105 Map<String, PropertyDefinition> virtualMachineInterfacePropertyDefMap = new HashMap<>();
106 virtualMachineInterfacePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
107 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
108 "Virtual Machine Interface name", false, null, null, null, null));
109 virtualMachineInterfacePropertyDefMap.put("virtual_machine_intefrace_mac_addresses",
111 .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of mac addresses.",
113 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
115 virtualMachineInterfacePropertyDefMap.put("virtual_network_refs", DataModelUtil
116 .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of virtual networks.",
118 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
120 virtualMachineInterfacePropertyDefMap.put("port_tuple_refs", DataModelUtil
121 .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of port tuples.", false,
123 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
125 virtualMachineInterfacePropertyDefMap.put("security_group_refs", DataModelUtil
126 .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of security groups.",
128 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
130 virtualMachineInterfacePropertyDefMap.put("virtual_machine_interface_properties", DataModelUtil
131 .createPropertyDefinition(
132 ToscaDataType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_PROPERTIES.getDisplayName(),
133 "virtual machine interface properties.", false, null, null, null, null));
134 return virtualMachineInterfacePropertyDefMap;