Merge "Update the nfv tosca definietion against the latest spec"
[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         super(ToscaBlockStorageAttachment,
28               self).__init__(template, type='OS::Cinder::VolumeAttachment')
29         self.nodetemplates = nodetemplates
30         self.instance_uuid = {'get_resource': instance_uuid}
31         self.volume_id = {'get_resource': volume_id}
32
33     def handle_properties(self):
34         tosca_props = {}
35         for prop in self.nodetemplate.get_properties_objects():
36             if isinstance(prop.value, GetInput):
37                 tosca_props[prop.name] = {'get_param': prop.value.input_name}
38             else:
39                 tosca_props[prop.name] = prop.value
40         self.properties = tosca_props
41         # instance_uuid and volume_id for Cinder volume attachment
42         self.properties['instance_uuid'] = self.instance_uuid
43         self.properties['volume_id'] = self.volume_id
44         if 'location' in self.properties:
45             self.properties['mountpoint'] = self.properties.pop('location')
46
47     def handle_life_cycle(self):
48         pass