aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NovaServerGlobalType.java
blob: d38d70a4f722b654af872c66b19ee2cf399742fb (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*-
 * ============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.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.datatypes.model.heatextend.PropertyTypeExt;
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 NovaServerGlobalType {

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


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

  private static NodeType createNovaServerNodeType() {
    NodeType novaServerNodeType = new NodeType();
    novaServerNodeType.setDerived_from(ToscaNodeType.COMPUTE.getDisplayName());
    novaServerNodeType.setProperties(createNovaServerProperties());
    novaServerNodeType.setAttributes(createNovaServerAttributes());
    return novaServerNodeType;
  }


  private static Map<String, PropertyDefinition> createNovaServerProperties() {
    Map<String, PropertyDefinition> novaServerPropertyDefMap = new HashMap<>();
    novaServerPropertyDefMap.put("flavor", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The ID or name of the flavor to boot onto", true, null, null, null, null));
    novaServerPropertyDefMap.put("admin_pass", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The administrator password for the server", false, null, null, null, null));
    novaServerPropertyDefMap.put("availability_zone", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Availability zone to create servers in", false, null, null, null, null));
    novaServerPropertyDefMap.put("config_drive", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "enable config drive on the server", false, null, null, null, null));
    novaServerPropertyDefMap.put("contrail_service_instance_ind", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "Nova server related to service instance indicator", false, null, null, null, false));
    novaServerPropertyDefMap.put("diskConfig", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Control how the disk is partitioned when the server is created", false,
            getDiskConfigConstraints(), null, null, null));
    novaServerPropertyDefMap.put("flavor_update_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Policy on how to apply a flavor update", false, getFlavorUpdatePolicyConstraints(),
            null, null, "RESIZE"));
    novaServerPropertyDefMap.put("image", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The ID or name of the image to boot with", false, null, null, null, null));
    novaServerPropertyDefMap.put("image_update_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Policy on how to apply an image-id update", false, getImageUpdatePolicyConstraints(),
            null, null, "REBUILD"));
    novaServerPropertyDefMap.put("key_name", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Name of keypair to inject into the server", false, null, null, null, null));
    novaServerPropertyDefMap.put("metadata", DataModelUtil
        .createPropertyDefinition(PropertyTypeExt.JSON.getDisplayName(),
            "Arbitrary JSON metadata to store for this server", false, null, null, null, null));
    novaServerPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Server name", false, null,
            null, null, null));
    novaServerPropertyDefMap.put("personality", DataModelUtil
        .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
            "A map of files to create/overwrite on the server upon boot", false, null, null,
            DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
            new HashMap<String, String>()));
    novaServerPropertyDefMap.put("reservation_id", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "A UUID for the set of servers being requested", false, null, null, null, null));
    novaServerPropertyDefMap.put("scheduler_hints", DataModelUtil
        .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
            "Arbitrary key-value pairs specified by the client to help boot a server", false, null,
            null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
            null));
    novaServerPropertyDefMap.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),
            new ArrayList<>()));
    novaServerPropertyDefMap.put("software_config_transport", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "How the server should receive the metadata required for software configuration", false,
            getSoftwareConfigTransportConstraints(), null, null, "POLL_SERVER_CFN"));
    novaServerPropertyDefMap.put("user_data", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "User data script to be executed by cloud-init", false, null, null, null, ""));
    novaServerPropertyDefMap.put("user_data_format", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "How the user_data should be formatted for the server", false,
            getUserDataFormatConstraint(), null, null, "HEAT_CFNTOOLS"));
    novaServerPropertyDefMap.put("user_data_update_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "Policy on how to apply a user_data update", false,
            getUserDataUpdatePolicyConstraints(), null, null, "REPLACE"));
    return novaServerPropertyDefMap;
  }

  private static Map<String, AttributeDefinition> createNovaServerAttributes() {
    Map<String, AttributeDefinition> novaServerAttributesDefMap = new HashMap<>();
    novaServerAttributesDefMap.put("accessIPv4", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "The manually assigned alternative public IPv4 address of the server", null, null,
            null));
    novaServerAttributesDefMap.put("accessIPv6", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "The manually assigned alternative public IPv6 address of the server", null, null,
            null));
    novaServerAttributesDefMap.put("addresses", DataModelUtil
        .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
            "A dict of all network addresses with corresponding port_id", null, DataModelUtil
                .createEntrySchema(ToscaDataType.NOVA_SERVER_NETWORK_ADDRESS_INFO.getDisplayName(),
                    null, null), null));
    novaServerAttributesDefMap.put("console_urls", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "URLs of servers consoles",
            null, null, null));
    novaServerAttributesDefMap.put("instance_name", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "AWS compatible instance name", null, null, null));
    novaServerAttributesDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Name of the server", null,
            null, null));
    novaServerAttributesDefMap.put("show", DataModelUtil
        .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
            "Detailed information about resource", null, null, null));
    return novaServerAttributesDefMap;
  }

  private static List<Constraint> getUserDataFormatConstraint() {
    List<Constraint> constraints;
    Constraint validValues;
    constraints = new ArrayList<>();
    validValues =
        DataModelUtil.createValidValuesConstraint("SOFTWARE_CONFIG", "RAW", "HEAT_CFNTOOLS");
    constraints.add(validValues);
    return constraints;
  }

  private static List<Constraint> getUserDataUpdatePolicyConstraints() {
    List<Constraint> constraints;
    Constraint validValues;
    constraints = new ArrayList<>();
    validValues = DataModelUtil.createValidValuesConstraint("REPLACE", "IGNORE");
    constraints.add(validValues);
    return constraints;
  }

  private static List<Constraint> getSoftwareConfigTransportConstraints() {
    List<Constraint> constraints;
    Constraint validValues;
    constraints = new ArrayList<>();
    validValues = DataModelUtil
        .createValidValuesConstraint("POLL_SERVER_CFN", "POLL_SERVER_HEAT", "POLL_TEMP_URL",
            "ZAQAR_MESSAGE");
    constraints.add(validValues);
    return constraints;
  }

  private static List<Constraint> getImageUpdatePolicyConstraints() {
    List<Constraint> constraints;
    Constraint validValues;
    constraints = new ArrayList<>();
    validValues = DataModelUtil
        .createValidValuesConstraint("REBUILD_PRESERVE_EPHEMERAL", "REPLACE", "REBUILD");
    constraints.add(validValues);
    return constraints;
  }

  private static List<Constraint> getFlavorUpdatePolicyConstraints() {
    Constraint validValues;
    List<Constraint> constraints = new ArrayList<>();
    validValues = DataModelUtil.createValidValuesConstraint("RESIZE", "REPLACE");
    constraints.add(validValues);
    return constraints;
  }

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

  private static Map<String, DataType> createGlobalDataTypes() {
    Map<String, DataType> globalDataTypes = new HashMap<>();
    globalDataTypes.put(ToscaDataType.NOVA_SERVER_PORT_EXTRA_PROPERTIES.getDisplayName(),
        createPortExtraDataDataType());
    globalDataTypes.put(ToscaDataType.NOVA_SERVER_NETWORK_ADDRESS_INFO.getDisplayName(),
        createAddressInfoDataType());
    return globalDataTypes;
  }

  private static DataType createAddressInfoDataType() {
    DataType addressInfoDataType = new DataType();
    addressInfoDataType.setDerived_from(ToscaDataType.NETWORK_NETWORK_INFO.getDisplayName());
    addressInfoDataType.setDescription("Network addresses with corresponding port id");

    Map<String, PropertyDefinition> addressInfoProp = new HashMap<>();
    addressInfoProp.put("port_id", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Port id", false, null,
            null, null, null));
    addressInfoDataType.setProperties(addressInfoProp);

    return addressInfoDataType;
  }


  private static DataType createPortExtraDataDataType() {
    DataType portExtraDataType = new DataType();
    portExtraDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
    portExtraDataType.setDescription("Nova server network expand properties for port");
    Map<String, PropertyDefinition> portExtraPropMap = new HashMap<>();

    portExtraPropMap.put("admin_state_up", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "The administrative state of this port", false, null, null, null, true));
    portExtraPropMap.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));

    List<Constraint> bindingVnicConstraints = new ArrayList<>();
    Constraint validValues =
        DataModelUtil.createValidValuesConstraint("macvtap", "direct", "normal");
    bindingVnicConstraints.add(validValues);
    portExtraPropMap.put("binding:vnic_type", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The vnic type to be bound on the neutron port", false, bindingVnicConstraints, null,
            null, null));

    portExtraPropMap.put("mac_address", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "MAC address to give to this port", false, null, null, null, null));
    portExtraPropMap.put("port_security_enabled", DataModelUtil
        .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
            "Flag to enable/disable port security on the port", false, null, null, null, null));
    portExtraPropMap.put("qos_policy", DataModelUtil
        .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
            "The name or ID of QoS policy to attach to this port", false, null, null, null, null));
    portExtraPropMap.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>()));
    portExtraDataType.setProperties(portExtraPropMap);
    return portExtraDataType;
  }

}