aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronPortGlobalType.java
blob: 2106b9b3bc3c773adc9d8cacd6a054f01d339781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.translator.services.heattotosca.globaltypes;

import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.tosca.datatypes.model.Constraint;
import org.openecomp.sdc.tosca.datatypes.model.DataType;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.services.heattotosca.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NeutronPortGlobalType {
  /**
   * Create service template service template.
   *
   * @return the service template
   */
  public static ServiceTemplate createServiceTemplate() {
    ServiceTemplate neutronPortServiceTemplate = new ServiceTemplate();
    neutronPortServiceTemplate
        .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
    neutronPortServiceTemplate.setMetadata(
        DataModelUtil.createMetadata(Constants.NEUTRON_PORT_TEMPLATE_NAME, "1.0.0", null));
    neutronPortServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
    neutronPortServiceTemplate.setDescription("Neutron Port TOSCA Global Types");
    neutronPortServiceTemplate.setData_types(createGlobalDataTypes());
    neutronPortServiceTemplate.setNode_types(createGlobalNodeTypes());
    return neutronPortServiceTemplate;
  }

  private static Map<String, DataType> createGlobalDataTypes() {
    Map<String, DataType> globalDataTypes = new HashMap<>();
    globalDataTypes
        .put(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), createFixedIpsDataType());
    return globalDataTypes;
  }

  private static DataType createFixedIpsDataType() {
    DataType dataType = new DataType();
    dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
    dataType.setDescription("subnet/ip_address");
    Map<String, PropertyDefinition> prop = new HashMap<>();

    prop.put("subnet", DataModelUtil.createPropertyDefinition(PropertyType.STRING.getDisplayName(),
        "Subnet in which to allocate the IP address for this port", false, null, null, null, null));
    prop.put("ip_address", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "IP address desired in the subnet for this port", false, null, null, null, null));

    dataType.setProperties(prop);
    return dataType;
  }

  private static Map<String, NodeType> createGlobalNodeTypes() {
    Map<String, NodeType> globalNodeTypes = new HashMap<>();
    globalNodeTypes.put(ToscaNodeType.NEUTRON_PORT.getDisplayName(), createNeutronPortNodeType());
    return globalNodeTypes;
  }

  private static NodeType createNeutronPortNodeType() {
    NodeType nodeType = new NodeType();
    nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
    nodeType.setProperties(createNeutronPortProperties());
    nodeType.setAttributes(createNeutronPortAttributes());
    nodeType.setCapabilities(createNeutronPortCapabilities());
    return nodeType;
  }

  private static Map<String, CapabilityDefinition> createNeutronPortCapabilities() {
    Map<String, CapabilityDefinition> capabilities = new HashMap<>();
    capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
    return capabilities;
  }

  private static Map<String, PropertyDefinition> createNeutronPortProperties() {
    Map<String, PropertyDefinition> neutronPortPropertyDefMap = new HashMap<>();
    neutronPortPropertyDefMap.put("admin_state_up", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "A boolean value specifying the administrative status of the network", false, null,
            null, null, true));
    neutronPortPropertyDefMap.put("allowed_address_pairs", DataModelUtil
        .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
            "Additional MAC/IP address pairs allowed to pass through the port", false, null, null,
            DataModelUtil
                .createEntrySchema(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), null, null),
            null));
    neutronPortPropertyDefMap.put("binding:vnic_type", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The vnic type to be bound on the neutron port", false, createBindingConstraint(), null,
            null, null));
    neutronPortPropertyDefMap.put("device_id", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Device ID of this port",
            false, null, null, null, null));
    neutronPortPropertyDefMap.put("device_owner", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Name of the network owning the port", false, null, null, null, null));
    neutronPortPropertyDefMap.put("fixed_ips", DataModelUtil
        .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Desired IPs for this port",
            false, null, null, DataModelUtil
                .createEntrySchema(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), null,
                    null), null));
    neutronPortPropertyDefMap.put("mac_address", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "MAC address to give to this port", false, null, null, null, null));
    neutronPortPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "A symbolic name for this port", false, null, null, null, null));
    neutronPortPropertyDefMap.put("port_security_enabled", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "Flag to enable/disable port security on the network", false, null, null, null, null));
    neutronPortPropertyDefMap.put("qos_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The name or ID of QoS policy to attach to this network", false, null, null, null,
            null));
    neutronPortPropertyDefMap.put(Constants.SECURITY_GROUPS_PROPERTY_NAME, DataModelUtil
        .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
            "List of security group names or IDs", false, null, null,
            DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
            null));
    neutronPortPropertyDefMap.put("value_specs", DataModelUtil
        .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
            "Extra parameters to include in the request", false, null, null,
            DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
            new HashMap<String, String>()));
    neutronPortPropertyDefMap.put("replacement_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Policy on how to respond to a stack-update for this resource", false,
            createReplacementPolicyConstrain(), null, null, "AUTO"));
    neutronPortPropertyDefMap.put("network", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Network this port belongs to", false, null, null, null, null));
    return neutronPortPropertyDefMap;
  }

  private static List<Constraint> createBindingConstraint() {
    List<Constraint> constraints = new ArrayList<>();
    Constraint validValues =
        DataModelUtil.createValidValuesConstraint("macvtap", "direct", "normal");
    constraints.add(validValues);
    return constraints;
  }

  private static List<Constraint> createReplacementPolicyConstrain() {
    List<Constraint> constraints = new ArrayList<>();
    Constraint validValues = DataModelUtil.createValidValuesConstraint("REPLACE_ALWAYS", "AUTO");
    constraints.add(validValues);
    return constraints;
  }

  private static Map<String, AttributeDefinition> createNeutronPortAttributes() {
    Map<String, AttributeDefinition> neutronPortAttributesDefMap = new HashMap<>();
    neutronPortAttributesDefMap.put("network_id", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "Unique identifier for the network owning the port", null, null, null));
    neutronPortAttributesDefMap.put("qos_policy_id", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "The QoS policy ID attached to this network", null, null, null));
    neutronPortAttributesDefMap.put("show", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "Detailed information about resource", null, null, null));
    neutronPortAttributesDefMap.put("status", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "The status of the network", null, null, null));
    neutronPortAttributesDefMap.put("subnets", DataModelUtil
        .createAttributeDefinition(PropertyType.LIST.getDisplayName(), "Subnets of this network",
            null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
            null));
    neutronPortAttributesDefMap.put("tenant_id", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Tenant owning the port",
            null, null, null));
    return neutronPortAttributesDefMap;
  }
}