1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# Copyright (c) 2017-2018 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import json
import uuid
import traceback
from django.conf import settings
from newton_base.registration import registration as newton_registration
from common.exceptions import VimDriverNewtonException
from common.msapi import extsys
from keystoneauth1.exceptions import HttpError
logger = logging.getLogger(__name__)
# DEBUG=True
class Registry(newton_registration.Registry):
def __init__(self):
self.proxy_prefix = settings.MULTICLOUD_PREFIX
self.aai_base_url = settings.AAI_BASE_URL
self._logger = logger
def _discover_flavors(self, vimid="", session=None, viminfo=None):
try:
cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
for flavor in self._get_list_resources(
"/flavors/detail", "compute", session, viminfo, vimid,
"flavors"):
flavor_info = {
'flavor-id': flavor['id'],
'flavor-name': flavor['name'],
'flavor-vcpus': flavor['vcpus'],
'flavor-ram': flavor['ram'],
'flavor-disk': flavor['disk'],
'flavor-ephemeral': flavor['OS-FLV-EXT-DATA:ephemeral'],
'flavor-swap': flavor['swap'],
'flavor-is-public': flavor['os-flavor-access:is_public'],
'flavor-disabled': flavor['OS-FLV-DISABLED:disabled'],
}
if flavor.get('link') and len(flavor['link']) > 0:
flavor_info['flavor-selflink'] = flavor['link'][0]['href'] or 'http://0.0.0.0',
else:
flavor_info['flavor-selflink'] = 'http://0.0.0.0',
# add hpa capabilities
if (flavor['name'].find('onap.') == 0):
req_resouce = "/flavors/%s/os-extra_specs" % flavor['id']
extraResp = self._get_list_resources(req_resouce, "compute", session, viminfo, vimid, "extra_specs")
hpa_capabilities = self._get_hpa_capabilities(flavor, extraResp)
flavor_info['hpa_capabilities'] = hpa_capabilities
self._update_resoure(
cloud_owner, cloud_region_id, flavor['id'],
flavor_info, "flavor")
except VimDriverNewtonException as e:
self._logger.error("VimDriverNewtonException: status:%s, response:%s" % (e.http_status, e.content))
return
except HttpError as e:
self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
return
except Exception as e:
self._logger.error(traceback.format_exc())
return
def _get_hpa_capabilities(self, flavor, extra_specs):
hpa_caps = []
# Basic capabilties
caps_dict = self._get_hpa_basic_capabilities(flavor)
if len(caps_dict) > 0:
self._logger.debug("basic_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# cpupining capabilities
caps_dict = self._get_cpupining_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("cpupining_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# cputopology capabilities
caps_dict = self._get_cputopology_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("cputopology_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# hugepages capabilities
caps_dict = self._get_hugepages_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("hugepages_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# numa capabilities
caps_dict = self._get_numa_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("numa_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# storage capabilities
caps_dict = self._get_storage_capabilities(flavor)
if len(caps_dict) > 0:
self._logger.debug("storage_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# CPU instruction set extension capabilities
caps_dict = self._get_instruction_set_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("instruction_set_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# PCI passthrough capabilities
caps_dict = self._get_pci_passthrough_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("pci_passthrough_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
# ovsdpdk capabilities
caps_dict = self._get_ovsdpdk_capabilities(extra_specs)
if len(caps_dict) > 0:
self._logger.debug("ovsdpdk_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
return hpa_caps
def _get_hpa_basic_capabilities(self, flavor):
basic_capability = {}
feature_uuid = uuid.uuid4()
basic_capability['hpaCapabilityID'] = str(feature_uuid)
basic_capability['hpaFeature'] = 'basicCapabilities'
basic_capability['hardwareArchitecture'] = 'generic'
basic_capability['version'] = 'v1'
basic_capability['attributes'] = []
basic_capability['attributes'].append({'hpa-attribute-key': 'numVirtualCpu',
'hpa-attribute-value':{'value': str(flavor['vcpus']) }})
basic_capability['attributes'].append({'hpa-attribute-key':'virtualMemSize',
'hpa-attribute-value': {'value':str(flavor['ram']), 'unit':'MB'}})
return basic_capability
def _get_cpupining_capabilities(self, extra_specs):
cpupining_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('hw:cpu_policy') or extra_specs.has_key('hw:cpu_thread_policy'):
cpupining_capability['hpaCapabilityID'] = str(feature_uuid)
cpupining_capability['hpaFeature'] = 'cpuPining'
cpupining_capability['hardwareArchitecture'] = 'generic'
cpupining_capability['version'] = 'v1'
cpupining_capability['attributes'] = []
if extra_specs.has_key('hw:cpu_thread_policy'):
cpupining_capability['attributes'].append({'hpa-attribute-key': 'logicalCpuThreadPinningPolicy',
'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_thread_policy'])}})
if extra_specs.has_key('hw:cpu_policy'):
cpupining_capability['attributes'].append({'hpa-attribute-key':'logicalCpuPinningPolicy',
'hpa-attribute-value': {'value':str(extra_specs['hw:cpu_policy'])}})
return cpupining_capability
def _get_cputopology_capabilities(self, extra_specs):
cputopology_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('hw:cpu_sockets') or extra_specs.has_key('hw:cpu_cores') or extra_specs.has_key('hw:cpu_threads'):
cputopology_capability['hpaCapabilityID'] = str(feature_uuid)
cputopology_capability['hpaFeature'] = 'cpuTopology'
cputopology_capability['hardwareArchitecture'] = 'generic'
cputopology_capability['version'] = 'v1'
cputopology_capability['attributes'] = []
if extra_specs.has_key('hw:cpu_sockets'):
cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuSockets',
'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_sockets'])}})
if extra_specs.has_key('hw:cpu_cores'):
cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuCores',
'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_cores'])}})
if extra_specs.has_key('hw:cpu_threads'):
cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuThreads',
'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_threads'])}})
return cputopology_capability
def _get_hugepages_capabilities(self, extra_specs):
hugepages_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('hw:mem_page_size'):
hugepages_capability['hpaCapabilityID'] = str(feature_uuid)
hugepages_capability['hpaFeature'] = 'hugePages'
hugepages_capability['hardwareArchitecture'] = 'generic'
hugepages_capability['version'] = 'v1'
hugepages_capability['attributes'] = []
hugepages_capability['attributes'].append({'hpa-attribute-key': 'memoryPageSize',
'hpa-attribute-value':{'value': str(extra_specs['hw:mem_page_size'])}})
return hugepages_capability
def _get_numa_capabilities(self, extra_specs):
numa_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('hw:numa_nodes'):
numa_capability['hpaCapabilityID'] = str(feature_uuid)
numa_capability['hpaFeature'] = 'numa'
numa_capability['hardwareArchitecture'] = 'generic'
numa_capability['version'] = 'v1'
numa_capability['attributes'] = []
numa_capability['attributes'].append({'hpa-attribute-key': 'numaNodes',
'hpa-attribute-value':{'value': str(extra_specs['hw:numa_nodes'])}})
for num in range(0, int(extra_specs['hw:numa_nodes'])):
numa_cpu_node = "hw:numa_cpus.%s" % num
numa_mem_node = "hw:numa_mem.%s" % num
numacpu_key = "numaCpu-%s" % num
numamem_key = "numaMem-%s" % num
if extra_specs.has_key(numa_cpu_node) and extra_specs.has_key(numa_mem_node):
numa_capability['attributes'].append({'hpa-attribute-key': numacpu_key,
'hpa-attribute-value':{'value': str(extra_specs[numa_cpu_node])}})
numa_capability['attributes'].append({'hpa-attribute-key': numamem_key,
'hpa-attribute-value':{'value': str(extra_specs[numa_mem_node]),'unit':'MB'}})
return numa_capability
def _get_storage_capabilities(self, flavor):
storage_capability = {}
feature_uuid = uuid.uuid4()
storage_capability['hpaCapabilityID'] = str(feature_uuid)
storage_capability['hpaFeature'] = 'localStorage'
storage_capability['hardwareArchitecture'] = 'generic'
storage_capability['version'] = 'v1'
storage_capability['attributes'] = []
storage_capability['attributes'].append({'hpa-attribute-key': 'diskSize',
'hpa-attribute-value':{'value': str(flavor['disk']), 'unit':'GB'}})
storage_capability['attributes'].append({'hpa-attribute-key': 'swapMemSize',
'hpa-attribute-value':{'value': str(flavor['swap']), 'unit':'MB'}})
storage_capability['attributes'].append({'hpa-attribute-key': 'ephemeralDiskSize',
'hpa-attribute-value':{'value': str(flavor['OS-FLV-EXT-DATA:ephemeral']), 'unit':'GB'}})
return storage_capability
def _get_instruction_set_capabilities(self, extra_specs):
instruction_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('hw:capabilities:cpu_info:features'):
instruction_capability['hpaCapabilityID'] = str(feature_uuid)
instruction_capability['hpaFeature'] = 'instructionSetExtensions'
instruction_capability['hardwareArchitecture'] = 'Intel64'
instruction_capability['version'] = 'v1'
instruction_capability['attributes'] = []
instruction_capability['attributes'].append({'hpa-attribute-key': 'instructionSetExtensions',
'hpa-attribute-value':{'value': str(extra_specs['hw:capabilities:cpu_info:features'])}})
return instruction_capability
def _get_pci_passthrough_capabilities(self, extra_specs):
instruction_capability = {}
feature_uuid = uuid.uuid4()
if extra_specs.has_key('pci_passthrough:alias'):
value1 = extra_specs['pci_passthrough:alias'].split(':')
value2 = value1[0].split('-')
instruction_capability['hpaCapabilityID'] = str(feature_uuid)
instruction_capability['hpaFeature'] = 'pciePassthrough'
instruction_capability['hardwareArchitecture'] = str(value2[2])
instruction_capability['version'] = 'v1'
instruction_capability['attributes'] = []
instruction_capability['attributes'].append({'hpa-attribute-key': 'pciCount',
'hpa-attribute-value':{'value': str(value1[1])}})
instruction_capability['attributes'].append({'hpa-attribute-key': 'pciVendorId',
'hpa-attribute-value':{'value': str(value2[3])}})
instruction_capability['attributes'].append({'hpa-attribute-key': 'pciDeviceId',
'hpa-attribute-value':{'value': str(value2[4])}})
return instruction_capability
def _get_ovsdpdk_capabilities(self, extra_specs):
instruction_capability = {}
feature_uuid = uuid.uuid4()
instruction_capability['hpaCapabilityID'] = str(feature_uuid)
instruction_capability['hpaFeature'] = 'ovsDpdk'
instruction_capability['hardwareArchitecture'] = 'Intel64'
instruction_capability['version'] = 'v1'
instruction_capability['attributes'] = []
instruction_capability['attributes'].append({'hpa-attribute-key': 'dataProcessingAccelerationLibrary',
'hpa-attribute-value':{'value': str('v17.02')}})
return instruction_capability
|