1 # Copyright (c) 2018 Amdocs
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:
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 def server_formatter(server, interfaces=[]):
20 "tenantId": server.project_id,
21 "availabilityZone": server.availability_zone,
22 "flavorId": server.flavor_id or server.flavor['id'],
26 # TODO finish following attributes
29 "userdata": server.user_data,
31 "status": server.status
34 r['nicArray'] = [{'portId': i.port_id} for i in interfaces]
36 r['nicArray'] = [{'portId': n['port']} for n in server.networks]
37 # TODO: wait sdk fix block_device_mapping
39 if server.attached_volumes:
40 r["volumeArray"] = [{'volumeId': v['id']}
41 for v in server.attached_volumes]
42 elif server.block_device_mapping:
43 r["volumeArray"] = [{'volumeId': v['uuid']}
44 for v in server.block_device_mapping]
46 r['volumeArray'] = [{'volumeId': ""}]
47 if server.image_id or server.image:
50 'imageId': server.image_id or server.image['id']
55 'volumeId': r['volumeArray'][0]['volumeId']
58 r["metadata"] = [{'keyName': k, 'value': v}
59 for k, v in six.iteritems(server.metadata)]
60 if server.security_groups:
61 r["securityGroups"] = [i['name'] for i in server.security_groups]
65 def flavor_formatter(flavor, extra_specs):
72 "ephemeral": flavor.ephemeral,
74 "isPublic": flavor.is_public}
76 r["extraSpecs"] = extra_specs_formatter(extra_specs)
80 def extra_specs_formatter(extra_specs):
81 return [{"keyName": k, "value": v}
82 for k, v in six.iteritems(extra_specs.extra_specs)]
85 def server_limits_formatter(limits):
88 'maxPersonality': limits.absolute.personality,
89 'maxPersonalitySize': limits.absolute.personality_size,
90 'maxServerGroupMembers': limits.absolute.server_group_members,
91 'maxServerGroups': limits.absolute.server_groups,
92 'maxImageMeta': limits.absolute.image_meta,
93 'maxTotalCores': limits.absolute.total_cores,
94 'maxTotalInstances': limits.absolute.instances,
95 'maxTotalKeypairs': limits.absolute.keypairs,
96 'maxTotalRAMSize': limits.absolute.total_ram,
97 'security_group_rules': limits.absolute.security_group_rules,
98 'security_group': limits.absolute.security_groups,
105 def service_formatter(service):
107 'service': service.binary,
108 'name': service.host,
109 'zone': service.zone,
113 def hypervisor_formatter(hypervisor):
115 'name': hypervisor.name,
116 'cpu': hypervisor.vcpus,
117 'disk_gb': hypervisor.local_disk_size,
118 'memory_mb': hypervisor.memory_size,