[sdc] docker file fix for cassandra
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / services / heattotosca / globaltypes / NeutronPortGlobalType.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
22
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.CapabilityDefinition;
27 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
28 import org.openecomp.sdc.tosca.datatypes.model.DataType;
29 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
30 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
31 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
32 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
33 import org.openecomp.sdc.tosca.services.DataModelUtil;
34 import org.openecomp.sdc.tosca.services.ToscaConstants;
35 import org.openecomp.sdc.translator.services.heattotosca.Constants;
36
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 public class NeutronPortGlobalType {
43   /**
44    * Create service template service template.
45    *
46    * @return the service template
47    */
48   public static ServiceTemplate createServiceTemplate() {
49     ServiceTemplate neutronPortServiceTemplate = new ServiceTemplate();
50     neutronPortServiceTemplate
51         .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
52     neutronPortServiceTemplate.setMetadata(
53         DataModelUtil.createMetadata(Constants.NEUTRON_PORT_TEMPLATE_NAME, "1.0.0", null));
54     neutronPortServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
55     neutronPortServiceTemplate.setDescription("Neutron Port TOSCA Global Types");
56     neutronPortServiceTemplate.setData_types(createGlobalDataTypes());
57     neutronPortServiceTemplate.setNode_types(createGlobalNodeTypes());
58     return neutronPortServiceTemplate;
59   }
60
61   private static Map<String, DataType> createGlobalDataTypes() {
62     Map<String, DataType> globalDataTypes = new HashMap<>();
63     globalDataTypes
64         .put(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), createFixedIpsDataType());
65     return globalDataTypes;
66   }
67
68   private static DataType createFixedIpsDataType() {
69     DataType dataType = new DataType();
70     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
71     dataType.setDescription("subnet/ip_address");
72     Map<String, PropertyDefinition> prop = new HashMap<>();
73
74     prop.put("subnet", DataModelUtil.createPropertyDefinition(PropertyType.STRING.getDisplayName(),
75         "Subnet in which to allocate the IP address for this port", false, null, null, null, null));
76     prop.put("ip_address", DataModelUtil
77         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
78             "IP address desired in the subnet for this port", false, null, null, null, null));
79
80     dataType.setProperties(prop);
81     return dataType;
82   }
83
84   private static Map<String, NodeType> createGlobalNodeTypes() {
85     Map<String, NodeType> globalNodeTypes = new HashMap<>();
86     globalNodeTypes.put(ToscaNodeType.NEUTRON_PORT.getDisplayName(), createNeutronPortNodeType());
87     return globalNodeTypes;
88   }
89
90   private static NodeType createNeutronPortNodeType() {
91     NodeType nodeType = new NodeType();
92     nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
93     nodeType.setProperties(createNeutronPortProperties());
94     nodeType.setAttributes(createNeutronPortAttributes());
95     nodeType.setCapabilities(createNeutronPortCapabilities());
96     return nodeType;
97   }
98
99   private static Map<String, CapabilityDefinition> createNeutronPortCapabilities() {
100     Map<String, CapabilityDefinition> capabilities = new HashMap<>();
101     capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
102     return capabilities;
103   }
104
105   private static Map<String, PropertyDefinition> createNeutronPortProperties() {
106     Map<String, PropertyDefinition> neutronPortPropertyDefMap = new HashMap<>();
107     neutronPortPropertyDefMap.put("admin_state_up", DataModelUtil
108         .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
109             "A boolean value specifying the administrative status of the network", false, null,
110             null, null, true));
111     neutronPortPropertyDefMap.put("allowed_address_pairs", DataModelUtil
112         .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
113             "Additional MAC/IP address pairs allowed to pass through the port", false, null, null,
114             DataModelUtil
115                 .createEntrySchema(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), null, null),
116             null));
117     neutronPortPropertyDefMap.put("binding:vnic_type", DataModelUtil
118         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
119             "The vnic type to be bound on the neutron port", false, createBindingConstraint(), null,
120             null, null));
121     neutronPortPropertyDefMap.put("device_id", DataModelUtil
122         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Device ID of this port",
123             false, null, null, null, null));
124     neutronPortPropertyDefMap.put("device_owner", DataModelUtil
125         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
126             "Name of the network owning the port", false, null, null, null, null));
127     neutronPortPropertyDefMap.put("fixed_ips", DataModelUtil
128         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Desired IPs for this port",
129             false, null, null, DataModelUtil
130                 .createEntrySchema(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), null,
131                     null), null));
132     neutronPortPropertyDefMap.put("mac_address", DataModelUtil
133         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
134             "MAC address to give to this port", false, null, null, null, null));
135     neutronPortPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
136         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
137             "A symbolic name for this port", false, null, null, null, null));
138     neutronPortPropertyDefMap.put("port_security_enabled", DataModelUtil
139         .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
140             "Flag to enable/disable port security on the network", false, null, null, null, null));
141     neutronPortPropertyDefMap.put("qos_policy", DataModelUtil
142         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
143             "The name or ID of QoS policy to attach to this network", false, null, null, null,
144             null));
145     neutronPortPropertyDefMap.put(Constants.SECURITY_GROUPS_PROPERTY_NAME, DataModelUtil
146         .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
147             "List of security group names or IDs", false, null, null,
148             DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
149             null));
150     neutronPortPropertyDefMap.put("value_specs", DataModelUtil
151         .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
152             "Extra parameters to include in the request", false, null, null,
153             DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
154             new HashMap<String, String>()));
155     neutronPortPropertyDefMap.put("replacement_policy", DataModelUtil
156         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
157             "Policy on how to respond to a stack-update for this resource", false,
158             createReplacementPolicyConstrain(), null, null, "AUTO"));
159     neutronPortPropertyDefMap.put("network", DataModelUtil
160         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
161             "Network this port belongs to", false, null, null, null, null));
162     return neutronPortPropertyDefMap;
163   }
164
165   private static List<Constraint> createBindingConstraint() {
166     List<Constraint> constraints = new ArrayList<>();
167     Constraint validValues =
168         DataModelUtil.createValidValuesConstraint("macvtap", "direct", "normal");
169     constraints.add(validValues);
170     return constraints;
171   }
172
173   private static List<Constraint> createReplacementPolicyConstrain() {
174     List<Constraint> constraints = new ArrayList<>();
175     Constraint validValues = DataModelUtil.createValidValuesConstraint("REPLACE_ALWAYS", "AUTO");
176     constraints.add(validValues);
177     return constraints;
178   }
179
180   private static Map<String, AttributeDefinition> createNeutronPortAttributes() {
181     Map<String, AttributeDefinition> neutronPortAttributesDefMap = new HashMap<>();
182     neutronPortAttributesDefMap.put("network_id", DataModelUtil
183         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
184             "Unique identifier for the network owning the port", null, null, null));
185     neutronPortAttributesDefMap.put("qos_policy_id", DataModelUtil
186         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
187             "The QoS policy ID attached to this network", null, null, null));
188     neutronPortAttributesDefMap.put("show", DataModelUtil
189         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
190             "Detailed information about resource", null, null, null));
191     neutronPortAttributesDefMap.put("status", DataModelUtil
192         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
193             "The status of the network", null, null, null));
194     neutronPortAttributesDefMap.put("subnets", DataModelUtil
195         .createAttributeDefinition(PropertyType.LIST.getDisplayName(), "Subnets of this network",
196             null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
197             null));
198     neutronPortAttributesDefMap.put("tenant_id", DataModelUtil
199         .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Tenant owning the port",
200             null, null, null));
201     return neutronPortAttributesDefMap;
202   }
203 }