Sync heat-translator code
[parser.git] / tosca2heat / heat-translator / translator / hot / tosca / tosca_block_storage_attachment.py
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13
14 from toscaparser.functions import GetInput
15 from translator.hot.syntax.hot_resource import HotResource
16
17 # Name used to dynamically load appropriate map class.
18 TARGET_CLASS_NAME = 'ToscaBlockStorageAttachment'
19
20
21 class ToscaBlockStorageAttachment(HotResource):
22     '''Translate TOSCA relationship AttachesTo for Compute and BlockStorage.'''
23
24     toscatype = 'tosca.nodes.BlockStorageAttachment'
25
26     def __init__(self, template, nodetemplates, instance_uuid, volume_id,
27                  csar_dir=None):
28         super(ToscaBlockStorageAttachment,
29               self).__init__(template, type='OS::Cinder::VolumeAttachment',
30                              csar_dir=csar_dir)
31         self.nodetemplates = nodetemplates
32         self.instance_uuid = {'get_resource': instance_uuid}
33         self.volume_id = {'get_resource': volume_id}
34
35     def handle_properties(self):
36         tosca_props = {}
37         for prop in self.nodetemplate.get_properties_objects():
38             if isinstance(prop.value, GetInput):
39                 tosca_props[prop.name] = {'get_param': prop.value.input_name}
40             else:
41                 tosca_props[prop.name] = prop.value
42         self.properties = tosca_props
43         # instance_uuid and volume_id for Cinder volume attachment
44         self.properties['instance_uuid'] = self.instance_uuid
45         self.properties['volume_id'] = self.volume_id
46         if 'location' in self.properties:
47             self.properties['mountpoint'] = self.properties.pop('location')
48
49         # TOSCA type can have a device name specified,
50         # this is unsupported by Heat
51         if 'device' in self.properties:
52             self.properties.pop('device')
53
54     def handle_life_cycle(self):
55         return None, None, None