# 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 json
import logging
import traceback
import uuid
from threading import Thread
-from lcm.nf.vnfs.const import vnfd_model_dict
from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, \
- SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel
+ SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel, NfvoRegInfoModel
from lcm.pub.exceptions import NFLCMException
from lcm.pub.msapi.catalog import query_rawdata_from_catalog
from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo, get_packageinfo_by_vnfdid
from lcm.pub.utils import toscautil
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
-from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean
+from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean, get_integer
from lcm.pub.vimapi import adaptor
logger = logging.getLogger(__name__)
self.nf_inst_id = nf_inst_id
self.job_id = job_id
self.vnfd_id = ''
+ self.vim_id = ignore_case_get(ignore_case_get(self.data, "additionalParams"), "vimId")
self.nfvo_inst_id = ''
self.vnfm_inst_id = ''
self.package_id = ''
JobUtil.add_job_status(self.job_id, 5, 'Get packageinfo by vnfd_id')
self.vnfd_id = vnf_insts[0].vnfdid
package_info = get_packageinfo_by_vnfdid(self.vnfd_id)
- for val in package_info:
- if self.vnfd_id == ignore_case_get(val, "vnfd_id"):
- self.package_id = ignore_case_get(val, "csar_id")
+ for val in ignore_case_get(package_info, "csars"):
+ if self.vnfd_id == ignore_case_get(val, "vnfdId"):
+ self.package_id = ignore_case_get(val, "csarId")
break
JobUtil.add_job_status(self.job_id, 10, 'Get rawdata from catalog by csar_id')
input_parameters = []
- for key, val in self.data['additionalParams'].items():
- input_parameters.append({"key": key, "value": val})
+ inputs = ignore_case_get(self.data['additionalParams'], "inputs")
+ if inputs:
+ if isinstance(inputs, (str, unicode)):
+ inputs = json.loads(inputs)
+ for key, val in inputs.items():
+ input_parameters.append({"key": key, "value": val})
raw_data = query_rawdata_from_catalog(self.package_id, input_parameters)
self.vnfd_info = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
self.vnfd_info = json.JSONDecoder().decode(self.vnfd_info)
- self.vnfd_info = vnfd_model_dict # just for test
+ # self.vnfd_info = vnfd_model_dict # just for test
self.update_cps()
self.check_parameter_exist()
vnfsoftwareversion = ignore_case_get(metadata, "version")
vnfd_model = self.vnfd_info
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\
- update(package_id=self.package_id, flavour_id=ignore_case_get(self.data, "flavourId"), version=version,
- vendor=vendor, netype=netype, vnfd_model=vnfd_model, status='NOT_INSTANTIATED', vnfdid=self.vnfd_id,
- localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'), input_params=self.data,
- vnfSoftwareVersion=vnfsoftwareversion, lastuptime=now_time())
+ update(package_id=self.package_id,
+ flavour_id=ignore_case_get(self.data, "flavourId"),
+ version=version,
+ vendor=vendor,
+ netype=netype,
+ vnfd_model=vnfd_model,
+ status='NOT_INSTANTIATED',
+ vnfdid=self.vnfd_id,
+ localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
+ input_params=self.data,
+ vnfSoftwareVersion=vnfsoftwareversion,
+ lastuptime=now_time())
+
+ logger.info("self.vim_id = %s" % self.vim_id)
+ NfvoRegInfoModel.objects.create(
+ nfvoid=self.nf_inst_id,
+ vnfminstid=ignore_case_get(self.data, "vnfmId"),
+ apiurl=self.vim_id)
JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish')
logger.info("Nf instancing pre-check finish")
content_args['addResource'].append(res_def)
res_index += 1
+ logger.debug("NfvoRegInfoModel filter nf_inst_id=%s", self.nf_inst_id)
+ vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
+ if len(vnfmInfo) == 0:
+ raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id)
+ content_args['additionalParam']['vnfmid'] = vnfmInfo[0].vnfminstid
+ content_args['additionalParam']['vimid'] = vnfmInfo[0].apiurl
logger.info('content_args=%s' % content_args)
- apply_result = apply_grant_to_nfvo(content_args)
- vim_info = ignore_case_get(apply_result, "vim")
+ apply_result = apply_grant_to_nfvo(json.dumps(content_args))
+ # vim_info = ignore_case_get(apply_result, "vim")
+ # vim_info = ignore_case_get(json.JSONDecoder().decode(apply_result), "vim")
for vdu in ignore_case_get(self.vnfd_info, "vdus"):
if "location_info" in vdu["properties"]:
- vdu["properties"]["location_info"]["vimid"] = ignore_case_get(vim_info, "vimid")
- vdu["properties"]["location_info"]["tenant"] = ignore_case_get(
- ignore_case_get(vim_info, "accessinfo"), "tenant")
+ vdu["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid")
+ vdu["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant")
else:
vdu["properties"]["location_info"] = {
- "vimid": ignore_case_get(vim_info, "vimid"),
- "tenant": ignore_case_get(ignore_case_get(vim_info, "accessinfo"), "tenant")}
+ "vimid": ignore_case_get(apply_result, "vimid"),
+ "tenant": ignore_case_get(apply_result, "tenant")}
+ logger.info('vdu["properties"]["location_info"]=%s' % vdu["properties"]["location_info"])
+ for vl in ignore_case_get(self.vnfd_info, "vls"):
+ if "location_info" in vl["properties"]:
+ vl["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid")
+ vl["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant")
+ else:
+ vl["properties"]["location_info"] = {
+ "vimid": ignore_case_get(apply_result, "vimid"),
+ "tenant": ignore_case_get(apply_result, "tenant")}
+ logger.info('vl["properties"]["location_info"]=%s' % vl["properties"]["location_info"])
+
+ logger.info('self.vnfd_info=%s' % self.vnfd_info)
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time())
JobUtil.add_job_status(self.job_id, 20, 'Nf instancing apply grant finish')
logger.info("Nf instancing apply grant finish")
{'vsInstanceId': port.portid,
'cpdid': port.nodeId,
'changeType': 'added',
- 'storageResource': {'vimId': port.vimid, 'resourceId': port.resouceid,
- 'resourceName': port.name, 'resourceType': 'port'}})
+ 'portResource': {'vimId': port.vimid, 'resourceId': port.resouceid,
+ 'resourceName': port.name, 'resourceType': 'port'}})
affected_vs = []
vss = StorageInstModel.objects.filter(instid=self.nf_inst_id)
for vs in vss:
'resourceName': vs.name, 'resourceType': 'volume'}})
content_args = {
"status": 'result',
- "nfInstanceId": self.nf_inst_id,
+ "vnfInstanceId": self.nf_inst_id,
"operation": 'instantiate',
"jobId": self.job_id,
'affectedVnfc': affected_vnfc,
'affectedVirtualLink': affected_vl,
'affectedVirtualStorage': affected_vs,
- 'affectedCp': affected_cp
- }
+ 'affectedCp': affected_cp}
+
+ vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
+ if len(vnfmInfo) == 0:
+ raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id)
+ content_args['VNFMID'] = vnfmInfo[0].vnfminstid
logger.info('content_args=%s' % content_args)
- resp = notify_lcm_to_nfvo(content_args)
+ resp = notify_lcm_to_nfvo(json.dumps(content_args))
logger.info('[NF instantiation] get lcm response %s' % resp)
logger.info('[NF instantiation] send notify request to nfvo end')
vimid=ignore_case_get(ret, "vimId"),
resouceid=ignore_case_get(ret, "id"),
tenant=ignore_case_get(ret, "tenantId"),
- vcpu=ignore_case_get(ret, "vcpu"),
- memory=ignore_case_get(ret, "memory"),
- disk=ignore_case_get(ret, "disk"),
- ephemeral=ignore_case_get(ret, "ephemeral"),
- swap=ignore_case_get(ret, "swap"),
+ vcpu=get_integer(ignore_case_get(ret, "vcpu")),
+ memory=get_integer(ignore_case_get(ret, "memory")),
+ disk=get_integer(ignore_case_get(ret, "disk")),
+ ephemeral=get_integer(ignore_case_get(ret, "ephemeral")),
+ swap=get_integer(ignore_case_get(ret, "swap")),
isPublic=get_boolean(ignore_case_get(ret, "isPublic")),
extraspecs=ignore_case_get(ret, "extraSpecs"),
is_predefined=ignore_case_get(ret, "returnCode"),
metadata=ignore_case_get(ret, "metadata"),
volume_array=ignore_case_get(ret, "volumeArray"),
server_group=ignore_case_get(ret, "serverGroup"),
- availability_zone=ignore_case_get(ret, "availabilityZone"),
+ availability_zone=str(ignore_case_get(ret, "availabilityZone", "undefined")),
flavor_id=ignore_case_get(ret, "flavorId"),
security_groups=ignore_case_get(ret, "securityGroups"),
operationalstate=ignore_case_get(ret, "status"),