Improve coverage of multicloud-azure plugin
[multicloud/azure.git] / azure / multicloud_azure / swagger / volume_utils.py
1 # Copyright (c) 2018 Amdocs
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
13
14 def volume_formatter(volume):
15
16     attachments = []
17     for attach in volume.attachments:
18         vim_attach = {
19             'device': attach['device'],
20             'volumeId': attach['volume_id'],
21             'hostName': attach['host_name'],
22             'Id': attach['attachment_id'],
23             'serverId': attach['server_id']
24         }
25         attachments.append(vim_attach)
26
27     return {
28         'id': volume.id,
29         'name': volume.name,
30         'createTime': volume.created_at,
31         'status': volume.status,
32         'type': volume.volume_type,
33         'size': volume.size,
34         'availabilityZone': volume.availability_zone,
35         'attachments': attachments
36     }
37
38
39 def vim_formatter(vim_info, tenantid):
40
41     rsp = {}
42     rsp['vimId'] = vim_info.get('vimId')
43     rsp['vimName'] = vim_info.get('name')
44     rsp['tenantId'] = tenantid
45     return rsp
46
47
48 def sdk_param_formatter(data):
49
50     param = {}
51     param['username'] = data.get('userName')
52     param['password'] = data.get('password')
53     param['auth_url'] = data.get('url')
54     param['project_id'] = data.get('tenant')
55     param['user_domain_name'] = 'default'
56     param['project_domain_name'] = 'default'
57     return param
58
59
60 def req_body_formatter(body):
61
62     param = {}
63     param['name'] = body.get('name')
64     param['size'] = body.get('volumeSize')
65
66     if body.get('volumeType'):
67         param['volume_type'] = body.get('volumeType')
68     if body.get('availabilityZone'):
69         param['availability_zone'] = body.get('availabilityZone')
70     if body.get('imageId'):
71         param['image_id'] = body.get('imageId')
72     return param