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.ToscaRelationshipType;
25 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
26 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
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.RelationshipType;
31 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
32 import org.openecomp.sdc.tosca.services.DataModelUtil;
33 import org.openecomp.sdc.tosca.services.ToscaConstants;
34 import org.openecomp.sdc.translator.services.heattotosca.Constants;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
41 public class CinderVolumeGlobalType {
44 * Create service template service template.
46 * @return the service template
48 public static ServiceTemplate createServiceTemplate() {
49 ServiceTemplate cinderVolumeServiceTemplate = new ServiceTemplate();
50 cinderVolumeServiceTemplate
51 .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
52 cinderVolumeServiceTemplate.setMetadata(
53 DataModelUtil.createMetadata(Constants.CINDER_VOLUME_TEMPLATE_NAME, "1.0.0", null));
54 cinderVolumeServiceTemplate.setDescription("Cinder Volume TOSCA Global Types");
55 cinderVolumeServiceTemplate.setRelationship_types(createGlobalRelationshipTypes());
56 cinderVolumeServiceTemplate.setNode_types(createGlobalNodeTypes());
57 return cinderVolumeServiceTemplate;
60 private static Map<String, NodeType> createGlobalNodeTypes() {
61 Map<String, NodeType> globalNodeTypes = new HashMap<>();
62 globalNodeTypes.put(ToscaNodeType.CINDER_VOLUME.getDisplayName(), createCinderVolumeNodeType());
63 return globalNodeTypes;
66 private static NodeType createCinderVolumeNodeType() {
67 NodeType cinderVolumeNodeType = new NodeType();
68 cinderVolumeNodeType.setDerived_from(ToscaNodeType.BLOCK_STORAGE.getDisplayName());
69 cinderVolumeNodeType.setProperties(createCinderVolumeProperties());
70 cinderVolumeNodeType.setAttributes(createCinderVolumeAttributes());
71 return cinderVolumeNodeType;
74 private static Map<String, RelationshipType> createGlobalRelationshipTypes() {
75 Map<String, RelationshipType> globalRelationshipTypes = new HashMap<>();
76 globalRelationshipTypes.put(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO.getDisplayName(),
77 createCinderVolumeAttachesToRelationshipType());
78 return globalRelationshipTypes;
81 private static RelationshipType createCinderVolumeAttachesToRelationshipType() {
82 RelationshipType cinderVolumeAttachesToRelationType = new RelationshipType();
83 cinderVolumeAttachesToRelationType
84 .setDerived_from(ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName());
85 cinderVolumeAttachesToRelationType
86 .setDescription("This type represents an attachment relationship for associating volume");
88 Map<String, PropertyDefinition> cinderVolumeAttachesToProps = new HashMap<>();
89 cinderVolumeAttachesToProps.put("location", DataModelUtil
90 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
91 "The location where the volume is exposed on the instance, mountpoint", false, null,
92 null, null, null)); //overridden location prop from attachesTo
93 cinderVolumeAttachesToProps.put("instance_uuid", DataModelUtil
94 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
95 "The ID of the server to which the volume attaches", true, null, null, null, null));
96 cinderVolumeAttachesToProps.put("volume_id", DataModelUtil
97 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
98 "The ID of the volume to be attached", true, null, null, null, null));
99 cinderVolumeAttachesToRelationType.setProperties(cinderVolumeAttachesToProps);
101 Map<String, AttributeDefinition> cinderVolumeAttachesToAttributes = new HashMap<>();
102 cinderVolumeAttachesToAttributes.put("show", DataModelUtil
103 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
104 "Detailed information about resource", null, null, null));
105 cinderVolumeAttachesToRelationType.setAttributes(cinderVolumeAttachesToAttributes);
107 return cinderVolumeAttachesToRelationType;
110 private static Map<String, PropertyDefinition> createCinderVolumeProperties() {
111 Map<String, PropertyDefinition> cinderVolumePropertyDefMap = new HashMap<>();
112 cinderVolumePropertyDefMap.put("availability_zone", DataModelUtil
113 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
114 "The availability zone in which the volume will be created", false, null, null, null,
116 cinderVolumePropertyDefMap.put("backup_id", DataModelUtil
117 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
118 "If specified, the backup to create the volume from", false, null, null, null, null));
119 cinderVolumePropertyDefMap.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
120 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
121 "A description of the volume", false, null, null, null, null));
122 cinderVolumePropertyDefMap.put("image", DataModelUtil
123 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
124 "If specified, the name or ID of the image to create the volume from", false, null,
126 cinderVolumePropertyDefMap.put("metadata", DataModelUtil
127 .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
128 "Key/value pairs to associate with the volume", false, null, null,
129 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
131 cinderVolumePropertyDefMap.put("multiattach", DataModelUtil
132 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
133 "Whether allow the volume to be attached more than once", false, null, null, null,
135 cinderVolumePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
136 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
137 "A name used to distinguish the volume", false, null, null, null, null));
138 cinderVolumePropertyDefMap.put("read_only", DataModelUtil
139 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
140 "Enables or disables read-only access mode of volume", false, null, null, null, null));
141 cinderVolumePropertyDefMap.put("scheduler_hints", DataModelUtil
142 .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
143 "Arbitrary key-value pairs specified by the client "
144 + "to help the Cinder scheduler creating a volume",
146 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
148 cinderVolumePropertyDefMap.put("size", DataModelUtil
149 .createPropertyDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(),
150 "The requested storage size (default unit is MB)", false, getSizeConstraints(), null,
152 cinderVolumePropertyDefMap.put("source_volid", DataModelUtil
153 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
154 "If specified, the volume to use as source", false, null, null, null, null));
155 cinderVolumePropertyDefMap.put("volume_type", DataModelUtil
156 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
157 "If specified, the type of volume to use, mapping to a specific backend", false, null,
159 cinderVolumePropertyDefMap.put("delete_on_termination", DataModelUtil
160 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
161 "Indicate whether the volume should be deleted when the server is terminated", false,
162 null, null, null, null));
163 cinderVolumePropertyDefMap.put("boot_index", DataModelUtil
164 .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
165 "Integer used for ordering the boot disks", false, null, null, null, null));
166 cinderVolumePropertyDefMap.put("device_type", DataModelUtil
167 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Device type", false,
168 getDeviceTypeConstraints(), null, null, null));
169 cinderVolumePropertyDefMap.put("disk_bus", DataModelUtil
170 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
171 "Bus of the device: hypervisor driver chooses a suitable default if omitted", false,
172 getDiskBusConstraints(), null, null, null));
173 cinderVolumePropertyDefMap.put("swap_size", DataModelUtil
174 .createPropertyDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(),
175 "The size of the swap, in MB", false, null, null, null, null));
177 return cinderVolumePropertyDefMap;
180 private static Map<String, AttributeDefinition> createCinderVolumeAttributes() {
181 Map<String, AttributeDefinition> cinderVolumeAttributesDefMap = new HashMap<>();
182 cinderVolumeAttributesDefMap.put("attachments", DataModelUtil
183 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
184 "The list of attachments of the volume", null,
185 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
187 cinderVolumeAttributesDefMap.put("bootable", DataModelUtil
188 .createAttributeDefinition(PropertyType.BOOLEAN.getDisplayName(),
189 "Boolean indicating if the volume can be booted or not", null, null, null));
190 cinderVolumeAttributesDefMap.put("created_at", DataModelUtil
191 .createAttributeDefinition(PropertyType.TIMESTAMP.getDisplayName(),
192 "The timestamp indicating volume creation", null, null, null));
193 cinderVolumeAttributesDefMap.put("display_description", DataModelUtil
194 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
195 "Description of the volume", null, null, null));
196 cinderVolumeAttributesDefMap.put("display_name", DataModelUtil
197 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Name of the volume", null,
199 cinderVolumeAttributesDefMap.put("encrypted", DataModelUtil
200 .createAttributeDefinition(PropertyType.BOOLEAN.getDisplayName(),
201 "Boolean indicating if the volume is encrypted or not", null, null, null));
202 cinderVolumeAttributesDefMap.put("metadata_values", DataModelUtil
203 .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
204 "Key/value pairs associated with the volume in raw dict form", null,
205 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
207 cinderVolumeAttributesDefMap.put("show", DataModelUtil
208 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
209 "Detailed information about resource", null, null, null));
210 cinderVolumeAttributesDefMap.put("status", DataModelUtil
211 .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
212 "The current status of the volume", null, null, null));
213 return cinderVolumeAttributesDefMap;
216 private static List<Constraint> getDeviceTypeConstraints() {
217 Constraint validValues;
218 List<Constraint> constraints = new ArrayList<>();
219 validValues = DataModelUtil.createValidValuesConstraint("cdrom", "disk");
220 constraints.add(validValues);
224 private static List<Constraint> getDiskBusConstraints() {
225 Constraint validValues;
226 List<Constraint> constraints = new ArrayList<>();
228 DataModelUtil.createValidValuesConstraint("ide", "lame_bus", "scsi", "usb", "virtio");
229 constraints.add(validValues);
234 private static List<Constraint> getSizeConstraints() {
235 List<Constraint> constraints;
236 constraints = new ArrayList<>();
237 Constraint constraint = new Constraint();
238 constraint.setGreater_or_equal("1 GB");
239 constraints.add(constraint);