summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/lcm/nf/const.py11
-rw-r--r--lcm/lcm/pub/vimapi/adaptor.py48
-rw-r--r--lcm/lcm/samples/tests.py39
3 files changed, 44 insertions, 54 deletions
diff --git a/lcm/lcm/nf/const.py b/lcm/lcm/nf/const.py
index f45e9f68..ff7fb1a6 100644
--- a/lcm/lcm/nf/const.py
+++ b/lcm/lcm/nf/const.py
@@ -715,6 +715,17 @@ vnfdModel = {
"vimid": "test",
"tenant": "chinamobile",
"availability_zone": "test",
+ "vnfId": "",
+ "vnfName": "",
+ "cloudOwner": "",
+ "cloudRegionId": "",
+ "vduInfo": [
+ {
+ "vduName": "VDU_vbng_0",
+ "flavorName": "flavor_1",
+ "directive": ""
+ }
+ ]
},
"name": "test",
"inject_files": [],
diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py
index bbc91098..f47c3370 100644
--- a/lcm/lcm/pub/vimapi/adaptor.py
+++ b/lcm/lcm/pub/vimapi/adaptor.py
@@ -14,7 +14,6 @@
import logging
import time
-import ast
import json
from lcm.pub.utils.values import ignore_case_get, set_opt_val
@@ -277,29 +276,16 @@ def parse_unit(val, base_unit):
return int(num) * unit_rate_map[unit.upper()] / unit_rate_map[base_unit.upper()]
-def search_flavor_aai(vim_id, memory_page_size, memory_page_unit):
+def search_flavor_aai(vim_id, flavor_name):
aai_flavors = get_flavor_info(vim_id)
if not aai_flavors:
return None
- logger.debug("aai_flavors:%s" % aai_flavors)
aai_flavor = aai_flavors["flavor"]
for one_aai_flavor in aai_flavor:
- if one_aai_flavor["flavor-name"].find("onap.") == -1:
- continue
- hpa_capabilities = one_aai_flavor["hpa-capabilities"]["hpa-capability"]
- logger.debug("hpa_capabilities=%s", hpa_capabilities)
- for one_hpa_capa in hpa_capabilities:
- logger.debug("one_hpa_capa=%s", one_hpa_capa)
- hpa_feature_attr = one_hpa_capa["hpa-feature-attributes"]
- for one_hpa_attr in hpa_feature_attr:
- hpa_key = one_hpa_attr["hpa-attribute-key"]
- hpa_attr_value = ast.literal_eval(one_hpa_attr["hpa-attribute-value"])
- mem_size = ignore_case_get(hpa_attr_value, 'value')
- mem_unit = ignore_case_get(hpa_attr_value, 'unit')
- value = mem_size + " " + mem_unit
- hpa_mem_size = parse_unit(value, memory_page_unit)
- if hpa_key == "memoryPageSize" and hpa_mem_size == memory_page_size:
- return one_aai_flavor
+ if one_aai_flavor["flavor-name"].find(flavor_name) == -1:
+ return one_aai_flavor
+
+ return None
def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type):
@@ -316,24 +302,19 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type):
"isPublic": True
}
- # just do memory huge page
- flavor_extra_specs = ""
- vdu_memory_requirements = ignore_case_get(virtual_memory, "vdu_memory_requirements")
- if "memoryPageSize" in vdu_memory_requirements:
- memory_page_size = int(vdu_memory_requirements["memoryPageSize"].replace('MB', '').strip())
- flavor_extra_specs = {"hw": memory_page_size, } # TODO
- logger.debug("flavor_extra_specs:%s" % flavor_extra_specs)
-
- # FIXME: search aai flavor
- aai_flavor = search_flavor_aai(vim_id, memory_page_size, "MB")
+ # Using flavor name returned by OOF to search falvor
+ vdu_id = ignore_case_get(flavor, "vdu_id")
+ for one_vdu in location_info["vduInfo"]:
+ if one_vdu["vduName"] == vdu_id:
+ break
+ aai_flavor = search_flavor_aai(vim_id, one_vdu["flavorName"])
- # add aai flavor
+ # Add aai flavor
if aai_flavor:
ret = aai_flavor
do_notify(res_type, ret)
set_res_cache(res_cache, res_type, flavor["vdu_id"], ret["flavor-id"])
else:
- extra_specs = []
disk_type = ignore_case_get(virtual_storage, "type_of_storage")
disk_size = int(ignore_case_get(virtual_storage, "size_of_storage").replace('GB', '').strip())
if disk_type == "root":
@@ -343,13 +324,10 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type):
elif disk_type == "swap":
param["swap"] = disk_size
- for es in flavor_extra_specs:
- extra_specs.append({"keyName": es, "value": flavor_extra_specs[es]})
-
- set_opt_val(param, "extraSpecs", extra_specs)
tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name)
logger.debug("param:%s" % param)
ret = api.create_flavor(vim_id, tenant_id, param)
+ logger.debug("hhb ret:%s" % ret)
do_notify(res_type, ret)
set_res_cache(res_cache, res_type, flavor["vdu_id"], ret["id"])
diff --git a/lcm/lcm/samples/tests.py b/lcm/lcm/samples/tests.py
index 42d96b01..a1d13be4 100644
--- a/lcm/lcm/samples/tests.py
+++ b/lcm/lcm/samples/tests.py
@@ -87,7 +87,18 @@ inst_res_data = {
"vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
"tenant": "vnfm",
"availability_zone": "zone1",
- "host": "host1"
+ "host": "host1",
+ "vnfId": "",
+ "vnfName": "",
+ "cloudOwner": "",
+ "cloudRegionId": "",
+ "vduInfo": [
+ {
+ "vduName": "VDU_vbng_0",
+ "flavorName": "flavor_1",
+ "directive": "",
+ },
+ ]
},
"descrption": "the virtual machine of vNat",
"boot_order": [
@@ -304,28 +315,17 @@ c4_data_create_port = {
"nodeId": "",
"id": "456"
}
+c5_data_create_flavor = {
+ "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
+ "nodeId": "",
+ "id": "6456",
+}
c5_data_get_flavor = {
"flavor": [
{
"flavor-id": "111111",
- "flavor-name": "onap.large",
- "hpa-capabilities":
- {
- "hpa-capability":
- [
- {
- "hpa-capability-id": "1243",
- "hpa-feature-attributes":
- [
- {
- "hpa-attribute-key": "memoryPageSize",
- "hpa-attribute-value": '{"value": "2", "unit": "MB"}'
- }
- ]
- }
- ]
- }
+ "flavor-name": "flavor_1",
}
]
}
@@ -373,6 +373,7 @@ class SampleViewTest(unittest.TestCase):
r3_data_create_subnet = [0, json.JSONEncoder().encode(c3_data_create_subnet), '200']
r4_data_create_port = [0, json.JSONEncoder().encode(c4_data_create_port), '200']
r5_data_get_flavor = [0, json.JSONEncoder().encode(c5_data_get_flavor), '200']
+ r5_data_create_flavor = [0, json.JSONEncoder().encode(c5_data_create_flavor), '200']
r6_data_list_image = [0, json.JSONEncoder().encode(c6_data_list_image), '200']
r6_data_create_vm = [0, json.JSONEncoder().encode(c6_data_create_vm), '200']
r6_data_get_vm = [0, json.JSONEncoder().encode(c6_data_get_vm), '200']
@@ -382,7 +383,7 @@ class SampleViewTest(unittest.TestCase):
r2_data_create_network,
r3_data_create_subnet,
r4_data_create_port,
- r5_data_get_flavor,
+ r5_data_get_flavor, r5_data_create_flavor,
r6_data_list_image, r6_data_create_vm, r6_data_get_vm]
resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json')
self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code)