summaryrefslogtreecommitdiffstats
path: root/windriver
diff options
context:
space:
mode:
Diffstat (limited to 'windriver')
-rw-r--r--windriver/titanium_cloud/registration/tests/test_registration.py9
-rw-r--r--windriver/titanium_cloud/registration/views/registration.py81
2 files changed, 89 insertions, 1 deletions
diff --git a/windriver/titanium_cloud/registration/tests/test_registration.py b/windriver/titanium_cloud/registration/tests/test_registration.py
index e0df5b1d..3dcbd547 100644
--- a/windriver/titanium_cloud/registration/tests/test_registration.py
+++ b/windriver/titanium_cloud/registration/tests/test_registration.py
@@ -45,6 +45,13 @@ MOCK_GET_FLAVOR_RESPONSE = {
]
}
+MOCK_GET_FLAVOR_EXTRA_SPECS_RESPONSE = {
+ "extra_specs" : {
+ "aggregate_instance_extra_specs:storage" : "local_image",
+ "capabilities:cpu_info:model" : "Haswell"
+ }
+}
+
MOCK_GET_IMAGE_RESPONSE = {
"images": [
{
@@ -145,6 +152,8 @@ class TestFlavors(test_base.TestRequest):
"side_effect": [
self._get_mock_response(MOCK_GET_TENANT_RESPONSE),
self._get_mock_response(MOCK_GET_FLAVOR_RESPONSE),
+ self._get_mock_response(MOCK_GET_FLAVOR_EXTRA_SPECS_RESPONSE),
+ self._get_mock_response(MOCK_GET_FLAVOR_EXTRA_SPECS_RESPONSE),
self._get_mock_response(MOCK_GET_IMAGE_RESPONSE),
self._get_mock_response(),
self._get_mock_response(MOCK_GET_AZ_RESPONSE),
diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py
index a7b2831f..d735336c 100644
--- a/windriver/titanium_cloud/registration/views/registration.py
+++ b/windriver/titanium_cloud/registration/views/registration.py
@@ -13,14 +13,20 @@
# 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
+DEBUG=True
class Registry(newton_registration.Registry):
@@ -28,3 +34,76 @@ class Registry(newton_registration.Registry):
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
+ 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)
+
+ 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
+